1/*global jQuery */ 2/*jshint bitwise: true, camelcase: true, curly: true, eqeqeq: true, forin: true, 3immed: true, indent: 4, latedef: true, newcap: true, nonew: true, quotmark: single, 4undef: true, unused: true, strict: true, trailing: true, browser: true */ 5 6/* 7 * jquery.rs.carousel-continuous 1.0.0 8 * https://github.com/richardscarrott/jquery-ui-carousel 9 * 10 * Copyright (c) 2013 Richard Scarrott 11 * http://www.richardscarrott.co.uk 12 * 13 * Dual licensed under the MIT and GPL licenses: 14 * http://www.opensource.org/licenses/mit-license.php 15 * http://www.gnu.org/licenses/gpl.html 16 * 17 * Depends: 18 * jquery.js v1.8+ 19 * jquery.ui.widget.js v1.8+ 20 * jquery.rs.carousel.js v0.11.1 21 */ 22 23(function ($, undefined) { 24 25 'use strict'; 26 27 var _super = $.rs.carousel.prototype; 28 29 $.widget('rs.carousel', $.rs.carousel, { 30 31 options: { 32 continuous: false 33 }, 34 35 _create: function () { 36 37 if (this.options.continuous) { 38 this.options.loop = true; 39 // clones fill whitespace 40 this.options.whitespace = true; 41 } 42 43 _super._create.apply(this, arguments); 44 45 return; 46 }, 47 48 refresh: function () { 49 50 _super.refresh.apply(this, arguments); 51 52 if (this.options.continuous) { 53 this._addClonedItems(); 54 this._setRunnerWidth(); 55 // jump to current page to avoid clones noting the carousel 56 // needs to be enabled beforehand 57 this.enable(); 58 this.goToPage(this.index, false, undefined, true); 59 this._checkDisabled(); 60 } 61 62 return; 63 }, 64 65 // appends and prepends items to provide illusion of continuous scrolling 66 _addClonedItems: function () { 67 68 if (this.options.disabled) { 69 this._removeClonedItems(); 70 return; 71 } 72 73 var elems = this.elements, 74 cloneClass = this.widgetFullName + '-item-clone', 75 visibleItems = this._getVisibleItems(0); 76 77 this._removeClonedItems(); 78 79 elems.clonedBeginning = visibleItems 80 .clone() 81 // add one extra item in case it's partially visible 82 .add(this.elements.items.slice(visibleItems.length).first().clone()) 83 .addClass(cloneClass) 84 .appendTo(elems.runner); 85 86 elems.clonedEnd = this.getPage(this.getNoOfPages() - 1) 87 .clone() 88 .addClass(cloneClass) 89 .prependTo(elems.runner); 90 91 return; 92 }, 93 94 _removeClonedItems: function () { 95 96 var elems = this.elements; 97 98 if (elems.clonedBeginning) { 99 elems.clonedBeginning.remove(); 100 elems.clonedBeginning = undefined; 101 } 102 103 if (elems.clonedEnd) { 104 elems.clonedEnd.remove(); 105 elems.clonedEnd = undefined; 106 } 107 108 }, 109 110 // needs to be overridden to take into account cloned items 111 _setRunnerWidth: function () { 112 113 var elems = this.elements, 114 width = 0; 115 116 if (this.options.continuous) { 117 118 // reset width in case orientation 119 // has been changed 120 elems.runner.width(''); 121 122 if (!this.isHorizontal) { 123 return; 124 } 125 126 elems.runner 127 .width(function () { 128 elems.items 129 .add(elems.clonedBeginning) 130 .add(elems.clonedEnd) 131 .each(function () { 132 width += $(this).outerWidth(true); 133 }); 134 135 return width; 136 }); 137 138 } 139 else { 140 _super._setRunnerWidth.apply(this, arguments); 141 } 142 143 return; 144 }, 145 146 _slide: function (e) { 147 148 var pos; 149 150 if (this.options.continuous) { 151 152 // if moving to first page 153 if (e.type === 'carousel:next' && this.index === 0) { 154 // jump to last page clone 155 pos = this.elements.clonedEnd 156 .first() 157 .position()[this.isHorizontal ? 'left' : 'top']; 158 } 159 // if moving to last page 160 else if (e.type === 'carousel:prev' && this.index === this.getNoOfPages() - 1) { 161 // jump to first page clone 162 pos = this.elements.clonedBeginning 163 .first() 164 .position()[this.isHorizontal ? 'left' : 'top']; 165 } 166 167 if (pos !== undefined) { 168 if (this.options.translate3d) { 169 this.elements.runner 170 .css('transform', 'translate3d(' + (this.isHorizontal ? -pos + 'px, 0, 0' : '0, ' + -pos + 'px, 0') + ')'); 171 } 172 else { 173 this.elements.runner 174 .css(this.isHorizontal ? 'left' : 'top', -pos); 175 } 176 } 177 } 178 179 // continue 180 _super._slide.apply(this, arguments); 181 182 return; 183 }, 184 185 // override to avoid clones 186 _recacheItems: function () { 187 188 var fullName = this.widgetFullName; 189 190 this.elements.items = this.elements.runner 191 .find(this.options.items) 192 .not('.' + fullName + '-item-clone') 193 .addClass(fullName + '-item'); 194 195 return; 196 }, 197 198 add: function (items) { 199 200 if (this.elements.items.length) { 201 202 this.elements.items 203 .last() 204 .after(items); 205 206 this.refresh();
207 208 return; 209 } 210 211 // cloned items won't exist so use add from prototype (appends to runner) 212 _super.add.apply(this, arguments); 213 214 return; 215 }, 216 217 _setOption: function (option, value) { 218 219 _super._setOption.apply(this, arguments); 220 221 if (option === 'continuous') { 222 223 this.options.loop = true; 224 this.options.whitespace = true; 225 226 if (!value) { 227 this._removeClonedItems(); 228 } 229 230 this.refresh(); 231 } 232 233 return; 234 }, 235 236 destroy: function () { 237 238 this._removeClonedItems(); 239 240 _super.destroy.apply(this); 241 242 return; 243 } 244 245 }); 246 247})(jQuery);
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.