1(function ($) { 2 3 function Slider(el, options) { 4 var self = this; 5 this.el = el; 6 this.$el = $(el); 7 8 this.options = { 9 element: 'li', 10 margin: 0, 11 delay: 100, 12 duration: 200, 13 nextPageDelay: 300, 14 prevButton: false, 15 nextButton: false, 16 loop: true, 17 afterInit: false, 18 autoscroll: false, 19 type: 'dynamic' 20 }; 21 $.extend(this.options, options); 22 self.initialize(true); 23 } 24 25 $.fn.reverse = [].reverse; 26 27 $.fn.juraSlider = function(options) { 28 return new Slider(this.get(0), options); 29 } 30 31 Slider.prototype = { 32 initialize: function(first_init) { 33 var self = this; 34 35 if (first_init == undefined) { 36 first_init = false; 37 } 38 39 this.afterAnimation(false); 40 41 var first_element_height = this.$el.find(this.options.element + ':first').outerHeight(); 42 43 var padding_left = parseInt(this.$el.parent().css('padding-left')); 44 var padding_right = parseInt(this.$el.parent().css('padding-right')); 45 46 this.$el.css({ 47 whiteSpace: 'nowrap', 48 left: padding_left, 49 right: padding_right, 50 top: 0, 51 bottom: 0, 52 height: first_element_height, 53 position: 'absolute', 54 clip: 'rect(auto, auto, ' + (first_element_height + 60) + 'px, auto)' 55 }); 56 57 this.$el.parent().css({ 58 height: first_element_height, 59 position: 'relative' 60 }); 61 62 this.$el.find(this.options.element).css({ 63 margin: 0, 64 position: 'absolute', 65 left: this.$el.outerWidth(), 66 top: 0, 67 zIndex: 1 68 }).removeClass('leftPosition currentPosition currentPosition-first currentPosition-last').addClass('rightPosition'); 69 70 if (first_init && this.options.nextButton) 71 this.options.nextButton.click(function() { 72 self.triggerNext(false); 73 }); 74 75 if (first_init && this.options.prevButton) 76 this.options.prevButton.click(function() { 77 self.triggerPrev(); 78 }); 79 80 if (first_init) { 81 $(window).resize(function() { 82 self.initialize(false); 83 }); 84 } 85 86 if (first_init && $.isFunction(this.options.afterInit)) 87 this.options.afterInit(); 88 89 this.triggerNext(true, this.options.type == 'one' ? true : !first_init); 90 91 this.$el.hover( 92 function() { 93 self.afterAnimation(false); 94 }, 95 function(){ 96 self.afterAnimation(); 97 } 98 ); 99 100 }, 101 102 beforeAnimation: function() { 103 this.is_animation = true; 104 if (this.autoscrollHandler) { 105 clearInterval(this.autoscrollHandler); 106 this.autoscrollHandler = false; 107 } 108 }, 109 110 afterAnimation: function(start) { 111 var self = this; 112 113 start = start === undefined ? true : false; 114 this.is_animation = false; 115 if (this.autoscrollHandler) { 116 clearInterval(this.autoscrollHandler); 117 this.autoscrollHandler = false; 118 } 119 if (start && this.options.autoscroll) { 120 this.autoscrollHandler = setInterval(function() { 121 self.triggerNext(false); 122 }, this.options.autoscroll); 123 } 124 }, 125 126 getNextCount: function() { 127 var self = this; 128 var count = 0; 129 var next_width = 0; 130 var index = 0; 131 var el_width = parseFloat(getComputedStyle(this.el, '').getPropertyValue('width')); 132 var new_width = 0; 133 this.$el.find(this.options.element + '.rightPosition').each(function() { 134 var width = parseFloat(getComputedStyle(this, '').getPropertyValue('width')); 135 if (index > 0) 136 width += self.options.margin; 137 new_width = next_width + width; 138 if (new_width > el_width) 139 return false; 140 next_width = next_width + width; 141 count += 1; 142 index += 1; 143 }); 144 if (this.options.loop && new_width < el_width) { 145 this.$el.find(this.options.element + '.leftPosition').each(function() { 146 var width = parseFloat(getComputedStyle(this, '').getPropertyValue('width')); 147 if (index > 0) 148 width += self.options.margin; 149 new_width = next_width + width; 150 if (new_width > el_width) 151 return false; 152 $(this).css({left: el_width}).removeClass('leftPosition').addClass('rightPosition').appendTo(self.$el); 153 next_width = next_width + width; 154 count += 1; 155 index += 1; 156 }); 157 } 158 return [count, next_width]; 159 }, 160 161 getNextRightItem: function() { 162 var firstRightItem = this.$el.find(this.options.element + '.rightPosition:first'); 163 if (firstRightItem.length) { 164 return firstRightItem[0]; 165 } 166 if (!this.options.loop) { 167 return null; 168 } 169 170 var firstLeftItem = this.$el.find(this.options.element + '.leftPosition:first'); 171 if (!firstLeftItem.length) { 172 return null; 173 } 174 175 firstLeftItem 176 .addClass('rightPosition') 177 .removeClass('leftPosition') 178 .css('left', this.$el.outerWidth()); 179 180 this.$el.append(firstLeftItem); 181 182 return firstLeftItem[0]; 183 }, 184 185 triggerNextOne: function() { 186 var app = this, 187 $currentItems = this.$el.find(this.options.element + '.currentPosition'), 188 firstCurrentItemWidth = parseFloat($currentItems.first().outerWidth()) 189 190 console.log($currentItems + firstCurrentItemWidth); 191 192 var rightItem = this.getNextRightItem(); 193 if (rightItem == null) { 194 return false;
195 } 196 197 $currentItems.push(rightItem); 198 var count = $currentItems.length; 199 200 app.beforeAnimation(); 201 202 $currentItems.removeClass('currentPosition-last').each(function(index) { 203 var itemLeft = parseFloat($(this).css('left')); 204 $(this).addClass('slider-animation' + (index == count - 1 ? ' currentPosition-last' : '')) 205 .animate({left: itemLeft - firstCurrentItemWidth}, { 206 duration: app.options.duration, 207 queue: false, 208 complete: function() { 209 $(this).removeClass('slider-animation'); 210 211 if (index == 0) { 212 $(this).removeClass('currentPosition currentPosition-first').addClass('leftPosition'); 213 } 214 215 if (index == 1) { 216 $(this).addClass('currentPosition-first'); 217 } 218 219 if (index == count - 1) { 220 $(this).removeClass('rightPosition').addClass('currentPosition'); 221 app.afterAnimation(); 222 } 223 } 224 }); 225 }); 226 }, 227 228 triggerNext: function(init, without_transition) { 229 if (this.is_animation) 230 return false; 231 232 if (without_transition == undefined) { 233 without_transition = false; 234 } 235 236 if (!init && this.options.type == 'one') { 237 this.triggerNextOne(); 238 return false; 239 } 240 241 var self = this; 242 var info = this.getNextCount(); 243 if (init && info[0] == this.$el.find(this.options.element).size()) { 244 if (this.options.nextButton) 245 this.options.nextButton.hide(); 246 if (this.options.prevButton) 247 this.options.prevButton.hide(); 248 } 249 if (info[0] < 1) 250 return false; 251 this.beforeAnimation(); 252 253 this.hideLeft(); 254 255 setTimeout(function() { 256 self.showNext(info, without_transition); 257 }, without_transition ? 1 : this.options.nextPageDelay); 258 }, 259 260 hideLeft: function() { 261 var delay = 0; 262 var app = this; 263 app.$el.find(app.options.element + '.currentPosition').each(function() { 264 var self = this; 265 setTimeout(function() { 266 var offset = $(self).outerWidth(); 267 $(self).addClass('slider-animation').animate({left: -offset}, { 268 duration: app.options.duration, 269 queue: false, 270 complete: function() { 271 $(this).removeClass('currentPosition slider-animation currentPosition-first currentPosition-last').addClass('leftPosition'); 272 } 273 }); 274 }, delay); 275 delay += app.options.delay; 276 }); 277 }, 278 279 showNext: function(info, without_transition) { 280 var app = this; 281 if (info[0] < 1) 282 return false; 283 284 var offset = (app.$el.width() - info[1]) / 2; 285 var delay = 0; 286 var index = 0; 287 app.$el.find(app.options.element + '.rightPosition:lt(' + info[0] + ')').each(function() { 288 var self = this; 289 if (without_transition) { 290 $(self) 291 .removeClass('leftPosition rightPosition') 292 .addClass('currentPosition') 293 .css({ 294 left: offset 295 }); 296 } else { 297 app.showElement(self, offset, delay, index, info[0]); 298 } 299 delay += app.options.delay; 300 offset += $(self).outerWidth() + app.options.margin; 301 index += 1; 302 }); 303 304 if (without_transition) { 305 app.afterAnimation(); 306 } 307 }, 308 309 showElement: function(element, offset, delay, index, count) { 310 var app = this; 311 setTimeout(function() { 312 $(element).addClass('slider-animation' + (index == 0 ? ' currentPosition-first' : '') + (index == count - 1 ? ' currentPosition-last' : '')).animate({left: offset}, { 313 duration: app.options.duration, 314 queue: false, 315 complete: function() { 316 $(this).removeClass('rightPosition leftPosition slider-animation').addClass('currentPosition'); 317 if (index == count - 1) { 318 app.afterAnimation(); 319 } 320 } 321 }); 322 }, delay); 323 }, 324 325 getPrevCount: function() { 326 var self = this; 327 var count = 0; 328 var prev_width = 0; 329 var index = 0; 330 var el_width = parseFloat(getComputedStyle(this.el, '').getPropertyValue('width')); 331 var new_width = 0; 332 this.$el.find(this.options.element + '.leftPosition').reverse().each(function() { 333 var width = parseFloat(getComputedStyle(this, '').getPropertyValue('width')); 334 if (index > 0) 335 width += self.options.margin; 336 new_width = prev_width + width; 337 if (new_width > el_width) 338 return false;
339 prev_width = prev_width + width; 340 count += 1; 341 index += 1; 342 }); 343 if (this.options.loop && new_width < el_width) { 344 this.$el.find(this.options.element + '.rightPosition').reverse().each(function() { 345 var width = parseFloat(getComputedStyle(this, '').getPropertyValue('width')); 346 if (index > 0) 347 width += self.options.margin; 348 new_width = prev_width + width; 349 if (new_width > el_width) 350 return false; 351 $(this).css({left: -width}).removeClass('rightPosition').addClass('leftPosition').prependTo(self.$el); 352 prev_width = prev_width + width; 353 count += 1; 354 index += 1; 355 }); 356 } 357 return [count, prev_width]; 358 }, 359 360 getPrevLeftItem: function() { 361 var lastLeftItem = this.$el.find(this.options.element + '.leftPosition:last'); 362 if (lastLeftItem.length) { 363 return lastLeftItem[0]; 364 } 365 if (!this.options.loop) { 366 return null; 367 } 368 369 var lastRightItem = this.$el.find(this.options.element + '.rightPosition:last'); 370 if (!lastRightItem.length) { 371 return null; 372 } 373 374 lastRightItem 375 .removeClass('rightPosition') 376 .addClass('leftPosition') 377 .css('left', -lastRightItem.outerWidth()); 378 379 this.$el.prepend(lastRightItem); 380 381 return lastRightItem[0]; 382 }, 383 384 triggerPrevOne: function() { 385 var app = this, 386 $currentItems = this.$el.find(this.options.element + '.currentPosition'), 387 lastCurrentItemWidth = parseFloat($currentItems.last().outerWidth()) 388 389 var leftItem = this.getPrevLeftItem(); 390 if (leftItem == null) { 391 return false; 392 } 393 394 $currentItems.reverse(); 395 $currentItems.push(leftItem); 396 var count = $currentItems.length; 397 398 app.beforeAnimation(); 399 400 $currentItems.removeClass('currentPosition-first').each(function(index) { 401 var itemLeft = parseFloat($(this).css('left')); 402 $(this).addClass('slider-animation' + (index == count - 1 ? ' currentPosition-first' : '')) 403 .animate({left: itemLeft + lastCurrentItemWidth}, { 404 duration: app.options.duration, 405 queue: false, 406 complete: function() { 407 $(this).removeClass('slider-animation'); 408 409 if (index == 0) { 410 $(this).removeClass('currentPosition currentPosition-last').addClass('rightPosition'); 411 } 412 413 if (index == 1) { 414 $(this).addClass('currentPosition-last'); 415 } 416 417 if (index == count - 1) { 418 $(this).removeClass('leftPosition').addClass('currentPosition'); 419 app.afterAnimation(); 420 } 421 } 422 }); 423 }); 424 }, 425 426 triggerPrev: function() { 427 if (this.is_animation) { 428 return false; 429 } 430 431 if (this.options.type == 'one') { 432 this.triggerPrevOne(); 433 return false; 434 } 435 436 var self = this; 437 var info = this.getPrevCount(); 438 if (info[0] < 1) 439 return false; 440 441 this.beforeAnimation(); 442 443 this.hideRight(); 444 445 setTimeout(function() { 446 self.showPrev(info); 447 }, this.options.nextPageDelay); 448 }, 449 450 hideRight: function() { 451 var delay = 0; 452 var app = this; 453 var offset = app.$el.width(); 454 app.$el.find(app.options.element + '.currentPosition').reverse().each(function() { 455 var self = this; 456 setTimeout(function() { 457 $(self).addClass('slider-animation').animate({left: offset}, { 458 duration: app.options.duration, 459 queue: false, 460 complete: function() { 461 $(this).removeClass('currentPosition slider-animation currentPosition-first currentPosition-last').addClass('rightPosition'); 462 } 463 }); 464 }, delay); 465 delay += app.options.delay; 466 }); 467 }, 468 469 showPrev: function(info) { 470 var app = this; 471 if (info[0] < 1) 472 return false; 473 474 var offset = info[1] + (app.$el.width() - info[1]) / 2; 475 var delay = 0; 476 var index = 0; 477 478 app.$el.find(app.options.element + '.leftPosition').slice(-info[0]).reverse().each(function() { 479 var self = this; 480 offset -= $(self).outerWidth(); 481 if (index > 0) 482 offset -= app.options.margin; 483 app.showElement(self, offset, delay, index, info[0]); 484 delay += app.options.delay; 485 index += 1; 486 }); 487 } 488 }; 489 490}(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.