1/*! Superslides - v0.6.3-wip - 2013-12-17 2* https://github.com/nicinabox/superslides 3* Copyright (c) 2013 Nic Aitch; Licensed MIT */ 4(function(window, $) { 5 6var Superslides, plugin = 'superslides'; 7 8Superslides = function(el, options) { 9 this.options = $.extend({ 10 play: false, 11 animation_speed: 600, 12 animation_easing: 'linear', 13 animation: 'slide', 14 inherit_width_from: window, 15 inherit_height_from: window, 16 pagination: true, 17 hashchange: false, 18 scrollable: true, 19 elements: { 20 preserve: '.preserve', 21 nav: '.rfwbs_navigation', 22 container: '.rfwbs_container', 23 pagination: '.rfwbs_pagination' 24 } 25 }, options); 26 27 var that = this, 28 $control = $('<div>', { "class": 'slides-control' }), 29 multiplier = 1; 30 31 this.$el = $(el); 32 this.$container = this.$el.find(this.options.elements.container); 33 34 // Private Methods 35 var initialize = function() { 36 multiplier = that._findMultiplier(); 37 38 that.$el.on('click', that.options.elements.nav + " a", function(e) { 39 e.preventDefault(); 40 41 that.stop(); 42 if ($(this).hasClass('rfwbs_next')) { 43 that.animate('rfwbs_next', function() { 44 that.start(); 45 }); 46 } else { 47 that.animate('rfwbs_prev', function() { 48 that.start(); 49 }); 50 } 51 }); 52 53 $(window).on('resize', function() { 54 setTimeout(function() { 55 var $children = that.$container.children(); 56 57 that.width = that._findWidth(); 58 that.height = that._findHeight(); 59 60 $children.css({ 61 width: that.width, 62 left: that.width 63 }); 64 65 that.css.containers(); 66 that.css.images(); 67 }, 10); 68 }); 69 70 if (that.options.hashchange) { 71 $(window).on('hashchange', function() { 72 var hash = that._parseHash(), index; 73 74 index = that._upcomingSlide(hash); 75 76 if (index >= 0 && index !== that.current) { 77 that.animate(index); 78 } 79 }); 80 } 81 82 that.pagination._events(); 83 84 that.start(); 85 return that; 86 }; 87 88var css = { 89 containers: function() { 90 if (that.init) { 91 that.$el.css({ 92 height: that.height 93 }); 94 95 that.$control.css({ 96 width: that.width * multiplier, 97 left: -that.width 98 }); 99 100 that.$container.css({ 101 102 }); 103 } else { 104 $('body').css({ 105 margin: 0 106 }); 107 108 that.$el.css({ 109 position: 'fixed', 110 overflow: 'hidden', 111 width: '100%', 112 height: that.height 113 }); 114 115 that.$control.css({ 116 position: 'relative', 117 transform: 'translate3d(0)', 118 height: '100%', 119 width: that.width * multiplier, 120 left: -that.width 121 }); 122 123 that.$container.css({ 124 display: 'none', 125 margin: '0', 126 padding: '0', 127 listStyle: 'none', 128 position: 'relative', 129 height: '100%' 130 }); 131 } 132 133 if (that.size() === 1) { 134 that.$el.find(that.options.elements.nav).hide(); 135 } 136 }, 137 images: function() { 138 var $images = that.$container.find('img').not(that.options.elements.preserve) 139 140 $images.removeAttr('width').removeAttr('height') 141 .css({ 142 "-ms-interpolation-mode": 'bicubic', 143 "position": 'absolute', 144 "left": '0', 145 "top": '0', 146 "z-index": '-1', 147 "max-width": 'none' 148 }); 149 150 $images.each(function() { 151 var image_aspect_ratio = that.image._aspectRatio(this), 152 image = this; 153 154 if (!$.data(this, 'processed')) { 155 var img = new Image(); 156 img.onload = function() { 157 that.image._scale(image, image_aspect_ratio); 158 that.image._center(image, image_aspect_ratio); 159 $.data(image, 'processed', true); 160 }; 161 img.src = this.src; 162 163 } else { 164 that.image._scale(image, image_aspect_ratio); 165 that.image._center(image, image_aspect_ratio); 166 } 167 }); 168 }, 169 children: function() { 170 var $children = that.$container.children(); 171 172 if ($children.is('img')) { 173 $children.each(function() { 174 if ($(this).is('img')) { 175 $(this).wrap('<div>'); 176 177 // move id attribute 178 var id = $(this).attr('id'); 179 $(this).removeAttr('id'); 180 $(this).parent().attr('id', id); 181 } 182 }); 183 184 $children = that.$container.children(); 185 } 186 187 if (!that.init) { 188 $children.css({ 189 display: 'none', 190 left: that.width * 2 191 }); 192 } 193 194 $children.css({ 195 position: 'absolute', 196 overflow: 'hidden', 197 height: '100%', 198 width: that.width, 199 top: 0, 200 zIndex: 0 201 }); 202 203 } 204} 205 206var fx = { 207 slide: function(orientation, complete) { 208 var $children = that.$container.children(), 209 $target = $children.eq(orientation.upcoming_slide); 210 211 $target.css({ 212 left: orientation.upcoming_position, 213 display: 'block' 214 }); 215 216 that.$control.animate({ 217 left: orientation.offset 218 }, 219 that.options.animation_speed, 220 that.options.animation_easing, 221 function() { 222 if (that.size() > 1) { 223 that.$control.css({ 224 left: -that.width 225 }); 226 227 $children.eq(orientation.upcoming_slide).css({ 228 left: that.width, 229 zIndex: 2 230 }); 231 232 if (orientation.outgoing_slide >= 0) { 233 $children.eq(orientation.outgoing_slide).css({ 234 left: that.width, 235 display: 'none', 236 zIndex: 0 237 }); 238 } 239 } 240 241 complete(); 242 }); 243 }, 244 fade: function(orientation, complete) { 245 246 var that = this, 247 $children = that.$container.children(), 248 $outgoing = $children.eq(orientation.outgoing_slide), 249 $target = $children.eq(orientation.upcoming_slide); 250 251 $target.css({ 252 left: this.width, 253 opacity: 1, 254 display: 'block' 255 }).animate({ 256 opacity: 1 257 }, 258 that.options.animation_speed, 259 that.options.animation_easing 260 ); 261 262 if (orientation.outgoing_slide >= 0) { 263 $outgoing.animate({ 264 opacity: 0 265 }, 266 that.options.animation_speed, 267 that.options.animation_easing, 268 function() { 269 if (that.size() > 1) { 270 $children.eq(orientation.upcoming_slide).css({ 271 zIndex: 2 272 }); 273 274 if (orientation.outgoing_slide >= 0) { 275 $children.eq(orientation.outgoing_slide).css({ 276 opacity: 1, 277 display: 'none', 278 zIndex: 0 279 }); 280 } 281 } 282 complete(); 283 }); 284 } else { 285 $target.css({ 286 zIndex: 99 287 }); 288 complete(); 289 } 290 } 291}; 292 293fx = $.extend(fx, $.fn.superslides.fx); 294 295var image = { 296 _centerY: function(image) { 297 var $img = $(image); 298 299 $img.css({ 300 top: (that.height - $img.height()) / 2 301 }); 302 }, 303 _centerX: function(image) { 304 var $img = $(image); 305 306 $img.css({ 307 left: (that.width - $img.width()) / 2 308 }); 309 }, 310 _center: function(image) { 311 that.image._centerX(image); 312 that.image._centerY(image); 313 }, 314 _aspectRatio: function(image) {
315 if (!image.naturalHeight && !image.naturalWidth) { 316 var img = new Image(); 317 img.src = image.src; 318 image.naturalHeight = img.height; 319 image.naturalWidth = img.width; 320 } 321 322 return image.naturalHeight / image.naturalWidth; 323 }, 324 _scale: function(image, image_aspect_ratio) { 325 image_aspect_ratio = image_aspect_ratio || that.image._aspectRatio(image); 326 327 var container_aspect_ratio = that.height / that.width, 328 $img = $(image); 329 330 if (container_aspect_ratio > image_aspect_ratio) { 331 $img.css({ 332 height: that.height, 333 width: that.height / image_aspect_ratio 334 }); 335 336 } else { 337 $img.css({ 338 height: that.width * image_aspect_ratio, 339 width: that.width 340 }); 341 } 342 } 343}; 344 345var pagination = { 346 _setCurrent: function(i) { 347 if (!that.$pagination) { return; } 348 349 var $pagination_children = that.$pagination.children(); 350 351 $pagination_children.removeClass('current'); 352 $pagination_children.eq(i) 353 .addClass('current'); 354 }, 355 _addItem: function(i) { 356 var slide_number = i + 1, 357 href = slide_number, 358 $slide = that.$container.children().eq(i), 359 slide_id = $slide.attr('id'); 360 361 if (slide_id) { 362 href = slide_id; 363 } 364 365 var $item = $("<a>", { 366 'href': "#" + href, 367 'text': href 368 }); 369 370 $item.appendTo(that.$pagination); 371 }, 372 _setup: function() { 373 if (!that.options.pagination || that.size() === 1) { return; } 374 375 var $pagination = $("<nav>", { 376 'class': that.options.elements.pagination.replace(/^\./, '') 377 }); 378 379 that.$pagination = $pagination.insertAfter( $( "#rfwbs_slider" ) ); 380 381 for (var i = 0; i < that.size(); i++) { 382 that.pagination._addItem(i); 383 } 384 }, 385 _events: function() { 386 $('body').on('click', '.rfwbs_pagination a', function(e) { 387 e.preventDefault(); 388 389 var hash = that._parseHash(this.hash), index; 390 index = that._upcomingSlide(hash, true); 391 392 if (index !== that.current) { 393 that.animate(index, function() { 394 that.start(); 395 }); 396 } 397 }); 398 } 399}; 400 401 this.css = css; 402 this.image = image; 403 this.pagination = pagination; 404 this.fx = fx; 405 this.animation = this.fx[this.options.animation]; 406 407 this.$control = this.$container.wrap($control).parent('.slides-control'); 408 409 that._findPositions(); 410 that.width = that._findWidth(); 411 that.height = that._findHeight(); 412 413 this.css.children(); 414 this.css.containers(); 415 this.css.images(); 416 this.pagination._setup(); 417 418 return initialize(); 419}; 420 421Superslides.prototype = { 422 _findWidth: function() { 423 return $(this.options.inherit_width_from).width(); 424 }, 425 _findHeight: function() { 426 return $(this.options.inherit_height_from).height(); 427 }, 428 429 _findMultiplier: function() { 430 return this.size() === 1 ? 1 : 3; 431 }, 432 433 _upcomingSlide: function(direction, from_hash_change) { 434 if (from_hash_change && !isNaN(direction)) { 435 direction = direction - 1; 436 } 437 438 if ((/next/).test(direction)) { 439 return this._nextInDom(); 440 441 } else if ((/prev/).test(direction)) { 442 return this._prevInDom(); 443 444 } else if ((/\d/).test(direction)) { 445 return +direction; 446 447 } else if (direction && (/\w/).test(direction)) { 448 var index = this._findSlideById(direction); 449 if (index >= 0) { 450 return index; 451 } else { 452 return 0; 453 } 454 455 } else { 456 return 0; 457 } 458 }, 459 460 _findSlideById: function(id) { 461 return this.$container.find('#' + id).index(); 462 }, 463 464 _findPositions: function(current, thisRef) { 465 thisRef = thisRef || this; 466 467 if (current === undefined) { 468 current = -1; 469 } 470 471 thisRef.current = current; 472 thisRef.next = thisRef._nextInDom(); 473 thisRef.prev = thisRef._prevInDom(); 474 }, 475 476 _nextInDom: function() { 477 var index = this.current + 1; 478 479 if (index === this.size()) { 480 index = 0; 481 } 482 483 return index; 484 }, 485 486 _prevInDom: function() { 487 var index = this.current - 1; 488 489 if (index < 0) { 490 index = this.size() - 1; 491 } 492 493 return index; 494 }, 495 496 _parseHash: function(hash) { 497 hash = hash || window.location.hash; 498 hash = hash.replace(/^#/, ''); 499 500 if (hash && !isNaN(+hash)) { 501 hash = +hash; 502 } 503 504 return hash; 505 }, 506 507 size: function() { 508 return this.$container.children().length; 509 }, 510 511 destroy: function() { 512 return this.$el.removeData(); 513 }, 514 515 update: function() { 516 this.css.children(); 517 this.css.containers(); 518 this.css.images(); 519 520 this.pagination._addItem(this.size()) 521 522 this._findPositions(this.current); 523 this.$el.trigger('updated.slides'); 524 }, 525 526 stop: function() { 527 clearInterval(this.play_id); 528 delete this.play_id; 529 530 this.$el.trigger('stopped.slides'); 531 }, 532 533 start: function() { 534 var that = this; 535 536 if (that.options.hashchange) { 537 $(window).trigger('hashchange'); 538 } else { 539 this.animate(); 540 } 541 542 if (this.options.play) { 543 if (this.play_id) { 544 this.stop(); 545 } 546 547 this.play_id = setInterval(function() { 548 that.animate(); 549 }, this.options.play); 550 } 551 552 this.$el.trigger('started.slides'); 553 }, 554 555 animate: function(direction, userCallback) { 556 var that = this, 557 orientation = {}; 558 559 if (this.animating) { 560 return; 561 } 562 563 this.animating = true; 564 565 if (direction === undefined) { 566 direction = 'rfwbs_next'; 567 } 568 569 orientation.upcoming_slide = this._upcomingSlide(direction); 570 571 if (orientation.upcoming_slide >= this.size()) { 572 return; 573 } 574 575 orientation.outgoing_slide = this.current; 576 orientation.upcoming_position = this.width * 2; 577 orientation.offset = -orientation.upcoming_position; 578 579 if (direction === 'rfwbs_prev' || direction < orientation.outgoing_slide) { 580 orientation.upcoming_position = 0; 581 orientation.offset = 0; 582 } 583 584 if (that.size() > 1) { 585 that.pagination._setCurrent(orientation.upcoming_slide); 586 } 587 588 if (that.options.hashchange) { 589 var hash = orientation.upcoming_slide + 1, 590 id = that.$container.children(':eq(' + orientation.upcoming_slide + ')').attr('id'); 591 592 if (id) { 593 window.location.hash = id; 594 } else { 595 window.location.hash = hash; 596 } 597 } 598 599 that.$el.trigger('animating.slides', [orientation]); 600 601 that.animation(orientation, function() { 602 that._findPositions(orientation.upcoming_slide, that); 603 604 if (typeof userCallback === 'function') { 605 userCallback(); 606 } 607 608 that.animating = false;
609 that.$el.trigger('animated.slides'); 610 611 if (!that.init) { 612 that.$el.trigger('init.slides'); 613 that.init = true; 614 that.$container.fadeIn('fast'); 615 } 616 }); 617 } 618}; 619 620// jQuery plugin definition 621 622$.fn[plugin] = function(option, args) { 623 var result = []; 624 625 this.each(function() { 626 var $this, data, options; 627 628 $this = $(this); 629 data = $this.data(plugin); 630 options = typeof option === 'object' && option; 631 632 if (!data) { 633 result = $this.data(plugin, (data = new Superslides(this, options))); 634 } 635 636 if (typeof option === "string") { 637 result = data[option]; 638 if (typeof result === 'function') { 639 return result = result.call(data, args); 640 } 641 } 642 }); 643 644 return result; 645}; 646 647$.fn[plugin].fx = {}; 648 649})(this, 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.