Skip to content

Commit c3628f8

Browse files
committed
feature(reveal): support node lists as first argument [closes #262]
1 parent 077b0e8 commit c3628f8

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/scrollreveal.js

+18-16
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,14 @@
139139
* become visible. If [interval] is provided, a new sequence is created
140140
* that will ensure elements reveal in the order they appear in the DOM.
141141
*
142-
* @param {string|Node} [selector] The element (node) or elements (selector) to animate.
143-
* @param {Object} [config] Override the defaults for this reveal set.
144-
* @param {number} [interval] Time between sequenced element animations (milliseconds).
145-
* @param {boolean} [sync] Used internally when updating reveals for async content.
142+
* @param {Node|NodeList|string} [target] The node, node list or selector to use for animation.
143+
* @param {Object} [config] Override the defaults for this reveal set.
144+
* @param {number} [interval] Time between sequenced element animations (milliseconds).
145+
* @param {boolean} [sync] Used internally when updating reveals for async content.
146146
*
147147
* @return {Object} The current ScrollReveal instance.
148148
*/
149-
ScrollReveal.prototype.reveal = function (selector, config, interval, sync) {
149+
ScrollReveal.prototype.reveal = function (target, config, interval, sync) {
150150
var container
151151
var elements
152152
var elem
@@ -161,16 +161,18 @@
161161
container = sr.defaults.container
162162
}
163163

164-
// Let’s check to see if a DOM node was passed in as the first argument,
165-
// otherwise query the container for all elements matching the selector.
166-
if (sr.tools.isNode(selector)) {
167-
elements = [selector]
164+
// Let’s check to see if a node or node list was passed in as the target,
165+
// otherwise query the container using target as a selector.
166+
if (sr.tools.isNode(target)) {
167+
elements = [target]
168+
} else if (sr.tools.isNodeList(target)) {
169+
elements = Array.prototype.slice.call(target)
168170
} else {
169-
elements = Array.prototype.slice.call(container.querySelectorAll(selector))
171+
elements = Array.prototype.slice.call(container.querySelectorAll(target))
170172
}
171173

172174
if (!elements.length) {
173-
console.log('ScrollReveal: reveal on "' + selector + '" failed, no elements found.')
175+
console.log('ScrollReveal: reveal on "' + target + '" failed, no elements found.')
174176
return sr
175177
}
176178

@@ -247,7 +249,7 @@
247249
// Since `reveal()` is called internally by `sync()`, we don’t want to
248250
// record or intiialize each reveal during syncing.
249251
if (!sync && sr.isSupported()) {
250-
_record(selector, config, interval)
252+
_record(target, config, interval)
251253

252254
// We push initialization to the event queue using setTimeout, so that we can
253255
// give ScrollReveal room to process all reveal calls before putting things into motion.
@@ -265,15 +267,15 @@
265267

266268
/**
267269
* Re-runs `reveal()` for each record stored in history, effectively capturing
268-
* any content loaded asynchronously that matches existing reveal set selectors.
270+
* any content loaded asynchronously that matches existing reveal set targets.
269271
*
270272
* @return {Object} The current ScrollReveal instance.
271273
*/
272274
ScrollReveal.prototype.sync = function () {
273275
if (sr.history.length && sr.isSupported()) {
274276
for (var i = 0; i < sr.history.length; i++) {
275277
var record = sr.history[i]
276-
sr.reveal(record.selector, record.config, record.interval, true)
278+
sr.reveal(record.target, record.config, record.interval, true)
277279
}
278280
_init()
279281
} else {
@@ -448,11 +450,11 @@
448450
sr.store.elements[elem.id] = elem
449451
}
450452

451-
function _record (selector, config, interval) {
453+
function _record (target, config, interval) {
452454
// Save the `reveal()` arguments that triggered this `_record()` call, so we
453455
// can re-trace our steps when calling the `sync()` method.
454456
var record = {
455-
selector: selector,
457+
target: target,
456458
config: config,
457459
interval: interval
458460
}

0 commit comments

Comments
 (0)