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