annotate forum/Themes/default/fader.js @ 82:6dd719d7c78b website

Add Sonic Annotator pages (probably best to host it here in future rather than with the omras2 site)
author Chris Cannam
date Mon, 20 Jan 2014 10:48:02 +0000
parents e3e11437ecea
children
rev   line source
Chris@76 1 // smfFadeIndex: the current item in smfFadeContent.
Chris@76 2 var smfFadeIndex = -1;
Chris@76 3 // smfFadePercent: percent of fade. (-64 to 510.)
Chris@76 4 var smfFadePercent = 510
Chris@76 5 // smfFadeSwitch: direction. (in or out)
Chris@76 6 var smfFadeSwitch = false;
Chris@76 7 // smfFadeScroller: the actual div to mess with.
Chris@76 8 var smfFadeScroller = document.getElementById('smfFadeScroller');
Chris@76 9 // The ranges to fade from for R, G, and B. (how far apart they are.)
Chris@76 10 var smfFadeRange = {
Chris@76 11 'r': smfFadeFrom.r - smfFadeTo.r,
Chris@76 12 'g': smfFadeFrom.g - smfFadeTo.g,
Chris@76 13 'b': smfFadeFrom.b - smfFadeTo.b
Chris@76 14 };
Chris@76 15
Chris@76 16 // Divide by 20 because we are doing it 20 times per one ms.
Chris@76 17 smfFadeDelay /= 20;
Chris@76 18
Chris@76 19 // Start the fader!
Chris@76 20 window.setTimeout('smfFader();', 20);
Chris@76 21
Chris@76 22 // Main fading function... called 50 times every second.
Chris@76 23 function smfFader()
Chris@76 24 {
Chris@76 25 if (smfFadeContent.length <= 1)
Chris@76 26 return;
Chris@76 27
Chris@76 28 // A fix for Internet Explorer 4: wait until the document is loaded so we can use setInnerHTML().
Chris@76 29 if (typeof(window.document.readyState) != "undefined" && window.document.readyState != "complete")
Chris@76 30 {
Chris@76 31 window.setTimeout('smfFader();', 20);
Chris@76 32 return;
Chris@76 33 }
Chris@76 34
Chris@76 35 // Starting out? Set up the first item.
Chris@76 36 if (smfFadeIndex == -1)
Chris@76 37 {
Chris@76 38 setInnerHTML(smfFadeScroller, smfFadeBefore + smfFadeContent[0] + smfFadeAfter);
Chris@76 39 smfFadeIndex = 1;
Chris@76 40
Chris@76 41 // In Mozilla, text jumps around from this when 1 or 0.5, etc...
Chris@76 42 if (typeof(smfFadeScroller.style.MozOpacity) != "undefined")
Chris@76 43 smfFadeScroller.style.MozOpacity = "0.90";
Chris@76 44 else if (typeof(smfFadeScroller.style.opacity) != "undefined")
Chris@76 45 smfFadeScroller.style.opacity = "0.90";
Chris@76 46 // In Internet Explorer, we have to define this to use it.
Chris@76 47 else if (typeof(smfFadeScroller.style.filter) != "undefined")
Chris@76 48 smfFadeScroller.style.filter = "alpha(opacity=100)";
Chris@76 49 }
Chris@76 50
Chris@76 51 // Are we already done fading in? If so, fade out.
Chris@76 52 if (smfFadePercent >= 510)
Chris@76 53 smfFadeSwitch = !smfFadeSwitch;
Chris@76 54 // All the way faded out?
Chris@76 55 else if (smfFadePercent <= -64)
Chris@76 56 {
Chris@76 57 smfFadeSwitch = !smfFadeSwitch;
Chris@76 58
Chris@76 59 // Go to the next item, or first if we're out of items.
Chris@76 60 setInnerHTML(smfFadeScroller, smfFadeBefore + smfFadeContent[smfFadeIndex++] + smfFadeAfter);
Chris@76 61 if (smfFadeIndex >= smfFadeContent.length)
Chris@76 62 smfFadeIndex = 0;
Chris@76 63 }
Chris@76 64
Chris@76 65 // Increment or decrement the fade percentage.
Chris@76 66 if (smfFadeSwitch)
Chris@76 67 smfFadePercent -= 255 / smfFadeDelay * 2;
Chris@76 68 else
Chris@76 69 smfFadePercent += 255 / smfFadeDelay * 2;
Chris@76 70
Chris@76 71 // If it's not outside 0 and 256... (otherwise it's just delay time.)
Chris@76 72 if (smfFadePercent < 256 && smfFadePercent > 0)
Chris@76 73 {
Chris@76 74 // Easier... also faster...
Chris@76 75 var tempPercent = smfFadePercent / 255, rounded;
Chris@76 76
Chris@76 77 if (typeof(smfFadeScroller.style.MozOpacity) != "undefined")
Chris@76 78 {
Chris@76 79 rounded = Math.round(tempPercent * 100) / 100;
Chris@76 80 smfFadeScroller.style.MozOpacity = rounded == 1 ? "0.99" : rounded;
Chris@76 81 }
Chris@76 82 else if (typeof(smfFadeScroller.style.opacity) != "undefined")
Chris@76 83 {
Chris@76 84 rounded = Math.round(tempPercent * 100) / 100;
Chris@76 85 smfFadeScroller.style.opacity = rounded == 1 ? "0.99" : rounded;
Chris@76 86 }
Chris@76 87 else
Chris@76 88 {
Chris@76 89 var done = false;
Chris@76 90 if (typeof(smfFadeScroller.filters.alpha) != "undefined")
Chris@76 91 {
Chris@76 92 // Internet Explorer 4 just can't handle "try".
Chris@76 93 eval("try\
Chris@76 94 {\
Chris@76 95 smfFadeScroller.filters.alpha.opacity = Math.round(tempPercent * 100);\
Chris@76 96 done = true;\
Chris@76 97 }\
Chris@76 98 catch (err)\
Chris@76 99 {\
Chris@76 100 }");
Chris@76 101 }
Chris@76 102
Chris@76 103 if (!done)
Chris@76 104 {
Chris@76 105 // Get the new R, G, and B. (it should be bottom + (range of color * percent)...)
Chris@76 106 var r = Math.ceil(smfFadeTo.r + smfFadeRange.r * tempPercent);
Chris@76 107 var g = Math.ceil(smfFadeTo.g + smfFadeRange.g * tempPercent);
Chris@76 108 var b = Math.ceil(smfFadeTo.b + smfFadeRange.b * tempPercent);
Chris@76 109
Chris@76 110 // Set the color in the style, thereby fading it.
Chris@76 111 smfFadeScroller.style.color = 'rgb(' + r + ', ' + g + ', ' + b + ')';
Chris@76 112 }
Chris@76 113 }
Chris@76 114 }
Chris@76 115
Chris@76 116 // Keep going.
Chris@76 117 window.setTimeout('smfFader();', 20);
Chris@76 118 }