|
139 | 139 | * become visible. If [interval] is provided, a new sequence is created
|
140 | 140 | * that will ensure elements reveal in the order they appear in the DOM.
|
141 | 141 | *
|
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. |
146 | 146 | *
|
147 | 147 | * @return {Object} The current ScrollReveal instance.
|
148 | 148 | */
|
149 |
| - ScrollReveal.prototype.reveal = function (selector, config, interval, sync) { |
| 149 | + ScrollReveal.prototype.reveal = function (target, config, interval, sync) { |
150 | 150 | var container
|
151 | 151 | var elements
|
152 | 152 | var elem
|
|
161 | 161 | container = sr.defaults.container
|
162 | 162 | }
|
163 | 163 |
|
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) |
168 | 170 | } else {
|
169 |
| - elements = Array.prototype.slice.call(container.querySelectorAll(selector)) |
| 171 | + elements = Array.prototype.slice.call(container.querySelectorAll(target)) |
170 | 172 | }
|
171 | 173 |
|
172 | 174 | 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.') |
174 | 176 | return sr
|
175 | 177 | }
|
176 | 178 |
|
|
247 | 249 | // Since `reveal()` is called internally by `sync()`, we don’t want to
|
248 | 250 | // record or intiialize each reveal during syncing.
|
249 | 251 | if (!sync && sr.isSupported()) {
|
250 |
| - _record(selector, config, interval) |
| 252 | + _record(target, config, interval) |
251 | 253 |
|
252 | 254 | // We push initialization to the event queue using setTimeout, so that we can
|
253 | 255 | // give ScrollReveal room to process all reveal calls before putting things into motion.
|
|
265 | 267 |
|
266 | 268 | /**
|
267 | 269 | * 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. |
269 | 271 | *
|
270 | 272 | * @return {Object} The current ScrollReveal instance.
|
271 | 273 | */
|
272 | 274 | ScrollReveal.prototype.sync = function () {
|
273 | 275 | if (sr.history.length && sr.isSupported()) {
|
274 | 276 | for (var i = 0; i < sr.history.length; i++) {
|
275 | 277 | 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) |
277 | 279 | }
|
278 | 280 | _init()
|
279 | 281 | } else {
|
|
448 | 450 | sr.store.elements[elem.id] = elem
|
449 | 451 | }
|
450 | 452 |
|
451 |
| - function _record (selector, config, interval) { |
| 453 | + function _record (target, config, interval) { |
452 | 454 | // Save the `reveal()` arguments that triggered this `_record()` call, so we
|
453 | 455 | // can re-trace our steps when calling the `sync()` method.
|
454 | 456 | var record = {
|
455 |
| - selector: selector, |
| 457 | + target: target, |
456 | 458 | config: config,
|
457 | 459 | interval: interval
|
458 | 460 | }
|
|
0 commit comments