1(function($, window, document, undefined) { 2 "use strict"; 3 var pluginName = "ezPager", 4 defaults = { 5 speed: 500, 6 timeout: 10000, 7 auto: false 8 }; 9 10 function Plugin(element, options) { 11 this.element = element; 12 this.$element = $(element); 13 this.$parent = this.$element.parent(); 14 this.$items = this.$element.children(); 15 this.$pagers = null; 16 this.options = $.extend({}, defaults, options); 17 this.length = this.$items.length; 18 this.index = 0; 19 this.interval = null; 20 this.init(); 21 } 22 23 $.extend(Plugin.prototype, { 24 init: function() { 25 this.addClasses(); 26 this.buildPager(); 27 this.startTimer(); 28 }, 29 addClasses: function() { 30 this.$element.addClass("ezpager"); 31 this.$items.addClass("ezpager-item").eq(0).addClass("ezpager-item--active"); 32 }, 33 buildPager: function() { 34 var _ = this; 35 var $pagerWrapper = $("<div class='ezpager-btns'></div>"); 36 if (this.length > 1) { 37 for (var i = 0; i < this.$items.length; i++) { 38 var $pager = $("<span class='ezpager-btn' data-index='" + i + "'></span>"); 39 if (i == 0) $pager.addClass("ezpager-btn--active"); 40 $pagerWrapper.append($pager); 41 $pager.on("click", function() { 42 _.showItem(this); 43 }); 44 } 45 if (this.options.placePagerAfter) { 46 $pagerWrapper.insertAfter(this.options.placePagerAfter); 47 } else { 48 this.$parent.append($pagerWrapper); 49 } 50 this.$pagers = $pagerWrapper.children(".ezpager-btn"); 51 } 52 }, 53 showItem: function(pager) { 54 var index = $(pager).attr("data-index"); 55 if (index) { 56 this.$items.removeClass("ezpager-item--active").eq(index).addClass("ezpager-item--active"); 57 this.$pagers.removeClass("ezpager-btn--active").eq(index).addClass("ezpager-btn--active"); 58 this.index = index; 59 if (this.options.auto) this.restartTimer(); 60 } 61 }, 62 goToNext: function() { 63 this.showItem(this.$pagers.eq(this.index + 1)); 64 }, 65 startTimer: function() { 66 var _ = this; 67 if (_.options.auto && _.length > 1) { 68 _.interval = setInterval(function() { 69 _.goToNext(); 70 }, _.options.timeout); 71 } 72 }, 73 restartTimer: function() { 74 var _ = this; 75 clearInterval(_.interval); 76 _.startTimer(); 77 } 78 }); 79 $.fn[pluginName] = function(options) { 80 return this.each(function() { 81 if (!$.data(this, "plugin_" + pluginName)) { 82 $.data(this, "plugin_" + 83 pluginName, new Plugin(this, options)); 84 } 85 }); 86 }; 87})(jQuery, window, document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.