Resources/Message Styles/renkoo.AdiumMessageStyle/Contents/Resources/Footer.html
author Stephen Holt <sholt@adium.im>
Fri Oct 30 15:16:01 2009 -0400 (2009-10-30)
changeset 2691 dd5939fd547b
parent 2682 6beac534df5b
child 2697 f5cbe34603f0
permissions -rw-r--r--
FIx renkoo.
     1 <script type="text/javascript">
     2 	isDebug = false;        
     3 	
     4 	// Fade interval in milliseconds
     5 	// Make this larger if you experience performance issues
     6 	Fadomatic.INTERVAL_MILLIS = 50;
     7 	
     8 	// Creates a fader
     9 	// element - The element to fade
    10 	// speed - The speed to fade at, from 0.0 to 100.0
    11 	// initialOpacity (optional, default 100) - element's starting opacity, 0 to 100
    12 	// minOpacity (optional, default 0) - element's minimum opacity, 0 to 100
    13 	// maxOpacity (optional, default 0) - element's minimum opacity, 0 to 100
    14 	function Fadomatic (element, rate, initialOpacity, minOpacity, maxOpacity) {
    15 		this._element = element;
    16 		this._intervalId = null;
    17 		this._rate = rate;
    18 		this._isFadeOut = true;
    19 	
    20 		// Set initial opacity and bounds
    21 		// NB use 99 instead of 100 to avoid flicker at start of fade
    22 		this._minOpacity = 0;
    23 		this._maxOpacity = 99;
    24 		this._opacity = 99;
    25 	
    26 		if (typeof minOpacity != 'undefined') {
    27 			if (minOpacity < 0) {
    28 				this._minOpacity = 0;
    29 			} else if (minOpacity > 99) {
    30 				this._minOpacity = 99;
    31 			} else {
    32 				this._minOpacity = minOpacity;
    33 			}
    34 		}
    35 	
    36 		if (typeof maxOpacity != 'undefined') {
    37 			if (maxOpacity < 0) {
    38 				this._maxOpacity = 0;
    39 			} else if (maxOpacity > 99) {
    40 				this._maxOpacity = 99;
    41 			} else {
    42 				this._maxOpacity = maxOpacity;
    43 			}
    44 	
    45 			if (this._maxOpacity < this._minOpacity) {
    46 				this._maxOpacity = this._minOpacity;
    47 			}
    48 		}
    49 		
    50 		if (typeof initialOpacity != 'undefined') {
    51 			if (initialOpacity > this._maxOpacity) {
    52 				this._opacity = this._maxOpacity;
    53 			} else if (initialOpacity < this._minOpacity) {
    54 				this._opacity = this._minOpacity;
    55 			} else {
    56 				this._opacity = initialOpacity;
    57 			}
    58 		}
    59 	
    60 		// See if we're using W3C opacity, MSIE filter, or just
    61 		// toggling visiblity
    62 		if(typeof element.style.opacity != 'undefined') {
    63 	
    64 			this._updateOpacity = this._updateOpacityW3c;
    65 	
    66 		} else if(typeof element.style.filter != 'undefined') {
    67 	
    68 			// If there's not an alpha filter on the element already,
    69 			// add one
    70 			if (element.style.filter.indexOf("alpha") == -1) {
    71 	
    72 				// Attempt to preserve existing filters
    73 				var existingFilters="";
    74 				if (element.style.filter) {
    75 					existingFilters = element.style.filter+" ";
    76 				}
    77 				element.style.filter = existingFilters+"alpha(opacity="+this._opacity+")";
    78 			}
    79 	
    80 			this._updateOpacity = this._updateOpacityMSIE;
    81 			
    82 		} else {
    83 	
    84 			this._updateOpacity = this._updateVisibility;
    85 		}
    86 	
    87 		this._updateOpacity();
    88 	}
    89 	
    90 	// Initiates a fade out
    91 	Fadomatic.prototype.fadeOut = function () {
    92 		this._isFadeOut = true;
    93 		this._beginFade();
    94 	}
    95 	
    96 	// Initiates a fade in
    97 	Fadomatic.prototype.fadeIn = function () {
    98 		this._isFadeOut = false;
    99 		this._beginFade();
   100 	}
   101 	
   102 	// Makes the element completely opaque, stops any fade in progress
   103 	Fadomatic.prototype.show = function () {
   104 		this.haltFade();
   105 		this._opacity = this._maxOpacity;
   106 		this._updateOpacity();
   107 	}
   108 	
   109 	// Makes the element completely transparent, stops any fade in progress
   110 	Fadomatic.prototype.hide = function () {
   111 		this.haltFade();
   112 		this._opacity = 0;
   113 		this._updateOpacity();
   114 	}
   115 	
   116 	// Halts any fade in progress
   117 	Fadomatic.prototype.haltFade = function () {
   118 	
   119 		clearInterval(this._intervalId);
   120 	}
   121 	
   122 	// Resumes a fade where it was halted
   123 	Fadomatic.prototype.resumeFade = function () {
   124 	
   125 		this._beginFade();
   126 	}
   127 	
   128 	// Pseudo-private members
   129 	
   130 	Fadomatic.prototype._beginFade = function () {
   131 	
   132 		this.haltFade();
   133 		var objref = this;
   134 		this._intervalId = setInterval(function() { objref._tickFade(); },Fadomatic.INTERVAL_MILLIS);
   135 	}
   136 	
   137 	Fadomatic.prototype._tickFade = function () {
   138 	
   139 		if (this._isFadeOut) {
   140 			this._opacity -= this._rate;
   141 			if (this._opacity < this._minOpacity) {
   142 				this._opacity = this._minOpacity;
   143 				this.haltFade();
   144 			}
   145 		} else {
   146 			this._opacity += this._rate;
   147 			if (this._opacity > this._maxOpacity ) {
   148 				this._opacity = this._maxOpacity;
   149 				this.haltFade();
   150 			}
   151 		}
   152 	
   153 		this._updateOpacity();
   154 	}
   155 	
   156 	Fadomatic.prototype._updateVisibility = function () {
   157 		
   158 		if (this._opacity > 0) {
   159 			this._element.style.visibility = 'visible';
   160 		} else {
   161 			this._element.style.visibility = 'hidden';
   162 		}
   163 	}
   164 	
   165 	Fadomatic.prototype._updateOpacityW3c = function () {
   166 		
   167 		this._element.style.opacity = this._opacity/100;
   168 		this._updateVisibility();
   169 	}
   170 	
   171 	Fadomatic.prototype._updateOpacityMSIE = function () {
   172 		
   173 		this._element.filters.alpha.opacity = this._opacity;
   174 		this._updateVisibility();
   175 	}
   176 	
   177 	Fadomatic.prototype._updateOpacity = null;
   178 
   179 
   180 	// Override CoalescedHTML methods
   181 	function outputHTML() {
   182 		var insert = document.getElementById("insert");
   183 		if(!!insert && coalescedHTML.isConsecutive) {
   184 			insert.parentNode.replaceChild(coalescedHTML.fragment, insert);
   185 		} else {
   186 			if(insert)
   187 				insert.parentNode.removeChild(insert);
   188 			// insert the documentFragment into the live DOM
   189 			try {
   190 				var fader = new Fadomatic(coalescedHTML.fragment, 9, 0, 0, 95);
   191 			} catch(e) {
   192 				trace(e);
   193 			}
   194 			fader.fadeIn();
   195 		}
   196 		
   197 		alignChat(coalescedHTML.shouldScroll);
   198 		
   199 		// reset state to empty/non-coalescing
   200 		coalescedHTML.shouldScroll = undefined;
   201 		coalescedHTML.isConsecutive = undefined;
   202 		coalescedHTML.isCoalescing = false;
   203 		coalescedHTML.coalesceRounds = 0;
   204 	}
   205 
   206 	CoalescedHTML.prototype.coalesce = function() {
   207 		window.clearTimeout(this.timeoutID);
   208 		this.timeoutID = window.setTimeout(outputHTML, 25);
   209 		this.isCoalescing = true;
   210 		this.coalesceRounds += 1;
   211 		if(400 < self.coalesceRounds)
   212 			this.cancel();
   213 	}
   214 	
   215 
   216 	
   217 </script>