1(function ($, window, document, undefined) { 2 var pluginName = "AnimatedSlider", 3 defaults = { 4 infiniteScroll: true, 5 visibleItems: 3, 6 changedCallback: null, 7 willChangeCallback: null, 8 userChangedCallback: null, 9 useTransitions: true, 10 }; 11 var supportsTransitions = _supportsTransitions(); 12 13 function Plugin(element, options) { 14 this.element = element; 15 this.jqElem = $(element); 16 this.items = $(this.element).children("li"); 17 this.numSliderItems = this.items.length; 18 this.currentItem = 1; 19 this.commandQueue = []; 20 this.jqElem.data(pluginName, this); 21 this.options = $.extend({}, 22 defaults, options); 23 this._defaults = defaults; 24 this._name = pluginName; 25 this.inTransition = false; 26 this.init() 27 } 28 Plugin.prototype.init = function () { 29 var pluginThis = this; 30 if (pluginThis.options.useTransitions) this.jqElem.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", function () { 31 if (pluginThis.inTransition) { 32 pluginThis.inTransition = false; 33 if (pluginThis.options.changedCallback) pluginThis.options.changedCallback(pluginThis, pluginThis.currentItem); 34 setTimeout(function () { 35 pluginThis.doCommandQueue() 36 }, 37 50) 38 } 39 }); 40 else { 41 this.items.css("transition", "none"); 42 this.items.find("*").css("transition", "none") 43 } 44 if (this.options.prevButton) $(this.options.prevButton).on("click", function (e) { 45 e.preventDefault(); 46 pluginThis.prevItem() 47 }); 48 if (this.options.nextButton) $(this.options.nextButton).on("click", function (e) { 49 e.preventDefault(); 50 pluginThis.nextItem() 51 }); 52 this.setItem(1); 53 this.inTransition = false 54 }; 55 Plugin.prototype.setItem = function (n) { 56 var sliderItems = this.items; 57 sliderItems.removeClass(); 58 var wrapFuncNone = function (n) { 59 return n 60 }; 61 var wrapFunc; 62 if (this.options.infiniteScroll) wrapFunc = this._wrapIndex; 63 else wrapFunc = wrapFuncNone; 64 for (var i = 0; i < sliderItems.length; i++) { 65 var item = sliderItems.eq(i); 66 if (i == n) item.addClass("current_item"); 67 else if (i < n) item.addClass("previous_hidden"); 68 else if (i > n) item.addClass("next_hidden") 69 } 70 if (this.options.infiniteScroll) { 71 sliderItems.eq(this._wrapIndex(n - 1)).removeClass().addClass("previous_item"); 72 sliderItems.eq(this._wrapIndex(n + 1)).removeClass().addClass("next_item"); 73 if (this.options.visibleItems == 3) { 74 sliderItems.eq(this._wrapIndex(n - 75 2)).removeClass().addClass("previous_hidden"); 76 sliderItems.eq(this._wrapIndex(n + 2)).removeClass().addClass("next_hidden") 77 } else if (this.options.visibleItems == 5) { 78 sliderItems.eq(this._wrapIndex(n - 2)).removeClass().addClass("previous_item_2"); 79 sliderItems.eq(this._wrapIndex(n + 2)).removeClass().addClass("next_item_2"); 80 sliderItems.eq(this._wrapIndex(n - 3)).removeClass().addClass("previous_hidden"); 81 sliderItems.eq(this._wrapIndex(n + 3)).removeClass().addClass("next_hidden") 82 } 83 } else { 84 if (n - 1 >= 0) sliderItems.eq(n - 1).removeClass().addClass("previous_item"); 85 if (n + 1 < this.numSliderItems) sliderItems.eq(n + 1).removeClass().addClass("next_item"); 86 if (this.options.visibleItems == 5) { 87 if (n - 2 >= 0) sliderItems.eq(n - 1).removeClass().addClass("previous_item_2"); 88 if (n + 2 < this.numSliderItems) sliderItems.eq(n + 1).removeClass().addClass("next_item_2") 89 } 90 } 91 currentItem = n; 92 if (supportsTransitions && this.options.useTransitions) { 93 this.inTransition = true; 94 if (this.options.willChangeCallback) this.options.willChangeCallback(this, this.currentItem) 95 } else { 96 if (this.options.willChangeCallback) this.options.willChangeCallback(this, 97 this.currentItem); 98 if (this.options.changedCallback) this.options.changedCallback(this, this.currentItem) 99 } 100 }; 101 Plugin.prototype.nextItem = function () { 102 if (this.inTransition) { 103 if (this.commandQueue.length < 3) this.commandQueue.push("nextItem"); 104 return 105 } 106 if (this.options.infiniteScroll || this.currentItem < this.numSliderItems - 1) { 107 this.currentItem += 1; 108 this.currentItem = this._wrapIndex(this.currentItem); 109 this.setItem(this.currentItem); 110 if (this.options.userChangedCallback) this.options.userChangedCallback(this, this.currentItem) 111 } 112 }; 113 Plugin.prototype.prevItem = function () { 114 if (this.inTransition) { 115 if (this.commandQueue.length < 3) this.commandQueue.push("prevItem"); 116 return 117 } 118 if (this.options.infiniteScroll || this.currentItem >= 1) { 119 this.currentItem -= 1; 120 this.currentItem = this._wrapIndex(this.currentItem); 121 this.setItem(this.currentItem); 122 if (this.options.userChangedCallback) this.options.userChangedCallback(this, this.currentItem) 123 } 124 }; 125 Plugin.prototype.clearAnimations = function () { 126 this.inTransition = false;
127 this.commandQueue = [] 128 }; 129 Plugin.prototype.doCommandQueue = 130 function () { 131 if (this.commandQueue.length == 0) return; 132 var cmd = this.commandQueue.splice(0, 1)[0]; 133 this[cmd]() 134 }; 135 Plugin.prototype.refresh = function () { 136 this.items = $(this.element).children("li"); 137 this.numSliderItems = this.items.length; 138 this.setItem(this.currentItem); 139 clearAnimations() 140 }; 141 Plugin.prototype._wrapIndex = function (n) { 142 if (n < 0) n += this.numSliderItems; 143 if (n >= this.numSliderItems) n -= this.numSliderItems; 144 return n 145 }; 146 $.fn[pluginName] = function (options) { 147 return this.each(function () { 148 if (!$.data(this, "plugin_" + pluginName)) $.data(this, 149 "plugin_" + pluginName, new Plugin(this, options)) 150 }) 151 }; 152 153 function _supportsTransitions() { 154 var b = document.body || document.documentElement; 155 var s = b.style; 156 var p = "transition"; 157 if (typeof s[p] == "string") return true; 158 v = ["Moz", "Webkit", "Khtml", "O", "ms"], p = p.charAt(0).toUpperCase() + p.substr(1); 159 for (var i = 0; i < v.length; i++) 160 if (typeof s[v[i] + p] == "string") return true; 161 return false 162 } 163})(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.