1/* 2 SlidesJS 3.0.3 3 4 Documentation and examples http://slidesjs.com 5 Support forum http://groups.google.com/group/slidesjs 6 Created by Nathan Searles http://nathansearles.com 7 8 Version: 3.0.3 9 Updated: March 15th, 2013 10 11 SlidesJS is an open source project, contribute at GitHub: 12 https://github.com/nathansearles/Slides 13 14 (c) 2013 by Nathan Searles 15 16 Licensed under the Apache License, Version 2.0 (the "License"); 17 you may not use this file except in compliance with the License. 18 You may obtain a copy of the License at 19 20 http://www.apache.org/licenses/LICENSE-2.0 21 22 Unless required by applicable law or agreed to in writing, software 23 distributed under the License is distributed on an "AS IS" BASIS, 24 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 25 See the License for the specific language governing permissions and 26 limitations under the License. 27*/ 28(function() { 29 30 (function($, window, document) { 31 var Plugin, defaults, pluginName; 32 pluginName = "slidesjs"; 33 defaults = { 34 width: 940, 35 height: 528, 36 start: 1, 37 navigation: { 38 active: true, 39 effect: "slide" 40 }, 41 pagination: { 42 active: true, 43 effect: "slide" 44 }, 45 play: { 46 active: false, 47 effect: "slide", 48 interval: 5000, 49 auto: false, 50 swap: true, 51 pauseOnHover: false, 52 restartDelay: 2500 53 }, 54 effect: { 55 slide: { 56 speed: 500 57 }, 58 fade: { 59 speed: 300, 60 crossfade: true 61 } 62 }, 63 callback: { 64 loaded: function() {}, 65 start: function() {}, 66 complete: function() {} 67 } 68 }; 69 Plugin = (function() { 70 71 function Plugin(element, options) { 72 this.element = element; 73 this.options = $.extend(true, {}, defaults, options); 74 this._defaults = defaults; 75 this._name = pluginName; 76 this.init(); 77 } 78 79 return Plugin; 80 81 })(); 82 Plugin.prototype.init = function() { 83 var $element, nextButton, pagination, playButton, prevButton, stopButton, 84 _this = this; 85 $element = $(this.element); 86 this.data = $.data(this); 87 $.data(this, "animating", false); 88 $.data(this, "total", $element.children().not(".slidesjs-navigation", $element).length); 89 $.data(this, "current", this.options.start - 1); 90 $.data(this, "vendorPrefix", this._getVendorPrefix()); 91 if (typeof TouchEvent !== "undefined") { 92 $.data(this, "touch", true); 93 this.options.effect.slide.speed = this.options.effect.slide.speed / 2; 94 } 95 $element.css({ 96 overflow: "hidden" 97 }); 98 $element.slidesContainer = $element.children().not(".slidesjs-navigation", $element).wrapAll("<div class='slidesjs-container'>", $element).parent().css({ 99 overflow: "hidden", 100 position: "relative" 101 }); 102 $(".slidesjs-container", $element).wrapInner("<div class='slidesjs-control'>", $element).children(); 103 $(".slidesjs-control", $element).css({ 104 position: "relative", 105 left: 0 106 }); 107 $(".slidesjs-control", $element).children().addClass("slidesjs-slide").css({ 108 position: "absolute", 109 top: 0, 110 left: 0, 111 width: "100%", 112 zIndex: 0, 113 display: "none", 114 webkitBackfaceVisibility: "hidden" 115 }); 116 $.each($(".slidesjs-control", $element).children(), function(i) { 117 var $slide; 118 $slide = $(this); 119 return $slide.attr("slidesjs-index", i); 120 }); 121 if (this.data.touch) { 122 $(".slidesjs-control", $element).on("touchstart", function(e) { 123 return _this._touchstart(e); 124 }); 125 $(".slidesjs-control", $element).on("touchmove", function(e) { 126 return _this._touchmove(e); 127 }); 128 $(".slidesjs-control", $element).on("touchend", function(e) { 129 return _this._touchend(e); 130 }); 131 } 132 $element.fadeIn(0); 133 this.update(); 134 if (this.data.touch) { 135 this._setuptouch(); 136 } 137 $(".slidesjs-control", $element).children(":eq(" + this.data.current + ")").eq(0).fadeIn(0, function() { 138 return $(this).css({ 139 zIndex: 10 140 }); 141 }); 142 if (this.options.navigation.active) { 143 prevButton = $("<a>", { 144 "class": "slidesjs-previous slidesjs-navigation", 145 href: "#", 146 title: "Previous", 147 text: "Previous" 148 }).appendTo($element); 149 nextButton = $("<a>", { 150 "class": "slidesjs-next slidesjs-navigation", 151 href: "#", 152 title: "Next", 153 text: "Next" 154 }).appendTo($element); 155 } 156 $(".slidesjs-next:first", $element).click(function(e) { 157 e.preventDefault(); 158 _this.stop(true); 159 return _this.next(_this.options.navigation.effect); 160 }); 161 $(".slidesjs-previous:first", $element).click(function(e) { 162 e.preventDefault(); 163 _this.stop(true); 164 return _this.previous(_this.options.navigation.effect); 165 }); 166 if (this.options.play.active) { 167 playButton = $("<a>", { 168 "class": "slidesjs-play slidesjs-navigation", 169 href: "#", 170 title: "Play", 171 text: "Play" 172 }).appendTo($element); 173 stopButton = $("<a>", { 174 "class": "slidesjs-stop slidesjs-navigation", 175 href: "#", 176 title: "Stop", 177 text: "Stop" 178 }).appendTo($element); 179 playButton.click(function(e) { 180 e.preventDefault(); 181 return _this.play(true); 182 }); 183 stopButton.click(function(e) { 184 e.preventDefault(); 185 return _this.stop(true); 186 }); 187 if (this.options.play.swap) { 188 stopButton.css({ 189 display: "none" 190 }); 191 } 192 } 193 if (this.options.pagination.active) { 194 pagination = $("<ul>", { 195 "class": "slidesjs-pagination" 196 }).appendTo($element); 197 $.each(new Array(this.data.total), function(i) { 198 var paginationItem, paginationLink; 199 paginationItem = $("<li>", { 200 "class": "slidesjs-pagination-item" 201 }).appendTo(pagination); 202 paginationLink = $("<a>", { 203 href: "#",
204 "data-slidesjs-item": i, 205 html: i + 1 206 }).appendTo(paginationItem); 207 return paginationLink.click(function(e) { 208 e.preventDefault(); 209 _this.stop(true); 210 return _this.goto(($(e.currentTarget).attr("data-slidesjs-item") * 1) + 1); 211 }); 212 }); 213 } 214 $(window).bind("resize", function() { 215 return _this.update(); 216 }); 217 this._setActive(); 218 if (this.options.play.auto) { 219 this.play(); 220 } 221 return this.options.callback.loaded(this.options.start); 222 }; 223 Plugin.prototype._setActive = function(number) { 224 var $element, current; 225 $element = $(this.element); 226 this.data = $.data(this); 227 current = number > -1 ? number : this.data.current; 228 $(".active", $element).removeClass("active"); 229 return $("li:eq(" + current + ") a", $element).addClass("active"); 230 }; 231 Plugin.prototype.update = function() { 232 var $element, height, width; 233 $element = $(this.element); 234 this.data = $.data(this); 235 $(".slidesjs-control:first", $element).children(":not(:eq(" + this.data.current + "))").css({ 236 display: "none", 237 left: 0, 238 zIndex: 0 239 }); 240 width = $element.width(); 241 height = (this.options.height / this.options.width) * width; 242 this.options.width = width; 243 this.options.height = height; 244 return $(".slidesjs-control:first, .slidesjs-container:first", $element).css({ 245 width: width, 246 height: height 247 }); 248 }; 249 Plugin.prototype.next = function(effect) { 250 var $element; 251 $element = $(this.element); 252 this.data = $.data(this); 253 if (this.data.total <= 1) 254 return; 255 $.data(this, "direction", "next"); 256 if (effect === void 0) { 257 effect = this.options.navigation.effect; 258 } 259 if (effect === "fade") { 260 return this._fade(); 261 } else { 262 return this._slide(); 263 } 264 }; 265 Plugin.prototype.previous = function(effect) { 266 var $element; 267 $element = $(this.element); 268 this.data = $.data(this); 269 270 if (this.data.total <= 1) 271 return; 272 273 $.data(this, "direction", "previous"); 274 if (effect === void 0) { 275 effect = this.options.navigation.effect; 276 } 277 if (effect === "fade") { 278 return this._fade(); 279 } else { 280 return this._slide(); 281 } 282 }; 283 Plugin.prototype.goto = function(number) { 284 var $element, effect; 285 $element = $(this.element); 286 this.data = $.data(this); 287 if (effect === void 0) { 288 effect = this.options.pagination.effect; 289 } 290 if (number > this.data.total) { 291 number = this.data.total; 292 } else if (number < 1) { 293 number = 1; 294 } 295 if (typeof number === "number") { 296 if (effect === "fade") { 297 return this._fade(number); 298 } else { 299 return this._slide(number); 300 } 301 } else if (typeof number === "string") { 302 if (number === "first") { 303 if (effect === "fade") { 304 return this._fade(0); 305 } else { 306 return this._slide(0); 307 } 308 } else if (number === "last") { 309 if (effect === "fade") { 310 return this._fade(this.data.total); 311 } else { 312 return this._slide(this.data.total); 313 } 314 } 315 } 316 }; 317 Plugin.prototype._setuptouch = function() { 318 var $element, next, previous, slidesControl; 319 $element = $(this.element); 320 this.data = $.data(this); 321 slidesControl = $(".slidesjs-control", $element); 322 next = this.data.current + 1; 323 previous = this.data.current - 1; 324 if (previous < 0) { 325 previous = this.data.total - 1; 326 } 327 if (next > this.data.total - 1) { 328 next = 0; 329 } 330 slidesControl.children(":eq(" + next + ")").css({ 331 display: "block", 332 left: this.options.width 333 }); 334 return slidesControl.children(":eq(" + previous + ")").css({ 335 display: "block", 336 left: -this.options.width 337 }); 338 }; 339 Plugin.prototype._touchstart = function(e) { 340 var $element, touches; 341 $element = $(this.element); 342 this.data = $.data(this); 343 touches = e.originalEvent.touches[0]; 344 this._setuptouch(); 345 $.data(this, "touchtimer", Number(new Date())); 346 $.data(this, "touchstartx", touches.pageX); 347 $.data(this, "touchstarty", touches.pageY); 348 return e.stopPropagation(); 349 }; 350 Plugin.prototype._touchend = function(e) { 351 var $element, duration, prefix, slidesControl, timing, touches, transform, 352 _this = this; 353 $element = $(this.element); 354 this.data = $.data(this); 355 touches = e.originalEvent.touches[0]; 356 slidesControl = $(".slidesjs-control", $element); 357 if (slidesControl.position().left > this.options.width * 0.5 || slidesControl.position().left > this.options.width * 0.1 && (Number(new Date()) - this.data.touchtimer < 250)) { 358 $.data(this, "direction", "previous"); 359 this._slide(); 360 } else if (slidesControl.position().left < -(this.options.width * 0.5) || slidesControl.position().left < -(this.options.width * 0.1) && (Number(new Date()) - this.data.touchtimer < 250)) { 361 $.data(this, "direction", "next"); 362 this._slide(); 363 } else { 364 prefix = this.data.vendorPrefix; 365 transform = prefix + "Transform"; 366 duration = prefix + "TransitionDuration"; 367 timing = prefix + "TransitionTimingFunction"; 368 slidesControl[0].style[transform] = "translateX(0px)"; 369 slidesControl[0].style[duration] = this.options.effect.slide.speed * 0.85 + "ms"; 370 } 371 slidesControl.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", function() { 372 prefix = _this.data.vendorPrefix; 373 transform = prefix + "Transform"; 374 duration = prefix + "TransitionDuration"; 375 timing = prefix + "TransitionTimingFunction"; 376 slidesControl[0].style[transform] = ""; 377 slidesControl[0].style[duration] = ""; 378 return slidesControl[0].style[timing] = ""; 379 }); 380 return e.stopPropagation(); 381 }; 382 Plugin.prototype._touchmove = function(e) { 383 var $element, prefix, slidesControl, touches, transform; 384 $element = $(this.element); 385 this.data = $.data(this); 386 touches = e.originalEvent.touches[0]; 387 prefix = this.data.vendorPrefix; 388 slidesControl = $(".slidesjs-control", $element); 389 transform = prefix + "Transform"; 390 $.data(this, "scrolling", Math.abs(touches.pageX - this.data.touchstartx) < Math.abs(touches.pageY - this.data.touchstarty)); 391 if (!this.data.animating && !this.data.scrolling) { 392 e.preventDefault(); 393 this._setuptouch();
394 slidesControl[0].style[transform] = "translateX(" + (touches.pageX - this.data.touchstartx) + "px)"; 395 } 396 return e.stopPropagation(); 397 }; 398 Plugin.prototype.play = function(next) { 399 var $element, currentSlide, slidesContainer, 400 _this = this; 401 $element = $(this.element); 402 this.data = $.data(this); 403 if (!this.data.playInterval) { 404 if (next) { 405 currentSlide = this.data.current; 406 this.data.direction = "next"; 407 if (this.options.play.effect === "fade") { 408 this._fade(); 409 } else { 410 this._slide(); 411 } 412 } 413 $.data(this, "playInterval", setInterval((function() { 414 currentSlide = _this.data.current; 415 _this.data.direction = "next"; 416 if (_this.options.play.effect === "fade") { 417 return _this._fade(); 418 } else { 419 return _this._slide(); 420 } 421 }), this.options.play.interval)); 422 slidesContainer = $(".slidesjs-container", $element); 423 if (this.options.play.pauseOnHover) { 424 slidesContainer.unbind(); 425 slidesContainer.bind("mouseenter", function() { 426 return _this.stop(); 427 }); 428 slidesContainer.bind("mouseleave", function() { 429 if (_this.options.play.restartDelay) { 430 return $.data(_this, "restartDelay", setTimeout((function() { 431 return _this.play(true); 432 }), _this.options.play.restartDelay)); 433 } else { 434 return _this.play(); 435 } 436 }); 437 } 438 $.data(this, "playing", true); 439 $(".slidesjs-play", $element).addClass("slidesjs-playing"); 440 if (this.options.play.swap) { 441 $(".slidesjs-play", $element).hide(); 442 return $(".slidesjs-stop", $element).show(); 443 } 444 } 445 }; 446 Plugin.prototype.stop = function(clicked) { 447 var $element; 448 $element = $(this.element); 449 this.data = $.data(this); 450 clearInterval(this.data.playInterval); 451 if (this.options.play.pauseOnHover && clicked) { 452 $(".slidesjs-container", $element).unbind(); 453 } 454 $.data(this, "playInterval", null); 455 $.data(this, "playing", false); 456 $(".slidesjs-play", $element).removeClass("slidesjs-playing"); 457 if (this.options.play.swap) { 458 $(".slidesjs-stop", $element).hide(); 459 return $(".slidesjs-play", $element).show(); 460 } 461 }; 462 Plugin.prototype._slide = function(number) { 463 var $element, currentSlide, direction, duration, next, prefix, slidesControl, timing, transform, value, 464 _this = this; 465 $element = $(this.element); 466 this.data = $.data(this); 467 if (!this.data.animating && number !== this.data.current + 1) { 468 469 $.data(this, "animating", true); 470 currentSlide = this.data.current; 471 if (number > -1) { 472 number = number - 1; 473 value = number > currentSlide ? 1 : -1; 474 direction = number > currentSlide ? -this.options.width : this.options.width; 475 next = number; 476 } else { 477 value = this.data.direction === "next" ? 1 : -1; 478 direction = this.data.direction === "next" ? -this.options.width : this.options.width; 479 next = currentSlide + value; 480 } 481 if (next === -1) { 482 next = this.data.total - 1; 483 } 484 if (next === this.data.total) { 485 next = 0; 486 } 487 this._setActive(next); 488 slidesControl = $(".slidesjs-control:first", $element); 489 if (number > -1) { 490 slidesControl.children(":not(:eq(" + currentSlide + "))").css({ 491 display: "none", 492 left: 0, 493 zIndex: 0 494 }); 495 } 496 slidesControl.children(":eq(" + next + ")").css({ 497 display: "block", 498 left: value * this.options.width, 499 zIndex: 10 500 }); 501 this.options.callback.start(currentSlide + 1); 502 if (this.data.vendorPrefix) { 503 prefix = this.data.vendorPrefix; 504 transform = prefix + "Transform"; 505 duration = prefix + "TransitionDuration"; 506 timing = prefix + "TransitionTimingFunction";
507 slidesControl[0].style[transform] = "translateX(" + direction + "px)"; 508 slidesControl[0].style[duration] = this.options.effect.slide.speed + "ms"; 509 return slidesControl.on("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd", function() { 510 slidesControl[0].style[transform] = ""; 511 slidesControl[0].style[duration] = ""; 512 slidesControl.children(":eq(" + next + ")").css({ 513 left: 0 514 }); 515 slidesControl.children(":eq(" + currentSlide + ")").css({ 516 display: "none", 517 left: 0, 518 zIndex: 0 519 }); 520 $.data(_this, "current", next); 521 $.data(_this, "animating", false); 522 slidesControl.unbind("transitionend webkitTransitionEnd oTransitionEnd otransitionend MSTransitionEnd"); 523 slidesControl.children(":not(:eq(" + next + "))").css({ 524 display: "none", 525 left: 0, 526 zIndex: 0 527 }); 528 if (_this.data.touch) { 529 _this._setuptouch(); 530 } 531 return _this.options.callback.complete(next + 1); 532 }); 533 } else { 534 return slidesControl.stop().animate({ 535 left: direction 536 }, this.options.effect.slide.speed, (function() { 537 slidesControl.css({ 538 left: 0 539 }); 540 slidesControl.children(":eq(" + next + ")").css({ 541 left: 0 542 }); 543 return slidesControl.children(":eq(" + currentSlide + ")").css({ 544 display: "none", 545 left: 0, 546 zIndex: 0 547 }, $.data(_this, "current", next), $.data(_this, "animating", false), _this.options.callback.complete(next + 1)); 548 })); 549 } 550 } 551 }; 552 Plugin.prototype._fade = function(number) { 553 var $element, currentSlide, next, slidesControl, value, 554 _this = this; 555 $element = $(this.element); 556 this.data = $.data(this); 557 if (!this.data.animating && number !== this.data.current + 1) { 558 $.data(this, "animating", true); 559 currentSlide = this.data.current; 560 if (number) { 561 number = number - 1; 562 value = number > currentSlide ? 1 : -1; 563 next = number; 564 } else { 565 value = this.data.direction === "next" ? 1 : -1; 566 next = currentSlide + value; 567 } 568 if (next === -1) { 569 next = this.data.total - 1; 570 } 571 if (next === this.data.total) { 572 next = 0; 573 } 574 this._setActive(next); 575 slidesControl = $(".slidesjs-control", $element); 576 slidesControl.children(":eq(" + next + ")").css({ 577 display: "none", 578 left: 0, 579 zIndex: 10 580 }); 581 this.options.callback.start(currentSlide + 1); 582 if (this.options.effect.fade.crossfade) { 583 slidesControl.children(":eq(" + this.data.current + ")").stop().fadeOut(this.options.effect.fade.speed); 584 return slidesControl.children(":eq(" + next + ")").stop().fadeIn(this.options.effect.fade.speed, (function() { 585 slidesControl.children(":eq(" + next + ")").css({ 586 zIndex: 0 587 }); 588 $.data(_this, "animating", false); 589 $.data(_this, "current", next); 590 return _this.options.callback.complete(next + 1); 591 })); 592 } else { 593 return slidesControl.children(":eq(" + currentSlide + ")").stop().fadeOut(this.options.effect.fade.speed, (function() { 594 slidesControl.children(":eq(" + next + ")").stop().fadeIn(_this.options.effect.fade.speed, (function() { 595 return slidesControl.children(":eq(" + next + ")").css({ 596 zIndex: 10 597 }); 598 })); 599 $.data(_this, "animating", false); 600 $.data(_this, "current", next); 601 return _this.options.callback.complete(next + 1); 602 })); 603 } 604 } 605 }; 606 Plugin.prototype._getVendorPrefix = function() { 607 var body, i, style, transition, vendor; 608 body = document.body || document.documentElement; 609 style = body.style; 610 transition = "transition"; 611 vendor = ["Moz", "Webkit", "Khtml", "O", "ms"]; 612 transition = transition.charAt(0).toUpperCase() + transition.substr(1); 613 i = 0; 614 while (i < vendor.length) { 615 if (typeof style[vendor[i] + transition] === "string") { 616 return vendor[i]; 617 } 618 i++; 619 } 620 return false;
621 }; 622 return $.fn[pluginName] = function(options) { 623 return this.each(function() { 624 if (!$.data(this, "plugin_" + pluginName)) { 625 return $.data(this, "plugin_" + pluginName, new Plugin(this, options)); 626 } 627 }); 628 }; 629 })(jQuery, window, document); 630 631}).call(this);
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.