1/*! 2 AnythingSlider v1.8.6 3 Original by Chris Coyier: http://css-tricks.com 4 Get the latest version: https://github.com/ProLoser/AnythingSlider 5 6 To use the navigationFormatter function, you must have a function that 7 accepts two paramaters, and returns a string of HTML text. 8 9 index = integer index (1 based); 10 panel = jQuery wrapped LI item this tab references 11 @return = Must return a string of HTML/Text 12 13 navigationFormatter: function(index, panel){ 14 return "Panel #" + index; // This would have each tab with the text 'Panel #X' where X = index 15 } 16*/ 17;(function($) { 18 19 $.anythingSlider = function(el, options) { 20 21 var base = this, o, t; 22 23 // Wraps the ul in the necessary divs and then gives Access to jQuery element 24 base.el = el; 25 base.$el = $(el).addClass('anythingBase').wrap('<div class="anythingSlider"><div class="anythingWindow" /></div>'); 26 27 // Add a reverse reference to the DOM object 28 base.$el.data("AnythingSlider", base); 29 30 base.init = function(){ 31 32 // Added "o" to be used in the code instead of "base.options" which doesn't get modifed by the compiler - reduces size by ~1k 33 base.options = o = $.extend({}, $.anythingSlider.defaults, options); 34 35 base.initialized = false; 36 if ($.isFunction(o.onBeforeInitialize)) { base.$el.bind('before_initialize', o.onBeforeInitialize); } 37 base.$el.trigger('before_initialize', base); 38 39 // Add "as-oldie" class to body for css purposes 40 $('<!--[if lte IE 8]><script>jQuery("body").addClass("as-oldie");</script><![endif]-->').appendTo('body').remove(); 41 42 // Cache existing DOM elements for later 43 // base.$el = original ul 44 // for wrap - get parent() then closest in case the ul has "anythingSlider" class 45 base.$wrapper = base.$el.parent().closest('div.anythingSlider').addClass('anythingSlider-' + o.theme); 46 base.$window = base.$el.closest('div.anythingWindow'); 47 base.win = window; 48 base.$win = $(base.win); 49 50 base.$controls = $('<div class="anythingControls"></div>'); 51 base.$nav = $('<ul class="thumbNav"><li><a><span></span></a></li></ul>'); 52 base.$startStop = $('<a href="#" class="start-stop"></a>'); 53 54 if (o.buildStartStop || o.buildNavigation) { 55 base.$controls.appendTo( (o.appendControlsTo && $(o.appendControlsTo).length) ? $(o.appendControlsTo) : base.$wrapper); 56 } 57 if (o.buildNavigation) { 58 base.$nav.appendTo( (o.appendNavigationTo && $(o.appendNavigationTo).length) ? $(o.appendNavigationTo) : base.$controls ); 59 } 60 if (o.buildStartStop) { 61 base.$startStop.appendTo( (o.appendStartStopTo && $(o.appendStartStopTo).length) ? $(o.appendStartStopTo) : base.$controls ); 62 } 63 64 // Figure out how many sliders are on the page for indexing 65 base.runTimes = $('.anythingBase').length; 66 base.regex = new RegExp('panel' + base.runTimes + '-(\\d+)', 'i'); // hash tag regex 67 if (base.runTimes === 1) { base.makeActive(); } // make the first slider on the page active 68 69 // Set up a few defaults & get details 70 base.flag = false; // event flag to prevent multiple calls (used in control click/focusin) 71 base.playing = o.autoPlay; // slideshow state; removed "startStopped" option 72 base.slideshow = false; // slideshow flag needed to correctly trigger slideshow events 73 base.hovered = false; // actively hovering over the slider 74 base.panelSize = []; // will contain dimensions and left position of each panel 75 base.currentPage = base.targetPage = o.startPanel = parseInt(o.startPanel,10) || 1; // make sure this isn't a string 76 o.changeBy = parseInt(o.changeBy,10) || 1; 77 78 // set slider type, but keep backward compatibility with the vertical option 79 t = (o.mode || 'h').toLowerCase().match(/(h|v|f)/); 80 t = o.vertical ? 'v' : (t || ['h'])[0]; 81 o.mode = t === 'v' ? 'vertical' : t === 'f' ? 'fade' : 'horizontal'; 82 if (t === 'f') { 83 o.showMultiple = 1; // all slides are stacked in fade mode 84 o.infiniteSlides = false; // no cloned slides 85 } 86 87 base.adj = (o.infiniteSlides) ? 0 : 1; // adjust page limits for infinite or limited modes 88 base.adjustMultiple = 0; 89 base.width = base.$el.width(); 90 base.height = base.$el.height(); 91 base.outerPad = [ base.$wrapper.innerWidth() - base.$wrapper.width(), base.$wrapper.innerHe
91ight() - base.$wrapper.height() ]; 92 if (o.playRtl) { base.$wrapper.addClass('rtl'); } 93 94 // Expand slider to fit parent 95 if (o.expand) { 96 base.$outer = base.$wrapper.parent(); 97 base.$window.css({ width: '100%', height: '100%' }); // needed for Opera 98 base.checkResize(); 99 } 100 101 // Build start/stop button 102 if (o.buildStartStop) { base.buildAutoPlay(); } 103 104 // Build forwards/backwards buttons 105 if (o.buildArrows) { base.buildNextBackButtons(); } 106 107 // can't lock autoplay it if it's not enabled 108 if (!o.autoPlay) { o.autoPlayLocked = false; } 109 110 base.$lastPage = base.$targetPage = base.$currentPage; 111 112 base.updateSlider(); 113 114 // Make sure easing function exists. 115 if (!$.isFunction($.easing[o.easing])) { o.easing = "swing"; } 116 117 // If pauseOnHover then add hover effects 118 if (o.pauseOnHover) { 119 base.$wrapper.hover(function() { 120 if (base.playing) { 121 base.$el.trigger('slideshow_paused', base); 122 base.clearTimer(true); 123 } 124 }, function() { 125 if (base.playing) { 126 base.$el.trigger('slideshow_unpaused', base); 127 base.startStop(base.playing, true); 128 } 129 }); 130 } 131 132 // Hide/Show navigation & play/stop controls 133 base.slideControls(false); 134 base.$wrapper.bind('mouseenter mouseleave', function(e){ 135 // add hovered class to outer wrapper 136 $(this)[e.type === 'mouseenter' ? 'addClass' : 'removeClass']('anythingSlider-hovered'); 137 base.hovered = (e.type === 'mouseenter') ? true : false; 138 base.slideControls(base.hovered); 139 }); 140 141 // Add keyboard navigation 142 $(document).keyup(function(e){ 143 // Stop arrow keys from working when focused on form items 144 if (o.enableKeyboard && base.$wrapper.hasClass('activeSlider') && !e.target.tagName.match('TEXTAREA|INPUT|SELECT')) { 145 if (o.mode !== 'vertical' && (e.which === 38 || e.which === 40)) { return; } 146 switch (e.which) { 147 case 39: case 40: // right & down arrow 148 base.goForward(); 149 break; 150 case 37: case 38: // left & up arrow 151 base.goBack(); 152 break; 153 } 154 } 155 }); 156 157 // If a hash can not be used to trigger the plugin, then go to start panel 158 base.currentPage = base.gotoHash() || o.startPanel || 1; 159 base.gotoPage(base.currentPage, false, null, -1); 160 161 // Binds events 162 var triggers = "slideshow_paused slideshow_unpaused slide_init slide_begin slideshow_stop slideshow_start initialized swf_completed".split(" "); 163 $.each("onShowPause onShowUnpause onSlideInit onSlideBegin onShowStop onShowStart onInitialized onSWFComplete".split(" "), function(i,f){ 164 if ($.isFunction(o[f])){ 165 base.$el.bind(triggers[i], o[f]); 166 } 167 }); 168 if ($.isFunction(o.onSlideComplete)){ 169 // Added setTimeout (zero time) to ensure animation is complete... see this bug report: http://bugs.jquery.com/ticket/7157 170 base.$el.bind('slide_complete', function(){ 171 setTimeout(function(){ o.onSlideComplete(base); }, 0); 172 return false; 173 }); 174 } 175 base.initialized = true; 176 base.$el.trigger('initialized', base); 177 178 // trigger the slideshow 179 base.startStop(o.autoPlay); 180 181 }; 182 183 // called during initialization & to update the slider if a panel is added or deleted 184 base.updateSlider = function(){ 185 // needed for updating the slider 186 base.$el.children('.cloned').remove(); 187 base.navTextVisible = base.$nav.find('span:first').css('visibility') !== 'hidden'; 188 base.$nav.empty(); 189 // set currentPage to 1 in case it was zero - occurs when adding slides after removing them all 190 base.currentPage = base.currentPage || 1; 191 192 base.$items = base.$el.children(); 193 base.pages = base.$items.length; 194 base.dir = (o.mode === 'vertical') ? 'top' : 'left'; 195 o.showMultiple = (o.mode === 'vertical') ? 1 : parseInt(o.showMultiple,10) || 1; // only integers allowed 196 o.navigationSize = (o.navigationSize === false) ? 0 : parseInt(o.navigationSize,10) || 0; 197 198 // Fix tabbing through the page, but don't change the view if the link is in view (showMultiple = true) 199 base.$items.find('a').unbind('focus.AnythingSlider').bind('focus.AnythingSlider', function(e){
200 var panel = $(this).closest('.panel'), 201 indx = base.$items.index(panel) + base.adj; // index can be -1 in nested sliders - issue #208 202 base.$items.find('.focusedLink').removeClass('focusedLink'); 203 $(this).addClass('focusedLink'); 204 base.$window.scrollLeft(0).scrollTop(0); 205 if ( ( indx !== -1 && (indx >= base.currentPage + o.showMultiple || indx < base.currentPage) ) ) { 206 base.gotoPage(indx); 207 e.preventDefault(); 208 } 209 }); 210 if (o.showMultiple > 1) { 211 if (o.showMultiple > base.pages) { o.showMultiple = base.pages; } 212 base.adjustMultiple = (o.infiniteSlides && base.pages > 1) ? 0 : o.showMultiple - 1; 213 } 214 215 // Hide navigation & player if there is only one page 216 base.$controls 217 .add(base.$nav) 218 .add(base.$startStop) 219 .add(base.$forward) 220 .add(base.$back)[(base.pages <= 1) ? 'hide' : 'show'](); 221 if (base.pages > 1) { 222 // Build/update navigation tabs 223 base.buildNavigation(); 224 } 225 226 // Top and tail the list with 'visible' number of items, top has the last section, and tail has the first 227 // This supports the "infinite" scrolling, also ensures any cloned elements don't duplicate an ID 228 // Moved removeAttr before addClass otherwise IE7 ignores the addClass: http://bugs.jquery.com/ticket/9871 229 if (o.mode !== 'fade' && o.infiniteSlides && base.pages > 1) { 230 base.$el.prepend( base.$items.filter(':last').clone().addClass('cloned') ); 231 // Add support for multiple sliders shown at the same time 232 if (o.showMultiple > 1) { 233 base.$el.append( base.$items.filter(':lt(' + o.showMultiple + ')').clone().addClass('cloned multiple') ); 234 } else { 235 base.$el.append( base.$items.filter(':first').clone().addClass('cloned') ); 236 } 237 base.$el.find('.cloned').each(function(){ 238 // disable all focusable elements in cloned panels to prevent shifting the panels by tabbing 239 $(this).find('a,input,textarea,select,button,area,form').attr({ disabled : 'disabled', name : '' }); 240 $(this).find('[id]').andSelf().removeAttr('id'); 241 }); 242 } 243 244 // We just added two items, time to re-cache the list, then get the dimensions of each panel 245 base.$items = base.$el.addClass(o.mode).children().addClass('panel'); 246 base.setDimensions(); 247 248 // Set the dimensions of each panel 249 if (o.resizeContents) { 250 base.$items.css('width', base.width); 251 base.$wrapper 252 .css('width', base.getDim(base.currentPage)[0]) 253 .add(base.$items).css('height', base.height); 254 } else { 255 base.$win.load(function(){ 256 // set dimensions after all images load 257 base.setDimensions(); 258 // make sure the outer wrapper is set properly 259 t = base.getDim(base.currentPage); 260 base.$wrapper.css({ width: t[0], height: t[1] }); 261 base.setCurrentPage(base.currentPage, false); 262 }); 263 } 264 265 if (base.currentPage > base.pages) { 266 base.currentPage = base.pages; 267 } 268 base.setCurrentPage(base.currentPage, false); 269 base.$nav.find('a').eq(base.currentPage - 1).addClass('cur'); // update current selection 270 271 if (o.mode === 'fade') { 272 var t = base.$items.eq(base.currentPage-1); 273 if (o.resumeOnVisible) { 274 // prevent display: none; 275 t.css({ opacity: 1 }).siblings().css({ opacity: 0 }); 276 } else { 277 // allow display: none; - resets video 278 base.$items.css('opacity',1); 279 t.fadeIn(0).siblings().fadeOut(0); 280 } 281 } 282 283 }; 284 285 // Creates the numbered navigation links 286 base.buildNavigation = function() { 287 if (o.buildNavigation && (base.pages > 1)) { 288 var a, c, i, t, $li; 289 base.$items.filter(':not(.cloned)').each(function(j){ 290 $li = $('<li/>'); 291 i = j + 1; 292 c = (i === 1 ? ' first' : '') + (i === base.pages ? ' last' : ''); 293 a = '<a class="panel' + i + ( base.navTextVisible ? '"' : ' ' + o.tooltipClass + '" title="@"' ) + ' href="#"><span>@</span></a>'; 294 // If a formatter function is present, use it 295 if ($.isFunction(o.navigationFormatter)) { 296 t = o.navigationFormatter(i, $(this)); 297 if (typeof(t) === "string") { 298 $li.html(a.replace(/@/g,t)); 299 } else { 300 $li = $('<li/>', t); 301 } 302 } else { 303 $li.html(a.replace(/@/g,i)); 304 } 305 $li 306 .appendTo(base.$nav) 307 .addClass(c) 308 .data('index', i); 309 }); 310 base.$nav.children('li').bind(o.clickControls, function(e) { 311 if (!base.flag && o.enableNavigation) { 312 // prevent running functions twice (once for click, second time for focusin) 313 base.flag = true; setTimeout(function(){ base.flag = false; }, 100); 314 base.gotoPage( $(this).data('index') ); 315 } 316 e.preventDefault(); 317 }); 318 319 // Add navigation tab scrolling - use !! in case someone sets the size to zero 320 if (!!o.navigationSize && o.navigationSize < base.pages) { 321 if (!base.$controls.find('.anythingNavWindow').length){ 322 base.$nav 323 .before('<ul><li class="prev"><a href="#"><span>' + o.backText + '</span></a></li></ul>') 324 .after('<ul><li class="next"><a href="#"><span>' + o.forwardText + '</span></a></li></ul>') 325 .wrap('<div class="anythingNavWindow"></div>'); 326 } 327 // include half of the left position to include extra width from themes like tabs-light and tabs-dark (still not perfect) 328 base.navWidths = base.$nav.find('li').map(function(){
329 return $(this).outerWidth(true) + Math.ceil(parseInt($(this).find('span').css('left'),10)/2 || 0); 330 }).get(); 331 base.navLeft = base.currentPage; 332 // add 25 pixels (old IE needs more than 5) to make sure the tabs don't wrap to the next line 333 base.$nav.width( base.navWidth( 1, base.pages + 1 ) + 25 ); 334 base.$controls.find('.anythingNavWindow') 335 .width( base.navWidth( 1, o.navigationSize + 1 ) ).end() 336 .find('.prev,.next').bind(o.clickControls, function(e) { 337 if (!base.flag) { 338 base.flag = true; setTimeout(function(){ base.flag = false; }, 200); 339 base.navWindow( base.navLeft + o.navigationSize * ( $(this).is('.prev') ? -1 : 1 ) ); 340 } 341 e.preventDefault(); 342 }); 343 } 344 345 } 346 }; 347 348 base.navWidth = function(x,y){ 349 var i, s = Math.min(x,y), 350 e = Math.max(x,y), 351 w = 0; 352 for (i = s; i < e; i++) { 353 w += base.navWidths[i-1] || 0; 354 } 355 return w; 356 }; 357 358 base.navWindow = function(n){ 359 if (!!o.navigationSize && o.navigationSize < base.pages && base.navWidths) { 360 var p = base.pages - o.navigationSize + 1; 361 n = (n <= 1) ? 1 : (n > 1 && n < p) ? n : p; 362 if (n !== base.navLeft) { 363 base.$controls.find('.anythingNavWindow').animate( 364 { scrollLeft: base.navWidth(1, n), width: base.navWidth(n, n + o.navigationSize) }, 365 { queue: false, duration: o.animationTime }); 366 base.navLeft = n; 367 } 368 } 369 }; 370 371 // Creates the Forward/Backward buttons 372 base.buildNextBackButtons = function() { 373 base.$forward = $('<span class="arrow forward"><a href="#"><span></span></a></span>'); 374 base.$back = $('<span class="arrow back"><a href="#"><span></span></a></span>'); 375 376 // Bind to the forward and back buttons 377 base.$back.bind(o.clickBackArrow, function(e) { 378 // prevent running functions twice (once for click, second time for swipe) 379 if (o.enableArrows && !base.flag) { 380 base.flag = true; setTimeout(function(){ base.flag = false; }, 100); 381 base.goBack(); 382 } 383 e.preventDefault(); 384 }); 385 base.$forward.bind(o.clickForwardArrow, function(e) { 386 // prevent running functions twice (once for click, second time for swipe) 387 if (o.enableArrows && !base.flag) { 388 base.flag = true; setTimeout(function(){ base.flag = false; }, 100); 389 base.goForward(); 390 } 391 e.preventDefault(); 392 }); 393 // using tab to get to arrow links will show they have focus (outline is disabled in css) 394 base.$back.add(base.$forward).find('a').bind('focusin focusout',function(){ 395 $(this).toggleClass('hover'); 396 }); 397 398 // Append elements to page 399 base.$back.appendTo( (o.appendBackTo && $(o.appendBackTo).length) ? $(o.appendBackTo) : base.$wrapper ); 400 base.$forward.appendTo( (o.appendForwardTo && $(o.appendForwardTo).length) ? $(o.appendForwardTo) : base.$wrapper ); 401 402 base.arrowWidth = base.$forward.width(); // assuming the left & right arrows are the same width - used for toggle 403 base.arrowRight = parseInt(base.$forward.css('right'), 10); 404 base.arrowLeft = parseInt(base.$back.css('left'), 10); 405 406 }; 407 408 // Creates the Start/Stop button 409 base.buildAutoPlay = function(){ 410 base.$startStop 411 .html('<span>' + (base.playing ? o.stopText : o.startText) + '</span>') 412 .bind(o.clickSlideshow, function(e) { 413 if (o.enableStartStop) { 414 base.startStop(!base.playing); 415 base.makeActive(); 416 if (base.playing && !o.autoPlayDelayed) { 417 base.goForward(true); 418 } 419 } 420 e.preventDefault(); 421 }) 422 // show button has focus while tabbing 423 .bind('focusin focusout',function(){ 424 $(this).toggleClass('hover'); 425 }); 426 }; 427 428 // Adjust slider dimensions on parent element resize 429 base.checkResize = function(stopTimer){ 430 clearTimeout(base.resizeTimer); 431 base.resizeTimer = setTimeout(function(){ 432 var w = base.$outer.width() - base.outerPad[0], 433 h = (base.$outer[0].tagName === "BODY" ? base.$win.height() : base.$outer.height()) - base.outerPad[1]; 434 // base.width = width of one panel, so multiply by # of panels; outerPad is padding added for arrows. 435 if (base.width * o.showMultiple !== w || base.height !== h) { 436 base.setDimensions(); // adjust panel sizes 437 // make sure page is lined up (use -1 animation time, so we can differeniate it from when animationTime = 0) 438 base.gotoPage(base.currentPage, base.playing, null, -1); 439 } 440 if (typeof(stopTimer) === 'undefined'){ base.checkResize(); } 441 }, 500); 442 }; 443 444 // Set panel dimensions to either resize content or adjust panel to content 445 base.setDimensions = function(){ 446 var w, h, c, t, edge = 0, 447 fullsize = { width: '100%', height: '100%' }, 448 // determine panel width 449 pw = (o.showMultiple > 1) ? base.width || base.$window.width()/o.showMultiple : base.$window.width(), 450 winw = base.$win.width(); 451 if (o.expand){ 452 w = base.$outer.width() - base.outerPad[0];
453 base.height = h = base.$outer.height() - base.outerPad[1]; 454 base.$wrapper.add(base.$window).add(base.$items).css({ width: w, height: h }); 455 base.width = pw = (o.showMultiple > 1) ? w/o.showMultiple : w; 456 } 457 base.$items.each(function(i){ 458 t = $(this); 459 c = t.children(); 460 if (o.resizeContents){ 461 // resize panel 462 w = base.width; 463 h = base.height; 464 t.css({ width: w, height: h }); 465 if (c.length) { 466 if (c[0].tagName === "EMBED") { c.attr(fullsize); } // needed for IE7; also c.length > 1 in IE7 467 if (c[0].tagName === "OBJECT") { c.find('embed').attr(fullsize); } 468 // resize panel contents, if solitary (wrapped content or solitary image) 469 if (c.length === 1){ c.css(fullsize); } 470 } 471 } else { 472 // get panel width & height and save it 473 w = t.width() || base.width; // if image hasn't finished loading, width will be zero, so set it to base width instead 474 if (c.length === 1 && w >= winw){ 475 w = (c.width() >= winw) ? pw : c.width(); // get width of solitary child 476 c.css('max-width', w); // set max width for all children 477 } 478 t.css('width', w); // set width of panel 479 h = (c.length === 1 ? c.outerHeight(true) : t.height()); // get height after setting width 480 if (h <= base.outerPad[1]) { h = base.height; } // if height less than the outside padding, then set it to the preset height 481 t.css('height', h); 482 } 483 base.panelSize[i] = [w,h,edge]; 484 edge += (o.mode === 'vertical') ? h : w; 485 }); 486 // Set total width of slider 487 base.$el.css((o.mode === 'vertical' ? 'height' : 'width'), o.mode === 'fade' ? base.width : edge ); 488 }; 489 490 // get dimension of multiple panels, as needed 491 base.getDim = function(page){ 492 var i, w = base.width, h = base.height; 493 if (base.pages < 1 || isNaN(page)) { return [ w, h ]; } // prevent errors when base.panelSize is empty 494 page = (o.infiniteSlides && base.pages > 1) ? page : page - 1; 495 i = base.panelSize[page]; 496 if (i) { 497 w = i[0] || w; 498 h = i[1] || h; 499 } 500 if (o.showMultiple > 1) { 501 for (i=1; i < o.showMultiple; i++) { 502 w += base.panelSize[(page + i)][0]; 503 h = Math.max(h, base.panelSize[page + i][1]); 504 } 505 } 506 return [w,h]; 507 }; 508 509 base.goForward = function(autoplay) { 510 // targetPage changes before animation so if rapidly changing pages, it will have the correct current page 511 base.gotoPage(base[ o.allowRapidChange ? 'targetPage' : 'currentPage'] + o.changeBy * (o.playRtl ? -1 : 1), autoplay); 512 }; 513 514 base.goBack = function(autoplay) { 515 base.gotoPage(base[ o.allowRapidChange ? 'targetPage' : 'currentPage'] + o.changeBy * (o.playRtl ? 1 : -1), autoplay); 516 }; 517 518 base.gotoPage = function(page, autoplay, callback, time) { 519 if (autoplay !== true) { 520 autoplay = false; 521 base.startStop(false); 522 base.makeActive(); 523 } 524 // check if page is an id or class name 525 if (/^[#|.]/.test(page) && $(page).length) { 526 page = $(page).closest('.panel').index() + base.adj; 527 } 528 529 // rewind effect occurs here when changeBy > 1 530 if (o.changeBy !== 1){ 531 var adj = base.pages - base.adjustMultiple; 532 if (page < 1) { 533 page = o.stopAtEnd ? 1 : ( o.infiniteSlides ? base.pages + page : ( o.showMultiple > 1 - page ? 1 : adj ) ); 534 } 535 if (page > base.pages) { 536 // 537 page = o.stopAtEnd ? base.pages : ( o.showMultiple > 1 - page ? 1 : page -= adj ); 538 } else if (page >= adj) { 539 // show multiple adjustments 540 page = adj; 541 } 542 } 543 544 if (base.pages <= 1) { return; } // prevents animation 545 base.$lastPage = base.$currentPage; 546 if (typeof(page) !== "number") { 547 page = parseInt(page,10) || o.startPanel; 548 base.setCurrentPage(page); 549 } 550 551 // pause YouTube videos before scrolling or prevent change if playing 552 if (autoplay && o.isVideoPlaying(base)) { return; } 553 554 base.exactPage = page; 555 if (page > base.pages + 1 - base.adj) { page = (!o.infiniteSlides && !o.stopAtEnd) ? 1 : base.pages; } 556 if (page < base.adj ) { page = (!o.infiniteSlides && !o.stopAtEnd) ? base.pages : 1; } 557 if (!o.infiniteSlides) { base.exactPage = page; } // exact page used by the fx extension 558 base.currentPage = ( page > base.pages ) ? base.pages : ( page < 1 ) ? 1 : base.currentPage; 559 base.$currentPage = base.$items.eq(base.currentPage - base.adj); 560 base.targetPage = (page === 0) ? base.pages : (page > base.pages) ? 1 : page; 561 base.$targetPage = base.$items.eq(base.targetPage - base.adj); 562 time = typeof time !== 'undefined' ? time : o.animationTime; 563 // don't trigger events when time < 0 - to prevent FX from firing multiple times on page resize 564 if (time >= 0) { base.$el.trigger('slide_init', base); }
565 // toggle arrows/controls only if there is time to see it - fix issue #317 566 if (time > 0) { base.slideControls(true); } 567 568 // Set visual 569 if (o.buildNavigation){ 570 base.setNavigation(base.targetPage); 571 } 572 573 // When autoplay isn't passed, we stop the timer 574 if (autoplay !== true) { autoplay = false; } 575 // Stop the slider when we reach the last page, if the option stopAtEnd is set to true 576 if (!autoplay || (o.stopAtEnd && page === base.pages)) { base.startStop(false); } 577 578 if (time >= 0) { base.$el.trigger('slide_begin', base); } 579 580 // delay starting slide animation 581 setTimeout(function(d){ 582 var p, empty = true; 583 if (o.allowRapidChange) { 584 base.$wrapper.add(base.$el).add(base.$items).stop(true, true); 585 } 586 // resize slider if content size varies 587 if (!o.resizeContents) { 588 // animating the wrapper resize before the window prevents flickering in Firefox 589 // don't animate the dimension if it hasn't changed - fix for issue #264 590 p = base.getDim(page); d = {}; 591 // prevent animating a dimension to zero 592 if (base.$wrapper.width() !== p[0]) { d.width = p[0] || base.width; empty = false; } 593 if (base.$wrapper.height() !== p[1]) { d.height = p[1] || base.height; empty = false; } 594 if (!empty) { 595 base.$wrapper.filter(':not(:animated)').animate(d, { queue: false, duration: (time < 0 ? 0 : time), easing: o.easing }); 596 } 597 } 598 599 if (o.mode === 'fade') { 600 if (base.$lastPage[0] !== base.$targetPage[0]) { 601 base.fadeIt( base.$lastPage, 0, time ); 602 base.fadeIt( base.$targetPage, 1, time, function(){ base.endAnimation(page, callback, time); }); 603 } else { 604 base.endAnimation(page, callback, time); 605 } 606 } else { 607 d = {}; 608 d[base.dir] = -base.panelSize[(o.infiniteSlides && base.pages > 1) ? page : page - 1][2]; 609 // Animate Slider 610 base.$el.filter(':not(:animated)').animate( 611 d, { queue: false, duration: time < 0 ? 0 : time, easing: o.easing, complete: function(){ base.endAnimation(page, callback, time); } } 612 ); 613 } 614 }, parseInt(o.delayBeforeAnimate, 10) || 0); 615 }; 616 617 base.endAnimation = function(page, callback, time){ 618 if (page === 0) { 619 base.$el.css( base.dir, o.mode === 'fade' ? 0 : -base.panelSize[base.pages][2]); 620 page = base.pages; 621 } else if (page > base.pages) { 622 // reset back to start position 623 base.$el.css( base.dir, o.mode === 'fade' ? 0 : -base.panelSize[1][2]); 624 page = 1; 625 } 626 base.exactPage = page; 627 base.setCurrentPage(page, false); 628 629 if (o.mode === 'fade') { 630 // make sure non current panels are hidden (rapid slide changes) 631 base.fadeIt( base.$items.not(':eq(' + (page - base.adj) + ')'), 0, 0); 632 } 633 634 if (!base.hovered) { base.slideControls(false); } 635 636 if (o.hashTags) { base.setHash(page); } 637 638 if (time >= 0) { base.$el.trigger('slide_complete', base); } 639 // callback from external slide control: $('#slider').anythingSlider(4, function(slider){ }) 640 if (typeof callback === 'function') { callback(base); } 641 642 // Continue slideshow after a delay 643 if (o.autoPlayLocked && !base.playing) { 644 setTimeout(function(){ 645 base.startStop(true); 646 // subtract out slide delay as the slideshow waits that additional time. 647 }, o.resumeDelay - (o.autoPlayDelayed ? o.delay : 0)); 648 } 649 }; 650 651 base.fadeIt = function(el, toOpacity, time, callback){ 652 var t = time < 0 ? 0 : time; 653 if (o.resumeOnVisible) { 654 el.filter(':not(:animated)').fadeTo(t, toOpacity, callback); 655 } else { 656 el.filter(':not(:animated)')[ toOpacity === 0 ? 'fadeOut' : 'fadeIn' ](t, callback); 657 } 658 }; 659 660 base.setCurrentPage = function(page, move) { 661 page = parseInt(page, 10); 662 663 if (base.pages < 1 || page === 0 || isNaN(page)) { return; } 664 if (page > base.pages + 1 - base.adj) { page = base.pages - base.adj; } 665 if (page < base.adj ) { page = 1; } 666 667 // hide/show arrows based on infinite scroll mode 668 if (o.buildArrows && !o.infiniteSlides && o.stopAtEnd){ 669 base.$forward[ page === base.pages - base.adjustMultiple ? 'addClass' : 'removeClass']('disabled'); 670 base.$back[ page === 1 ? 'addClass' : 'removeClass']('disabled'); 671 if (page === base.pages && base.playing) { base.startStop(); } 672 } 673 674 // Only change left if move does not equal false 675 if (!move) { 676 var d = base.getDim(page); 677 base.$wrapper 678 .css({ width: d[0], height: d[1] }) 679 .add(base.$window).scrollLeft(0).scrollTop(0); // reset in case tabbing changed this scrollLeft - probably overly redundant 680 base.$el.css( base.dir, o.mode === 'fade' ? 0 : -base.panelSize[(o.infiniteSlides && base.pages > 1) ? page : page - 1][2] ); 681 } 682 683 // Update local variable 684 base.currentPage = page; 685 base.$currentPage = base.$items.removeClass('activePage').eq(page - base.adj).addClass('activePage'); 686 687 if (o.buildNavigation){ 688 base.setNavigation(page); 689 } 690 691 }; 692 693 base.setNavigation = function(page){ 694 base.$nav 695 .find('.cur').removeClass('cur').end() 696 .find('a').eq(page - 1).addClass('cur'); 697 }; 698 699 base.makeActive = function(){ 700 // Set current slider as active so keyboard navigation works properly 701 if (!base.$wrapper.hasClass('activeSlider')){ 702 $('.activeSlider').removeClass('activeSlider'); 703 base.$wrapper.addClass('activeSlider'); 704 } 705 }; 706 707 // This method tries to find a hash that matches an ID and panel-X 708 // If either found, it tries to find a matching item 709 // If that is found as well, then it returns the page number 710 base.gotoHash = function(){ 711 var h = base.win.location.hash, 712 i = h.indexOf('&'), 713 n = h.match(base.regex); 714 // test for "/#/" or "/#!/" used by the jquery address plugin - $('#/') breaks jQuery 715 if (n === null && !/^#&/.test(h) && !/#!?\//.test(h)) { 716 // #quote2&panel1-3&panel3-3 717 h = h.substring(0, (i >= 0 ? i : h.length)); 718 // ensure the element is in the same slider 719 n = ($(h).length && $(h).closest('.anythingBase')[0] === base.el) ? base.$items.index($(h).closest('.panel')) + base.adj : null; 720 } else if (n !== null) { 721 // #&panel1-3&panel3-3 722 n = (o.hashTags) ? parseInt(n[1],10) : null; 723 } 724 return n; 725 }; 726 727 base.setHash = function(n){ 728 var s = 'panel' + base.runTimes + '-', 729 h = base.win.location.hash; 730 if ( typeof h !== 'undefined' ) { 731 base.win.location.hash = (h.indexOf(s) > 0) ? h.replace(base.regex, s + n) : h + "&" + s + n; 732 } 733 }; 734 735 // Slide controls (nav and play/stop button up or down) 736 base.slideControls = function(toggle){ 737 var dir = (toggle) ? 'slideDown' : 'slideUp', 738 t1 = (toggle) ? 0 : o.animationTime, 739 t2 = (toggle) ? o.animationTime : 0, 740 op = (toggle) ? 1 : 0, 741 sign = (toggle) ? 0 : 1; // 0 = visible, 1 = hidden 742 if (o.toggleControls) { 743 base.$controls.stop(true,true).delay(t1)[dir](o.animationTime/2).delay(t2); 744 } 745 if (o.buildArrows && o.toggleArrows) { 746 if (!base.hovered && base.playing) { sign = 1; op = 0; } // don't animate arrows during slideshow 747 base.$forward.stop(true,true).delay(t1).animate({ right: base.arrowRight + (sign * base.arrowWidth), opacity: op }, o.animationTime/2); 748 base.$back.stop(true,true).delay(t1).animate({ left: base.arrowLeft + (sign * base.arrowWidth), opacity: op }, o.animationTime/2); 749 } 750 }; 751 752 base.clearTimer = function(paused){ 753 // Clear the timer only if it is set 754 if (base.timer) { 755 base.win.clearInterval(base.timer); 756 if (!paused && base.slideshow) { 757 base.$el.trigger('slideshow_stop', base); 758 base.slideshow = false; 759 } 760 } 761 }; 762 763 // Pass startStop(false) to stop and startStop(true) to play 764 base.startStop = function(playing, paused) { 765 if (playing !== true) { playing = false; } // Default if not supplied is false 766 base.playing = playing; 767 768 if (playing && !paused) { 769 base.$el.trigger('slideshow_start', base); 770 base.slideshow = true; 771 } 772 773 // Toggle playing and text 774 if (o.buildStartStop) { 775 base.$startStop.toggleClass('playing', playing).find('span').html( playing ? o.stopText : o.startText ); 776 // add button text to title attribute if it is hidden by text-indent 777 if ( base.$startStop.find('span').css('visibility') === "hidden" ) { 778 base.$startStop.addClass(o.tooltipClass).attr( 'title', playing ? o.stopText : o.startText ); 779 } 780 } 781 782 // Pause slideshow while video is playing 783 if (playing){ 784 base.clearTimer(true); // Just in case this was triggered twice in a row 785 base.timer = base.win.setInterval(function() { 786 // prevent autoplay if video is playing 787 if ( !o.isVideoPlaying(base) ) { 788 base.goForward(true); 789 // stop slideshow if resume if false 790 } else if (!o.resumeOnVideoEnd) { 791 base.startStop(); 792 } 793 }, o.delay); 794 } else { 795 base.clearTimer(); 796 } 797 }; 798
799 // Trigger the initialization 800 base.init(); 801 }; 802 803 $.anythingSlider.defaults = { 804 // Appearance 805 theme : "default", // Theme name, add the css stylesheet manually 806 mode : "horiz", // Set mode to "horizontal", "vertical" or "fade" (only first letter needed); replaces vertical option 807 expand : true, // If true, the entire slider will expand to fit the parent element 808 resizeContents : true, // If true, solitary images/objects in the panel will expand to fit the viewport 809 showMultiple : false, // Set this value to a number and it will show that many slides at once 810 easing : "swing", // Anything other than "linear" or "swing" requires the easing plugin or jQuery UI 811 812 buildArrows : true, // If true, builds the forwards and backwards buttons 813 buildNavigation : true, // If true, builds a list of anchor links to link to each panel 814 buildStartStop : true, // ** If true, builds the start/stop button 815 816/* 817 // commented out as this will reduce the size of the minified version 818 appendForwardTo : null, // Append forward arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null 819 appendBackTo : null, // Append back arrow to a HTML element (jQuery Object, selector or HTMLNode), if not null 820 appendControlsTo : null, // Append controls (navigation + start-stop) to a HTML element (jQuery Object, selector or HTMLNode), if not null 821 appendNavigationTo : null, // Append navigation buttons to a HTML element (jQuery Object, selector or HTMLNode), if not null 822 appendStartStopTo : null, // Append start-stop button to a HTML element (jQuery Object, selector or HTMLNode), if not null 823*/ 824 825 toggleArrows : false, // If true, side navigation arrows will slide out on hovering & hide @ other times 826 toggleControls : false, // if true, slide in controls (navigation + play/stop button) on hover and slide change, hide @ other times 827 828 startText : "Start", // Start button text 829 stopText : "Stop", // Stop button text 830 forwardText : "→", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image) 831 backText : "←", // Link text used to move the slider back (hidden by CSS, replace with arrow image) 832 tooltipClass : "tooltip", // Class added to navigation & start/stop button (text copied to title if it is hidden by a negative text indent) 833 834 // Function 835 enableArrows : true, // if false, arrows will be visible, but not clickable. 836 enableNavigation : true, // if false, navigation links will still be visible, but not clickable. 837 enableStartStop : true, // if false, the play/stop button will still be visible, but not clickable. Previously "enablePlay" 838 enableKeyboard : true, // if false, keyboard arrow keys will not work for this slider. 839 840 // Navigation 841 startPanel : 1, // This sets the initial panel 842 changeBy : 1, // Amount to go forward or back when changing panels. 843 hashTags : false, // Should links change the hashtag in the URL? 844 infiniteSlides : true, // if false, the slider will not wrap & not clone any panels 845 navigationFormatter : null, // Details at the top of the file on this use (advanced use) 846 navigationSize : false, // Set this to the maximum number of visible navigation tabs; false to disable 847 848 // Slideshow options 849 autoPlay : false, // If true, the slideshow will start running; replaces "startStopped" option 850 autoPlayLocked : false, // If true, user changing slides will not stop the slideshow 851 autoPlayDelayed : false, // If true, starting a slideshow will delay advancing slides; if false, the slider will immediately advance to the next slide when slideshow starts 852 pauseOnHover : true, // If true & the slideshow is active, the slideshow will pause on hover 853 stopAtEnd : false, // If true & the slideshow is active, the slideshow will stop on the last page. This also stops the rewind effect when infiniteSlides is false. 854 playRtl : false, // If true, the slideshow will move right-to-left 855 856 // Times 857 delay : 3000, // How long between slideshow transitions in AutoPlay mode (in milliseconds) 858 resumeDelay : 15000, // Resume slideshow after user interaction, only if autoplayLocked is true (in milliseconds). 859 animationTime : 600, // How long the slideshow transition takes (in milliseconds) 860 delayBeforeAnimate : 0, // How long to pause slide animation before going to the desired slide (used if you want your "out" FX to show). 861 862/* 863 // Callbacks - commented out to reduce size of the minified version - they still work 864 onBeforeInitialize : function(e, slider) {}, // Callback before the plugin initializes 865 onInitialized : function(e, slider) {}, // Callback when the plugin finished initializing 866 onShowStart : function(e, slider) {}, // Callback on slideshow start 867 onShowStop : function(e, slider) {}, // Callback after slideshow stops 868 onShowPause : function(e, slider) {}, // Callback when slideshow pauses 869 onShowUnpause : function(e, slider) {}, // Callback when slideshow unpauses - may not trigger properly if user clicks on any controls 870 onSlideInit : function(e, slider) {}, // Callback when slide initiates, before control animation 871 onSlideBegin : function(e, slider) {}, // Callback before slide animates 872 onSlideComplete : function(slider) {}, // Callback when slide completes - no event variable! 873*/ 874 875 // Interactivity 876 clickForwardArrow : "click", // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight") 877 clickBackArrow : "click", // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft") 878 clickControls : "click focusin", // Events used to activate navigation control functionality 879 clickSlideshow : "click", // Event used to activate slideshow play/stop button 880 allowRapidChange : false, // If true, allow rapid changing of the active pane, instead of ignoring activity during animation 881 882 // Video 883 resumeOnVideoEnd : true, // If true & the slideshow is active & a supported video is playing, it will pause the autoplay until the video is complete 884 resumeOnVisible : true, // If true the video will resume playing (if previously paused, except for YouTube iframe - known issue); if false, the video remains paused. 885 addWmodeToObject : "opaque", // If your slider has an embedded object, the script will automatically add a wmode parameter with this setting 886 isVideoPlaying : function(base){ return false; } // return true if video is playing or false if not - used by video extension 887 888 }; 889 890 $.fn.anythingSlider = function(options, callback) { 891 892 return this.each(function(){ 893 var page, anySlide = $(this).data('AnythingSlider'); 894 895 // initialize the slider but prevent multiple initializations 896 if ((typeof(options)).match('object|undefined')){ 897 if (!anySlide) { 898 (new $.anythingSlider(this, options)); 899 } else { 900 anySlide.updateSlider(); 901 } 902 // If options is a number, process as an external link to page #: $(element).anythingSlider(#) 903 } else if (/\d/.test(options) && !isNaN(options) && anySlide) {
904 page = (typeof(options) === "number") ? options : parseInt($.trim(options),10); // accepts " 2 " 905 // ignore out of bound pages 906 if ( page >= 1 && page <= anySlide.pages ) { 907 anySlide.gotoPage(page, false, callback); // page #, autoplay, one time callback 908 } 909 // Accept id or class name 910 } else if (/^[#|.]/.test(options) && $(options).length) { 911 anySlide.gotoPage(options, false, callback); 912 } 913 }); 914 }; 915 916})(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.