/** * slider jquery plugin * * this plugin allow to create sliders from images, video or html content. * * @author olivier bossel (andes) * @created 21.02.2012 * @updated 13.01.2016 * @version 1.3.23 */ (function (factory) { if (typeof define === 'function' && define.amd) { // amd. register as an anonymous module. define(['jquery'], factory); } else if (typeof exports === 'object') { // node/commonjs factory(require('jquery')); } else { // browser globals factory(jquery); } }(function ($) { /** * plugin : */ function slidizle(item, options) { // vars : this.settings = { /** * some classes applied on different elements */ classes : { // class applied on content wrrapper content : 'slidizle-content', // class applied on next navigation element next : 'slidizle-next', // class applied on previous navigation element previous : 'slidizle-previous', // class applied on all slides that are before the active one beforeactive : 'before-active', // class applied on all slides that are after the active one afteractive : 'after-active', // class applied on the next active slide nextactive : 'next', // class applied on the previous active slide previousactive : 'previous', // class applied on container when the slider is in forward mode forward : 'forward', // class applied on container when the slider is in backward mode backward : 'backward', // class applied on navigation element navigation : 'slidizle-navigation', // class applied on timer element timer : 'slidizle-timer', // not documented // class applied on each slide slide : 'slidizle-slide', // class applied on the next and previous navigation, or the all slider when disabled disabled : 'disabled', // the class applied on container when the slider is at his first slide first : 'first', // the class applied on container when the slider is at his last slide last : 'last', // the play class applied on the container play : 'played', // the pause class applied on the container pause : 'paused', // the stop class applied on the container stop : 'stoped', // an class to access the slider slider : 'slidizle', // the classname to add to active navigation, slides, etc... active : 'active', // the classname to add to the slider and slides when it is in loading mode loading : 'loading' }, // the slider interval time between each medias timeout : null, // set if the slider has to make pause on mouse hover pauseonhover : false, // set if the slider has to go next on mouse click nextonclick : false, // set if the slider has to go first item when next on last loop : false, // set if the slider has to play directly or not if a timeout is specified autoplay : true, // activate or not the keyboard keyboardenabled : true, // activate or not the touch navigation for mobile (swipe) touchenabled : true, // specify if need to load the next content before the transition loadbeforetransition : true, // specify if the slider is disabled or not (can be a function that return true or false) disabled : false, // callback when the slider is inited oninit : null, // callback when a slide is clicked onclick : null, // callback before the slider change from one media to another beforechange : null, // callback when the slider change from one media to another onchange : null, // callback after the slider change from one media to another afterchange : null, // callback before the slider begin to load the slide beforeloading : null, // callback during the loading progress onloading : null, // callback after the slider has loaded the next slide (before the actual change) afterloading : null, // callback when the slider change for the next slide onnext : null, // callback when the slider change for the previous slide onprevious : null, // callback when the slider change his state to play onplay : null, // callback when the slider change his state to pause onpause : null, // callback when the slider resume after a pause onresume : null }; this.$refs = { slider : null, // save the reference to the slider container itself content : null, // save the reference to the content element medias : null, // save the references to all medias element nextslide : null, // save the reference to the next media element previousslide : null, // save the reference to the previous media element currentslide : null, // save the reference to the current media element beforeactiveslides : null, afteractiveslides : null, navigation : null, // save the reference to the navigation element next : null, // save the reference to the next button element previous : null, // save the reference to the previous button element current : null, // save the reference to the current media displayed timer : null // save the reference to the timer element if exist }; this.loadingprogress = 0; // store the loading progress of the next slide this.current_timeout_time = 0; // save the current time of the timeout this._internaltimer = null; // save the internal timer used to calculate the remaining timeout etc... this.timeout = null; // save the timeout for playing slider this.previous_index = 0; // save the index of the previous media displayed this.current_index = 0; // save the index of the current media displayed this.next_index = 0; // save the index of the next media this._previous_active_index = 0; // save the index of the previous activate media this._isplaying = false; // save the playing state this._ispause = false; // save the pause status this._isover = false; // save the over state this.total = 0; // save the total number of element in the slider this.$this = $(item); // save the jquery item to access it this.clickevent = navigator.useragent.match(/mobile/gi) ? 'touchend' : 'click'; // the best click event depending on device // init : this.init($(item), options); } /** * init : init the plugin * * @param jquery item the jquery item * @param object options the options */ slidizle.prototype.init = function(item, options) { // vars : var _this = this, $this = item; // add bb-slider class if needed : if (!$this.hasclass(_this.settings.classes.slider)) $this.addclass(_this.settings.classes.slider); // update options : _this._extendsettings(options); // save all references : _this.$refs.slider = $this; _this.$refs.content = $this.find('[data-slidizle-content]').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); }); _this.$refs.navigation = $this.find('[data-slidizle-navigation]').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); });; _this.$refs.previous = $this.find('[data-slidizle-previous]').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); });; _this.$refs.next = $this.find('[data-slidizle-next]').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); });; _this.$refs.timer = $this.find('[data-slidizle-timer]').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); });; // apply class : if (_this.$refs.content) _this.$refs.content.addclass(_this.settings.classes.content); if (_this.$refs.next) _this.$refs.next.addclass(_this.settings.classes.next); if (_this.$refs.previous) _this.$refs.previous.addclass(_this.settings.classes.previous); if (_this.$refs.navigation) _this.$refs.navigation.addclass(_this.settings.classes.navigation); if (_this.$refs.timer) _this.$refs.timer.addclass(_this.settings.classes.timer); // get all medias in the slider : var $content_childs = _this.$refs.content.children(':first-child'); if ($content_childs.length > 0) { var content_childs_type = $content_childs[0]['nodename'].tolowercase(); _this.$refs.medias = _this.$refs.content.children(content_childs_type); } // apply class : $this.addclass(_this.settings.classes.slider); _this.$refs.medias.filter(':first-child').addclass(_this.settings.classes.first); _this.$refs.medias.filter(':last-child').addclass(_this.settings.classes.last); // check if are some medias : if (_this.$refs.medias) { // add class on medias : _this.$refs.medias.addclass(_this.settings.classes.slide); // adding click on slides : _this.$refs.medias.bind(_this.clickevent, function(e) { // trigger an event : $this.trigger('slidizle.click',[_this]); // callback : if (_this.settings.onclick) _this.settings.onclick(_this); }); // creating data : _this.total = _this.$refs.medias.length; _this.current_index = 0; // init navigation : if (_this.$refs.navigation.length>=1) _this._initnavigation(); _this.initpreviousnextnavigation(); // check if a content is already active : var $active_slide = _this.$refs.medias.filter('.active:first'); if ($active_slide.length >= 1) { // go to specific slide : _this.current_index = $active_slide.index(); } // update slides refs : _this._updateslidesrefs(); // check if pauseonhover is set to true : if (_this.settings.pauseonhover) { // add hover listener : $this.hover(function(e) { // update _isover state : _this._isover = true; // pause : _this.pause(); }, function(e) { // update _isover state : _this._isover = false; // resume : _this.resume(); }); } // keyboard navigation : if (_this.settings.keyboardenabled && _this.settings.keyboardenabled != 'false') _this._initkeyboardnavigation(); // touch navigation : if (_this.settings.touchenabled && navigator.useragent.match(/mobile/gi)) _this._inittouchnavigation(); // play : if (_this.settings.autoplay && _this.$refs.medias.length > 1) _this.play(); // check if next on click : if (_this.settings.nextonclick) { _this.$refs.content.bind('click', function() { _this.next(); }); } // check the on init : if (_this.settings.oninit) _this.settings.oninit(_this); $this.trigger('slidizle.init', [_this]); // add forward class : _this.$this.addclass(_this.settings.classes.forward); // change medias for the first time : _this._changemedias(); } else { // check the on init : if (_this.settings.oninit) _this.settings.oninit(_this); $this.trigger('slidizle.init', [_this]); } } /** * creation of the navigation : */ slidizle.prototype._initnavigation = function() { // vars : var _this = this, $this = _this.$this; // check if is an navigation tag : if (!_this.$refs.navigation) return false; // check if we need to hide navigation if only 1 element if (_this.total <= 1) _this.$refs.navigation.hide(); // check if we have to popule the navigation : if (_this.$refs.navigation.children().length <= 0) { // determine how to populate the navigation : var navigation_type = _this.$refs.navigation[0]['nodename'].tolowercase(), navigation_children_type = (navigation_type == 'dl') ? 'dt' : (navigation_type == 'ol') ? 'li' : (navigation_type == 'ul') ? 'li' : 'div'; // create an navigation element for each media : for (var i=0; i<_this.total; i++) { // create an navigation element : _this.$refs.navigation.append('<'+navigation_children_type+'>'+(i+1)+''); } } // add click event on navigation : _this.$refs.navigation.children().bind(_this.clickevent, function(e) { // vars : var $nav = $(this), slide_id = $nav.attr('data-slidizle-slide-id'), content_by_slide_id = _this.$refs.medias.filter('[data-slidizle-slide-id="'+slide_id+'"]'); // saving previous var : _this.previous_index = _this.current_index; // check if nav has an slide id : if (slide_id && content_by_slide_id) { // get index : var idx = content_by_slide_id.index(); // check if index is not the same as now : if (idx != _this.current_index) { // updating current index : _this.current_index = idx; // change media : _this._changemedias(); } } else { // check if is not the same : if ($(this).index() != _this.current_index) { // updating current var : _this.current_index = $(this).index(); // change media : _this._changemedias(); } } // prevent default behaviors : e.preventdefault(); }); } /** * init keyboard navigation : */ slidizle.prototype._initkeyboardnavigation = function() { // vars : var _this = this, $this = _this.$this; // listen for keyboard events : $(document).bind('keyup', function(e) { // check the pressed key : switch (e.keycode) { case 39: _this.next(); break; case 37: _this.previous(); break; } }); } /** * init touch navigation : */ slidizle.prototype._inittouchnavigation = function() { // vars : var _this = this, $this = _this.$this, xstart, ystart; // listen for needed events : $(document).bind('touchstart', function(e) { xstart = e.originalevent.touches[0].clientx; ystart = e.originalevent.touches[0].clienty; }); $(document).bind('touchmove', function(e) { if ( ! xstart || ! ystart) return; var x = e.originalevent.touches[0].clientx, y = e.originalevent.touches[0].clienty, xdiff = xstart - x, ydiff = ystart - y; // check direction : if (math.abs(xdiff) > math.abs(ydiff)) { if (xdiff > 0) { _this.next(); } else { _this.previous(); } } // reset values : xstart = ystart = null; }); } /** * init next and prev links : */ slidizle.prototype.initpreviousnextnavigation = function() { // vars : var _this = this, $this = _this.$this; // add click event on previous tag : if (_this.$refs.previous) { // add click handler : if (_this.total > 1) _this.$refs.previous.bind(_this.clickevent, function() { _this.previous(); }); // hide if no multiple medias : if (_this.total <= 1) _this.$refs.previous.hide(); } // add click event on next tag : if (_this.$refs.next) { // add click handler : if (_this.total > 1) _this.$refs.next.bind(_this.clickevent, function() { _this.next(); }); // hide if no multiple medias : if (_this.total <= 1) _this.$refs.next.hide(); } } /** * pause the timer : */ slidizle.prototype._pausetimer = function() { // vars : var _this = this; // stop the timer : clearinterval(_this._internaltimer); }; /** * stop the timer : */ slidizle.prototype._stoptimer = function() { // vars : var _this = this; // stop the timer : clearinterval(_this._internaltimer); // reset timer : _this._resettimer(); }; /** * reset timer values : */ slidizle.prototype._resettimer = function() { // vars : var _this = this; // reset values : _this.current_timeout_time = _this.$refs.currentslide.data('slidizle-timeout') || _this.settings.timeout; _this.total_timeout_time = _this.$refs.currentslide.data('slidizle-timeout') || _this.settings.timeout; }; /** * start the timer : */ slidizle.prototype._starttimer = function() { // vars : var _this = this, $this = _this.$this; // init the internal timer : clearinterval(_this._internaltimer); _this._internaltimer = setinterval(function() { // update current timeout : _this.current_timeout_time -= 10; // check current timeout time : if (_this.current_timeout_time <= 0) { // change media : _this.next(); } },10); }; /** * managing the media change : */ slidizle.prototype._changemedias = function() { // vars : var _this = this, $this = _this.$this, disabledclass = _this.settings.classes.disabled; // update slides references : _this._updateslidesrefs(); // before change callback : if (_this.settings.beforechange) _this.settings.beforechange(_this); $this.trigger('slidizle.beforechange', [_this]); // clear timer (relaunched on transition) : _this._stoptimer(); // manage disabled class on navigation : if (_this.$refs.next) { if (_this.islast() && ! _this.isloop()) { _this.$refs.next.addclass(disabledclass); } else { if (_this.$refs.next.hasclass(disabledclass)) _this.$refs.next.removeclass(disabledclass); } } if (_this.$refs.previous) { if (_this.$refs.previous && _this.isfirst() && ! _this.isloop()) { _this.$refs.previous.addclass(disabledclass); } else { if (_this.$refs.previous.hasclass(disabledclass)) _this.$refs.previous.removeclass(disabledclass); } } // manage navigation classes : var current_slide_id = _this.$refs.currentslide.attr('data-slidizle-slide-id'); _this.$refs.navigation.each(function() { var $nav = $(this), current_navigation_by_slide_id = $(this).children('[data-slidizle-slide-id="'+current_slide_id+'"]'); if (current_slide_id && current_navigation_by_slide_id) { $nav.children().removeclass(_this.settings.classes.active); current_navigation_by_slide_id.addclass(_this.settings.classes.active); } else { $nav.children().removeclass(_this.settings.classes.active); $nav.children(':eq('+_this.current_index+')').addclass(_this.settings.classes.active); } }); // add the loading class to the slider : _this.$refs.slider.addclass(_this.settings.classes.loading); // add load class on current element : _this.$refs.currentslide.addclass(_this.settings.classes.loading); // launch transition : if ( ! _this.settings.loadbeforetransition || _this.settings.loadbeforetransition == 'false') { // launch transition directly : launchtransition(); } else { // before loading callback : if (_this.settings.beforeloading) _this.settings.beforeloading(_this); $this.trigger('slidizle.beforeloading', [_this]); // load content of slide : _this._loadslide(_this.$refs.currentslide, function($slide) { // remove loading class $slide.removeclass(_this.settings.classes.loading); // remove loading class : _this.$refs.slider.removeclass(_this.settings.classes.loading); // after loading callback : if (_this.settings.afterloading) _this.settings.afterloading(_this); $this.trigger('slidizle.afterloading', [_this]); // launch transition if has to be launched after loading : launchtransition(); }); } // launch transition and dispatch en change event : function launchtransition() { // remove the class of the current media on the container : if (_this.$refs.previousactiveslide) _this.$this.removeclass('slide-'+_this.$refs.previousactiveslide.index()); // set the class of the current media on the container : _this.$this.addclass('slide-'+_this.$refs.currentslide.index()); // manage first and last class : if (_this.islast()) _this.$this.addclass(_this.settings.classes.last); else _this.$this.removeclass(_this.settings.classes.last); if (_this.isfirst()) _this.$this.addclass(_this.settings.classes.first); else _this.$this.removeclass(_this.settings.classes.first); // remove the class of the current media on the container : if (_this.$refs.previousactiveslide) _this.$this.removeclass('loaded-slide-'+_this.$refs.previousactiveslide.index()); // set the class of the current media on the container : _this.$this.addclass('loaded-slide-'+_this.$refs.currentslide.index()); // delete active_class before change : _this.$refs.medias.removeclass(_this.settings.classes.active); // add active_class before change : _this.$refs.currentslide.addclass(_this.settings.classes.active); // remove the before active and after active class _this.$refs.medias .removeclass(_this.settings.classes.beforeactive) .removeclass(_this.settings.classes.afteractive); // add the before active class _this.getbeforeactiveslides().addclass(_this.settings.classes.beforeactive); _this.getafteractiveslides().addclass(_this.settings.classes.afteractive); // remove the previous and next class _this.$refs.medias .removeclass(_this.settings.classes.previousactive) .removeclass(_this.settings.classes.nextactive); // add the previous and next class _this.getpreviousslide().addclass(_this.settings.classes.previousactive); _this.getnextslide().addclass(_this.settings.classes.nextactive); // callback : if (_this.settings.onchange) _this.settings.onchange(_this); $this.trigger('slidizle.change', [_this]); // manage onnext onprevious events : if (_this.$refs.currentslide.index() == 0 && _this.$refs.previousslide) { if (_this.$refs.previousslide.index() == _this.$refs.medias.length-1) { if (_this.settings.onnext) _this.settings.onnext(_this); $this.trigger('slidizle.next', [_this]); } else { if (_this.settings.onprevious) _this.settings.onprevious(_this); $this.trigger('slidizle.previous', [_this]); } } else if (_this.$refs.currentslide.index() == _this.$refs.medias.length-1 && _this.$refs.previousslide) { if (_this.$refs.previousslide.index() == 0) { if (_this.settings.onprevious) _this.settings.onprevious(_this); $this.trigger('slidizle.previous', [_this]); } else { if (_this.settings.onnext) _this.settings.onnext(_this); $this.trigger('slidizle.next', [_this]); } } else if (_this.$refs.previousslide) { if (_this.$refs.currentslide.index() > _this.$refs.previousslide.index()) { if (_this.settings.onnext) _this.settings.onnext(_this); $this.trigger('slidizle.next', [_this]); } else { if (_this.settings.onprevious) _this.settings.onprevious(_this); $this.trigger('slidizle.previous', [_this]); } } else { if (_this.settings.onnext) _this.settings.onnext(_this); $this.trigger('slidizle.next', [_this]); } // start timer : if (_this.gettotaltimeout() && ! _this._isover && _this.isplay() ) _this._starttimer(); // after change callback : if (_this.settings.afterchange) _this.settings.afterchange(_this); $this.trigger('slidizle.afterchange', [_this]); } } /** * update slides refs : */ slidizle.prototype._updateslidesrefs = function() { // vars : var _this = this, $this = _this.$this; // manage indexes : var ci = _this.current_index || 0, ni = _this.next_index || (_this.current_index+1 < _this.total) ? _this.current_index+1 : 0, pi = _this.previous_index || (_this.current_index-1 >= 0) ? _this.current_index-1 : _this.total-1; // save the reference to previous activate media : if ( _this.$refs.currentslide) _this.$refs.previousactiveslide = _this.$refs.currentslide; // save the reference to the previous media displayed : _this.$refs.previousslide = _this.$refs.content.children(':eq('+pi+')');; // save the reference to the current media displayed : _this.$refs.currentslide = _this.$refs.content.children(':eq('+ci+')'); // save the reference to next media : _this.$refs.nextslide = _this.$refs.content.children(':eq('+ni+')'); // save the before active slides refs : _this.$refs.beforeactiveslides = _this.$refs.medias.filter(':lt('+ci+')'); // save the after active slides refs : _this.$refs.afteractiveslides = _this.$refs.medias.filter(':gt('+ci+')'); } /** * load a slide : */ slidizle.prototype._loadslide = function(content, callback) { // vars : var _this = this, $this = _this.$this, $content = $(content), toload = [], loaded = 0; // get contents in slide : var $items = $content.find('*:not(script)').filter(function() { return $(this).closest('[data-slidizle]').get(0) == _this.$this.get(0); }); // add the slide itself : $items = $items.add($content); // loop on each content : $items.each(function() { // vars : var $item = $(this), imgurl; // check if is a custom element to load : if (typeof $item.attr('data-slidizle-preload-custom') != 'undefined' && $item.attr('data-slidizle-preload-custom') !== false) { // add to load array : toload.push({ type : 'custom', $elm : $item }); return; } // check if image is in css : if ($item.css('background-image').indexof('none') == -1) { var bkg = $item.css('background-image'); if (bkg.indexof('url') != -1) { var temp = bkg.match(/url\((.*?)\)/); imgurl = temp[1].replace(/\"/g, ''); } } else if ($item.get(0).nodename.tolowercase() == 'img' && typeof($item.attr('src')) != 'undefined') { imgurl = $item.attr('src'); } if ( ! imgurl) return; // add image to array : toload.push({ type : 'image', url : imgurl }); }); // check if has nothing to load : if ( ! toload.length) { callback($content); return; } // loop on all the elements to load : $(toload).each(function(index, item) { // switch on type : switch (item.type) { case 'image': // create image : var imgload = new image(); $(imgload).load(function() { // call loaded callback : loadedcallback(); }).error(function() { // call loaded : loadedcallback(); }).attr('src', item.url); break; case 'custom': // bind event : item.$elm.bind('slidizle.loaded', function(e) { // call loaded : loadedcallback(); }); break; } }); // loading progress : _this.loadingprogress = 0; // loaded callback : function loadedcallback() { // update number of elements loaded : loaded++; // calculate progress : _this.loadingprogress = 100 / toload.length * loaded; // onloading callback : if (_this.settings.onloading) _this.settings.onloading(_this); $this.trigger('slidizle.onloading', [_this]); // check if loading is finished : if (loaded >= toload.length) callback($content); } } /** * play : */ slidizle.prototype.play = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // protect : if (_this._isplaying || ! _this.gettotaltimeout() || ! _this.$refs.medias.length) return; // remove the pause class : _this.$this.removeclass(_this.settings.classes.pause); _this.$this.removeclass(_this.settings.classes.stop); // add the play class : _this.$this.addclass(_this.settings.classes.play); // update the pause state : _this._ispause = false; // update the state : _this._isplaying = true; // reset the timeout : _this._resettimer(); // the timer is started in changemedia _this._starttimer(); // trigger callback : if (_this.settings.onplay) _this.settings.onplay(_this); $this.trigger('slidizle.play', [_this]); } /** * resume : */ slidizle.prototype.resume = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // protect : if ( ! _this.ispause()) return; // remove the pause class : _this.$this.removeclass(_this.settings.classes.pause); _this.$this.removeclass(_this.settings.classes.stop); // add the play class : _this.$this.addclass(_this.settings.classes.play); // start timer : _this._starttimer(); // update state : _this._ispause = false; _this._isplaying = true; // trigger callback : if (_this.settings.onresume) _this.settings.onresume(_this); $this.trigger('slidizle.resume', [_this]); }; /** * pause : */ slidizle.prototype.pause = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // protect : if ( ! _this.isplay()) return; // remove the play class : _this.$this.removeclass(_this.settings.classes.play); _this.$this.removeclass(_this.settings.classes.stop); // update the pause state : _this._ispause = true; // update the state : _this._isplaying = false; // pause the timer : _this._pausetimer(); // add the pause class : _this.$this.addclass(_this.settings.classes.pause); // trigger callback : if (_this.settings.onpause) _this.settings.onpause(_this); $this.trigger('slidizle.pause', [_this]); } /** * stop : * stop timer and reset it */ slidizle.prototype.stop = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // protect : if ( ! _this.isplay()) return; // remove the play and pause class : _this.$this.removeclass(_this.settings.classes.play); _this.$this.removeclass(_this.settings.classes.pause); // update the pause state : _this._ispause = false; // update the state : _this._isplaying = false; // stop the timer : _this._stoptimer(); // add the pause class : _this.$this.addclass(_this.settings.classes.stop); // trigger callback : if (_this.settings.onstop) _this.settings.onstop(_this); $this.trigger('slidizle.stop', [_this]); } /** * toggle play pause : */ slidizle.prototype.toggleplaypause = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // check the status : if (_this._isplaying) _this.pause(); else _this.play(); } /** * next media : */ slidizle.prototype.next = function() { // vars : var _this = this, $this = _this.$this, disabledclass = _this.settings.classes.disabled; // do nothing if disabled : if (_this.isdisabled()) return; // in on last item : if ( ! _this.isloop() && _this.islast()) return; // manage the backward forward class on container : _this.$this.removeclass(_this.settings.classes.backward); _this.$this.addclass(_this.settings.classes.forward); // save previous active index : _this._previous_active_index = _this.current_index; // managing current : _this.current_index = (_this.current_index+1 < _this.total) ? _this.current_index+1 : 0; // saving previous : _this.previous_index = (_this.current_index-1 >= 0) ? _this.current_index-1 : _this.total-1; // managing next : _this.next_index = (_this.current_index+1 < _this.total) ? _this.current_index+1 : 0; // change medias : _this._changemedias(); } /** * previous media : */ slidizle.prototype.previous = function() { // vars : var _this = this, $this = _this.$this; // do nothing if disabled : if (_this.isdisabled()) return; // check if on last item and the slider if on loop : if ( ! _this.isloop() && _this.isfirst()) return; // manage the backward forward class on container : _this.$this.removeclass(_this.settings.classes.forward); _this.$this.addclass(_this.settings.classes.backward); // save previous active index : _this._previous_active_index = _this.current_index; // managing current : _this.current_index = (_this.current_index-1 < 0) ? _this.total-1 : _this.current_index-1; // saving previous : _this.previous_index = (_this.current_index-1 >= 0) ? _this.current_index-1 : _this.total-1; // managing next : _this.next_index = (_this.current_index+1 < _this.total) ? _this.current_index+1 : 0; // change medias : _this._changemedias(); } /** * go to a specific slide : * * @param string|int ref the slide reference (can be an index(int) or a string (class or id)) */ slidizle.prototype.goto = function(ref) { // vars : var _this = this, $this = _this.$this, $slide = null; // do nothing if disabled : if (_this.isdisabled()) return; // check the ref : if (typeof ref == 'string') { // check if is an selector specified : if (ref.substr(0,1) == '.' || ref.substr(0,1) == '#') { // try to find the slide by selector : $slide = _this.$refs.content.children(ref); } else { // check if we can find an slide ref : var slidebyid = _this.$refs.medias.filter('[data-slidizle-slide-id="'+ref+'"]'); if (slidebyid.length == 1) { $slide = slidebyid; } else if (_this.$refs.medias.filter('#'+ref).length == 1) { $slide = _this.$refs.medias.filter('#'+ref); } } } else if (typeof ref == 'number') { // get the slide : $slide = _this.$refs.medias.filter(':eq('+ref+')'); } // try to get the index of the slide : if ($slide && $slide.index() != null) { // set the current index : _this.current_index = $slide.index(); // change media : _this._changemedias(); } } /** * go to and play : * * @param string|int ref the slide reference (can be an index(int) or a string (class or id)) */ slidizle.prototype.gotoandplay = function(ref) { // do nothing if disabled : if (this.isdisabled()) return; // go to a slide : this.gotoslide(ref); // play : this.play(); } /** * go to and stop : * * @param string|int ref the slide reference (can be an index(int) or a string (class or id)) */ slidizle.prototype.gotoandstop = function(ref) { // do nothing if disabled : if (this.isdisabled()) return; // go to a slide : this.gotoslide(ref); // play : this.stop(); } /** * get current media : * * @return jquery object the current media reference */ slidizle.prototype.getcurrentslide = function() { return this.$refs.currentslide; } /** * get active slide (alias) */ slidizle.prototype.getactiveslide = slidizle.prototype.getcurrentslide; /** * get previous slide : * * @return jquery object the previous media reference */ slidizle.prototype.getpreviousslide = function() { return this.$refs.previousslide; } /** * get the next slide : * * @return jquery object the next media reference */ slidizle.prototype.getnextslide = function() { return this.$refs.nextslide; } /** * get the before active slides * * @return jquery object all the slides that are before the active one */ slidizle.prototype.getbeforeactiveslides = function() { return this.$refs.beforeactiveslides; } /** * get the after active slides * * @return jquery object all the slides that are after the active one */ slidizle.prototype.getafteractiveslides = function() { return this.$refs.afteractiveslides; } /** * get the previous active slide */ slidizle.prototype.getpreviousactiveslide = function() { return this.$refs.previousactiveslide; } /** * get all slide : * * @return jquery object all medias references */ slidizle.prototype.getallslides = function() { return this.$refs.medias; } /** * get settings : */ slidizle.prototype.getsettings = function() { return this.settings; } /** * get loading percentage : */ slidizle.prototype.getloadingprogress = function() { return this.loadingprogress; } /** * get remaining timeout : */ slidizle.prototype.getremainingtimeout = function() { return this.current_timeout_time; }; /** * get current timeout */ slidizle.prototype.getcurrenttimeout = function() { var t = this.$refs.currentslide.data('slidizle-timeout') || this.settings.timeout; if ( ! t) return null; return t - this.current_timeout_time; }; /** * get total timeout */ slidizle.prototype.gettotaltimeout = function() { return this.total_timeout_time || this.settings.timeout || false; }; /** * return if is last or not : * * @return boolean true | false */ slidizle.prototype.islast = function() { return (this.getcurrentslide().index() >= this.getallslides().length-1); } /** * return if is first or not : * * @return boolean true | false */ slidizle.prototype.isfirst = function() { return (this.getcurrentslide().index() <= 0); } /** * is hover : */ slidizle.prototype.ishover = function() { return this._isover; } /** * is disabled : */ slidizle.prototype.isdisabled = function() { // check if is disabled : var disabled = false; if (typeof this.settings.disabled == 'function') disabled = this.settings.disabled(); else disabled = this.settings.disabled; // manage disabled class : if (disabled) this.$this.addclass(this.settings.classes.disabled); else this.$this.removeclass(this.settings.classes.disabled); // return the result : return disabled; } /** * is loop : */ slidizle.prototype.isloop = function() { var loop = this.settings.loop; return (loop && loop != 'false'); }; /** * is play : */ slidizle.prototype.isplay = function() { return this._isplaying; }; /** * is pause : */ slidizle.prototype.ispause = function() { return this._ispause; }; /** * is stop : */ slidizle.prototype.isstop = function() { return ( ! this._isplaying && ! this._ispause); }; /** * extend settings : */ slidizle.prototype._extendsettings = function(options) { // vars : var _this = this, $this = _this.$this; // extend with options : _this.settings = $.extend(_this.settings, options, true); // flatten an object with parent.child.child pattern : var flattenobject = function(ob) { var toreturn = {}; for (var i in ob) { if (!ob.hasownproperty(i)) continue; if ((typeof ob[i]) == 'object' && ob[i] != null) { var flatobject = flattenobject(ob[i]); for (var x in flatobject) { if (!flatobject.hasownproperty(x)) continue; toreturn[i + '.' + x] = flatobject[x]; } } else { toreturn[i] = ob[i]; } } return toreturn; }; // flatten the settings var flatsettings = flattenobject(_this.settings); // loop on each settings to get value on the dom element for (var name in flatsettings) { // split the setting name : var inline_setting = 'slidizle-' + name.replace('.','-').replace(/([a-z])([a-z])/g, '$1-$2').tolowercase(), inline_attr = $this.data(inline_setting); // check if element has inline setting : if (typeof inline_attr !== 'undefined') { // set the setting : if (typeof inline_attr == 'number' || typeof inline_attr == 'boolean') eval('_this.settings.'+name+' = '+inline_attr); else eval('_this.settings.'+name+' = "'+inline_attr+'"'); } } }; /** * jquery bb_counter controller : */ $.fn.slidizle = function(method) { // check what to do : if (slidizle.prototype[method]) { // store args to use later : var args = array.prototype.slice.call(arguments, 1); // apply on each elements : this.each(function() { // get the plugin : var plugin = $(this).data('slidizle_api'); // call the method on api : plugin[method].apply(plugin, args); }); } else if (typeof method == 'object' || ! method) { // store args to use later : var args = array.prototype.slice.call(arguments); // apply on each : this.each(function() { $this = $(this); // stop if already inited : if ($this.data('slidizle_api') != null && $this.data('slidizle_api') != '') return; // make a new instance : var api = new slidizle($this, args[0]); // save api in element : $this.data('slidizle_api', api); }); } else { // error : $.error( 'method ' + method + ' does not exist on jquery.slidizle' ); } // return this : return this; } // return plugin : return slidizle; }));