diff --git a/shower.js b/shower.js index 0c10fd1..2feec0b 100755 --- a/shower.js +++ b/shower.js @@ -7,8 +7,8 @@ window.shower = window.shower || (function(window, document, undefined) { var shower = {}, url = window.location, body = document.body, - slides = document.querySelectorAll('.slide'), - progress = document.querySelector('div.progress div'), + slides = [], + progress = [], slideList = [], timer, isHistoryApiSupported = !!(window.history && history.pushState), @@ -25,19 +25,36 @@ window.shower = window.shower || (function(window, document, undefined) { return element.dataset ? element.dataset[name] : element.getAttribute('data-' + name); }; - for (i = 0; i < l; i++) { - // Slide IDs are optional. In case of missing ID we set it to the - // slide number - if ( ! slides[i].id) { - slides[i].id = i + 1; + /** + * Init + * @param {String} slideSelector + * @param {String} progressBarSelector + * @returns {Object} shower + */ + shower.init = function(slideSelector, progressSelector) { + slideSelector = slideSelector || '.slide'; + progressSelector = progressSelector || 'div.progress div'; + + slides = document.querySelectorAll(slideSelector); + progress = document.querySelector(progressSelector); + slideList = [], + + for (i = 0; i < l; i++) { + // Slide IDs are optional. In case of missing ID we set it to the + // slide number + if ( ! slides[i].id) { + slides[i].id = i + 1; + } + + slideList.push({ + id: slides[i].id, + hasInnerNavigation: null !== slides[i].querySelector('.next'), + hasTiming: (shower._getData(slides[i], 'timing') && shower._getData(slides[i], 'timing').indexOf(':') !== -1) + }); } - slideList.push({ - id: slides[i].id, - hasInnerNavigation: null !== slides[i].querySelector('.next'), - hasTiming: (shower._getData(slides[i], 'timing') && shower._getData(slides[i], 'timing').indexOf(':') !== -1) - }); - } + }; + /** * Get slide scale value. @@ -723,6 +740,8 @@ window.shower = window.shower || (function(window, document, undefined) { } }, false); + shower.init(); + return shower; -})(this, this.document); \ No newline at end of file +})(this, this.document);