Commit 79843ed1 authored by Vadim Makeev's avatar Vadim Makeev

Merge pull request #124 from Patternslib/init-api

Using showing without automatic triggering
parents 72f44b7a 049818b4
...@@ -7,12 +7,11 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -7,12 +7,11 @@ window.shower = window.shower || (function(window, document, undefined) {
var shower = {}, var shower = {},
url = window.location, url = window.location,
body = document.body, body = document.body,
slides = document.querySelectorAll('.slide'), slides = [],
progress = document.querySelector('div.progress div'), progress = [],
slideList = [], slideList = [],
timer, timer,
isHistoryApiSupported = !!(window.history && history.pushState), isHistoryApiSupported = !!(window.history && history.pushState);
l = slides.length, i;
/** /**
* Get value at named data store for the DOM element. * Get value at named data store for the DOM element.
...@@ -25,19 +24,36 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -25,19 +24,36 @@ window.shower = window.shower || (function(window, document, undefined) {
return element.dataset ? element.dataset[name] : element.getAttribute('data-' + name); 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 * Init
// slide number * @param {String} slideSelector
if ( ! slides[i].id) { * @param {String} progressBarSelector
slides[i].id = i + 1; * @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 (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) {
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)
});
} }
return shower;
};
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. * Get slide scale value.
...@@ -684,6 +700,8 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -684,6 +700,8 @@ window.shower = window.shower || (function(window, document, undefined) {
} }
}, false); }, false);
shower.init();
document.addEventListener('click', function(e) { document.addEventListener('click', function(e) {
var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target)); var slideNumber = shower.getSlideNumber(shower._getSlideIdByEl(e.target));
...@@ -725,4 +743,4 @@ window.shower = window.shower || (function(window, document, undefined) { ...@@ -725,4 +743,4 @@ window.shower = window.shower || (function(window, document, undefined) {
return shower; return shower;
})(this, this.document); })(this, this.document);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment