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