1 2/** 3 * @file 4 * A simple jQuery Cycle Div Slideshow Rotator. 5 */ 6 7/** 8 * This will set our initial behavior, by starting up each individual slideshow. 9 */ 10(function ($) { 11 Backdrop.behaviors.viewsSlideshowCycle = { 12 attach: function (context) { 13 $('.views_slideshow_cycle_main:not(.viewsSlideshowCycle-processed)', context).addClass('viewsSlideshowCycle-processed').each(function() { 14 var fullId = '#' + $(this).attr('id'); 15 var settings = Backdrop.settings.viewsSlideshowCycle[fullId]; 16 settings.targetId = '#' + $(fullId + " :first").attr('id'); 17 18 settings.slideshowId = settings.targetId.replace('#views_slideshow_cycle_teaser_section_', ''); 19 // Pager after function. 20 var pager_after_fn = function(curr, next, opts) { 21 // Need to do some special handling on first load. 22 var slideNum = opts.currSlide; 23 if (typeof settings.processedAfter == 'undefined' || !settings.processedAfter) { 24 settings.processedAfter = 1; 25 slideNum = (typeof settings.opts.startingSlide == 'undefined') ? 0 : settings.opts.startingSlide; 26 } 27 Backdrop.viewsSlideshow.action({ "action": 'transitionEnd', "slideshowID": settings.slideshowId, "slideNum": slideNum }); 28 } 29 // Pager before function. 30 var pager_before_fn = function(curr, next, opts) { 31 var slideNum = opts.nextSlide; 32 33 // Remember last slide. 34 if (settings.remember_slide) { 35 createCookie(settings.vss_id, slideNum, settings.remember_slide_days); 36 } 37 38 // Make variable height. 39 if (!settings.fixed_height) { 40 //get the height of the current slide 41 var $ht = $(next).height(); 42 //set the container's height to that of the current slide 43 $(next).parent().animate({height: $ht}); 44 } 45 46 // Need to do some special handling on first load. 47 if (typeof settings.processedBefore == 'undefined' || !settings.processedBefore) { 48 settings.processedBefore = 1; 49 slideNum = (typeof opts.startingSlide == 'undefined') ? 0 : opts.startingSlide; 50 } 51 52 Backdrop.viewsSlideshow.action({ "action": 'transitionBegin', "slideshowID": settings.slideshowId, "slideNum": slideNum }); 53 } 54 settings.loaded = false; 55 56 settings.opts = { 57 speed:settings.speed, 58 timeout:settings.timeout, 59 delay:settings.delay, 60 sync:settings.sync, 61 random:settings.random, 62 nowrap:settings.nowrap, 63 after:pager_after_fn, 64 before:pager_before_fn, 65 cleartype:(settings.cleartype)? true : false, 66 cleartypeNoBg:(settings.cleartypenobg)? true : false 67 } 68 69 // Set the starting slide if we are supposed to remember the slide 70 if (settings.remember_slide) { 71 var startSlide = readCookie(settings.vss_id); 72 if (startSlide == null) { 73 startSlide = 0; 74 } 75 settings.opts.startingSlide = parseInt(startSlide); 76 } 77 78 if (settings.effect == 'none') { 79 settings.opts.speed = 1; 80 } 81 else { 82 settings.opts.fx = settings.effect; 83 } 84 85 // Take starting item from fragment. 86 var hash = location.hash; 87 if (hash) { 88 var hash = hash.replace('#', ''); 89 var aHash = hash.split(';'); 90 var aHashLen = aHash.length; 91 92 // Loop through all the possible starting points. 93 for (var i = 0; i < aHashLen; i++) { 94 // Split the hash into two parts. One part is the slideshow id the 95 // other is the slide number. 96 var initialInfo = aHash[i].split(':'); 97 // The id in the hash should match our slideshow. 98 // The slide number chosen shouldn't be larger than the number of 99 // slides we have. 100 if (settings.slideshowId == initialInfo[0] && settings.num_divs > initialInfo[1]) { 101 settings.opts.startingSlide = parseInt(initialInfo[1]); 102 } 103 } 104 } 105 106 // Pause on hover. 107 if (settings.pause) { 108 var mouseIn = function() { 109 Backdrop.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId }); 110 } 111 112 var mouseOut = function() { 113 Backdrop.viewsSlideshow.action({ "action": 'play', "slideshowID": settings.slideshowId }); 114 } 115 116 if (jQuery.fn.hoverIntent) { 117 $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hoverIntent(mouseIn, mouseOut); 118 } 119 else { 120 $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).hover(mouseIn, mouseOut); 121 } 122 } 123 124 // Pause on clicking of the slide. 125 if (settings.pause_on_click) { 126 $('#views_slideshow_cycle_teaser_section_' + settings.vss_id).click(function() { 127 Backdrop.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId, "force": true }); 128 }); 129 } 130 131 if (typeof JSON != 'undefined') { 132 var advancedOptions = JSON.parse(settings.advanced_options); 133 for (var option in advancedOptions) { 134 switch(option) { 135 136 // Standard Options 137 case "activePagerClass": 138 case "allowPagerClickBubble": 139 case "autostop": 140 case "autostopCount": 141 case "backwards": 142 case "bounce": 143 case "cleartype": 144 case "cleartypeNoBg": 145 case "containerResize": 146 case "continuous": 147 case "delay": 148 case "easeIn": 149 case "easeOut": 150 case "easing": 151 case "fastOnEvent": 152 case "fit": 153 case "fx": 154 case "height": 155 case "manualTrump": 156 case "metaAttr": 157 case "next": 158 case "nowrap": 159 case "pager": 160 case "pagerEvent": 161 case "pause": 162 case "pauseOnPagerHover": 163 case "prev": 164 case "prevNextEvent": 165 case "random": 166 case "randomizeEffects": 167 case "requeueOnImageNotLoaded": 168 case "requeueTimeout": 169 case "rev": 170 case "slideExpr": 171 case "slideResize": 172 case "speed": 173 case "speedIn": 174 case "speedOut": 175 case "startingSlide": 176 case "sync": 177 case "timeout": 178 case "width": 179 var optionValue = advancedOptions[option]; 180 optionValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(optionValue); 181 settings.opts[option] = optionValue; 182 break; 183 184 // These process options that look like {top:50, bottom:20} 185 case "animIn": 186 case "animOut": 187 case "cssBefore": 188 case "cssAfter": 189 case "shuffle": 190 var cssValue = advancedOptions[option]; 191 cssValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(cssValue); 192 settings.opts[option] = eval('(' + cssValue + ')'); 193 break; 194 195 // These options have their own functions. 196 case "after": 197 var afterValue = advancedOptions[option]; 198 afterValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(afterValue); 199 // transition callback (scope set to element that was shown): function(currSlideElement, nextSlideElement, options, forwardFlag) 200 settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) { 201 pager_after_fn(currSlideElement, nextSlideElement, options); 202 eval(afterValue); 203 } 204 break; 205 206 case "before": 207 var beforeValue = advancedOptions[option]; 208 beforeValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(beforeValue); 209 // transition callback (scope set to element to be shown): function(currSlideElement, nextSlideElement, options, forwardFlag) 210 settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) { 211 pager_before_fn(currSlideElement, nextSlideElement, options); 212 eval(beforeValue); 213 } 214 break; 215 216 case "end": 217 var endValue = advancedOptions[option]; 218 endValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(endValue); 219 // callback invoked when the slideshow terminates (use with autostop or nowrap options): function(options) 220 settings.opts[option] = function(options) { 221 eval(endValue); 222 } 223 break; 224 225 case "fxFn": 226 var fxFnValue = advancedOptions[option]; 227 fxFnValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(fxFnValue); 228 // function used to control the transition: function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) 229 settings.opts[option] = function(currSlideElement, nextSlideElement, options, afterCalback, forwardFlag) { 230 eval(fxFnValue); 231 } 232 break; 233 234 case "onPagerEvent": 235 var onPagerEventValue = advancedOptions[option]; 236 onPagerEventValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(onPagerEventValue); 237 settings.opts[option] = function(zeroBasedSlideIndex, slideElement) { 238 eval(onPagerEventValue); 239 } 240 break; 241 242 case "onPrevNextEvent": 243 var onPrevNextEventValue = advancedOptions[option]; 244 onPrevNextEventValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(onPrevNextEventValue); 245 settings.opts[option] = function(isNext, zeroBasedSlideIndex, slideElement) { 246 eval(onPrevNextEventValue); 247 } 248 break; 249 250 case "pagerAnchorBuilder": 251 var pagerAnchorBuilderValue = advancedOptions[option]; 252 pagerAnchorBuilderValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(pagerAnchorBuilderValue); 253 // callback fn for building anchor links: function(index, DOMelement) 254 settings.opts[option] = function(index, DOMelement) { 255 var returnVal = ''; 256 eval(pagerAnchorBuilderValue); 257 return returnVal; 258 } 259 break; 260 261 case "pagerClick": 262 var pagerClickValue = advancedOptions[option]; 263 pagerClickValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(pagerClickValue); 264 // callback fn for pager clicks: function(zeroBasedSlideIndex, slideElement) 265 settings.opts[option] = function(zeroBasedSlideIndex, slideElement) { 266 eval(pagerClickValue); 267 } 268 break; 269 270 case "paused": 271 var pausedValue = advancedOptions[option]; 272 pausedValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(pausedValue); 273 // undocumented callback when slideshow is paused: function(cont, opts, byHover) 274 settings.opts[option] = function(cont, opts, byHover) { 275 eval(pausedValue); 276 } 277 break; 278 279 case "resumed": 280 var resumedValue = advancedOptions[option]; 281 resumedValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(resumedValue); 282 // undocumented callback when slideshow is resumed: function(cont, opts, byHover) 283 settings.opts[option] = function(cont, opts, byHover) { 284 eval(resumedValue); 285 } 286 break; 287 288 case "timeoutFn": 289 var timeoutFnValue = advancedOptions[option]; 290 timeoutFnValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(timeoutFnValue); 291 settings.opts[option] = function(currSlideElement, nextSlideElement, options, forwardFlag) { 292 eval(timeoutFnValue); 293 } 294 break; 295 296 case "updateActivePagerLink": 297 var updateActivePagerLinkValue = advancedOptions[option]; 298 updateActivePagerLinkValue = Backdrop.viewsSlideshowCycle.advancedOptionCleanup(updateActivePagerLinkValue); 299 // callback fn invoked to update the active pager link (adds/removes activePagerClass style) 300 settings.opts[option] = function(pager, currSlideIndex) { 301 eval(updateActivePagerLinkValue); 302 } 303 break; 304 } 305 } 306 } 307 308 // If selected wait for the images to be loaded. 309 // otherwise just load the slideshow. 310 if (settings.wait_for_image_load) { 311 // For IE/Chrome/Opera we if there are images then we need to make 312 // sure the images are loaded before starting the slideshow. 313 settings.totalImages = $(settings.targetId + ' img').length; 314 if (settings.totalImages) { 315 settings.loadedImages = 0; 316 317 // Add a load event for each image. 318 $(settings.targetId + ' img').each(function() { 319 var $imageElement = $(this); 320 $imageElement.bind('load', function () { 321 Backdrop.viewsSlideshowCycle.imageWait(fullId); 322 }); 323 324 // Removing the source and adding it again will fire the load event. 325 var imgSrc = $imageElement.attr('src'); 326 $imageElement.attr('src', ''); 327 $imageElement.attr('src', imgSrc); 328 }); 329 330 // We need to set a timeout so that the slideshow doesn't wait 331 // indefinitely for all images to load. 332 setTimeout("Backdrop.viewsSlideshowCycle.load('" + fullId + "')", settings.wait_for_image_load_timeout); 333 } 334 else { 335 Backdrop.viewsSlideshowCycle.load(fullId); 336 } 337 } 338 else { 339 Backdrop.viewsSlideshowCycle.load(fullId); 340 } 341 }); 342 } 343 }; 344 345 Backdrop.viewsSlideshowCycle = Backdrop.viewsSlideshowCycle || {}; 346 347 // Cleanup the values of advanced options. 348 Backdrop.viewsSlideshowCycle.advancedOptionCleanup = function(value) { 349 value = $.trim(value); 350 value = value.replace(/\n/g, ''); 351 if (value.match(/^[\d.]+%$/)) { 352 // noop 353 } 354 else if (!isNaN(parseInt(value))) { 355 value = parseInt(value); 356 } 357 else if (value.toLowerCase() == 'true') { 358 value = true; 359 } 360 else if (value.toLowerCase() == 'false') { 361 value = false;
362 } 363 364 return value; 365 } 366 367 // This checks to see if all the images have been loaded. 368 // If they have then it starts the slideshow. 369 Backdrop.viewsSlideshowCycle.imageWait = function(fullId) { 370 if (++Backdrop.settings.viewsSlideshowCycle[fullId].loadedImages == Backdrop.settings.viewsSlideshowCycle[fullId].totalImages) { 371 Backdrop.viewsSlideshowCycle.load(fullId); 372 } 373 }; 374 375 // Start the slideshow. 376 Backdrop.viewsSlideshowCycle.load = function (fullId) { 377 var settings = Backdrop.settings.viewsSlideshowCycle[fullId]; 378 379 // Make sure the slideshow isn't already loaded. 380 if (!settings.loaded) { 381 $(settings.targetId).cycle(settings.opts); 382 settings.loaded = true; 383 384 // Start Paused 385 if (settings.start_paused) { 386 Backdrop.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId, "force": true }); 387 } 388 389 // Pause if hidden. 390 if (settings.pause_when_hidden) { 391 var checkPause = function(settings) { 392 // If the slideshow is visible and it is paused then resume. 393 // otherwise if the slideshow is not visible and it is not paused then 394 // pause it. 395 var visible = viewsSlideshowCycleIsVisible(settings.targetId, settings.pause_when_hidden_type, settings.amount_allowed_visible); 396 if (visible) { 397 Backdrop.viewsSlideshow.action({ "action": 'play', "slideshowID": settings.slideshowId }); 398 } 399 else { 400 Backdrop.viewsSlideshow.action({ "action": 'pause', "slideshowID": settings.slideshowId }); 401 } 402 } 403 404 // Check when scrolled. 405 $(window).scroll(function() { 406 checkPause(settings); 407 }); 408 409 // Check when the window is resized. 410 $(window).resize(function() { 411 checkPause(settings); 412 }); 413 } 414 } 415 }; 416 417 Backdrop.viewsSlideshowCycle.pause = function (options) { 418 //Eat TypeError, cycle doesn't handle pause well if options isn't defined. 419 try{ 420 if (options.pause_in_middle && $.fn.pause) { 421 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).pause(); 422 } 423 else { 424 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('pause'); 425 } 426 } 427 catch(e){ 428 if(!e instanceof TypeError){ 429 throw e; 430 } 431 } 432 }; 433 434 Backdrop.viewsSlideshowCycle.play = function (options) { 435 Backdrop.settings.viewsSlideshowCycle['#views_slideshow_cycle_main_' + options.slideshowID].paused = false; 436 if (options.pause_in_middle && $.fn.resume) { 437 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).resume(); 438 } 439 else { 440 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('resume'); 441 } 442 }; 443 444 Backdrop.viewsSlideshowCycle.previousSlide = function (options) { 445 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('prev'); 446 }; 447 448 Backdrop.viewsSlideshowCycle.nextSlide = function (options) { 449 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle('next'); 450 }; 451 452 Backdrop.viewsSlideshowCycle.goToSlide = function (options) { 453 $('#views_slideshow_cycle_teaser_section_' + options.slideshowID).cycle(options.slideNum); 454 }; 455 456 // Verify that the value is a number. 457 function IsNumeric(sText) { 458 var ValidChars = "0123456789"; 459 var IsNumber=true; 460 var Char; 461 462 for (var i=0; i < sText.length && IsNumber == true; i++) { 463 Char = sText.charAt(i); 464 if (ValidChars.indexOf(Char) == -1) { 465 IsNumber = false; 466 } 467 } 468 return IsNumber; 469 } 470 471 /** 472 * Cookie Handling Functions 473 */ 474 function createCookie(name,value,days) { 475 if (days) { 476 var date = new Date(); 477 date.setTime(date.getTime()+(days*24*60*60*1000)); 478 var expires = "; expires="+date.toGMTString(); 479 } 480 else { 481 var expires = ""; 482 } 483 document.cookie = name+"="+value+expires+"; path=/"; 484 } 485 486 function readCookie(name) { 487 var nameEQ = name + "="; 488 var ca = document.cookie.split(';'); 489 for(var i=0;i < ca.length;i++) { 490 var c = ca[i]; 491 while (c.charAt(0)==' ') c = c.substring(1,c.length); 492 if (c.indexOf(nameEQ) == 0) { 493 return c.substring(nameEQ.length,c.length); 494 } 495 } 496 return null; 497 } 498
499 function eraseCookie(name) { 500 createCookie(name,"",-1); 501 } 502 503 /** 504 * Checks to see if the slide is visible enough. 505 * elem = element to check. 506 * type = The way to calculate how much is visible. 507 * amountVisible = amount that should be visible. Either in percent or px. If 508 * it's not defined then all of the slide must be visible. 509 * 510 * Returns true or false 511 */ 512 function viewsSlideshowCycleIsVisible(elem, type, amountVisible) { 513 // Get the top and bottom of the window; 514 var docViewTop = $(window).scrollTop(); 515 var docViewBottom = docViewTop + $(window).height(); 516 var docViewLeft = $(window).scrollLeft(); 517 var docViewRight = docViewLeft + $(window).width(); 518 519 // Get the top, bottom, and height of the slide; 520 var elemTop = $(elem).offset().top; 521 var elemHeight = $(elem).height(); 522 var elemBottom = elemTop + elemHeight; 523 var elemLeft = $(elem).offset().left; 524 var elemWidth = $(elem).width(); 525 var elemRight = elemLeft + elemWidth; 526 var elemArea = elemHeight * elemWidth; 527 528 // Calculate what's hiding in the slide. 529 var missingLeft = 0; 530 var missingRight = 0; 531 var missingTop = 0; 532 var missingBottom = 0; 533 534 // Find out how much of the slide is missing from the left. 535 if (elemLeft < docViewLeft) { 536 missingLeft = docViewLeft - elemLeft; 537 } 538 539 // Find out how much of the slide is missing from the right. 540 if (elemRight > docViewRight) { 541 missingRight = elemRight - docViewRight; 542 } 543 544 // Find out how much of the slide is missing from the top. 545 if (elemTop < docViewTop) { 546 missingTop = docViewTop - elemTop; 547 } 548 549 // Find out how much of the slide is missing from the bottom. 550 if (elemBottom > docViewBottom) { 551 missingBottom = elemBottom - docViewBottom; 552 } 553 554 // If there is no amountVisible defined then check to see if the whole slide 555 // is visible. 556 if (type == 'full') { 557 return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom) 558 && (elemBottom <= docViewBottom) && (elemTop >= docViewTop) 559 && (elemLeft >= docViewLeft) && (elemRight <= docViewRight) 560 && (elemLeft <= docViewRight) && (elemRight >= docViewLeft)); 561 } 562 else if(type == 'vertical') { 563 var verticalShowing = elemHeight - missingTop - missingBottom; 564 565 // If user specified a percentage then find out if the current shown percent 566 // is larger than the allowed percent. 567 // Otherwise check to see if the amount of px shown is larger than the 568 // allotted amount. 569 if (amountVisible.indexOf('%')) { 570 return (((verticalShowing/elemHeight)*100) >= parseInt(amountVisible)); 571 } 572 else { 573 return (verticalShowing >= parseInt(amountVisible)); 574 } 575 } 576 else if(type == 'horizontal') { 577 var horizontalShowing = elemWidth - missingLeft - missingRight; 578 579 // If user specified a percentage then find out if the current shown percent 580 // is larger than the allowed percent. 581 // Otherwise check to see if the amount of px shown is larger than the 582 // allotted amount. 583 if (amountVisible.indexOf('%')) { 584 return (((horizontalShowing/elemWidth)*100) >= parseInt(amountVisible)); 585 } 586 else { 587 return (horizontalShowing >= parseInt(amountVisible)); 588 } 589 } 590 else if(type == 'area') { 591 var areaShowing = (elemWidth - missingLeft - missingRight) * (elemHeight - missingTop - missingBottom); 592 593 // If user specified a percentage then find out if the current shown percent 594 // is larger than the allowed percent. 595 // Otherwise check to see if the amount of px shown is larger than the 596 // allotted amount. 597 if (amountVisible.indexOf('%')) { 598 return (((areaShowing/elemArea)*100) >= parseInt(amountVisible)); 599 } 600 else { 601 return (areaShowing >= parseInt(amountVisible)); 602 } 603 } 604 } 605 /** 606 * Responsive support from 607 * https://www.drupal.org/node/1510526#comment-7865577 608 */ 609 $(window).resize(function(){ 610 $('.views_slideshow_cycle_main').each(function(){ 611 var cycleMain = $(this); 612 var img_width = 0, 613 img_height = 0; 614 var clearCSS = {width: "auto", height: "auto"};
615 var cycle = cycleMain.children('.views-slideshow-cycle-main-frame'); 616 cycleElements = cycle.data("cycle.opts"); 617 cycle.css(clearCSS); 618 cycleMain.find('.views-slideshow-cycle-main-frame-row').each(function(i){ 619 $(this).css(clearCSS); 620 var tmp_img_width = $(this).width(); 621 var tmp_img_height = $(this).height(); 622 if(tmp_img_width > img_width) 623 img_width = tmp_img_width; 624 if(tmp_img_height > img_height) 625 img_height = tmp_img_height; 626 cycleElements.elements[i].cycleW = tmp_img_width; 627 cycleElements.elements[i].cycleH = tmp_img_height; 628 $(this).css({width: tmp_img_width, height: tmp_img_height}); 629 }); 630 cycleMain.height(img_height); 631 cycle.css({width: img_width, height: img_height}); 632 cycle.data("cycle.opts.elements", cycleElements); 633 }); 634 }); 635 636})(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.