From e1443282ac82690f5167e4559ff5de220a369b11 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Wed, 6 Mar 2013 14:27:55 +0100 Subject: [PATCH 1/3] Add init API method to help with shower/shower#124 --- shower.js | 47 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 14 deletions(-) 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); From 39aa43eb6f2ee978879708a2de040541a5d4836e Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Wed, 6 Mar 2013 14:46:41 +0100 Subject: [PATCH 2/3] Fix initialisation problems. --- shower.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/shower.js b/shower.js index 2feec0b..5353c1d 100755 --- a/shower.js +++ b/shower.js @@ -11,8 +11,7 @@ window.shower = window.shower || (function(window, document, undefined) { progress = [], slideList = [], timer, - isHistoryApiSupported = !!(window.history && history.pushState), - l = slides.length, i; + isHistoryApiSupported = !!(window.history && history.pushState); /** * Get value at named data store for the DOM element. @@ -37,9 +36,9 @@ window.shower = window.shower || (function(window, document, undefined) { slides = document.querySelectorAll(slideSelector); progress = document.querySelector(progressSelector); - slideList = [], + slideList = []; - for (i = 0; i < l; i++) { + for (var i = 0; i < slides.length; i++) { // Slide IDs are optional. In case of missing ID we set it to the // slide number if ( ! slides[i].id) { @@ -701,6 +700,8 @@ window.shower = window.shower || (function(window, document, undefined) { } }, false); + shower.init(); + document.addEventListener('click', function(e) { var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)); @@ -740,8 +741,6 @@ window.shower = window.shower || (function(window, document, undefined) { } }, false); - shower.init(); - return shower; })(this, this.document); From 049818b4a2a02ed4522c1b4df0b27765f6b79936 Mon Sep 17 00:00:00 2001 From: Wichert Akkerman Date: Wed, 6 Mar 2013 14:48:34 +0100 Subject: [PATCH 3/3] API match: return shower object from init. --- shower.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shower.js b/shower.js index 5353c1d..1baf734 100755 --- a/shower.js +++ b/shower.js @@ -51,7 +51,7 @@ window.shower = window.shower || (function(window, document, undefined) { hasTiming: (shower._getData(slides[i], 'timing') && shower._getData(slides[i], 'timing').indexOf(':') !== -1) }); } - + return shower; };