1// FancyZoom.js - v1.1 - http://www.fancyzoom.com 2// 3// Copyright (c) 2008 Cabel Sasser / Panic Inc 4// All rights reserved. 5// 6// Requires: FancyZoomHTML.js 7// Instructions: Include JS files in page, call setupZoom() in onLoad. That's it! 8// Any <a href> links to images will be updated to zoom inline. 9// Add rel="nozoom" to your <a href> to disable zooming for an image. 10// 11// Redistribution and use of this effect in source form, with or without modification, 12// are permitted provided that the following conditions are met: 13// 14// * USE OF SOURCE ON COMMERCIAL (FOR-PROFIT) WEBSITE REQUIRES ONE-TIME LICENSE FEE PER DOMAIN. 15// Reasonably priced! Visit www.fancyzoom.com for licensing instructions. Thanks! 16// 17// * Non-commercial (personal) website use is permitted without license/payment! 18// 19// * Redistribution of source code must retain the above copyright notice, 20// this list of conditions and the following disclaimer. 21// 22// * Redistribution of source code and derived works cannot be sold without specific 23// written prior permission. 24// 25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 37var includeCaption = true; // Turn on the "caption" feature, and write out the caption HTML 38var zoomTime = 5; // Milliseconds between frames of zoom animation 39var zoomSteps = 15; // Number of zoom animation frames 40var includeFade = 1; // Set to 1 to fade the image in / out as it zooms 41var minBorder = 90; // Amount of padding between large, scaled down images, and the window edges 42var shadowSettings = '0px 5px 25px rgba(0, 0, 0, '; // Blur, radius, color of shadow for compatible browsers 43 44var zoomImagesURI = '/images-global/zoom/'; // Location of the zoom and shadow images 45 46// SRG 47if (typeof(zoomImagesBase) != "undefined") { 48 zoomImagesURI = zoomImagesBase + zoomImagesURI; 49} 50// SRG END 51 52// Init. Do not add anything below this line, unless it's something awesome. 53 54var myWidth = 0, myHeight = 0, myScroll = 0; myScrollWidth = 0; myScrollHeight = 0; 55var zoomOpen = false, preloadFrame = 1, preloadActive = false, preloadTime = 0, imgPreload = new Image(); 56var preloadAnimTimer = 0; 57 58var zoomActive = new Array(); var zoomTimer = new Array(); 59var zoomOrigW = new Array(); var zoomOrigH = new Array(); 60var zoomOrigX = new Array(); var zoomOrigY = new Array(); 61 62var zoomID = "ZoomBox"; 63var theID = "ZoomImage"; 64var zoomCaption = "ZoomCaption"; 65var zoomCaptionDiv = "ZoomCapDiv"; 66 67if (navigator.userAgent.indexOf("MSIE") != -1) { 68 var browserIsIE = true; 69} 70 71// Zoom: Setup The Page! Called in your <body>'s onLoad handler. 72 73function setupZoom() { 74 prepZooms(); 75 insertZoomHTML(); 76 zoomdiv = document.getElementById(zoomID); 77 zoomimg = document.getElementById(theID); 78} 79 80// Zoom: Inject Javascript functions into hrefs pointing to images, one by one! 81// Skip any href that contains a rel="nozoom" tag. 82// This is done at page load time via an onLoad() handler. 83 84function prepZooms() { 85 if (! document.getElementsByTagName) { 86 return; 87 } 88 var links = document.getElementsByTagName("a"); 89 for (i = 0; i < links.length; i++) { 90 if (links[i].getAttribute("href")) { 91 if (links[i].getAttribute("href").search(/(.*)\.(jpg|jpeg|gif|png|bmp|tif|tiff)/gi) != -1) { 92 if (links[i].getAttribute("rel") != "nozoom") { 93 links[i].onclick = function (event) { return zoomClick(this, event); }; 94 links[i].onmouseover = function () { zoomPreload(this); }; 95 } 96 } 97 } 98 } 99} 100 101// Zoom: Load an image into an image object. When done loading, function sets preloadActive to false, 102// so other bits know that they can proceed with the zoom. 103// Preloaded image is stored in imgPreload and swapped out in the zoom function. 104 105function zoomPreload(from) { 106 107 var theimage = from.getAttribute("href"); 108 109 // Only preload if we have to, i.e. the image isn't this image already 110 111 if (imgPreload.src.indexOf(from.getAttribute("href").substr(from.getAttribute("href").lastIndexOf("/"))) == -1) { 112 preloadActive = true; 113 imgPreload = new Image(); 114 115 // Set a function to fire when the preload is complete, setting flags along the way. 116 117 imgPreload.onload = function() { 118 preloadActive = false;
119 } 120 121 // Load it! 122 imgPreload.src = theimage; 123 } 124} 125 126// Zoom: Start the preloading animation cycle. 127 128function preloadAnimStart() { 129 preloadTime = new Date(); 130 document.getElementById("ZoomSpin").style.left = (myWidth / 2) + 'px'; 131 document.getElementById("ZoomSpin").style.top = ((myHeight / 2) + myScroll) + 'px'; 132 document.getElementById("ZoomSpin").style.visibility = "visible"; 133 preloadFrame = 1; 134 document.getElementById("SpinImage").src = zoomImagesURI+'zoom-spin-'+preloadFrame+'.png'; 135 preloadAnimTimer = setInterval("preloadAnim()", 100); 136} 137 138// Zoom: Display and ANIMATE the jibber-jabber widget. Once preloadActive is false, bail and zoom it up! 139 140function preloadAnim(from) { 141 if (preloadActive != false) { 142 document.getElementById("SpinImage").src = zoomImagesURI+'zoom-spin-'+preloadFrame+'.png'; 143 preloadFrame++; 144 if (preloadFrame > 12) preloadFrame = 1; 145 } else { 146 document.getElementById("ZoomSpin").style.visibility = "hidden"; 147 clearInterval(preloadAnimTimer); 148 preloadAnimTimer = 0; 149 zoomIn(preloadFrom); 150 } 151} 152 153// ZOOM CLICK: We got a click! Should we do the zoom? Or wait for the preload to complete? 154// todo?: Double check that imgPreload src = clicked src 155 156function zoomClick(from, evt) { 157 158 var shift = getShift(evt); 159 160 // Check for Command / Alt key. If pressed, pass them through -- don't zoom! 161 if (! evt && window.event && (window.event.metaKey || window.event.altKey)) { 162 return true; 163 } else if (evt && (evt.metaKey|| evt.altKey)) { 164 return true; 165 } 166 167 // Get browser dimensions 168 getSize(); 169 170 // If preloading still, wait, and display the spinner. 171 if (preloadActive == true) { 172 // But only display the spinner if it's not already being displayed! 173 if (preloadAnimTimer == 0) { 174 preloadFrom = from; 175 preloadAnimStart(); 176 } 177 } else { 178 // Otherwise, we're loaded: do the zoom! 179 zoomIn(from, shift); 180 } 181 182 return false; 183 184} 185 186// Zoom: Move an element in to endH endW, using zoomHost as a starting point. 187// "from" is an object reference to the href that spawned the zoom. 188 189function zoomIn(from, shift) { 190 191 zoomimg.src = from.getAttribute("href"); 192 193 // Determine the zoom settings from where we came from, the element in the <a>. 194 // If there's no element in the <a>, or we can't get the width, make stuff up 195 196 if (from.childNodes[0].width) { 197 startW = from.childNodes[0].width; 198 startH = from.childNodes[0].height; 199 startPos = findElementPos(from.childNodes[0]); 200 } else { 201 startW = 50; 202 startH = 12; 203 startPos = findElementPos(from); 204 } 205 206 hostX = startPos[0]; 207 hostY = startPos[1]; 208 209 // Make up for a scrolled containing div. 210 // TODO: This HAS to move into findElementPos. 211 212 if (document.getElementById('scroller')) { 213 hostX = hostX - document.getElementById('scroller').scrollLeft; 214 } 215 216 // Determine the target zoom settings from the preloaded image object 217 218 endW = imgPreload.width; 219 endH = imgPreload.height; 220 221 // Start! But only if we're not zooming already! 222 223 if (zoomActive[theID] != true) { 224 225 // Clear everything out just in case something is already open 226 227 if (document.getElementById("ShadowBox")) { 228 document.getElementById("ShadowBox").style.visibility = "hidden"; 229 } else if (! browserIsIE) { 230 231 // Wipe timer if shadow is fading in still 232 if (fadeActive["ZoomImage"]) { 233 clearInterval(fadeTimer["ZoomImage"]); 234 fadeActive["ZoomImage"] = false; 235 fadeTimer["ZoomImage"] = false; 236 } 237 238 document.getElementById("ZoomImage").style.webkitBoxShadow = shadowSettings + '0.0)'; 239 } 240 241 document.getElementById("ZoomClose").style.visibility = "hidden"; 242 243 // Setup the CAPTION, if existing. Hide it first, set the text. 244 245 if (includeCaption) { 246 document.getElementById(zoomCaptionDiv).style.visibility = "hidden"; 247 if (from.getAttribute('title') && includeCaption) { 248 // Yes, there's a caption, set it up 249 document.getElementById(zoomCaption).innerHTML = from.getAttribute('title'); 250 } else { 251 document.getElementById(zoomCaption).innerHTML = ""; 252 } 253 } 254 255 // Store original position in an array for future zoomOut. 256 257 zoomOrigW[theID] = startW; 258 zoomOrigH[theID] = startH; 259 zoomOrigX[theID] = hostX; 260 zoomOrigY[theID] = hostY; 261 262 // Now set the starting dimensions 263 264 zoomimg.style.width = startW + 'px'; 265 zoomimg.style.height = startH + 'px'; 266 zoomdiv.style.left = hostX + 'px'; 267 zoomdiv.style.top = hostY + 'px'; 268 269 // Show the zooming image container, make it invisible 270 271 if (includeFade == 1) { 272 setOpacity(0, zoomID); 273 } 274 zoomdiv.style.visibility = "visible"; 275 276 // If it's too big to fit in the window, shrink the width and height to fit (with ratio). 277 278 sizeRatio = endW / endH; 279 if (endW > myWidth - minBorder) { 280 endW = myWidth - minBorder; 281 endH = endW / sizeRatio; 282 } 283 if (endH > myHeight - minBorder) { 284 endH = myHeight - minBorder; 285 endW = endH * sizeRatio; 286 } 287 288 zoomChangeX = ((myWidth / 2) - (endW / 2) - hostX); 289 zoomChangeY = (((myHeight / 2) - (endH / 2) - hostY) + myScroll); 290 zoomChangeW = (endW - startW); 291 zoomChangeH = (endH - startH); 292 293 // Shift key? 294 295 if (shift) { 296 tempSteps = zoomSteps * 7; 297 } else { 298 tempSteps = zoomSteps; 299 } 300 301 // Setup Zoom 302 303 zoomCurrent = 0; 304 305 // Setup Fade with Zoom, If Requested 306 307 if (includeFade == 1) { 308 fadeCurrent = 0; 309 fadeAmount = (0 - 100) / tempSteps; 310 } else { 311 fadeAmount = 0; 312 } 313 314 // Do It! 315 316 zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+hostX+", "+zoomChangeX+", "+hostY+", "+zoomChangeY+", "+tempSteps+", "+includeFade+", "+fadeAmount+", 'zoomDoneIn(zoomID)')", zoomTime); 317 zoomActive[theID] = true; 318 } 319} 320 321// Zoom it back out. 322 323function zoomOut(from, evt) { 324 325 // Get shift key status. 326 // IE events don't seem to get passed through the function, so grab it from the window. 327 328 if (getShift(evt)) { 329 tempSteps = zoomSteps * 7; 330 } else { 331 tempSteps = zoomSteps; 332 } 333 334 // Check to see if something is happening/open 335 336 if (zoomActive[theID] != true) { 337 338 // First, get rid of the shadow if necessary. 339 340 if (document.getElementById("ShadowBox")) { 341 document.getElementById("ShadowBox").style.visibility = "hidden"; 342 } else if (! browserIsIE) { 343 344 // Wipe timer if shadow is fading in still 345 if (fadeActive["ZoomImage"]) { 346 clearInterval(fadeTimer["ZoomImage"]); 347 fadeActive["ZoomImage"] = false;
348 fadeTimer["ZoomImage"] = false; 349 } 350 351 document.getElementById("ZoomImage").style.webkitBoxShadow = shadowSettings + '0.0)'; 352 } 353 354 // ..and the close box... 355 356 document.getElementById("ZoomClose").style.visibility = "hidden"; 357 358 // ...and the caption if necessary! 359 360 if (includeCaption && document.getElementById(zoomCaption).innerHTML != "") { 361 // fadeElementSetup(zoomCaptionDiv, 100, 0, 5, 1); 362 document.getElementById(zoomCaptionDiv).style.visibility = "hidden"; 363 } 364 365 // Now, figure out where we came from, to get back there 366 367 startX = parseInt(zoomdiv.style.left); 368 startY = parseInt(zoomdiv.style.top); 369 startW = zoomimg.width; 370 startH = zoomimg.height; 371 zoomChangeX = zoomOrigX[theID] - startX; 372 zoomChangeY = zoomOrigY[theID] - startY; 373 zoomChangeW = zoomOrigW[theID] - startW; 374 zoomChangeH = zoomOrigH[theID] - startH; 375 376 // Setup Zoom 377 378 zoomCurrent = 0; 379 380 // Setup Fade with Zoom, If Requested 381 382 if (includeFade == 1) { 383 fadeCurrent = 0; 384 fadeAmount = (100 - 0) / tempSteps; 385 } else { 386 fadeAmount = 0; 387 } 388 389 // Do It! 390 391 zoomTimer[theID] = setInterval("zoomElement('"+zoomID+"', '"+theID+"', "+zoomCurrent+", "+startW+", "+zoomChangeW+", "+startH+", "+zoomChangeH+", "+startX+", "+zoomChangeX+", "+startY+", "+zoomChangeY+", "+tempSteps+", "+includeFade+", "+fadeAmount+", 'zoomDone(zoomID, theID)')", zoomTime); 392 zoomActive[theID] = true; 393 } 394} 395 396// Finished Zooming In 397 398function zoomDoneIn(zoomdiv, theID) { 399 400 // Note that it's open 401 402 zoomOpen = true; 403 zoomdiv = document.getElementById(zoomdiv); 404 405 // Position the table shadow behind the zoomed in image, and display it 406 407 if (document.getElementById("ShadowBox")) { 408 409 setOpacity(0, "ShadowBox"); 410 shadowdiv = document.getElementById("ShadowBox"); 411 412 shadowLeft = parseInt(zoomdiv.style.left) - 13; 413 shadowTop = parseInt(zoomdiv.style.top) - 8; 414 shadowWidth = zoomdiv.offsetWidth + 26; 415 shadowHeight = zoomdiv.offsetHeight + 26; 416 417 shadowdiv.style.width = shadowWidth + 'px'; 418 shadowdiv.style.height = shadowHeight + 'px'; 419 shadowdiv.style.left = shadowLeft + 'px'; 420 shadowdiv.style.top = shadowTop + 'px'; 421 422 document.getElementById("ShadowBox").style.visibility = "visible"; 423 fadeElementSetup("ShadowBox", 0, 100, 5); 424 425 } else if (! browserIsIE) { 426 // Or, do a fade of the modern shadow 427 fadeElementSetup("ZoomImage", 0, .8, 5, 0, "shadow"); 428 } 429 430 // Position and display the CAPTION, if existing 431 432 if (includeCaption && document.getElementById(zoomCaption).innerHTML != "") { 433 // setOpacity(0, zoomCaptionDiv); 434 zoomcapd = document.getElementById(zoomCaptionDiv); 435 zoomcapd.style.top = parseInt(zoomdiv.style.top) + (zoomdiv.offsetHeight + 15) + 'px'; 436 zoomcapd.style.left = (myWidth / 2) - (zoomcapd.offsetWidth / 2) + 'px'; 437 zoomcapd.style.visibility = "visible"; 438 // fadeElementSetup(zoomCaptionDiv, 0, 100, 5); 439 } 440 441 // Display Close Box (fade it if it's not IE) 442 443 if (!browserIsIE) setOpacity(0, "ZoomClose"); 444 document.getElementById("ZoomClose").style.visibility = "visible"; 445 if (!browserIsIE) fadeElementSetup("ZoomClose", 0, 100, 5); 446 447 // Get keypresses 448 document.onkeypress = getKey; 449 450} 451 452// Finished Zooming Out 453 454function zoomDone(zoomdiv, theID) { 455 456 // No longer open 457 458 zoomOpen = false; 459 460 // Clear stuff out, clean up 461 462 zoomOrigH[theID] = ""; 463 zoomOrigW[theID] = ""; 464 document.getElementById(zoomdiv).style.visibility = "hidden"; 465 zoomActive[theID] == false; 466 467 // Stop getting keypresses 468 469 document.onkeypress = null; 470 471} 472 473// Actually zoom the element 474 475function zoomElement(zoomdiv, theID, zoomCurrent, zoomStartW, zoomChangeW, zoomStartH, zoomChangeH, zoomStartX, zoomChangeX, zoomStartY, zoomChangeY, zoomSteps, includeFade, fadeAmount, execWhenDone) { 476 477 // console.log("Zooming Step #"+zoomCurrent+ " of "+zoomSteps+" (zoom " + zoomStartW + "/" + zoomChangeW + ") (zoom " + zoomStartH + "/" + zoomChangeH + ") (zoom " + zoomStartX + "/" + zoomChangeX + ") (zoom " + zoomStartY + "/" + zoomChangeY + ") Fade: "+fadeAmount); 478 479 // Test if we're done, or if we continue 480 481 if (zoomCurrent == (zoomSteps + 1)) { 482 zoomActive[theID] = false; 483 clearInterval(zoomTimer[theID]); 484 485 if (execWhenDone != "") { 486 eval(execWhenDone); 487 } 488 } else { 489 490 // Do the Fade! 491 492 if (includeFade == 1) { 493 if (fadeAmount < 0) { 494 setOpacity(Math.abs(zoomCurrent * fadeAmount), zoomdiv); 495 } else { 496 setOpacity(100 - (zoomCurrent * fadeAmount), zoomdiv); 497 } 498 } 499 500 // Calculate this step's difference, and move it! 501 502 moveW = cubicInOut(zoomCurrent, zoomStartW, zoomChangeW, zoomSteps); 503 moveH = cubicInOut(zoomCurrent, zoomStartH, zoomChangeH, zoomSteps); 504 moveX = cubicInOut(zoomCurrent, zoomStartX, zoomChangeX, zoomSteps); 505 moveY = cubicInOut(zoomCurrent, zoomStartY, zoomChangeY, zoomSteps); 506 507 // ###SRG added Math.floor() to next two lines (c.f. http://www.michaelvanallen.com/development/tweaking-fancyzoom-for-firefox-3-5/) 508 document.getElementById(zoomdiv).style.left = Math.floor(moveX) + 'px'; 509 document.getElementById(zoomdiv).style.top = Math.floor(moveY) + 'px'; 510 zoomimg.style.width = moveW + 'px'; 511 zoomimg.style.height = moveH + 'px'; 512 513 zoomCurrent++; 514 515 clearInterval(zoomTimer[theID]); 516 zoomTimer[theID] = setInterval("zoomElement('"+zoomdiv+"', '"+theID+"', "+zoomCurrent+", "+zoomStartW+", "+zoomChangeW+", "+zoomStartH+", "+zoomChangeH+", "+zoomStartX+", "+zoomChangeX+", "+zoomStartY+", "+zoomChangeY+", "+zoomSteps+", "+includeFade+", "+fadeAmount+", '"+execWhenDone+"')", zoomTime); 517 } 518} 519 520// Zoom Utility: Get Key Press when image is open, and act accordingly 521 522function getKey(evt) { 523 if (! evt) { 524 theKey = event.keyCode; 525 } else { 526 theKey = evt.keyCode; 527 } 528 529 if (theKey == 27) { // ESC 530 zoomOut(this, evt); 531 } 532} 533
534//////////////////////////// 535// 536// FADE Functions 537// 538 539function fadeOut(elem) { 540 if (elem.id) { 541 fadeElementSetup(elem.id, 100, 0, 10); 542 } 543} 544 545function fadeIn(elem) { 546 if (elem.id) { 547 fadeElementSetup(elem.id, 0, 100, 10); 548 } 549} 550 551// Fade: Initialize the fade function 552 553var fadeActive = new Array(); 554var fadeQueue = new Array(); 555var fadeTimer = new Array(); 556var fadeClose = new Array(); 557var fadeMode = new Array(); 558 559function fadeElementSetup(theID, fdStart, fdEnd, fdSteps, fdClose, fdMode) { 560 561 // alert("Fading: "+theID+" Steps: "+fdSteps+" Mode: "+fdMode); 562 563 if (fadeActive[theID] == true) { 564 // Already animating, queue up this command 565 fadeQueue[theID] = new Array(theID, fdStart, fdEnd, fdSteps); 566 } else { 567 fadeSteps = fdSteps; 568 fadeCurrent = 0; 569 fadeAmount = (fdStart - fdEnd) / fadeSteps; 570 fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15); 571 fadeActive[theID] = true; 572 fadeMode[theID] = fdMode; 573 574 if (fdClose == 1) { 575 fadeClose[theID] = true; 576 } else { 577 fadeClose[theID] = false; 578 } 579 } 580} 581 582// Fade: Do the fade. This function will call itself, modifying the parameters, so 583// many instances can run concurrently. Can fade using opacity, or fade using a box-shadow. 584 585function fadeElement(theID, fadeCurrent, fadeAmount, fadeSteps) { 586 587 if (fadeCurrent == fadeSteps) { 588 589 // We're done, so clear. 590 591 clearInterval(fadeTimer[theID]); 592 fadeActive[theID] = false; 593 fadeTimer[theID] = false; 594 595 // Should we close it once the fade is complete? 596 597 if (fadeClose[theID] == true) { 598 document.getElementById(theID).style.visibility = "hidden"; 599 } 600 601 // Hang on.. did a command queue while we were working? If so, make it happen now 602 603 if (fadeQueue[theID] && fadeQueue[theID] != false) { 604 fadeElementSetup(fadeQueue[theID][0], fadeQueue[theID][1], fadeQueue[theID][2], fadeQueue[theID][3]); 605 fadeQueue[theID] = false; 606 } 607 } else { 608 609 fadeCurrent++; 610 611 // Now actually do the fade adjustment. 612 613 if (fadeMode[theID] == "shadow") { 614 615 // Do a special fade on the webkit-box-shadow of the object 616 617 if (fadeAmount < 0) { 618 document.getElementById(theID).style.webkitBoxShadow = shadowSettings + (Math.abs(fadeCurrent * fadeAmount)) + ')'; 619 } else { 620 document.getElementById(theID).style.webkitBoxShadow = shadowSettings + (100 - (fadeCurrent * fadeAmount)) + ')'; 621 } 622 623 } else { 624 625 // Set the opacity depending on if we're adding or subtracting (pos or neg) 626 627 if (fadeAmount < 0) { 628 setOpacity(Math.abs(fadeCurrent * fadeAmount), theID); 629 } else { 630 setOpacity(100 - (fadeCurrent * fadeAmount), theID); 631 } 632 } 633 634 // Keep going, and send myself the updated variables 635 clearInterval(fadeTimer[theID]); 636 fadeTimer[theID] = setInterval("fadeElement('"+theID+"', '"+fadeCurrent+"', '"+fadeAmount+"', '"+fadeSteps+"')", 15); 637 } 638} 639 640//////////////////////////// 641// 642// UTILITY functions 643// 644 645// Utility: Set the opacity, compatible with a number of browsers. Value from 0 to 100. 646 647function setOpacity(opacity, theID) { 648 649 var object = document.getElementById(theID).style; 650 651 // If it's 100, set it to 99 for Firefox. 652 653 if (navigator.userAgent.indexOf("Firefox") != -1) { 654 if (opacity == 100) { opacity = 99.9999; } // This is majorly awkward 655 } 656 657 // Multi-browser opacity setting 658 659 object.filter = "alpha(opacity=" + opacity + ")"; // IE/Win 660 object.opacity = (opacity / 100); // Safari 1.2, Firefox+Mozilla 661 662} 663 664// Utility: Math functions for animation calucations - From http://www.robertpenner.com/easing/ 665// 666// t = time, b = begin, c = change, d = duration 667// time = current frame, begin is fixed, change is basically finish - begin, duration is fixed (frames), 668 669function linear(t, b, c, d) 670{ 671 return c*t/d + b; 672} 673 674function sineInOut(t, b, c, d) 675{ 676 return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; 677} 678 679function cubicIn(t, b, c, d) { 680 return c*(t/=d)*t*t + b; 681} 682 683function cubicOut(t, b, c, d) { 684 return c*((t=t/d-1)*t*t + 1) + b; 685} 686 687function cubicInOut(t, b, c, d) 688{ 689 if ((t/=d/2) < 1) return c/2*t*t*t + b; 690 return c/2*((t-=2)*t*t + 2) + b; 691} 692 693function bounceOut(t, b, c, d) 694{ 695 if ((t/=d) < (1/2.75)){ 696 return c*(7.5625*t*t) + b; 697 } else if (t < (2/2.75)){ 698 return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; 699 } else if (t < (2.5/2.75)){ 700 return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; 701 } else { 702 return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; 703 } 704} 705 706 707// Utility: Get the size of the window, and set myWidth and myHeight 708// Credit to quirksmode.org 709 710function getSize() { 711 712 // Window Size 713
714 if (self.innerHeight) { // Everyone but IE 715 myWidth = window.innerWidth; 716 myHeight = window.innerHeight; 717 myScroll = window.pageYOffset; 718 } else if (document.documentElement && document.documentElement.clientHeight) { // IE6 Strict 719 myWidth = document.documentElement.clientWidth; 720 myHeight = document.documentElement.clientHeight; 721 myScroll = document.documentElement.scrollTop; 722 } else if (document.body) { // Other IE, such as IE7 723 myWidth = document.body.clientWidth; 724 myHeight = document.body.clientHeight; 725 myScroll = document.body.scrollTop; 726 } 727 728 // Page size w/offscreen areas 729 730 if (window.innerHeight && window.scrollMaxY) { 731 myScrollWidth = document.body.scrollWidth; 732 myScrollHeight = window.innerHeight + window.scrollMaxY; 733 } else if (document.body.scrollHeight > document.body.offsetHeight) { // All but Explorer Mac 734 myScrollWidth = document.body.scrollWidth; 735 myScrollHeight = document.body.scrollHeight; 736 } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari 737 myScrollWidth = document.body.offsetWidth; 738 myScrollHeight = document.body.offsetHeight; 739 } 740} 741 742// Utility: Get Shift Key Status 743// IE events don't seem to get passed through the function, so grab it from the window. 744 745function getShift(evt) { 746 var shift = false; 747 if (! evt && window.event) { 748 shift = window.event.shiftKey; 749 } else if (evt) { 750 shift = evt.shiftKey; 751 if (shift) evt.stopPropagation(); // Prevents Firefox from doing shifty things 752 } 753 return shift; 754} 755 756// Utility: Find the Y position of an element on a page. Return Y and X as an array 757 758function findElementPos(elemFind) 759{ 760 var elemX = 0; 761 var elemY = 0; 762 do { 763 elemX += elemFind.offsetLeft; 764 elemY += elemFind.offsetTop; 765 } while ( elemFind = elemFind.offsetParent ) 766 767 return Array(elemX, elemY); 768}
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.