Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | // script.aculo.us effects.js v1.7.1_beta2, Tue May 15 15:15:45 EDT 2007 |
michael@0 | 2 | |
michael@0 | 3 | // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) |
michael@0 | 4 | // Contributors: |
michael@0 | 5 | // Justin Palmer (http://encytemedia.com/) |
michael@0 | 6 | // Mark Pilgrim (http://diveintomark.org/) |
michael@0 | 7 | // Martin Bialasinki |
michael@0 | 8 | // |
michael@0 | 9 | // script.aculo.us is freely distributable under the terms of an MIT-style license. |
michael@0 | 10 | // For details, see the script.aculo.us web site: http://script.aculo.us/ |
michael@0 | 11 | |
michael@0 | 12 | // converts rgb() and #xxx to #xxxxxx format, |
michael@0 | 13 | // returns self (or first argument) if not convertable |
michael@0 | 14 | String.prototype.parseColor = function() { |
michael@0 | 15 | var color = '#'; |
michael@0 | 16 | if(this.slice(0,4) == 'rgb(') { |
michael@0 | 17 | var cols = this.slice(4,this.length-1).split(','); |
michael@0 | 18 | var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3); |
michael@0 | 19 | } else { |
michael@0 | 20 | if(this.slice(0,1) == '#') { |
michael@0 | 21 | if(this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase(); |
michael@0 | 22 | if(this.length==7) color = this.toLowerCase(); |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | return(color.length==7 ? color : (arguments[0] || this)); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | /*--------------------------------------------------------------------------*/ |
michael@0 | 29 | |
michael@0 | 30 | Element.collectTextNodes = function(element) { |
michael@0 | 31 | return $A($(element).childNodes).collect( function(node) { |
michael@0 | 32 | return (node.nodeType==3 ? node.nodeValue : |
michael@0 | 33 | (node.hasChildNodes() ? Element.collectTextNodes(node) : '')); |
michael@0 | 34 | }).flatten().join(''); |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | Element.collectTextNodesIgnoreClass = function(element, className) { |
michael@0 | 38 | return $A($(element).childNodes).collect( function(node) { |
michael@0 | 39 | return (node.nodeType==3 ? node.nodeValue : |
michael@0 | 40 | ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? |
michael@0 | 41 | Element.collectTextNodesIgnoreClass(node, className) : '')); |
michael@0 | 42 | }).flatten().join(''); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | Element.setContentZoom = function(element, percent) { |
michael@0 | 46 | element = $(element); |
michael@0 | 47 | element.setStyle({fontSize: (percent/100) + 'em'}); |
michael@0 | 48 | if(Prototype.Browser.WebKit) window.scrollBy(0,0); |
michael@0 | 49 | return element; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | Element.getInlineOpacity = function(element){ |
michael@0 | 53 | return $(element).style.opacity || ''; |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | Element.forceRerendering = function(element) { |
michael@0 | 57 | try { |
michael@0 | 58 | element = $(element); |
michael@0 | 59 | var n = document.createTextNode(' '); |
michael@0 | 60 | element.appendChild(n); |
michael@0 | 61 | element.removeChild(n); |
michael@0 | 62 | } catch(e) { } |
michael@0 | 63 | }; |
michael@0 | 64 | |
michael@0 | 65 | /*--------------------------------------------------------------------------*/ |
michael@0 | 66 | |
michael@0 | 67 | Array.prototype.call = function() { |
michael@0 | 68 | var args = arguments; |
michael@0 | 69 | this.each(function(f){ f.apply(this, args) }); |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | /*--------------------------------------------------------------------------*/ |
michael@0 | 73 | |
michael@0 | 74 | var Effect = { |
michael@0 | 75 | _elementDoesNotExistError: { |
michael@0 | 76 | name: 'ElementDoesNotExistError', |
michael@0 | 77 | message: 'The specified DOM element does not exist, but is required for this effect to operate' |
michael@0 | 78 | }, |
michael@0 | 79 | tagifyText: function(element) { |
michael@0 | 80 | if(typeof Builder == 'undefined') |
michael@0 | 81 | throw("Effect.tagifyText requires including script.aculo.us' builder.js library"); |
michael@0 | 82 | |
michael@0 | 83 | var tagifyStyle = 'position:relative'; |
michael@0 | 84 | if(Prototype.Browser.IE) tagifyStyle += ';zoom:1'; |
michael@0 | 85 | |
michael@0 | 86 | element = $(element); |
michael@0 | 87 | $A(element.childNodes).each( function(child) { |
michael@0 | 88 | if(child.nodeType==3) { |
michael@0 | 89 | child.nodeValue.toArray().each( function(character) { |
michael@0 | 90 | element.insertBefore( |
michael@0 | 91 | Builder.node('span',{style: tagifyStyle}, |
michael@0 | 92 | character == ' ' ? String.fromCharCode(160) : character), |
michael@0 | 93 | child); |
michael@0 | 94 | }); |
michael@0 | 95 | Element.remove(child); |
michael@0 | 96 | } |
michael@0 | 97 | }); |
michael@0 | 98 | }, |
michael@0 | 99 | multiple: function(element, effect) { |
michael@0 | 100 | var elements; |
michael@0 | 101 | if(((typeof element == 'object') || |
michael@0 | 102 | (typeof element == 'function')) && |
michael@0 | 103 | (element.length)) |
michael@0 | 104 | elements = element; |
michael@0 | 105 | else |
michael@0 | 106 | elements = $(element).childNodes; |
michael@0 | 107 | |
michael@0 | 108 | var options = Object.extend({ |
michael@0 | 109 | speed: 0.1, |
michael@0 | 110 | delay: 0.0 |
michael@0 | 111 | }, arguments[2] || {}); |
michael@0 | 112 | var masterDelay = options.delay; |
michael@0 | 113 | |
michael@0 | 114 | $A(elements).each( function(element, index) { |
michael@0 | 115 | new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay })); |
michael@0 | 116 | }); |
michael@0 | 117 | }, |
michael@0 | 118 | PAIRS: { |
michael@0 | 119 | 'slide': ['SlideDown','SlideUp'], |
michael@0 | 120 | 'blind': ['BlindDown','BlindUp'], |
michael@0 | 121 | 'appear': ['Appear','Fade'] |
michael@0 | 122 | }, |
michael@0 | 123 | toggle: function(element, effect) { |
michael@0 | 124 | element = $(element); |
michael@0 | 125 | effect = (effect || 'appear').toLowerCase(); |
michael@0 | 126 | var options = Object.extend({ |
michael@0 | 127 | queue: { position:'end', scope:(element.id || 'global'), limit: 1 } |
michael@0 | 128 | }, arguments[2] || {}); |
michael@0 | 129 | Effect[element.visible() ? |
michael@0 | 130 | Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options); |
michael@0 | 131 | } |
michael@0 | 132 | }; |
michael@0 | 133 | |
michael@0 | 134 | var Effect2 = Effect; // deprecated |
michael@0 | 135 | |
michael@0 | 136 | /* ------------- transitions ------------- */ |
michael@0 | 137 | |
michael@0 | 138 | Effect.Transitions = { |
michael@0 | 139 | linear: Prototype.K, |
michael@0 | 140 | sinoidal: function(pos) { |
michael@0 | 141 | return (-Math.cos(pos*Math.PI)/2) + 0.5; |
michael@0 | 142 | }, |
michael@0 | 143 | reverse: function(pos) { |
michael@0 | 144 | return 1-pos; |
michael@0 | 145 | }, |
michael@0 | 146 | flicker: function(pos) { |
michael@0 | 147 | var pos = ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; |
michael@0 | 148 | return (pos > 1 ? 1 : pos); |
michael@0 | 149 | }, |
michael@0 | 150 | wobble: function(pos) { |
michael@0 | 151 | return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; |
michael@0 | 152 | }, |
michael@0 | 153 | pulse: function(pos, pulses) { |
michael@0 | 154 | pulses = pulses || 5; |
michael@0 | 155 | return ( |
michael@0 | 156 | Math.round((pos % (1/pulses)) * pulses) == 0 ? |
michael@0 | 157 | ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : |
michael@0 | 158 | 1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) |
michael@0 | 159 | ); |
michael@0 | 160 | }, |
michael@0 | 161 | none: function(pos) { |
michael@0 | 162 | return 0; |
michael@0 | 163 | }, |
michael@0 | 164 | full: function(pos) { |
michael@0 | 165 | return 1; |
michael@0 | 166 | } |
michael@0 | 167 | }; |
michael@0 | 168 | |
michael@0 | 169 | /* ------------- core effects ------------- */ |
michael@0 | 170 | |
michael@0 | 171 | Effect.ScopedQueue = Class.create(); |
michael@0 | 172 | Object.extend(Object.extend(Effect.ScopedQueue.prototype, Enumerable), { |
michael@0 | 173 | initialize: function() { |
michael@0 | 174 | this.effects = []; |
michael@0 | 175 | this.interval = null; |
michael@0 | 176 | }, |
michael@0 | 177 | _each: function(iterator) { |
michael@0 | 178 | this.effects._each(iterator); |
michael@0 | 179 | }, |
michael@0 | 180 | add: function(effect) { |
michael@0 | 181 | var timestamp = new Date().getTime(); |
michael@0 | 182 | |
michael@0 | 183 | var position = (typeof effect.options.queue == 'string') ? |
michael@0 | 184 | effect.options.queue : effect.options.queue.position; |
michael@0 | 185 | |
michael@0 | 186 | switch(position) { |
michael@0 | 187 | case 'front': |
michael@0 | 188 | // move unstarted effects after this effect |
michael@0 | 189 | this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) { |
michael@0 | 190 | e.startOn += effect.finishOn; |
michael@0 | 191 | e.finishOn += effect.finishOn; |
michael@0 | 192 | }); |
michael@0 | 193 | break; |
michael@0 | 194 | case 'with-last': |
michael@0 | 195 | timestamp = this.effects.pluck('startOn').max() || timestamp; |
michael@0 | 196 | break; |
michael@0 | 197 | case 'end': |
michael@0 | 198 | // start effect after last queued effect has finished |
michael@0 | 199 | timestamp = this.effects.pluck('finishOn').max() || timestamp; |
michael@0 | 200 | break; |
michael@0 | 201 | } |
michael@0 | 202 | |
michael@0 | 203 | effect.startOn += timestamp; |
michael@0 | 204 | effect.finishOn += timestamp; |
michael@0 | 205 | |
michael@0 | 206 | if(!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit)) |
michael@0 | 207 | this.effects.push(effect); |
michael@0 | 208 | |
michael@0 | 209 | if(!this.interval) |
michael@0 | 210 | this.interval = setInterval(this.loop.bind(this), 15); |
michael@0 | 211 | }, |
michael@0 | 212 | remove: function(effect) { |
michael@0 | 213 | this.effects = this.effects.reject(function(e) { return e==effect }); |
michael@0 | 214 | if(this.effects.length == 0) { |
michael@0 | 215 | clearInterval(this.interval); |
michael@0 | 216 | this.interval = null; |
michael@0 | 217 | } |
michael@0 | 218 | }, |
michael@0 | 219 | loop: function() { |
michael@0 | 220 | var timePos = new Date().getTime(); |
michael@0 | 221 | for(var i=0, len=this.effects.length;i<len;i++) |
michael@0 | 222 | this.effects[i] && this.effects[i].loop(timePos); |
michael@0 | 223 | } |
michael@0 | 224 | }); |
michael@0 | 225 | |
michael@0 | 226 | Effect.Queues = { |
michael@0 | 227 | instances: $H(), |
michael@0 | 228 | get: function(queueName) { |
michael@0 | 229 | if(typeof queueName != 'string') return queueName; |
michael@0 | 230 | |
michael@0 | 231 | if(!this.instances[queueName]) |
michael@0 | 232 | this.instances[queueName] = new Effect.ScopedQueue(); |
michael@0 | 233 | |
michael@0 | 234 | return this.instances[queueName]; |
michael@0 | 235 | } |
michael@0 | 236 | } |
michael@0 | 237 | Effect.Queue = Effect.Queues.get('global'); |
michael@0 | 238 | |
michael@0 | 239 | Effect.DefaultOptions = { |
michael@0 | 240 | transition: Effect.Transitions.sinoidal, |
michael@0 | 241 | duration: 1.0, // seconds |
michael@0 | 242 | fps: 100, // 100= assume 66fps max. |
michael@0 | 243 | sync: false, // true for combining |
michael@0 | 244 | from: 0.0, |
michael@0 | 245 | to: 1.0, |
michael@0 | 246 | delay: 0.0, |
michael@0 | 247 | queue: 'parallel' |
michael@0 | 248 | } |
michael@0 | 249 | |
michael@0 | 250 | Effect.Base = function() {}; |
michael@0 | 251 | Effect.Base.prototype = { |
michael@0 | 252 | position: null, |
michael@0 | 253 | start: function(options) { |
michael@0 | 254 | function codeForEvent(options,eventName){ |
michael@0 | 255 | return ( |
michael@0 | 256 | (options[eventName+'Internal'] ? 'this.options.'+eventName+'Internal(this);' : '') + |
michael@0 | 257 | (options[eventName] ? 'this.options.'+eventName+'(this);' : '') |
michael@0 | 258 | ); |
michael@0 | 259 | } |
michael@0 | 260 | if(options.transition === false) options.transition = Effect.Transitions.linear; |
michael@0 | 261 | this.options = Object.extend(Object.extend({},Effect.DefaultOptions), options || {}); |
michael@0 | 262 | this.currentFrame = 0; |
michael@0 | 263 | this.state = 'idle'; |
michael@0 | 264 | this.startOn = this.options.delay*1000; |
michael@0 | 265 | this.finishOn = this.startOn+(this.options.duration*1000); |
michael@0 | 266 | this.fromToDelta = this.options.to-this.options.from; |
michael@0 | 267 | this.totalTime = this.finishOn-this.startOn; |
michael@0 | 268 | this.totalFrames = this.options.fps*this.options.duration; |
michael@0 | 269 | |
michael@0 | 270 | eval('this.render = function(pos){ '+ |
michael@0 | 271 | 'if(this.state=="idle"){this.state="running";'+ |
michael@0 | 272 | codeForEvent(options,'beforeSetup')+ |
michael@0 | 273 | (this.setup ? 'this.setup();':'')+ |
michael@0 | 274 | codeForEvent(options,'afterSetup')+ |
michael@0 | 275 | '};if(this.state=="running"){'+ |
michael@0 | 276 | 'pos=this.options.transition(pos)*'+this.fromToDelta+'+'+this.options.from+';'+ |
michael@0 | 277 | 'this.position=pos;'+ |
michael@0 | 278 | codeForEvent(options,'beforeUpdate')+ |
michael@0 | 279 | (this.update ? 'this.update(pos);':'')+ |
michael@0 | 280 | codeForEvent(options,'afterUpdate')+ |
michael@0 | 281 | '}}'); |
michael@0 | 282 | |
michael@0 | 283 | this.event('beforeStart'); |
michael@0 | 284 | if(!this.options.sync) |
michael@0 | 285 | Effect.Queues.get(typeof this.options.queue == 'string' ? |
michael@0 | 286 | 'global' : this.options.queue.scope).add(this); |
michael@0 | 287 | }, |
michael@0 | 288 | loop: function(timePos) { |
michael@0 | 289 | if(timePos >= this.startOn) { |
michael@0 | 290 | if(timePos >= this.finishOn) { |
michael@0 | 291 | this.render(1.0); |
michael@0 | 292 | this.cancel(); |
michael@0 | 293 | this.event('beforeFinish'); |
michael@0 | 294 | if(this.finish) this.finish(); |
michael@0 | 295 | this.event('afterFinish'); |
michael@0 | 296 | return; |
michael@0 | 297 | } |
michael@0 | 298 | var pos = (timePos - this.startOn) / this.totalTime, |
michael@0 | 299 | frame = Math.round(pos * this.totalFrames); |
michael@0 | 300 | if(frame > this.currentFrame) { |
michael@0 | 301 | this.render(pos); |
michael@0 | 302 | this.currentFrame = frame; |
michael@0 | 303 | } |
michael@0 | 304 | } |
michael@0 | 305 | }, |
michael@0 | 306 | cancel: function() { |
michael@0 | 307 | if(!this.options.sync) |
michael@0 | 308 | Effect.Queues.get(typeof this.options.queue == 'string' ? |
michael@0 | 309 | 'global' : this.options.queue.scope).remove(this); |
michael@0 | 310 | this.state = 'finished'; |
michael@0 | 311 | }, |
michael@0 | 312 | event: function(eventName) { |
michael@0 | 313 | if(this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this); |
michael@0 | 314 | if(this.options[eventName]) this.options[eventName](this); |
michael@0 | 315 | }, |
michael@0 | 316 | inspect: function() { |
michael@0 | 317 | var data = $H(); |
michael@0 | 318 | for(property in this) |
michael@0 | 319 | if(typeof this[property] != 'function') data[property] = this[property]; |
michael@0 | 320 | return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>'; |
michael@0 | 321 | } |
michael@0 | 322 | } |
michael@0 | 323 | |
michael@0 | 324 | Effect.Parallel = Class.create(); |
michael@0 | 325 | Object.extend(Object.extend(Effect.Parallel.prototype, Effect.Base.prototype), { |
michael@0 | 326 | initialize: function(effects) { |
michael@0 | 327 | this.effects = effects || []; |
michael@0 | 328 | this.start(arguments[1]); |
michael@0 | 329 | }, |
michael@0 | 330 | update: function(position) { |
michael@0 | 331 | this.effects.invoke('render', position); |
michael@0 | 332 | }, |
michael@0 | 333 | finish: function(position) { |
michael@0 | 334 | this.effects.each( function(effect) { |
michael@0 | 335 | effect.render(1.0); |
michael@0 | 336 | effect.cancel(); |
michael@0 | 337 | effect.event('beforeFinish'); |
michael@0 | 338 | if(effect.finish) effect.finish(position); |
michael@0 | 339 | effect.event('afterFinish'); |
michael@0 | 340 | }); |
michael@0 | 341 | } |
michael@0 | 342 | }); |
michael@0 | 343 | |
michael@0 | 344 | Effect.Event = Class.create(); |
michael@0 | 345 | Object.extend(Object.extend(Effect.Event.prototype, Effect.Base.prototype), { |
michael@0 | 346 | initialize: function() { |
michael@0 | 347 | var options = Object.extend({ |
michael@0 | 348 | duration: 0 |
michael@0 | 349 | }, arguments[0] || {}); |
michael@0 | 350 | this.start(options); |
michael@0 | 351 | }, |
michael@0 | 352 | update: Prototype.emptyFunction |
michael@0 | 353 | }); |
michael@0 | 354 | |
michael@0 | 355 | Effect.Opacity = Class.create(); |
michael@0 | 356 | Object.extend(Object.extend(Effect.Opacity.prototype, Effect.Base.prototype), { |
michael@0 | 357 | initialize: function(element) { |
michael@0 | 358 | this.element = $(element); |
michael@0 | 359 | if(!this.element) throw(Effect._elementDoesNotExistError); |
michael@0 | 360 | // make this work on IE on elements without 'layout' |
michael@0 | 361 | if(Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) |
michael@0 | 362 | this.element.setStyle({zoom: 1}); |
michael@0 | 363 | var options = Object.extend({ |
michael@0 | 364 | from: this.element.getOpacity() || 0.0, |
michael@0 | 365 | to: 1.0 |
michael@0 | 366 | }, arguments[1] || {}); |
michael@0 | 367 | this.start(options); |
michael@0 | 368 | }, |
michael@0 | 369 | update: function(position) { |
michael@0 | 370 | this.element.setOpacity(position); |
michael@0 | 371 | } |
michael@0 | 372 | }); |
michael@0 | 373 | |
michael@0 | 374 | Effect.Move = Class.create(); |
michael@0 | 375 | Object.extend(Object.extend(Effect.Move.prototype, Effect.Base.prototype), { |
michael@0 | 376 | initialize: function(element) { |
michael@0 | 377 | this.element = $(element); |
michael@0 | 378 | if(!this.element) throw(Effect._elementDoesNotExistError); |
michael@0 | 379 | var options = Object.extend({ |
michael@0 | 380 | x: 0, |
michael@0 | 381 | y: 0, |
michael@0 | 382 | mode: 'relative' |
michael@0 | 383 | }, arguments[1] || {}); |
michael@0 | 384 | this.start(options); |
michael@0 | 385 | }, |
michael@0 | 386 | setup: function() { |
michael@0 | 387 | // Bug in Opera: Opera returns the "real" position of a static element or |
michael@0 | 388 | // relative element that does not have top/left explicitly set. |
michael@0 | 389 | // ==> Always set top and left for position relative elements in your stylesheets |
michael@0 | 390 | // (to 0 if you do not need them) |
michael@0 | 391 | this.element.makePositioned(); |
michael@0 | 392 | this.originalLeft = parseFloat(this.element.getStyle('left') || '0'); |
michael@0 | 393 | this.originalTop = parseFloat(this.element.getStyle('top') || '0'); |
michael@0 | 394 | if(this.options.mode == 'absolute') { |
michael@0 | 395 | // absolute movement, so we need to calc deltaX and deltaY |
michael@0 | 396 | this.options.x = this.options.x - this.originalLeft; |
michael@0 | 397 | this.options.y = this.options.y - this.originalTop; |
michael@0 | 398 | } |
michael@0 | 399 | }, |
michael@0 | 400 | update: function(position) { |
michael@0 | 401 | this.element.setStyle({ |
michael@0 | 402 | left: Math.round(this.options.x * position + this.originalLeft) + 'px', |
michael@0 | 403 | top: Math.round(this.options.y * position + this.originalTop) + 'px' |
michael@0 | 404 | }); |
michael@0 | 405 | } |
michael@0 | 406 | }); |
michael@0 | 407 | |
michael@0 | 408 | // for backwards compatibility |
michael@0 | 409 | Effect.MoveBy = function(element, toTop, toLeft) { |
michael@0 | 410 | return new Effect.Move(element, |
michael@0 | 411 | Object.extend({ x: toLeft, y: toTop }, arguments[3] || {})); |
michael@0 | 412 | }; |
michael@0 | 413 | |
michael@0 | 414 | Effect.Scale = Class.create(); |
michael@0 | 415 | Object.extend(Object.extend(Effect.Scale.prototype, Effect.Base.prototype), { |
michael@0 | 416 | initialize: function(element, percent) { |
michael@0 | 417 | this.element = $(element); |
michael@0 | 418 | if(!this.element) throw(Effect._elementDoesNotExistError); |
michael@0 | 419 | var options = Object.extend({ |
michael@0 | 420 | scaleX: true, |
michael@0 | 421 | scaleY: true, |
michael@0 | 422 | scaleContent: true, |
michael@0 | 423 | scaleFromCenter: false, |
michael@0 | 424 | scaleMode: 'box', // 'box' or 'contents' or {} with provided values |
michael@0 | 425 | scaleFrom: 100.0, |
michael@0 | 426 | scaleTo: percent |
michael@0 | 427 | }, arguments[2] || {}); |
michael@0 | 428 | this.start(options); |
michael@0 | 429 | }, |
michael@0 | 430 | setup: function() { |
michael@0 | 431 | this.restoreAfterFinish = this.options.restoreAfterFinish || false; |
michael@0 | 432 | this.elementPositioning = this.element.getStyle('position'); |
michael@0 | 433 | |
michael@0 | 434 | this.originalStyle = {}; |
michael@0 | 435 | ['top','left','width','height','fontSize'].each( function(k) { |
michael@0 | 436 | this.originalStyle[k] = this.element.style[k]; |
michael@0 | 437 | }.bind(this)); |
michael@0 | 438 | |
michael@0 | 439 | this.originalTop = this.element.offsetTop; |
michael@0 | 440 | this.originalLeft = this.element.offsetLeft; |
michael@0 | 441 | |
michael@0 | 442 | var fontSize = this.element.getStyle('font-size') || '100%'; |
michael@0 | 443 | ['em','px','%','pt'].each( function(fontSizeType) { |
michael@0 | 444 | if(fontSize.indexOf(fontSizeType)>0) { |
michael@0 | 445 | this.fontSize = parseFloat(fontSize); |
michael@0 | 446 | this.fontSizeType = fontSizeType; |
michael@0 | 447 | } |
michael@0 | 448 | }.bind(this)); |
michael@0 | 449 | |
michael@0 | 450 | this.factor = (this.options.scaleTo - this.options.scaleFrom)/100; |
michael@0 | 451 | |
michael@0 | 452 | this.dims = null; |
michael@0 | 453 | if(this.options.scaleMode=='box') |
michael@0 | 454 | this.dims = [this.element.offsetHeight, this.element.offsetWidth]; |
michael@0 | 455 | if(/^content/.test(this.options.scaleMode)) |
michael@0 | 456 | this.dims = [this.element.scrollHeight, this.element.scrollWidth]; |
michael@0 | 457 | if(!this.dims) |
michael@0 | 458 | this.dims = [this.options.scaleMode.originalHeight, |
michael@0 | 459 | this.options.scaleMode.originalWidth]; |
michael@0 | 460 | }, |
michael@0 | 461 | update: function(position) { |
michael@0 | 462 | var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); |
michael@0 | 463 | if(this.options.scaleContent && this.fontSize) |
michael@0 | 464 | this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType }); |
michael@0 | 465 | this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale); |
michael@0 | 466 | }, |
michael@0 | 467 | finish: function(position) { |
michael@0 | 468 | if(this.restoreAfterFinish) this.element.setStyle(this.originalStyle); |
michael@0 | 469 | }, |
michael@0 | 470 | setDimensions: function(height, width) { |
michael@0 | 471 | var d = {}; |
michael@0 | 472 | if(this.options.scaleX) d.width = Math.round(width) + 'px'; |
michael@0 | 473 | if(this.options.scaleY) d.height = Math.round(height) + 'px'; |
michael@0 | 474 | if(this.options.scaleFromCenter) { |
michael@0 | 475 | var topd = (height - this.dims[0])/2; |
michael@0 | 476 | var leftd = (width - this.dims[1])/2; |
michael@0 | 477 | if(this.elementPositioning == 'absolute') { |
michael@0 | 478 | if(this.options.scaleY) d.top = this.originalTop-topd + 'px'; |
michael@0 | 479 | if(this.options.scaleX) d.left = this.originalLeft-leftd + 'px'; |
michael@0 | 480 | } else { |
michael@0 | 481 | if(this.options.scaleY) d.top = -topd + 'px'; |
michael@0 | 482 | if(this.options.scaleX) d.left = -leftd + 'px'; |
michael@0 | 483 | } |
michael@0 | 484 | } |
michael@0 | 485 | this.element.setStyle(d); |
michael@0 | 486 | } |
michael@0 | 487 | }); |
michael@0 | 488 | |
michael@0 | 489 | Effect.Highlight = Class.create(); |
michael@0 | 490 | Object.extend(Object.extend(Effect.Highlight.prototype, Effect.Base.prototype), { |
michael@0 | 491 | initialize: function(element) { |
michael@0 | 492 | this.element = $(element); |
michael@0 | 493 | if(!this.element) throw(Effect._elementDoesNotExistError); |
michael@0 | 494 | var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || {}); |
michael@0 | 495 | this.start(options); |
michael@0 | 496 | }, |
michael@0 | 497 | setup: function() { |
michael@0 | 498 | // Prevent executing on elements not in the layout flow |
michael@0 | 499 | if(this.element.getStyle('display')=='none') { this.cancel(); return; } |
michael@0 | 500 | // Disable background image during the effect |
michael@0 | 501 | this.oldStyle = {}; |
michael@0 | 502 | if (!this.options.keepBackgroundImage) { |
michael@0 | 503 | this.oldStyle.backgroundImage = this.element.getStyle('background-image'); |
michael@0 | 504 | this.element.setStyle({backgroundImage: 'none'}); |
michael@0 | 505 | } |
michael@0 | 506 | if(!this.options.endcolor) |
michael@0 | 507 | this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff'); |
michael@0 | 508 | if(!this.options.restorecolor) |
michael@0 | 509 | this.options.restorecolor = this.element.getStyle('background-color'); |
michael@0 | 510 | // init color calculations |
michael@0 | 511 | this._base = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this)); |
michael@0 | 512 | this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this)); |
michael@0 | 513 | }, |
michael@0 | 514 | update: function(position) { |
michael@0 | 515 | this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){ |
michael@0 | 516 | return m+(Math.round(this._base[i]+(this._delta[i]*position)).toColorPart()); }.bind(this)) }); |
michael@0 | 517 | }, |
michael@0 | 518 | finish: function() { |
michael@0 | 519 | this.element.setStyle(Object.extend(this.oldStyle, { |
michael@0 | 520 | backgroundColor: this.options.restorecolor |
michael@0 | 521 | })); |
michael@0 | 522 | } |
michael@0 | 523 | }); |
michael@0 | 524 | |
michael@0 | 525 | Effect.ScrollTo = Class.create(); |
michael@0 | 526 | Object.extend(Object.extend(Effect.ScrollTo.prototype, Effect.Base.prototype), { |
michael@0 | 527 | initialize: function(element) { |
michael@0 | 528 | this.element = $(element); |
michael@0 | 529 | this.start(arguments[1] || {}); |
michael@0 | 530 | }, |
michael@0 | 531 | setup: function() { |
michael@0 | 532 | Position.prepare(); |
michael@0 | 533 | var offsets = Position.cumulativeOffset(this.element); |
michael@0 | 534 | if(this.options.offset) offsets[1] += this.options.offset; |
michael@0 | 535 | var max = window.innerHeight ? |
michael@0 | 536 | window.height - window.innerHeight : |
michael@0 | 537 | document.body.scrollHeight - |
michael@0 | 538 | (document.documentElement.clientHeight ? |
michael@0 | 539 | document.documentElement.clientHeight : document.body.clientHeight); |
michael@0 | 540 | this.scrollStart = Position.deltaY; |
michael@0 | 541 | this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart; |
michael@0 | 542 | }, |
michael@0 | 543 | update: function(position) { |
michael@0 | 544 | Position.prepare(); |
michael@0 | 545 | window.scrollTo(Position.deltaX, |
michael@0 | 546 | this.scrollStart + (position*this.delta)); |
michael@0 | 547 | } |
michael@0 | 548 | }); |
michael@0 | 549 | |
michael@0 | 550 | /* ------------- combination effects ------------- */ |
michael@0 | 551 | |
michael@0 | 552 | Effect.Fade = function(element) { |
michael@0 | 553 | element = $(element); |
michael@0 | 554 | var oldOpacity = element.getInlineOpacity(); |
michael@0 | 555 | var options = Object.extend({ |
michael@0 | 556 | from: element.getOpacity() || 1.0, |
michael@0 | 557 | to: 0.0, |
michael@0 | 558 | afterFinishInternal: function(effect) { |
michael@0 | 559 | if(effect.options.to!=0) return; |
michael@0 | 560 | effect.element.hide().setStyle({opacity: oldOpacity}); |
michael@0 | 561 | }}, arguments[1] || {}); |
michael@0 | 562 | return new Effect.Opacity(element,options); |
michael@0 | 563 | } |
michael@0 | 564 | |
michael@0 | 565 | Effect.Appear = function(element) { |
michael@0 | 566 | element = $(element); |
michael@0 | 567 | var options = Object.extend({ |
michael@0 | 568 | from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0), |
michael@0 | 569 | to: 1.0, |
michael@0 | 570 | // force Safari to render floated elements properly |
michael@0 | 571 | afterFinishInternal: function(effect) { |
michael@0 | 572 | effect.element.forceRerendering(); |
michael@0 | 573 | }, |
michael@0 | 574 | beforeSetup: function(effect) { |
michael@0 | 575 | effect.element.setOpacity(effect.options.from).show(); |
michael@0 | 576 | }}, arguments[1] || {}); |
michael@0 | 577 | return new Effect.Opacity(element,options); |
michael@0 | 578 | } |
michael@0 | 579 | |
michael@0 | 580 | Effect.Puff = function(element) { |
michael@0 | 581 | element = $(element); |
michael@0 | 582 | var oldStyle = { |
michael@0 | 583 | opacity: element.getInlineOpacity(), |
michael@0 | 584 | position: element.getStyle('position'), |
michael@0 | 585 | top: element.style.top, |
michael@0 | 586 | left: element.style.left, |
michael@0 | 587 | width: element.style.width, |
michael@0 | 588 | height: element.style.height |
michael@0 | 589 | }; |
michael@0 | 590 | return new Effect.Parallel( |
michael@0 | 591 | [ new Effect.Scale(element, 200, |
michael@0 | 592 | { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }), |
michael@0 | 593 | new Effect.Opacity(element, { sync: true, to: 0.0 } ) ], |
michael@0 | 594 | Object.extend({ duration: 1.0, |
michael@0 | 595 | beforeSetupInternal: function(effect) { |
michael@0 | 596 | Position.absolutize(effect.effects[0].element) |
michael@0 | 597 | }, |
michael@0 | 598 | afterFinishInternal: function(effect) { |
michael@0 | 599 | effect.effects[0].element.hide().setStyle(oldStyle); } |
michael@0 | 600 | }, arguments[1] || {}) |
michael@0 | 601 | ); |
michael@0 | 602 | } |
michael@0 | 603 | |
michael@0 | 604 | Effect.BlindUp = function(element) { |
michael@0 | 605 | element = $(element); |
michael@0 | 606 | element.makeClipping(); |
michael@0 | 607 | return new Effect.Scale(element, 0, |
michael@0 | 608 | Object.extend({ scaleContent: false, |
michael@0 | 609 | scaleX: false, |
michael@0 | 610 | restoreAfterFinish: true, |
michael@0 | 611 | afterFinishInternal: function(effect) { |
michael@0 | 612 | effect.element.hide().undoClipping(); |
michael@0 | 613 | } |
michael@0 | 614 | }, arguments[1] || {}) |
michael@0 | 615 | ); |
michael@0 | 616 | } |
michael@0 | 617 | |
michael@0 | 618 | Effect.BlindDown = function(element) { |
michael@0 | 619 | element = $(element); |
michael@0 | 620 | var elementDimensions = element.getDimensions(); |
michael@0 | 621 | return new Effect.Scale(element, 100, Object.extend({ |
michael@0 | 622 | scaleContent: false, |
michael@0 | 623 | scaleX: false, |
michael@0 | 624 | scaleFrom: 0, |
michael@0 | 625 | scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, |
michael@0 | 626 | restoreAfterFinish: true, |
michael@0 | 627 | afterSetup: function(effect) { |
michael@0 | 628 | effect.element.makeClipping().setStyle({height: '0px'}).show(); |
michael@0 | 629 | }, |
michael@0 | 630 | afterFinishInternal: function(effect) { |
michael@0 | 631 | effect.element.undoClipping(); |
michael@0 | 632 | } |
michael@0 | 633 | }, arguments[1] || {})); |
michael@0 | 634 | } |
michael@0 | 635 | |
michael@0 | 636 | Effect.SwitchOff = function(element) { |
michael@0 | 637 | element = $(element); |
michael@0 | 638 | var oldOpacity = element.getInlineOpacity(); |
michael@0 | 639 | return new Effect.Appear(element, Object.extend({ |
michael@0 | 640 | duration: 0.4, |
michael@0 | 641 | from: 0, |
michael@0 | 642 | transition: Effect.Transitions.flicker, |
michael@0 | 643 | afterFinishInternal: function(effect) { |
michael@0 | 644 | new Effect.Scale(effect.element, 1, { |
michael@0 | 645 | duration: 0.3, scaleFromCenter: true, |
michael@0 | 646 | scaleX: false, scaleContent: false, restoreAfterFinish: true, |
michael@0 | 647 | beforeSetup: function(effect) { |
michael@0 | 648 | effect.element.makePositioned().makeClipping(); |
michael@0 | 649 | }, |
michael@0 | 650 | afterFinishInternal: function(effect) { |
michael@0 | 651 | effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity}); |
michael@0 | 652 | } |
michael@0 | 653 | }) |
michael@0 | 654 | } |
michael@0 | 655 | }, arguments[1] || {})); |
michael@0 | 656 | } |
michael@0 | 657 | |
michael@0 | 658 | Effect.DropOut = function(element) { |
michael@0 | 659 | element = $(element); |
michael@0 | 660 | var oldStyle = { |
michael@0 | 661 | top: element.getStyle('top'), |
michael@0 | 662 | left: element.getStyle('left'), |
michael@0 | 663 | opacity: element.getInlineOpacity() }; |
michael@0 | 664 | return new Effect.Parallel( |
michael@0 | 665 | [ new Effect.Move(element, {x: 0, y: 100, sync: true }), |
michael@0 | 666 | new Effect.Opacity(element, { sync: true, to: 0.0 }) ], |
michael@0 | 667 | Object.extend( |
michael@0 | 668 | { duration: 0.5, |
michael@0 | 669 | beforeSetup: function(effect) { |
michael@0 | 670 | effect.effects[0].element.makePositioned(); |
michael@0 | 671 | }, |
michael@0 | 672 | afterFinishInternal: function(effect) { |
michael@0 | 673 | effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle); |
michael@0 | 674 | } |
michael@0 | 675 | }, arguments[1] || {})); |
michael@0 | 676 | } |
michael@0 | 677 | |
michael@0 | 678 | Effect.Shake = function(element) { |
michael@0 | 679 | element = $(element); |
michael@0 | 680 | var oldStyle = { |
michael@0 | 681 | top: element.getStyle('top'), |
michael@0 | 682 | left: element.getStyle('left') }; |
michael@0 | 683 | return new Effect.Move(element, |
michael@0 | 684 | { x: 20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { |
michael@0 | 685 | new Effect.Move(effect.element, |
michael@0 | 686 | { x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { |
michael@0 | 687 | new Effect.Move(effect.element, |
michael@0 | 688 | { x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { |
michael@0 | 689 | new Effect.Move(effect.element, |
michael@0 | 690 | { x: -40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { |
michael@0 | 691 | new Effect.Move(effect.element, |
michael@0 | 692 | { x: 40, y: 0, duration: 0.1, afterFinishInternal: function(effect) { |
michael@0 | 693 | new Effect.Move(effect.element, |
michael@0 | 694 | { x: -20, y: 0, duration: 0.05, afterFinishInternal: function(effect) { |
michael@0 | 695 | effect.element.undoPositioned().setStyle(oldStyle); |
michael@0 | 696 | }}) }}) }}) }}) }}) }}); |
michael@0 | 697 | } |
michael@0 | 698 | |
michael@0 | 699 | Effect.SlideDown = function(element) { |
michael@0 | 700 | element = $(element).cleanWhitespace(); |
michael@0 | 701 | // SlideDown need to have the content of the element wrapped in a container element with fixed height! |
michael@0 | 702 | var oldInnerBottom = element.down().getStyle('bottom'); |
michael@0 | 703 | var elementDimensions = element.getDimensions(); |
michael@0 | 704 | return new Effect.Scale(element, 100, Object.extend({ |
michael@0 | 705 | scaleContent: false, |
michael@0 | 706 | scaleX: false, |
michael@0 | 707 | scaleFrom: window.opera ? 0 : 1, |
michael@0 | 708 | scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width}, |
michael@0 | 709 | restoreAfterFinish: true, |
michael@0 | 710 | afterSetup: function(effect) { |
michael@0 | 711 | effect.element.makePositioned(); |
michael@0 | 712 | effect.element.down().makePositioned(); |
michael@0 | 713 | if(window.opera) effect.element.setStyle({top: ''}); |
michael@0 | 714 | effect.element.makeClipping().setStyle({height: '0px'}).show(); |
michael@0 | 715 | }, |
michael@0 | 716 | afterUpdateInternal: function(effect) { |
michael@0 | 717 | effect.element.down().setStyle({bottom: |
michael@0 | 718 | (effect.dims[0] - effect.element.clientHeight) + 'px' }); |
michael@0 | 719 | }, |
michael@0 | 720 | afterFinishInternal: function(effect) { |
michael@0 | 721 | effect.element.undoClipping().undoPositioned(); |
michael@0 | 722 | effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); } |
michael@0 | 723 | }, arguments[1] || {}) |
michael@0 | 724 | ); |
michael@0 | 725 | } |
michael@0 | 726 | |
michael@0 | 727 | Effect.SlideUp = function(element) { |
michael@0 | 728 | element = $(element).cleanWhitespace(); |
michael@0 | 729 | var oldInnerBottom = element.down().getStyle('bottom'); |
michael@0 | 730 | return new Effect.Scale(element, window.opera ? 0 : 1, |
michael@0 | 731 | Object.extend({ scaleContent: false, |
michael@0 | 732 | scaleX: false, |
michael@0 | 733 | scaleMode: 'box', |
michael@0 | 734 | scaleFrom: 100, |
michael@0 | 735 | restoreAfterFinish: true, |
michael@0 | 736 | beforeStartInternal: function(effect) { |
michael@0 | 737 | effect.element.makePositioned(); |
michael@0 | 738 | effect.element.down().makePositioned(); |
michael@0 | 739 | if(window.opera) effect.element.setStyle({top: ''}); |
michael@0 | 740 | effect.element.makeClipping().show(); |
michael@0 | 741 | }, |
michael@0 | 742 | afterUpdateInternal: function(effect) { |
michael@0 | 743 | effect.element.down().setStyle({bottom: |
michael@0 | 744 | (effect.dims[0] - effect.element.clientHeight) + 'px' }); |
michael@0 | 745 | }, |
michael@0 | 746 | afterFinishInternal: function(effect) { |
michael@0 | 747 | effect.element.hide().undoClipping().undoPositioned().setStyle({bottom: oldInnerBottom}); |
michael@0 | 748 | effect.element.down().undoPositioned(); |
michael@0 | 749 | } |
michael@0 | 750 | }, arguments[1] || {}) |
michael@0 | 751 | ); |
michael@0 | 752 | } |
michael@0 | 753 | |
michael@0 | 754 | // Bug in opera makes the TD containing this element expand for a instance after finish |
michael@0 | 755 | Effect.Squish = function(element) { |
michael@0 | 756 | return new Effect.Scale(element, window.opera ? 1 : 0, { |
michael@0 | 757 | restoreAfterFinish: true, |
michael@0 | 758 | beforeSetup: function(effect) { |
michael@0 | 759 | effect.element.makeClipping(); |
michael@0 | 760 | }, |
michael@0 | 761 | afterFinishInternal: function(effect) { |
michael@0 | 762 | effect.element.hide().undoClipping(); |
michael@0 | 763 | } |
michael@0 | 764 | }); |
michael@0 | 765 | } |
michael@0 | 766 | |
michael@0 | 767 | Effect.Grow = function(element) { |
michael@0 | 768 | element = $(element); |
michael@0 | 769 | var options = Object.extend({ |
michael@0 | 770 | direction: 'center', |
michael@0 | 771 | moveTransition: Effect.Transitions.sinoidal, |
michael@0 | 772 | scaleTransition: Effect.Transitions.sinoidal, |
michael@0 | 773 | opacityTransition: Effect.Transitions.full |
michael@0 | 774 | }, arguments[1] || {}); |
michael@0 | 775 | var oldStyle = { |
michael@0 | 776 | top: element.style.top, |
michael@0 | 777 | left: element.style.left, |
michael@0 | 778 | height: element.style.height, |
michael@0 | 779 | width: element.style.width, |
michael@0 | 780 | opacity: element.getInlineOpacity() }; |
michael@0 | 781 | |
michael@0 | 782 | var dims = element.getDimensions(); |
michael@0 | 783 | var initialMoveX, initialMoveY; |
michael@0 | 784 | var moveX, moveY; |
michael@0 | 785 | |
michael@0 | 786 | switch (options.direction) { |
michael@0 | 787 | case 'top-left': |
michael@0 | 788 | initialMoveX = initialMoveY = moveX = moveY = 0; |
michael@0 | 789 | break; |
michael@0 | 790 | case 'top-right': |
michael@0 | 791 | initialMoveX = dims.width; |
michael@0 | 792 | initialMoveY = moveY = 0; |
michael@0 | 793 | moveX = -dims.width; |
michael@0 | 794 | break; |
michael@0 | 795 | case 'bottom-left': |
michael@0 | 796 | initialMoveX = moveX = 0; |
michael@0 | 797 | initialMoveY = dims.height; |
michael@0 | 798 | moveY = -dims.height; |
michael@0 | 799 | break; |
michael@0 | 800 | case 'bottom-right': |
michael@0 | 801 | initialMoveX = dims.width; |
michael@0 | 802 | initialMoveY = dims.height; |
michael@0 | 803 | moveX = -dims.width; |
michael@0 | 804 | moveY = -dims.height; |
michael@0 | 805 | break; |
michael@0 | 806 | case 'center': |
michael@0 | 807 | initialMoveX = dims.width / 2; |
michael@0 | 808 | initialMoveY = dims.height / 2; |
michael@0 | 809 | moveX = -dims.width / 2; |
michael@0 | 810 | moveY = -dims.height / 2; |
michael@0 | 811 | break; |
michael@0 | 812 | } |
michael@0 | 813 | |
michael@0 | 814 | return new Effect.Move(element, { |
michael@0 | 815 | x: initialMoveX, |
michael@0 | 816 | y: initialMoveY, |
michael@0 | 817 | duration: 0.01, |
michael@0 | 818 | beforeSetup: function(effect) { |
michael@0 | 819 | effect.element.hide().makeClipping().makePositioned(); |
michael@0 | 820 | }, |
michael@0 | 821 | afterFinishInternal: function(effect) { |
michael@0 | 822 | new Effect.Parallel( |
michael@0 | 823 | [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }), |
michael@0 | 824 | new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }), |
michael@0 | 825 | new Effect.Scale(effect.element, 100, { |
michael@0 | 826 | scaleMode: { originalHeight: dims.height, originalWidth: dims.width }, |
michael@0 | 827 | sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true}) |
michael@0 | 828 | ], Object.extend({ |
michael@0 | 829 | beforeSetup: function(effect) { |
michael@0 | 830 | effect.effects[0].element.setStyle({height: '0px'}).show(); |
michael@0 | 831 | }, |
michael@0 | 832 | afterFinishInternal: function(effect) { |
michael@0 | 833 | effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle); |
michael@0 | 834 | } |
michael@0 | 835 | }, options) |
michael@0 | 836 | ) |
michael@0 | 837 | } |
michael@0 | 838 | }); |
michael@0 | 839 | } |
michael@0 | 840 | |
michael@0 | 841 | Effect.Shrink = function(element) { |
michael@0 | 842 | element = $(element); |
michael@0 | 843 | var options = Object.extend({ |
michael@0 | 844 | direction: 'center', |
michael@0 | 845 | moveTransition: Effect.Transitions.sinoidal, |
michael@0 | 846 | scaleTransition: Effect.Transitions.sinoidal, |
michael@0 | 847 | opacityTransition: Effect.Transitions.none |
michael@0 | 848 | }, arguments[1] || {}); |
michael@0 | 849 | var oldStyle = { |
michael@0 | 850 | top: element.style.top, |
michael@0 | 851 | left: element.style.left, |
michael@0 | 852 | height: element.style.height, |
michael@0 | 853 | width: element.style.width, |
michael@0 | 854 | opacity: element.getInlineOpacity() }; |
michael@0 | 855 | |
michael@0 | 856 | var dims = element.getDimensions(); |
michael@0 | 857 | var moveX, moveY; |
michael@0 | 858 | |
michael@0 | 859 | switch (options.direction) { |
michael@0 | 860 | case 'top-left': |
michael@0 | 861 | moveX = moveY = 0; |
michael@0 | 862 | break; |
michael@0 | 863 | case 'top-right': |
michael@0 | 864 | moveX = dims.width; |
michael@0 | 865 | moveY = 0; |
michael@0 | 866 | break; |
michael@0 | 867 | case 'bottom-left': |
michael@0 | 868 | moveX = 0; |
michael@0 | 869 | moveY = dims.height; |
michael@0 | 870 | break; |
michael@0 | 871 | case 'bottom-right': |
michael@0 | 872 | moveX = dims.width; |
michael@0 | 873 | moveY = dims.height; |
michael@0 | 874 | break; |
michael@0 | 875 | case 'center': |
michael@0 | 876 | moveX = dims.width / 2; |
michael@0 | 877 | moveY = dims.height / 2; |
michael@0 | 878 | break; |
michael@0 | 879 | } |
michael@0 | 880 | |
michael@0 | 881 | return new Effect.Parallel( |
michael@0 | 882 | [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }), |
michael@0 | 883 | new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}), |
michael@0 | 884 | new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }) |
michael@0 | 885 | ], Object.extend({ |
michael@0 | 886 | beforeStartInternal: function(effect) { |
michael@0 | 887 | effect.effects[0].element.makePositioned().makeClipping(); |
michael@0 | 888 | }, |
michael@0 | 889 | afterFinishInternal: function(effect) { |
michael@0 | 890 | effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); } |
michael@0 | 891 | }, options) |
michael@0 | 892 | ); |
michael@0 | 893 | } |
michael@0 | 894 | |
michael@0 | 895 | Effect.Pulsate = function(element) { |
michael@0 | 896 | element = $(element); |
michael@0 | 897 | var options = arguments[1] || {}; |
michael@0 | 898 | var oldOpacity = element.getInlineOpacity(); |
michael@0 | 899 | var transition = options.transition || Effect.Transitions.sinoidal; |
michael@0 | 900 | var reverser = function(pos){ return transition(1-Effect.Transitions.pulse(pos, options.pulses)) }; |
michael@0 | 901 | reverser.bind(transition); |
michael@0 | 902 | return new Effect.Opacity(element, |
michael@0 | 903 | Object.extend(Object.extend({ duration: 2.0, from: 0, |
michael@0 | 904 | afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); } |
michael@0 | 905 | }, options), {transition: reverser})); |
michael@0 | 906 | } |
michael@0 | 907 | |
michael@0 | 908 | Effect.Fold = function(element) { |
michael@0 | 909 | element = $(element); |
michael@0 | 910 | var oldStyle = { |
michael@0 | 911 | top: element.style.top, |
michael@0 | 912 | left: element.style.left, |
michael@0 | 913 | width: element.style.width, |
michael@0 | 914 | height: element.style.height }; |
michael@0 | 915 | element.makeClipping(); |
michael@0 | 916 | return new Effect.Scale(element, 5, Object.extend({ |
michael@0 | 917 | scaleContent: false, |
michael@0 | 918 | scaleX: false, |
michael@0 | 919 | afterFinishInternal: function(effect) { |
michael@0 | 920 | new Effect.Scale(element, 1, { |
michael@0 | 921 | scaleContent: false, |
michael@0 | 922 | scaleY: false, |
michael@0 | 923 | afterFinishInternal: function(effect) { |
michael@0 | 924 | effect.element.hide().undoClipping().setStyle(oldStyle); |
michael@0 | 925 | } }); |
michael@0 | 926 | }}, arguments[1] || {})); |
michael@0 | 927 | }; |
michael@0 | 928 | |
michael@0 | 929 | Effect.Morph = Class.create(); |
michael@0 | 930 | Object.extend(Object.extend(Effect.Morph.prototype, Effect.Base.prototype), { |
michael@0 | 931 | initialize: function(element) { |
michael@0 | 932 | this.element = $(element); |
michael@0 | 933 | if(!this.element) throw(Effect._elementDoesNotExistError); |
michael@0 | 934 | var options = Object.extend({ |
michael@0 | 935 | style: {} |
michael@0 | 936 | }, arguments[1] || {}); |
michael@0 | 937 | if (typeof options.style == 'string') { |
michael@0 | 938 | if(options.style.indexOf(':') == -1) { |
michael@0 | 939 | var cssText = '', selector = '.' + options.style; |
michael@0 | 940 | $A(document.styleSheets).reverse().each(function(styleSheet) { |
michael@0 | 941 | if (styleSheet.cssRules) cssRules = styleSheet.cssRules; |
michael@0 | 942 | else if (styleSheet.rules) cssRules = styleSheet.rules; |
michael@0 | 943 | $A(cssRules).reverse().each(function(rule) { |
michael@0 | 944 | if (selector == rule.selectorText) { |
michael@0 | 945 | cssText = rule.style.cssText; |
michael@0 | 946 | throw $break; |
michael@0 | 947 | } |
michael@0 | 948 | }); |
michael@0 | 949 | if (cssText) throw $break; |
michael@0 | 950 | }); |
michael@0 | 951 | this.style = cssText.parseStyle(); |
michael@0 | 952 | options.afterFinishInternal = function(effect){ |
michael@0 | 953 | effect.element.addClassName(effect.options.style); |
michael@0 | 954 | effect.transforms.each(function(transform) { |
michael@0 | 955 | if(transform.style != 'opacity') |
michael@0 | 956 | effect.element.style[transform.style] = ''; |
michael@0 | 957 | }); |
michael@0 | 958 | } |
michael@0 | 959 | } else this.style = options.style.parseStyle(); |
michael@0 | 960 | } else this.style = $H(options.style) |
michael@0 | 961 | this.start(options); |
michael@0 | 962 | }, |
michael@0 | 963 | setup: function(){ |
michael@0 | 964 | function parseColor(color){ |
michael@0 | 965 | if(!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff'; |
michael@0 | 966 | color = color.parseColor(); |
michael@0 | 967 | return $R(0,2).map(function(i){ |
michael@0 | 968 | return parseInt( color.slice(i*2+1,i*2+3), 16 ) |
michael@0 | 969 | }); |
michael@0 | 970 | } |
michael@0 | 971 | this.transforms = this.style.map(function(pair){ |
michael@0 | 972 | var property = pair[0], value = pair[1], unit = null; |
michael@0 | 973 | |
michael@0 | 974 | if(value.parseColor('#zzzzzz') != '#zzzzzz') { |
michael@0 | 975 | value = value.parseColor(); |
michael@0 | 976 | unit = 'color'; |
michael@0 | 977 | } else if(property == 'opacity') { |
michael@0 | 978 | value = parseFloat(value); |
michael@0 | 979 | if(Prototype.Browser.IE && (!this.element.currentStyle.hasLayout)) |
michael@0 | 980 | this.element.setStyle({zoom: 1}); |
michael@0 | 981 | } else if(Element.CSS_LENGTH.test(value)) { |
michael@0 | 982 | var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/); |
michael@0 | 983 | value = parseFloat(components[1]); |
michael@0 | 984 | unit = (components.length == 3) ? components[2] : null; |
michael@0 | 985 | } |
michael@0 | 986 | |
michael@0 | 987 | var originalValue = this.element.getStyle(property); |
michael@0 | 988 | return { |
michael@0 | 989 | style: property.camelize(), |
michael@0 | 990 | originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0), |
michael@0 | 991 | targetValue: unit=='color' ? parseColor(value) : value, |
michael@0 | 992 | unit: unit |
michael@0 | 993 | }; |
michael@0 | 994 | }.bind(this)).reject(function(transform){ |
michael@0 | 995 | return ( |
michael@0 | 996 | (transform.originalValue == transform.targetValue) || |
michael@0 | 997 | ( |
michael@0 | 998 | transform.unit != 'color' && |
michael@0 | 999 | (isNaN(transform.originalValue) || isNaN(transform.targetValue)) |
michael@0 | 1000 | ) |
michael@0 | 1001 | ) |
michael@0 | 1002 | }); |
michael@0 | 1003 | }, |
michael@0 | 1004 | update: function(position) { |
michael@0 | 1005 | var style = {}, transform, i = this.transforms.length; |
michael@0 | 1006 | while(i--) |
michael@0 | 1007 | style[(transform = this.transforms[i]).style] = |
michael@0 | 1008 | transform.unit=='color' ? '#'+ |
michael@0 | 1009 | (Math.round(transform.originalValue[0]+ |
michael@0 | 1010 | (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() + |
michael@0 | 1011 | (Math.round(transform.originalValue[1]+ |
michael@0 | 1012 | (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() + |
michael@0 | 1013 | (Math.round(transform.originalValue[2]+ |
michael@0 | 1014 | (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() : |
michael@0 | 1015 | transform.originalValue + Math.round( |
michael@0 | 1016 | ((transform.targetValue - transform.originalValue) * position) * 1000)/1000 + transform.unit; |
michael@0 | 1017 | this.element.setStyle(style, true); |
michael@0 | 1018 | } |
michael@0 | 1019 | }); |
michael@0 | 1020 | |
michael@0 | 1021 | Effect.Transform = Class.create(); |
michael@0 | 1022 | Object.extend(Effect.Transform.prototype, { |
michael@0 | 1023 | initialize: function(tracks){ |
michael@0 | 1024 | this.tracks = []; |
michael@0 | 1025 | this.options = arguments[1] || {}; |
michael@0 | 1026 | this.addTracks(tracks); |
michael@0 | 1027 | }, |
michael@0 | 1028 | addTracks: function(tracks){ |
michael@0 | 1029 | tracks.each(function(track){ |
michael@0 | 1030 | var data = $H(track).values().first(); |
michael@0 | 1031 | this.tracks.push($H({ |
michael@0 | 1032 | ids: $H(track).keys().first(), |
michael@0 | 1033 | effect: Effect.Morph, |
michael@0 | 1034 | options: { style: data } |
michael@0 | 1035 | })); |
michael@0 | 1036 | }.bind(this)); |
michael@0 | 1037 | return this; |
michael@0 | 1038 | }, |
michael@0 | 1039 | play: function(){ |
michael@0 | 1040 | return new Effect.Parallel( |
michael@0 | 1041 | this.tracks.map(function(track){ |
michael@0 | 1042 | var elements = [$(track.ids) || $$(track.ids)].flatten(); |
michael@0 | 1043 | return elements.map(function(e){ return new track.effect(e, Object.extend({ sync:true }, track.options)) }); |
michael@0 | 1044 | }).flatten(), |
michael@0 | 1045 | this.options |
michael@0 | 1046 | ); |
michael@0 | 1047 | } |
michael@0 | 1048 | }); |
michael@0 | 1049 | |
michael@0 | 1050 | Element.CSS_PROPERTIES = $w( |
michael@0 | 1051 | 'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' + |
michael@0 | 1052 | 'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' + |
michael@0 | 1053 | 'borderRightColor borderRightStyle borderRightWidth borderSpacing ' + |
michael@0 | 1054 | 'borderTopColor borderTopStyle borderTopWidth bottom clip color ' + |
michael@0 | 1055 | 'fontSize fontWeight height left letterSpacing lineHeight ' + |
michael@0 | 1056 | 'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+ |
michael@0 | 1057 | 'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' + |
michael@0 | 1058 | 'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' + |
michael@0 | 1059 | 'right textIndent top width wordSpacing zIndex'); |
michael@0 | 1060 | |
michael@0 | 1061 | Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; |
michael@0 | 1062 | |
michael@0 | 1063 | String.prototype.parseStyle = function(){ |
michael@0 | 1064 | var element = document.createElement('div'); |
michael@0 | 1065 | element.innerHTML = '<div style="' + this + '"></div>'; |
michael@0 | 1066 | var style = element.childNodes[0].style, styleRules = $H(); |
michael@0 | 1067 | |
michael@0 | 1068 | Element.CSS_PROPERTIES.each(function(property){ |
michael@0 | 1069 | if(style[property]) styleRules[property] = style[property]; |
michael@0 | 1070 | }); |
michael@0 | 1071 | if(Prototype.Browser.IE && this.indexOf('opacity') > -1) { |
michael@0 | 1072 | styleRules.opacity = this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]; |
michael@0 | 1073 | } |
michael@0 | 1074 | return styleRules; |
michael@0 | 1075 | }; |
michael@0 | 1076 | |
michael@0 | 1077 | Element.morph = function(element, style) { |
michael@0 | 1078 | new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || {})); |
michael@0 | 1079 | return element; |
michael@0 | 1080 | }; |
michael@0 | 1081 | |
michael@0 | 1082 | ['getInlineOpacity','forceRerendering','setContentZoom', |
michael@0 | 1083 | 'collectTextNodes','collectTextNodesIgnoreClass','morph'].each( |
michael@0 | 1084 | function(f) { Element.Methods[f] = Element[f]; } |
michael@0 | 1085 | ); |
michael@0 | 1086 | |
michael@0 | 1087 | Element.Methods.visualEffect = function(element, effect, options) { |
michael@0 | 1088 | s = effect.dasherize().camelize(); |
michael@0 | 1089 | effect_class = s.charAt(0).toUpperCase() + s.substring(1); |
michael@0 | 1090 | new Effect[effect_class](element, options); |
michael@0 | 1091 | return $(element); |
michael@0 | 1092 | }; |
michael@0 | 1093 | |
michael@0 | 1094 | Element.addMethods(); |