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