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