1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/ajax/mochikit/MochiKit/Visual.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,1981 @@ 1.4 +/*** 1.5 + 1.6 +MochiKit.Visual 1.4 1.7 + 1.8 +See <http://mochikit.com/> for documentation, downloads, license, etc. 1.9 + 1.10 +(c) 2005 Bob Ippolito and others. All rights Reserved. 1.11 + 1.12 +***/ 1.13 + 1.14 +if (typeof(dojo) != 'undefined') { 1.15 + dojo.provide('MochiKit.Visual'); 1.16 + dojo.require('MochiKit.Base'); 1.17 + dojo.require('MochiKit.DOM'); 1.18 + dojo.require('MochiKit.Style'); 1.19 + dojo.require('MochiKit.Color'); 1.20 + dojo.require('MochiKit.Position'); 1.21 +} 1.22 + 1.23 +if (typeof(JSAN) != 'undefined') { 1.24 + JSAN.use("MochiKit.Base", []); 1.25 + JSAN.use("MochiKit.DOM", []); 1.26 + JSAN.use("MochiKit.Style", []); 1.27 + JSAN.use("MochiKit.Color", []); 1.28 + JSAN.use("MochiKit.Position", []); 1.29 +} 1.30 + 1.31 +try { 1.32 + if (typeof(MochiKit.Base) === 'undefined' || 1.33 + typeof(MochiKit.DOM) === 'undefined' || 1.34 + typeof(MochiKit.Style) === 'undefined' || 1.35 + typeof(MochiKit.Position) === 'undefined' || 1.36 + typeof(MochiKit.Color) === 'undefined') { 1.37 + throw ""; 1.38 + } 1.39 +} catch (e) { 1.40 + throw "MochiKit.Visual depends on MochiKit.Base, MochiKit.DOM, MochiKit.Style, MochiKit.Position and MochiKit.Color!"; 1.41 +} 1.42 + 1.43 +if (typeof(MochiKit.Visual) == "undefined") { 1.44 + MochiKit.Visual = {}; 1.45 +} 1.46 + 1.47 +MochiKit.Visual.NAME = "MochiKit.Visual"; 1.48 +MochiKit.Visual.VERSION = "1.4"; 1.49 + 1.50 +MochiKit.Visual.__repr__ = function () { 1.51 + return "[" + this.NAME + " " + this.VERSION + "]"; 1.52 +}; 1.53 + 1.54 +MochiKit.Visual.toString = function () { 1.55 + return this.__repr__(); 1.56 +}; 1.57 + 1.58 +MochiKit.Visual._RoundCorners = function (e, options) { 1.59 + e = MochiKit.DOM.getElement(e); 1.60 + this._setOptions(options); 1.61 + if (this.options.__unstable__wrapElement) { 1.62 + e = this._doWrap(e); 1.63 + } 1.64 + 1.65 + var color = this.options.color; 1.66 + var C = MochiKit.Color.Color; 1.67 + if (this.options.color === "fromElement") { 1.68 + color = C.fromBackground(e); 1.69 + } else if (!(color instanceof C)) { 1.70 + color = C.fromString(color); 1.71 + } 1.72 + this.isTransparent = (color.asRGB().a <= 0); 1.73 + 1.74 + var bgColor = this.options.bgColor; 1.75 + if (this.options.bgColor === "fromParent") { 1.76 + bgColor = C.fromBackground(e.offsetParent); 1.77 + } else if (!(bgColor instanceof C)) { 1.78 + bgColor = C.fromString(bgColor); 1.79 + } 1.80 + 1.81 + this._roundCornersImpl(e, color, bgColor); 1.82 +}; 1.83 + 1.84 +MochiKit.Visual._RoundCorners.prototype = { 1.85 + _doWrap: function (e) { 1.86 + var parent = e.parentNode; 1.87 + var doc = MochiKit.DOM.currentDocument(); 1.88 + if (typeof(doc.defaultView) === "undefined" 1.89 + || doc.defaultView === null) { 1.90 + return e; 1.91 + } 1.92 + var style = doc.defaultView.getComputedStyle(e, null); 1.93 + if (typeof(style) === "undefined" || style === null) { 1.94 + return e; 1.95 + } 1.96 + var wrapper = MochiKit.DOM.DIV({"style": { 1.97 + display: "block", 1.98 + // convert padding to margin 1.99 + marginTop: style.getPropertyValue("padding-top"), 1.100 + marginRight: style.getPropertyValue("padding-right"), 1.101 + marginBottom: style.getPropertyValue("padding-bottom"), 1.102 + marginLeft: style.getPropertyValue("padding-left"), 1.103 + // remove padding so the rounding looks right 1.104 + padding: "0px" 1.105 + /* 1.106 + paddingRight: "0px", 1.107 + paddingLeft: "0px" 1.108 + */ 1.109 + }}); 1.110 + wrapper.innerHTML = e.innerHTML; 1.111 + e.innerHTML = ""; 1.112 + e.appendChild(wrapper); 1.113 + return e; 1.114 + }, 1.115 + 1.116 + _roundCornersImpl: function (e, color, bgColor) { 1.117 + if (this.options.border) { 1.118 + this._renderBorder(e, bgColor); 1.119 + } 1.120 + if (this._isTopRounded()) { 1.121 + this._roundTopCorners(e, color, bgColor); 1.122 + } 1.123 + if (this._isBottomRounded()) { 1.124 + this._roundBottomCorners(e, color, bgColor); 1.125 + } 1.126 + }, 1.127 + 1.128 + _renderBorder: function (el, bgColor) { 1.129 + var borderValue = "1px solid " + this._borderColor(bgColor); 1.130 + var borderL = "border-left: " + borderValue; 1.131 + var borderR = "border-right: " + borderValue; 1.132 + var style = "style='" + borderL + ";" + borderR + "'"; 1.133 + el.innerHTML = "<div " + style + ">" + el.innerHTML + "</div>"; 1.134 + }, 1.135 + 1.136 + _roundTopCorners: function (el, color, bgColor) { 1.137 + var corner = this._createCorner(bgColor); 1.138 + for (var i = 0; i < this.options.numSlices; i++) { 1.139 + corner.appendChild( 1.140 + this._createCornerSlice(color, bgColor, i, "top") 1.141 + ); 1.142 + } 1.143 + el.style.paddingTop = 0; 1.144 + el.insertBefore(corner, el.firstChild); 1.145 + }, 1.146 + 1.147 + _roundBottomCorners: function (el, color, bgColor) { 1.148 + var corner = this._createCorner(bgColor); 1.149 + for (var i = (this.options.numSlices - 1); i >= 0; i--) { 1.150 + corner.appendChild( 1.151 + this._createCornerSlice(color, bgColor, i, "bottom") 1.152 + ); 1.153 + } 1.154 + el.style.paddingBottom = 0; 1.155 + el.appendChild(corner); 1.156 + }, 1.157 + 1.158 + _createCorner: function (bgColor) { 1.159 + var dom = MochiKit.DOM; 1.160 + return dom.DIV({style: {backgroundColor: bgColor.toString()}}); 1.161 + }, 1.162 + 1.163 + _createCornerSlice: function (color, bgColor, n, position) { 1.164 + var slice = MochiKit.DOM.SPAN(); 1.165 + 1.166 + var inStyle = slice.style; 1.167 + inStyle.backgroundColor = color.toString(); 1.168 + inStyle.display = "block"; 1.169 + inStyle.height = "1px"; 1.170 + inStyle.overflow = "hidden"; 1.171 + inStyle.fontSize = "1px"; 1.172 + 1.173 + var borderColor = this._borderColor(color, bgColor); 1.174 + if (this.options.border && n === 0) { 1.175 + inStyle.borderTopStyle = "solid"; 1.176 + inStyle.borderTopWidth = "1px"; 1.177 + inStyle.borderLeftWidth = "0px"; 1.178 + inStyle.borderRightWidth = "0px"; 1.179 + inStyle.borderBottomWidth = "0px"; 1.180 + // assumes css compliant box model 1.181 + inStyle.height = "0px"; 1.182 + inStyle.borderColor = borderColor.toString(); 1.183 + } else if (borderColor) { 1.184 + inStyle.borderColor = borderColor.toString(); 1.185 + inStyle.borderStyle = "solid"; 1.186 + inStyle.borderWidth = "0px 1px"; 1.187 + } 1.188 + 1.189 + if (!this.options.compact && (n == (this.options.numSlices - 1))) { 1.190 + inStyle.height = "2px"; 1.191 + } 1.192 + 1.193 + this._setMargin(slice, n, position); 1.194 + this._setBorder(slice, n, position); 1.195 + 1.196 + return slice; 1.197 + }, 1.198 + 1.199 + _setOptions: function (options) { 1.200 + this.options = { 1.201 + corners: "all", 1.202 + color: "fromElement", 1.203 + bgColor: "fromParent", 1.204 + blend: true, 1.205 + border: false, 1.206 + compact: false, 1.207 + __unstable__wrapElement: false 1.208 + }; 1.209 + MochiKit.Base.update(this.options, options); 1.210 + 1.211 + this.options.numSlices = (this.options.compact ? 2 : 4); 1.212 + }, 1.213 + 1.214 + _whichSideTop: function () { 1.215 + var corners = this.options.corners; 1.216 + if (this._hasString(corners, "all", "top")) { 1.217 + return ""; 1.218 + } 1.219 + 1.220 + var has_tl = (corners.indexOf("tl") != -1); 1.221 + var has_tr = (corners.indexOf("tr") != -1); 1.222 + if (has_tl && has_tr) { 1.223 + return ""; 1.224 + } 1.225 + if (has_tl) { 1.226 + return "left"; 1.227 + } 1.228 + if (has_tr) { 1.229 + return "right"; 1.230 + } 1.231 + return ""; 1.232 + }, 1.233 + 1.234 + _whichSideBottom: function () { 1.235 + var corners = this.options.corners; 1.236 + if (this._hasString(corners, "all", "bottom")) { 1.237 + return ""; 1.238 + } 1.239 + 1.240 + var has_bl = (corners.indexOf('bl') != -1); 1.241 + var has_br = (corners.indexOf('br') != -1); 1.242 + if (has_bl && has_br) { 1.243 + return ""; 1.244 + } 1.245 + if (has_bl) { 1.246 + return "left"; 1.247 + } 1.248 + if (has_br) { 1.249 + return "right"; 1.250 + } 1.251 + return ""; 1.252 + }, 1.253 + 1.254 + _borderColor: function (color, bgColor) { 1.255 + if (color == "transparent") { 1.256 + return bgColor; 1.257 + } else if (this.options.border) { 1.258 + return this.options.border; 1.259 + } else if (this.options.blend) { 1.260 + return bgColor.blendedColor(color); 1.261 + } 1.262 + return ""; 1.263 + }, 1.264 + 1.265 + 1.266 + _setMargin: function (el, n, corners) { 1.267 + var marginSize = this._marginSize(n) + "px"; 1.268 + var whichSide = ( 1.269 + corners == "top" ? this._whichSideTop() : this._whichSideBottom() 1.270 + ); 1.271 + var style = el.style; 1.272 + 1.273 + if (whichSide == "left") { 1.274 + style.marginLeft = marginSize; 1.275 + style.marginRight = "0px"; 1.276 + } else if (whichSide == "right") { 1.277 + style.marginRight = marginSize; 1.278 + style.marginLeft = "0px"; 1.279 + } else { 1.280 + style.marginLeft = marginSize; 1.281 + style.marginRight = marginSize; 1.282 + } 1.283 + }, 1.284 + 1.285 + _setBorder: function (el, n, corners) { 1.286 + var borderSize = this._borderSize(n) + "px"; 1.287 + var whichSide = ( 1.288 + corners == "top" ? this._whichSideTop() : this._whichSideBottom() 1.289 + ); 1.290 + 1.291 + var style = el.style; 1.292 + if (whichSide == "left") { 1.293 + style.borderLeftWidth = borderSize; 1.294 + style.borderRightWidth = "0px"; 1.295 + } else if (whichSide == "right") { 1.296 + style.borderRightWidth = borderSize; 1.297 + style.borderLeftWidth = "0px"; 1.298 + } else { 1.299 + style.borderLeftWidth = borderSize; 1.300 + style.borderRightWidth = borderSize; 1.301 + } 1.302 + }, 1.303 + 1.304 + _marginSize: function (n) { 1.305 + if (this.isTransparent) { 1.306 + return 0; 1.307 + } 1.308 + 1.309 + var o = this.options; 1.310 + if (o.compact && o.blend) { 1.311 + var smBlendedMarginSizes = [1, 0]; 1.312 + return smBlendedMarginSizes[n]; 1.313 + } else if (o.compact) { 1.314 + var compactMarginSizes = [2, 1]; 1.315 + return compactMarginSizes[n]; 1.316 + } else if (o.blend) { 1.317 + var blendedMarginSizes = [3, 2, 1, 0]; 1.318 + return blendedMarginSizes[n]; 1.319 + } else { 1.320 + var marginSizes = [5, 3, 2, 1]; 1.321 + return marginSizes[n]; 1.322 + } 1.323 + }, 1.324 + 1.325 + _borderSize: function (n) { 1.326 + var o = this.options; 1.327 + var borderSizes; 1.328 + if (o.compact && (o.blend || this.isTransparent)) { 1.329 + return 1; 1.330 + } else if (o.compact) { 1.331 + borderSizes = [1, 0]; 1.332 + } else if (o.blend) { 1.333 + borderSizes = [2, 1, 1, 1]; 1.334 + } else if (o.border) { 1.335 + borderSizes = [0, 2, 0, 0]; 1.336 + } else if (this.isTransparent) { 1.337 + borderSizes = [5, 3, 2, 1]; 1.338 + } else { 1.339 + return 0; 1.340 + } 1.341 + return borderSizes[n]; 1.342 + }, 1.343 + 1.344 + _hasString: function (str) { 1.345 + for (var i = 1; i< arguments.length; i++) { 1.346 + if (str.indexOf(arguments[i]) != -1) { 1.347 + return true; 1.348 + } 1.349 + } 1.350 + return false; 1.351 + }, 1.352 + 1.353 + _isTopRounded: function () { 1.354 + return this._hasString(this.options.corners, 1.355 + "all", "top", "tl", "tr" 1.356 + ); 1.357 + }, 1.358 + 1.359 + _isBottomRounded: function () { 1.360 + return this._hasString(this.options.corners, 1.361 + "all", "bottom", "bl", "br" 1.362 + ); 1.363 + }, 1.364 + 1.365 + _hasSingleTextChild: function (el) { 1.366 + return (el.childNodes.length == 1 && el.childNodes[0].nodeType == 3); 1.367 + } 1.368 +}; 1.369 + 1.370 +/** @id MochiKit.Visual.roundElement */ 1.371 +MochiKit.Visual.roundElement = function (e, options) { 1.372 + new MochiKit.Visual._RoundCorners(e, options); 1.373 +}; 1.374 + 1.375 +/** @id MochiKit.Visual.roundClass */ 1.376 +MochiKit.Visual.roundClass = function (tagName, className, options) { 1.377 + var elements = MochiKit.DOM.getElementsByTagAndClassName( 1.378 + tagName, className 1.379 + ); 1.380 + for (var i = 0; i < elements.length; i++) { 1.381 + MochiKit.Visual.roundElement(elements[i], options); 1.382 + } 1.383 +}; 1.384 + 1.385 +/** @id MochiKit.Visual.tagifyText */ 1.386 +MochiKit.Visual.tagifyText = function (element, /* optional */tagifyStyle) { 1.387 + /*** 1.388 + 1.389 + Change a node text to character in tags. 1.390 + 1.391 + @param tagifyStyle: the style to apply to character nodes, default to 1.392 + 'position: relative'. 1.393 + 1.394 + ***/ 1.395 + tagifyStyle = tagifyStyle || 'position:relative'; 1.396 + if (/MSIE/.test(navigator.userAgent)) { 1.397 + tagifyStyle += ';zoom:1'; 1.398 + } 1.399 + element = MochiKit.DOM.getElement(element); 1.400 + var ma = MochiKit.Base.map; 1.401 + ma(function (child) { 1.402 + if (child.nodeType == 3) { 1.403 + ma(function (character) { 1.404 + element.insertBefore( 1.405 + MochiKit.DOM.SPAN({style: tagifyStyle}, 1.406 + character == ' ' ? String.fromCharCode(160) : character), child); 1.407 + }, child.nodeValue.split('')); 1.408 + MochiKit.DOM.removeElement(child); 1.409 + } 1.410 + }, element.childNodes); 1.411 +}; 1.412 + 1.413 +/** @id MochiKit.Visual.forceRerendering */ 1.414 +MochiKit.Visual.forceRerendering = function (element) { 1.415 + try { 1.416 + element = MochiKit.DOM.getElement(element); 1.417 + var n = document.createTextNode(' '); 1.418 + element.appendChild(n); 1.419 + element.removeChild(n); 1.420 + } catch(e) { 1.421 + } 1.422 +}; 1.423 + 1.424 +/** @id MochiKit.Visual.multiple */ 1.425 +MochiKit.Visual.multiple = function (elements, effect, /* optional */options) { 1.426 + /*** 1.427 + 1.428 + Launch the same effect subsequently on given elements. 1.429 + 1.430 + ***/ 1.431 + options = MochiKit.Base.update({ 1.432 + speed: 0.1, delay: 0.0 1.433 + }, options || {}); 1.434 + var masterDelay = options.delay; 1.435 + var index = 0; 1.436 + MochiKit.Base.map(function (innerelement) { 1.437 + options.delay = index * options.speed + masterDelay; 1.438 + new effect(innerelement, options); 1.439 + index += 1; 1.440 + }, elements); 1.441 +}; 1.442 + 1.443 +MochiKit.Visual.PAIRS = { 1.444 + 'slide': ['slideDown', 'slideUp'], 1.445 + 'blind': ['blindDown', 'blindUp'], 1.446 + 'appear': ['appear', 'fade'], 1.447 + 'size': ['grow', 'shrink'] 1.448 +}; 1.449 + 1.450 +/** @id MochiKit.Visual.toggle */ 1.451 +MochiKit.Visual.toggle = function (element, /* optional */effect, /* optional */options) { 1.452 + /*** 1.453 + 1.454 + Toggle an item between two state depending of its visibility, making 1.455 + a effect between these states. Default effect is 'appear', can be 1.456 + 'slide' or 'blind'. 1.457 + 1.458 + ***/ 1.459 + element = MochiKit.DOM.getElement(element); 1.460 + effect = (effect || 'appear').toLowerCase(); 1.461 + options = MochiKit.Base.update({ 1.462 + queue: {position: 'end', scope: (element.id || 'global'), limit: 1} 1.463 + }, options || {}); 1.464 + var v = MochiKit.Visual; 1.465 + v[MochiKit.Style.getStyle(element, 'display') != 'none' ? 1.466 + v.PAIRS[effect][1] : v.PAIRS[effect][0]](element, options); 1.467 +}; 1.468 + 1.469 +/*** 1.470 + 1.471 +Transitions: define functions calculating variations depending of a position. 1.472 + 1.473 +***/ 1.474 + 1.475 +MochiKit.Visual.Transitions = {}; 1.476 + 1.477 +/** @id MochiKit.Visual.Transitions.linear */ 1.478 +MochiKit.Visual.Transitions.linear = function (pos) { 1.479 + return pos; 1.480 +}; 1.481 + 1.482 +/** @id MochiKit.Visual.Transitions.sinoidal */ 1.483 +MochiKit.Visual.Transitions.sinoidal = function (pos) { 1.484 + return (-Math.cos(pos*Math.PI)/2) + 0.5; 1.485 +}; 1.486 + 1.487 +/** @id MochiKit.Visual.Transitions.reverse */ 1.488 +MochiKit.Visual.Transitions.reverse = function (pos) { 1.489 + return 1 - pos; 1.490 +}; 1.491 + 1.492 +/** @id MochiKit.Visual.Transitions.flicker */ 1.493 +MochiKit.Visual.Transitions.flicker = function (pos) { 1.494 + return ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4; 1.495 +}; 1.496 + 1.497 +/** @id MochiKit.Visual.Transitions.wobble */ 1.498 +MochiKit.Visual.Transitions.wobble = function (pos) { 1.499 + return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5; 1.500 +}; 1.501 + 1.502 +/** @id MochiKit.Visual.Transitions.pulse */ 1.503 +MochiKit.Visual.Transitions.pulse = function (pos, pulses) { 1.504 + if (!pulses) { 1.505 + return (Math.floor(pos*10) % 2 === 0 ? 1.506 + (pos*10 - Math.floor(pos*10)) : 1 - (pos*10 - Math.floor(pos*10))); 1.507 + } 1.508 + return (Math.round((pos % (1/pulses)) * pulses) == 0 ? 1.509 + ((pos * pulses * 2) - Math.floor(pos * pulses * 2)) : 1.510 + 1 - ((pos * pulses * 2) - Math.floor(pos * pulses * 2))); 1.511 +}; 1.512 + 1.513 +/** @id MochiKit.Visual.Transitions.none */ 1.514 +MochiKit.Visual.Transitions.none = function (pos) { 1.515 + return 0; 1.516 +}; 1.517 + 1.518 +/** @id MochiKit.Visual.Transitions.full */ 1.519 +MochiKit.Visual.Transitions.full = function (pos) { 1.520 + return 1; 1.521 +}; 1.522 + 1.523 +/*** 1.524 + 1.525 +Core effects 1.526 + 1.527 +***/ 1.528 + 1.529 +MochiKit.Visual.ScopedQueue = function () { 1.530 + var cls = arguments.callee; 1.531 + if (!(this instanceof cls)) { 1.532 + return new cls(); 1.533 + } 1.534 + this.__init__(); 1.535 +}; 1.536 + 1.537 +MochiKit.Base.update(MochiKit.Visual.ScopedQueue.prototype, { 1.538 + __init__: function () { 1.539 + this.effects = []; 1.540 + this.interval = null; 1.541 + }, 1.542 + 1.543 + /** @id MochiKit.Visual.ScopedQueue.prototype.add */ 1.544 + add: function (effect) { 1.545 + var timestamp = new Date().getTime(); 1.546 + 1.547 + var position = (typeof(effect.options.queue) == 'string') ? 1.548 + effect.options.queue : effect.options.queue.position; 1.549 + 1.550 + var ma = MochiKit.Base.map; 1.551 + switch (position) { 1.552 + case 'front': 1.553 + // move unstarted effects after this effect 1.554 + ma(function (e) { 1.555 + if (e.state == 'idle') { 1.556 + e.startOn += effect.finishOn; 1.557 + e.finishOn += effect.finishOn; 1.558 + } 1.559 + }, this.effects); 1.560 + break; 1.561 + case 'end': 1.562 + var finish; 1.563 + // start effect after last queued effect has finished 1.564 + ma(function (e) { 1.565 + var i = e.finishOn; 1.566 + if (i >= (finish || i)) { 1.567 + finish = i; 1.568 + } 1.569 + }, this.effects); 1.570 + timestamp = finish || timestamp; 1.571 + break; 1.572 + case 'break': 1.573 + ma(function (e) { 1.574 + e.finalize(); 1.575 + }, this.effects); 1.576 + break; 1.577 + } 1.578 + 1.579 + effect.startOn += timestamp; 1.580 + effect.finishOn += timestamp; 1.581 + if (!effect.options.queue.limit || 1.582 + this.effects.length < effect.options.queue.limit) { 1.583 + this.effects.push(effect); 1.584 + } 1.585 + 1.586 + if (!this.interval) { 1.587 + this.interval = this.startLoop(MochiKit.Base.bind(this.loop, this), 1.588 + 40); 1.589 + } 1.590 + }, 1.591 + 1.592 + /** @id MochiKit.Visual.ScopedQueue.prototype.startLoop */ 1.593 + startLoop: function (func, interval) { 1.594 + return setInterval(func, interval); 1.595 + }, 1.596 + 1.597 + /** @id MochiKit.Visual.ScopedQueue.prototype.remove */ 1.598 + remove: function (effect) { 1.599 + this.effects = MochiKit.Base.filter(function (e) { 1.600 + return e != effect; 1.601 + }, this.effects); 1.602 + if (!this.effects.length) { 1.603 + this.stopLoop(this.interval); 1.604 + this.interval = null; 1.605 + } 1.606 + }, 1.607 + 1.608 + /** @id MochiKit.Visual.ScopedQueue.prototype.stopLoop */ 1.609 + stopLoop: function (interval) { 1.610 + clearInterval(interval); 1.611 + }, 1.612 + 1.613 + /** @id MochiKit.Visual.ScopedQueue.prototype.loop */ 1.614 + loop: function () { 1.615 + var timePos = new Date().getTime(); 1.616 + MochiKit.Base.map(function (effect) { 1.617 + effect.loop(timePos); 1.618 + }, this.effects); 1.619 + } 1.620 +}); 1.621 + 1.622 +MochiKit.Visual.Queues = { 1.623 + instances: {}, 1.624 + 1.625 + get: function (queueName) { 1.626 + if (typeof(queueName) != 'string') { 1.627 + return queueName; 1.628 + } 1.629 + 1.630 + if (!this.instances[queueName]) { 1.631 + this.instances[queueName] = new MochiKit.Visual.ScopedQueue(); 1.632 + } 1.633 + return this.instances[queueName]; 1.634 + } 1.635 +}; 1.636 + 1.637 +MochiKit.Visual.Queue = MochiKit.Visual.Queues.get('global'); 1.638 + 1.639 +MochiKit.Visual.DefaultOptions = { 1.640 + transition: MochiKit.Visual.Transitions.sinoidal, 1.641 + duration: 1.0, // seconds 1.642 + fps: 25.0, // max. 25fps due to MochiKit.Visual.Queue implementation 1.643 + sync: false, // true for combining 1.644 + from: 0.0, 1.645 + to: 1.0, 1.646 + delay: 0.0, 1.647 + queue: 'parallel' 1.648 +}; 1.649 + 1.650 +MochiKit.Visual.Base = function () {}; 1.651 + 1.652 +MochiKit.Visual.Base.prototype = { 1.653 + /*** 1.654 + 1.655 + Basic class for all Effects. Define a looping mechanism called for each step 1.656 + of an effect. Don't instantiate it, only subclass it. 1.657 + 1.658 + ***/ 1.659 + 1.660 + __class__ : MochiKit.Visual.Base, 1.661 + 1.662 + /** @id MochiKit.Visual.Base.prototype.start */ 1.663 + start: function (options) { 1.664 + var v = MochiKit.Visual; 1.665 + this.options = MochiKit.Base.setdefault(options || {}, 1.666 + v.DefaultOptions); 1.667 + this.currentFrame = 0; 1.668 + this.state = 'idle'; 1.669 + this.startOn = this.options.delay*1000; 1.670 + this.finishOn = this.startOn + (this.options.duration*1000); 1.671 + this.event('beforeStart'); 1.672 + if (!this.options.sync) { 1.673 + v.Queues.get(typeof(this.options.queue) == 'string' ? 1.674 + 'global' : this.options.queue.scope).add(this); 1.675 + } 1.676 + }, 1.677 + 1.678 + /** @id MochiKit.Visual.Base.prototype.loop */ 1.679 + loop: function (timePos) { 1.680 + if (timePos >= this.startOn) { 1.681 + if (timePos >= this.finishOn) { 1.682 + return this.finalize(); 1.683 + } 1.684 + var pos = (timePos - this.startOn) / (this.finishOn - this.startOn); 1.685 + var frame = 1.686 + Math.round(pos * this.options.fps * this.options.duration); 1.687 + if (frame > this.currentFrame) { 1.688 + this.render(pos); 1.689 + this.currentFrame = frame; 1.690 + } 1.691 + } 1.692 + }, 1.693 + 1.694 + /** @id MochiKit.Visual.Base.prototype.render */ 1.695 + render: function (pos) { 1.696 + if (this.state == 'idle') { 1.697 + this.state = 'running'; 1.698 + this.event('beforeSetup'); 1.699 + this.setup(); 1.700 + this.event('afterSetup'); 1.701 + } 1.702 + if (this.state == 'running') { 1.703 + if (this.options.transition) { 1.704 + pos = this.options.transition(pos); 1.705 + } 1.706 + pos *= (this.options.to - this.options.from); 1.707 + pos += this.options.from; 1.708 + this.event('beforeUpdate'); 1.709 + this.update(pos); 1.710 + this.event('afterUpdate'); 1.711 + } 1.712 + }, 1.713 + 1.714 + /** @id MochiKit.Visual.Base.prototype.cancel */ 1.715 + cancel: function () { 1.716 + if (!this.options.sync) { 1.717 + MochiKit.Visual.Queues.get(typeof(this.options.queue) == 'string' ? 1.718 + 'global' : this.options.queue.scope).remove(this); 1.719 + } 1.720 + this.state = 'finished'; 1.721 + }, 1.722 + 1.723 + /** @id MochiKit.Visual.Base.prototype.finalize */ 1.724 + finalize: function () { 1.725 + this.render(1.0); 1.726 + this.cancel(); 1.727 + this.event('beforeFinish'); 1.728 + this.finish(); 1.729 + this.event('afterFinish'); 1.730 + }, 1.731 + 1.732 + setup: function () { 1.733 + }, 1.734 + 1.735 + finish: function () { 1.736 + }, 1.737 + 1.738 + update: function (position) { 1.739 + }, 1.740 + 1.741 + /** @id MochiKit.Visual.Base.prototype.event */ 1.742 + event: function (eventName) { 1.743 + if (this.options[eventName + 'Internal']) { 1.744 + this.options[eventName + 'Internal'](this); 1.745 + } 1.746 + if (this.options[eventName]) { 1.747 + this.options[eventName](this); 1.748 + } 1.749 + }, 1.750 + 1.751 + /** @id MochiKit.Visual.Base.prototype.repr */ 1.752 + repr: function () { 1.753 + return '[' + this.__class__.NAME + ', options:' + 1.754 + MochiKit.Base.repr(this.options) + ']'; 1.755 + } 1.756 +}; 1.757 + 1.758 + /** @id MochiKit.Visual.Parallel */ 1.759 +MochiKit.Visual.Parallel = function (effects, options) { 1.760 + var cls = arguments.callee; 1.761 + if (!(this instanceof cls)) { 1.762 + return new cls(effects, options); 1.763 + } 1.764 + 1.765 + this.__init__(effects, options); 1.766 +}; 1.767 + 1.768 +MochiKit.Visual.Parallel.prototype = new MochiKit.Visual.Base(); 1.769 + 1.770 +MochiKit.Base.update(MochiKit.Visual.Parallel.prototype, { 1.771 + /*** 1.772 + 1.773 + Run multiple effects at the same time. 1.774 + 1.775 + ***/ 1.776 + 1.777 + __class__ : MochiKit.Visual.Parallel, 1.778 + 1.779 + __init__: function (effects, options) { 1.780 + this.effects = effects || []; 1.781 + this.start(options); 1.782 + }, 1.783 + 1.784 + /** @id MochiKit.Visual.Parallel.prototype.update */ 1.785 + update: function (position) { 1.786 + MochiKit.Base.map(function (effect) { 1.787 + effect.render(position); 1.788 + }, this.effects); 1.789 + }, 1.790 + 1.791 + /** @id MochiKit.Visual.Parallel.prototype.finish */ 1.792 + finish: function () { 1.793 + MochiKit.Base.map(function (effect) { 1.794 + effect.finalize(); 1.795 + }, this.effects); 1.796 + } 1.797 +}); 1.798 + 1.799 +/** @id MochiKit.Visual.Opacity */ 1.800 +MochiKit.Visual.Opacity = function (element, options) { 1.801 + var cls = arguments.callee; 1.802 + if (!(this instanceof cls)) { 1.803 + return new cls(element, options); 1.804 + } 1.805 + this.__init__(element, options); 1.806 +}; 1.807 + 1.808 +MochiKit.Visual.Opacity.prototype = new MochiKit.Visual.Base(); 1.809 + 1.810 +MochiKit.Base.update(MochiKit.Visual.Opacity.prototype, { 1.811 + /*** 1.812 + 1.813 + Change the opacity of an element. 1.814 + 1.815 + @param options: 'from' and 'to' change the starting and ending opacities. 1.816 + Must be between 0.0 and 1.0. Default to current opacity and 1.0. 1.817 + 1.818 + ***/ 1.819 + 1.820 + __class__ : MochiKit.Visual.Opacity, 1.821 + 1.822 + __init__: function (element, /* optional */options) { 1.823 + var b = MochiKit.Base; 1.824 + var s = MochiKit.Style; 1.825 + this.element = MochiKit.DOM.getElement(element); 1.826 + // make this work on IE on elements without 'layout' 1.827 + if (this.element.currentStyle && 1.828 + (!this.element.currentStyle.hasLayout)) { 1.829 + s.setStyle(this.element, {zoom: 1}); 1.830 + } 1.831 + options = b.update({ 1.832 + from: s.getStyle(this.element, 'opacity') || 0.0, 1.833 + to: 1.0 1.834 + }, options || {}); 1.835 + this.start(options); 1.836 + }, 1.837 + 1.838 + /** @id MochiKit.Visual.Opacity.prototype.update */ 1.839 + update: function (position) { 1.840 + MochiKit.Style.setStyle(this.element, {'opacity': position}); 1.841 + } 1.842 +}); 1.843 + 1.844 +/** @id MochiKit.Visual.Move.prototype */ 1.845 +MochiKit.Visual.Move = function (element, options) { 1.846 + var cls = arguments.callee; 1.847 + if (!(this instanceof cls)) { 1.848 + return new cls(element, options); 1.849 + } 1.850 + this.__init__(element, options); 1.851 +}; 1.852 + 1.853 +MochiKit.Visual.Move.prototype = new MochiKit.Visual.Base(); 1.854 + 1.855 +MochiKit.Base.update(MochiKit.Visual.Move.prototype, { 1.856 + /*** 1.857 + 1.858 + Move an element between its current position to a defined position 1.859 + 1.860 + @param options: 'x' and 'y' for final positions, default to 0, 0. 1.861 + 1.862 + ***/ 1.863 + 1.864 + __class__ : MochiKit.Visual.Move, 1.865 + 1.866 + __init__: function (element, /* optional */options) { 1.867 + this.element = MochiKit.DOM.getElement(element); 1.868 + options = MochiKit.Base.update({ 1.869 + x: 0, 1.870 + y: 0, 1.871 + mode: 'relative' 1.872 + }, options || {}); 1.873 + this.start(options); 1.874 + }, 1.875 + 1.876 + /** @id MochiKit.Visual.Move.prototype.setup */ 1.877 + setup: function () { 1.878 + // Bug in Opera: Opera returns the 'real' position of a static element 1.879 + // or relative element that does not have top/left explicitly set. 1.880 + // ==> Always set top and left for position relative elements in your 1.881 + // stylesheets (to 0 if you do not need them) 1.882 + MochiKit.DOM.makePositioned(this.element); 1.883 + 1.884 + var s = this.element.style; 1.885 + var originalVisibility = s.visibility; 1.886 + var originalDisplay = s.display; 1.887 + if (originalDisplay == 'none') { 1.888 + s.visibility = 'hidden'; 1.889 + s.display = ''; 1.890 + } 1.891 + 1.892 + this.originalLeft = parseFloat(MochiKit.Style.getStyle(this.element, 'left') || '0'); 1.893 + this.originalTop = parseFloat(MochiKit.Style.getStyle(this.element, 'top') || '0'); 1.894 + 1.895 + if (this.options.mode == 'absolute') { 1.896 + // absolute movement, so we need to calc deltaX and deltaY 1.897 + this.options.x -= this.originalLeft; 1.898 + this.options.y -= this.originalTop; 1.899 + } 1.900 + if (originalDisplay == 'none') { 1.901 + s.visibility = originalVisibility; 1.902 + s.display = originalDisplay; 1.903 + } 1.904 + }, 1.905 + 1.906 + /** @id MochiKit.Visual.Move.prototype.update */ 1.907 + update: function (position) { 1.908 + MochiKit.Style.setStyle(this.element, { 1.909 + left: Math.round(this.options.x * position + this.originalLeft) + 'px', 1.910 + top: Math.round(this.options.y * position + this.originalTop) + 'px' 1.911 + }); 1.912 + } 1.913 +}); 1.914 + 1.915 +/** @id MochiKit.Visual.Scale */ 1.916 +MochiKit.Visual.Scale = function (element, percent, options) { 1.917 + var cls = arguments.callee; 1.918 + if (!(this instanceof cls)) { 1.919 + return new cls(element, percent, options); 1.920 + } 1.921 + this.__init__(element, percent, options); 1.922 +}; 1.923 + 1.924 +MochiKit.Visual.Scale.prototype = new MochiKit.Visual.Base(); 1.925 + 1.926 +MochiKit.Base.update(MochiKit.Visual.Scale.prototype, { 1.927 + /*** 1.928 + 1.929 + Change the size of an element. 1.930 + 1.931 + @param percent: final_size = percent*original_size 1.932 + 1.933 + @param options: several options changing scale behaviour 1.934 + 1.935 + ***/ 1.936 + 1.937 + __class__ : MochiKit.Visual.Scale, 1.938 + 1.939 + __init__: function (element, percent, /* optional */options) { 1.940 + this.element = MochiKit.DOM.getElement(element); 1.941 + options = MochiKit.Base.update({ 1.942 + scaleX: true, 1.943 + scaleY: true, 1.944 + scaleContent: true, 1.945 + scaleFromCenter: false, 1.946 + scaleMode: 'box', // 'box' or 'contents' or {} with provided values 1.947 + scaleFrom: 100.0, 1.948 + scaleTo: percent 1.949 + }, options || {}); 1.950 + this.start(options); 1.951 + }, 1.952 + 1.953 + /** @id MochiKit.Visual.Scale.prototype.setup */ 1.954 + setup: function () { 1.955 + this.restoreAfterFinish = this.options.restoreAfterFinish || false; 1.956 + this.elementPositioning = MochiKit.Style.getStyle(this.element, 1.957 + 'position'); 1.958 + 1.959 + var ma = MochiKit.Base.map; 1.960 + var b = MochiKit.Base.bind; 1.961 + this.originalStyle = {}; 1.962 + ma(b(function (k) { 1.963 + this.originalStyle[k] = this.element.style[k]; 1.964 + }, this), ['top', 'left', 'width', 'height', 'fontSize']); 1.965 + 1.966 + this.originalTop = this.element.offsetTop; 1.967 + this.originalLeft = this.element.offsetLeft; 1.968 + 1.969 + var fontSize = MochiKit.Style.getStyle(this.element, 1.970 + 'font-size') || '100%'; 1.971 + ma(b(function (fontSizeType) { 1.972 + if (fontSize.indexOf(fontSizeType) > 0) { 1.973 + this.fontSize = parseFloat(fontSize); 1.974 + this.fontSizeType = fontSizeType; 1.975 + } 1.976 + }, this), ['em', 'px', '%']); 1.977 + 1.978 + this.factor = (this.options.scaleTo - this.options.scaleFrom)/100; 1.979 + 1.980 + if (/^content/.test(this.options.scaleMode)) { 1.981 + this.dims = [this.element.scrollHeight, this.element.scrollWidth]; 1.982 + } else if (this.options.scaleMode == 'box') { 1.983 + this.dims = [this.element.offsetHeight, this.element.offsetWidth]; 1.984 + } else { 1.985 + this.dims = [this.options.scaleMode.originalHeight, 1.986 + this.options.scaleMode.originalWidth]; 1.987 + } 1.988 + }, 1.989 + 1.990 + /** @id MochiKit.Visual.Scale.prototype.update */ 1.991 + update: function (position) { 1.992 + var currentScale = (this.options.scaleFrom/100.0) + 1.993 + (this.factor * position); 1.994 + if (this.options.scaleContent && this.fontSize) { 1.995 + MochiKit.Style.setStyle(this.element, { 1.996 + fontSize: this.fontSize * currentScale + this.fontSizeType 1.997 + }); 1.998 + } 1.999 + this.setDimensions(this.dims[0] * currentScale, 1.1000 + this.dims[1] * currentScale); 1.1001 + }, 1.1002 + 1.1003 + /** @id MochiKit.Visual.Scale.prototype.finish */ 1.1004 + finish: function () { 1.1005 + if (this.restoreAfterFinish) { 1.1006 + MochiKit.Style.setStyle(this.element, this.originalStyle); 1.1007 + } 1.1008 + }, 1.1009 + 1.1010 + /** @id MochiKit.Visual.Scale.prototype.setDimensions */ 1.1011 + setDimensions: function (height, width) { 1.1012 + var d = {}; 1.1013 + var r = Math.round; 1.1014 + if (/MSIE/.test(navigator.userAgent)) { 1.1015 + r = Math.ceil; 1.1016 + } 1.1017 + if (this.options.scaleX) { 1.1018 + d.width = r(width) + 'px'; 1.1019 + } 1.1020 + if (this.options.scaleY) { 1.1021 + d.height = r(height) + 'px'; 1.1022 + } 1.1023 + if (this.options.scaleFromCenter) { 1.1024 + var topd = (height - this.dims[0])/2; 1.1025 + var leftd = (width - this.dims[1])/2; 1.1026 + if (this.elementPositioning == 'absolute') { 1.1027 + if (this.options.scaleY) { 1.1028 + d.top = this.originalTop - topd + 'px'; 1.1029 + } 1.1030 + if (this.options.scaleX) { 1.1031 + d.left = this.originalLeft - leftd + 'px'; 1.1032 + } 1.1033 + } else { 1.1034 + if (this.options.scaleY) { 1.1035 + d.top = -topd + 'px'; 1.1036 + } 1.1037 + if (this.options.scaleX) { 1.1038 + d.left = -leftd + 'px'; 1.1039 + } 1.1040 + } 1.1041 + } 1.1042 + MochiKit.Style.setStyle(this.element, d); 1.1043 + } 1.1044 +}); 1.1045 + 1.1046 +/** @id MochiKit.Visual.Highlight */ 1.1047 +MochiKit.Visual.Highlight = function (element, options) { 1.1048 + var cls = arguments.callee; 1.1049 + if (!(this instanceof cls)) { 1.1050 + return new cls(element, options); 1.1051 + } 1.1052 + this.__init__(element, options); 1.1053 +}; 1.1054 + 1.1055 +MochiKit.Visual.Highlight.prototype = new MochiKit.Visual.Base(); 1.1056 + 1.1057 +MochiKit.Base.update(MochiKit.Visual.Highlight.prototype, { 1.1058 + /*** 1.1059 + 1.1060 + Highlight an item of the page. 1.1061 + 1.1062 + @param options: 'startcolor' for choosing highlighting color, default 1.1063 + to '#ffff99'. 1.1064 + 1.1065 + ***/ 1.1066 + 1.1067 + __class__ : MochiKit.Visual.Highlight, 1.1068 + 1.1069 + __init__: function (element, /* optional */options) { 1.1070 + this.element = MochiKit.DOM.getElement(element); 1.1071 + options = MochiKit.Base.update({ 1.1072 + startcolor: '#ffff99' 1.1073 + }, options || {}); 1.1074 + this.start(options); 1.1075 + }, 1.1076 + 1.1077 + /** @id MochiKit.Visual.Highlight.prototype.setup */ 1.1078 + setup: function () { 1.1079 + var b = MochiKit.Base; 1.1080 + var s = MochiKit.Style; 1.1081 + // Prevent executing on elements not in the layout flow 1.1082 + if (s.getStyle(this.element, 'display') == 'none') { 1.1083 + this.cancel(); 1.1084 + return; 1.1085 + } 1.1086 + // Disable background image during the effect 1.1087 + this.oldStyle = { 1.1088 + backgroundImage: s.getStyle(this.element, 'background-image') 1.1089 + }; 1.1090 + s.setStyle(this.element, { 1.1091 + backgroundImage: 'none' 1.1092 + }); 1.1093 + 1.1094 + if (!this.options.endcolor) { 1.1095 + this.options.endcolor = 1.1096 + MochiKit.Color.Color.fromBackground(this.element).toHexString(); 1.1097 + } 1.1098 + if (b.isUndefinedOrNull(this.options.restorecolor)) { 1.1099 + this.options.restorecolor = s.getStyle(this.element, 1.1100 + 'background-color'); 1.1101 + } 1.1102 + // init color calculations 1.1103 + this._base = b.map(b.bind(function (i) { 1.1104 + return parseInt( 1.1105 + this.options.startcolor.slice(i*2 + 1, i*2 + 3), 16); 1.1106 + }, this), [0, 1, 2]); 1.1107 + this._delta = b.map(b.bind(function (i) { 1.1108 + return parseInt(this.options.endcolor.slice(i*2 + 1, i*2 + 3), 16) 1.1109 + - this._base[i]; 1.1110 + }, this), [0, 1, 2]); 1.1111 + }, 1.1112 + 1.1113 + /** @id MochiKit.Visual.Highlight.prototype.update */ 1.1114 + update: function (position) { 1.1115 + var m = '#'; 1.1116 + MochiKit.Base.map(MochiKit.Base.bind(function (i) { 1.1117 + m += MochiKit.Color.toColorPart(Math.round(this._base[i] + 1.1118 + this._delta[i]*position)); 1.1119 + }, this), [0, 1, 2]); 1.1120 + MochiKit.Style.setStyle(this.element, { 1.1121 + backgroundColor: m 1.1122 + }); 1.1123 + }, 1.1124 + 1.1125 + /** @id MochiKit.Visual.Highlight.prototype.finish */ 1.1126 + finish: function () { 1.1127 + MochiKit.Style.setStyle(this.element, 1.1128 + MochiKit.Base.update(this.oldStyle, { 1.1129 + backgroundColor: this.options.restorecolor 1.1130 + })); 1.1131 + } 1.1132 +}); 1.1133 + 1.1134 +/** @id MochiKit.Visual.ScrollTo */ 1.1135 +MochiKit.Visual.ScrollTo = function (element, options) { 1.1136 + var cls = arguments.callee; 1.1137 + if (!(this instanceof cls)) { 1.1138 + return new cls(element, options); 1.1139 + } 1.1140 + this.__init__(element, options); 1.1141 +}; 1.1142 + 1.1143 +MochiKit.Visual.ScrollTo.prototype = new MochiKit.Visual.Base(); 1.1144 + 1.1145 +MochiKit.Base.update(MochiKit.Visual.ScrollTo.prototype, { 1.1146 + /*** 1.1147 + 1.1148 + Scroll to an element in the page. 1.1149 + 1.1150 + ***/ 1.1151 + 1.1152 + __class__ : MochiKit.Visual.ScrollTo, 1.1153 + 1.1154 + __init__: function (element, /* optional */options) { 1.1155 + this.element = MochiKit.DOM.getElement(element); 1.1156 + this.start(options || {}); 1.1157 + }, 1.1158 + 1.1159 + /** @id MochiKit.Visual.ScrollTo.prototype.setup */ 1.1160 + setup: function () { 1.1161 + var p = MochiKit.Position; 1.1162 + p.prepare(); 1.1163 + var offsets = p.cumulativeOffset(this.element); 1.1164 + if (this.options.offset) { 1.1165 + offsets.y += this.options.offset; 1.1166 + } 1.1167 + var max; 1.1168 + if (window.innerHeight) { 1.1169 + max = window.innerHeight - window.height; 1.1170 + } else if (document.documentElement && 1.1171 + document.documentElement.clientHeight) { 1.1172 + max = document.documentElement.clientHeight - 1.1173 + document.body.scrollHeight; 1.1174 + } else if (document.body) { 1.1175 + max = document.body.clientHeight - document.body.scrollHeight; 1.1176 + } 1.1177 + this.scrollStart = p.windowOffset.y; 1.1178 + this.delta = (offsets.y > max ? max : offsets.y) - this.scrollStart; 1.1179 + }, 1.1180 + 1.1181 + /** @id MochiKit.Visual.ScrollTo.prototype.update */ 1.1182 + update: function (position) { 1.1183 + var p = MochiKit.Position; 1.1184 + p.prepare(); 1.1185 + window.scrollTo(p.windowOffset.x, this.scrollStart + (position * this.delta)); 1.1186 + } 1.1187 +}); 1.1188 + 1.1189 +MochiKit.Visual.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/; 1.1190 + 1.1191 +MochiKit.Visual.Morph = function (element, options) { 1.1192 + var cls = arguments.callee; 1.1193 + if (!(this instanceof cls)) { 1.1194 + return new cls(element, options); 1.1195 + } 1.1196 + this.__init__(element, options); 1.1197 +}; 1.1198 + 1.1199 +MochiKit.Visual.Morph.prototype = new MochiKit.Visual.Base(); 1.1200 + 1.1201 +MochiKit.Base.update(MochiKit.Visual.Morph.prototype, { 1.1202 + /*** 1.1203 + 1.1204 + Morph effect: make a transformation from current style to the given style, 1.1205 + automatically making a transition between the two. 1.1206 + 1.1207 + ***/ 1.1208 + 1.1209 + __class__ : MochiKit.Visual.Morph, 1.1210 + 1.1211 + __init__: function (element, /* optional */options) { 1.1212 + this.element = MochiKit.DOM.getElement(element); 1.1213 + this.start(options || {}); 1.1214 + }, 1.1215 + 1.1216 + /** @id MochiKit.Visual.Morph.prototype.setup */ 1.1217 + setup: function () { 1.1218 + var b = MochiKit.Base; 1.1219 + var style = this.options.style; 1.1220 + this.styleStart = {}; 1.1221 + this.styleEnd = {}; 1.1222 + this.units = {}; 1.1223 + var value, unit; 1.1224 + for (var s in style) { 1.1225 + value = style[s]; 1.1226 + s = b.camelize(s); 1.1227 + if (MochiKit.Visual.CSS_LENGTH.test(value)) { 1.1228 + var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/); 1.1229 + value = parseFloat(components[1]); 1.1230 + unit = (components.length == 3) ? components[2] : null; 1.1231 + this.styleEnd[s] = value; 1.1232 + this.units[s] = unit; 1.1233 + value = MochiKit.Style.getStyle(this.element, s); 1.1234 + components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/); 1.1235 + value = parseFloat(components[1]); 1.1236 + this.styleStart[s] = value; 1.1237 + } else { 1.1238 + var c = MochiKit.Color.Color; 1.1239 + value = c.fromString(value); 1.1240 + if (value) { 1.1241 + this.units[s] = "color"; 1.1242 + this.styleEnd[s] = value.toHexString(); 1.1243 + value = MochiKit.Style.getStyle(this.element, s); 1.1244 + this.styleStart[s] = c.fromString(value).toHexString(); 1.1245 + 1.1246 + this.styleStart[s] = b.map(b.bind(function (i) { 1.1247 + return parseInt( 1.1248 + this.styleStart[s].slice(i*2 + 1, i*2 + 3), 16); 1.1249 + }, this), [0, 1, 2]); 1.1250 + this.styleEnd[s] = b.map(b.bind(function (i) { 1.1251 + return parseInt( 1.1252 + this.styleEnd[s].slice(i*2 + 1, i*2 + 3), 16); 1.1253 + }, this), [0, 1, 2]); 1.1254 + } 1.1255 + } 1.1256 + } 1.1257 + }, 1.1258 + 1.1259 + /** @id MochiKit.Visual.Morph.prototype.update */ 1.1260 + update: function (position) { 1.1261 + var value; 1.1262 + for (var s in this.styleStart) { 1.1263 + if (this.units[s] == "color") { 1.1264 + var m = '#'; 1.1265 + var start = this.styleStart[s]; 1.1266 + var end = this.styleEnd[s]; 1.1267 + MochiKit.Base.map(MochiKit.Base.bind(function (i) { 1.1268 + m += MochiKit.Color.toColorPart(Math.round(start[i] + 1.1269 + (end[i] - start[i])*position)); 1.1270 + }, this), [0, 1, 2]); 1.1271 + this.element.style[s] = m; 1.1272 + } else { 1.1273 + value = this.styleStart[s] + Math.round((this.styleEnd[s] - this.styleStart[s]) * position * 1000) / 1000 + this.units[s]; 1.1274 + this.element.style[s] = value; 1.1275 + } 1.1276 + } 1.1277 + } 1.1278 +}); 1.1279 + 1.1280 +/*** 1.1281 + 1.1282 +Combination effects. 1.1283 + 1.1284 +***/ 1.1285 + 1.1286 +/** @id MochiKit.Visual.fade */ 1.1287 +MochiKit.Visual.fade = function (element, /* optional */ options) { 1.1288 + /*** 1.1289 + 1.1290 + Fade a given element: change its opacity and hide it in the end. 1.1291 + 1.1292 + @param options: 'to' and 'from' to change opacity. 1.1293 + 1.1294 + ***/ 1.1295 + var s = MochiKit.Style; 1.1296 + var oldOpacity = s.getStyle(element, 'opacity'); 1.1297 + options = MochiKit.Base.update({ 1.1298 + from: s.getStyle(element, 'opacity') || 1.0, 1.1299 + to: 0.0, 1.1300 + afterFinishInternal: function (effect) { 1.1301 + if (effect.options.to !== 0) { 1.1302 + return; 1.1303 + } 1.1304 + s.hideElement(effect.element); 1.1305 + s.setStyle(effect.element, {'opacity': oldOpacity}); 1.1306 + } 1.1307 + }, options || {}); 1.1308 + return new MochiKit.Visual.Opacity(element, options); 1.1309 +}; 1.1310 + 1.1311 +/** @id MochiKit.Visual.appear */ 1.1312 +MochiKit.Visual.appear = function (element, /* optional */ options) { 1.1313 + /*** 1.1314 + 1.1315 + Make an element appear. 1.1316 + 1.1317 + @param options: 'to' and 'from' to change opacity. 1.1318 + 1.1319 + ***/ 1.1320 + var s = MochiKit.Style; 1.1321 + var v = MochiKit.Visual; 1.1322 + options = MochiKit.Base.update({ 1.1323 + from: (s.getStyle(element, 'display') == 'none' ? 0.0 : 1.1324 + s.getStyle(element, 'opacity') || 0.0), 1.1325 + to: 1.0, 1.1326 + // force Safari to render floated elements properly 1.1327 + afterFinishInternal: function (effect) { 1.1328 + v.forceRerendering(effect.element); 1.1329 + }, 1.1330 + beforeSetupInternal: function (effect) { 1.1331 + s.setStyle(effect.element, {'opacity': effect.options.from}); 1.1332 + s.showElement(effect.element); 1.1333 + } 1.1334 + }, options || {}); 1.1335 + return new v.Opacity(element, options); 1.1336 +}; 1.1337 + 1.1338 +/** @id MochiKit.Visual.puff */ 1.1339 +MochiKit.Visual.puff = function (element, /* optional */ options) { 1.1340 + /*** 1.1341 + 1.1342 + 'Puff' an element: grow it to double size, fading it and make it hidden. 1.1343 + 1.1344 + ***/ 1.1345 + var s = MochiKit.Style; 1.1346 + var v = MochiKit.Visual; 1.1347 + element = MochiKit.DOM.getElement(element); 1.1348 + var oldStyle = { 1.1349 + position: s.getStyle(element, 'position'), 1.1350 + top: element.style.top, 1.1351 + left: element.style.left, 1.1352 + width: element.style.width, 1.1353 + height: element.style.height, 1.1354 + opacity: s.getStyle(element, 'opacity') 1.1355 + }; 1.1356 + options = MochiKit.Base.update({ 1.1357 + beforeSetupInternal: function (effect) { 1.1358 + MochiKit.Position.absolutize(effect.effects[0].element); 1.1359 + }, 1.1360 + afterFinishInternal: function (effect) { 1.1361 + s.hideElement(effect.effects[0].element); 1.1362 + s.setStyle(effect.effects[0].element, oldStyle); 1.1363 + }, 1.1364 + scaleContent: true, 1.1365 + scaleFromCenter: true 1.1366 + }, options || {}); 1.1367 + return new v.Parallel( 1.1368 + [new v.Scale(element, 200, 1.1369 + {sync: true, scaleFromCenter: options.scaleFromCenter, 1.1370 + scaleContent: options.scaleContent, restoreAfterFinish: true}), 1.1371 + new v.Opacity(element, {sync: true, to: 0.0 })], 1.1372 + options); 1.1373 +}; 1.1374 + 1.1375 +/** @id MochiKit.Visual.blindUp */ 1.1376 +MochiKit.Visual.blindUp = function (element, /* optional */ options) { 1.1377 + /*** 1.1378 + 1.1379 + Blind an element up: change its vertical size to 0. 1.1380 + 1.1381 + ***/ 1.1382 + var d = MochiKit.DOM; 1.1383 + element = d.getElement(element); 1.1384 + var elemClip = d.makeClipping(element); 1.1385 + options = MochiKit.Base.update({ 1.1386 + scaleContent: false, 1.1387 + scaleX: false, 1.1388 + restoreAfterFinish: true, 1.1389 + afterFinishInternal: function (effect) { 1.1390 + MochiKit.Style.hideElement(effect.element); 1.1391 + d.undoClipping(effect.element, elemClip); 1.1392 + } 1.1393 + }, options || {}); 1.1394 + 1.1395 + return new MochiKit.Visual.Scale(element, 0, options); 1.1396 +}; 1.1397 + 1.1398 +/** @id MochiKit.Visual.blindDown */ 1.1399 +MochiKit.Visual.blindDown = function (element, /* optional */ options) { 1.1400 + /*** 1.1401 + 1.1402 + Blind an element down: restore its vertical size. 1.1403 + 1.1404 + ***/ 1.1405 + var d = MochiKit.DOM; 1.1406 + var s = MochiKit.Style; 1.1407 + element = d.getElement(element); 1.1408 + var elementDimensions = s.getElementDimensions(element); 1.1409 + var elemClip; 1.1410 + options = MochiKit.Base.update({ 1.1411 + scaleContent: false, 1.1412 + scaleX: false, 1.1413 + scaleFrom: 0, 1.1414 + scaleMode: {originalHeight: elementDimensions.h, 1.1415 + originalWidth: elementDimensions.w}, 1.1416 + restoreAfterFinish: true, 1.1417 + afterSetupInternal: function (effect) { 1.1418 + elemClip = d.makeClipping(effect.element); 1.1419 + s.setStyle(effect.element, {height: '0px'}); 1.1420 + s.showElement(effect.element); 1.1421 + }, 1.1422 + afterFinishInternal: function (effect) { 1.1423 + d.undoClipping(effect.element, elemClip); 1.1424 + } 1.1425 + }, options || {}); 1.1426 + return new MochiKit.Visual.Scale(element, 100, options); 1.1427 +}; 1.1428 + 1.1429 +/** @id MochiKit.Visual.switchOff */ 1.1430 +MochiKit.Visual.switchOff = function (element, /* optional */ options) { 1.1431 + /*** 1.1432 + 1.1433 + Apply a switch-off-like effect. 1.1434 + 1.1435 + ***/ 1.1436 + var d = MochiKit.DOM; 1.1437 + element = d.getElement(element); 1.1438 + var oldOpacity = MochiKit.Style.getStyle(element, 'opacity'); 1.1439 + var elemClip; 1.1440 + options = MochiKit.Base.update({ 1.1441 + duration: 0.3, 1.1442 + scaleFromCenter: true, 1.1443 + scaleX: false, 1.1444 + scaleContent: false, 1.1445 + restoreAfterFinish: true, 1.1446 + beforeSetupInternal: function (effect) { 1.1447 + d.makePositioned(effect.element); 1.1448 + elemClip = d.makeClipping(effect.element); 1.1449 + }, 1.1450 + afterFinishInternal: function (effect) { 1.1451 + MochiKit.Style.hideElement(effect.element); 1.1452 + d.undoClipping(effect.element, elemClip); 1.1453 + d.undoPositioned(effect.element); 1.1454 + MochiKit.Style.setStyle(effect.element, {'opacity': oldOpacity}); 1.1455 + } 1.1456 + }, options || {}); 1.1457 + var v = MochiKit.Visual; 1.1458 + return new v.appear(element, { 1.1459 + duration: 0.4, 1.1460 + from: 0, 1.1461 + transition: v.Transitions.flicker, 1.1462 + afterFinishInternal: function (effect) { 1.1463 + new v.Scale(effect.element, 1, options); 1.1464 + } 1.1465 + }); 1.1466 +}; 1.1467 + 1.1468 +/** @id MochiKit.Visual.dropOut */ 1.1469 +MochiKit.Visual.dropOut = function (element, /* optional */ options) { 1.1470 + /*** 1.1471 + 1.1472 + Make an element fall and disappear. 1.1473 + 1.1474 + ***/ 1.1475 + var d = MochiKit.DOM; 1.1476 + var s = MochiKit.Style; 1.1477 + element = d.getElement(element); 1.1478 + var oldStyle = { 1.1479 + top: s.getStyle(element, 'top'), 1.1480 + left: s.getStyle(element, 'left'), 1.1481 + opacity: s.getStyle(element, 'opacity') 1.1482 + }; 1.1483 + 1.1484 + options = MochiKit.Base.update({ 1.1485 + duration: 0.5, 1.1486 + distance: 100, 1.1487 + beforeSetupInternal: function (effect) { 1.1488 + d.makePositioned(effect.effects[0].element); 1.1489 + }, 1.1490 + afterFinishInternal: function (effect) { 1.1491 + s.hideElement(effect.effects[0].element); 1.1492 + d.undoPositioned(effect.effects[0].element); 1.1493 + s.setStyle(effect.effects[0].element, oldStyle); 1.1494 + } 1.1495 + }, options || {}); 1.1496 + var v = MochiKit.Visual; 1.1497 + return new v.Parallel( 1.1498 + [new v.Move(element, {x: 0, y: options.distance, sync: true}), 1.1499 + new v.Opacity(element, {sync: true, to: 0.0})], 1.1500 + options); 1.1501 +}; 1.1502 + 1.1503 +/** @id MochiKit.Visual.shake */ 1.1504 +MochiKit.Visual.shake = function (element, /* optional */ options) { 1.1505 + /*** 1.1506 + 1.1507 + Move an element from left to right several times. 1.1508 + 1.1509 + ***/ 1.1510 + var d = MochiKit.DOM; 1.1511 + var v = MochiKit.Visual; 1.1512 + var s = MochiKit.Style; 1.1513 + element = d.getElement(element); 1.1514 + options = MochiKit.Base.update({ 1.1515 + x: -20, 1.1516 + y: 0, 1.1517 + duration: 0.05, 1.1518 + afterFinishInternal: function (effect) { 1.1519 + d.undoPositioned(effect.element); 1.1520 + s.setStyle(effect.element, oldStyle); 1.1521 + } 1.1522 + }, options || {}); 1.1523 + var oldStyle = { 1.1524 + top: s.getStyle(element, 'top'), 1.1525 + left: s.getStyle(element, 'left') }; 1.1526 + return new v.Move(element, 1.1527 + {x: 20, y: 0, duration: 0.05, afterFinishInternal: function (effect) { 1.1528 + new v.Move(effect.element, 1.1529 + {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 1.1530 + new v.Move(effect.element, 1.1531 + {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 1.1532 + new v.Move(effect.element, 1.1533 + {x: -40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 1.1534 + new v.Move(effect.element, 1.1535 + {x: 40, y: 0, duration: 0.1, afterFinishInternal: function (effect) { 1.1536 + new v.Move(effect.element, options 1.1537 + ) }}) }}) }}) }}) }}); 1.1538 +}; 1.1539 + 1.1540 +/** @id MochiKit.Visual.slideDown */ 1.1541 +MochiKit.Visual.slideDown = function (element, /* optional */ options) { 1.1542 + /*** 1.1543 + 1.1544 + Slide an element down. 1.1545 + It needs to have the content of the element wrapped in a container 1.1546 + element with fixed height. 1.1547 + 1.1548 + ***/ 1.1549 + var d = MochiKit.DOM; 1.1550 + var b = MochiKit.Base; 1.1551 + var s = MochiKit.Style; 1.1552 + element = d.getElement(element); 1.1553 + if (!element.firstChild) { 1.1554 + throw "MochiKit.Visual.slideDown must be used on a element with a child"; 1.1555 + } 1.1556 + d.removeEmptyTextNodes(element); 1.1557 + var oldInnerBottom = s.getStyle(element.firstChild, 'bottom') || 0; 1.1558 + var elementDimensions = s.getElementDimensions(element); 1.1559 + var elemClip; 1.1560 + options = b.update({ 1.1561 + scaleContent: false, 1.1562 + scaleX: false, 1.1563 + scaleFrom: 0, 1.1564 + scaleMode: {originalHeight: elementDimensions.h, 1.1565 + originalWidth: elementDimensions.w}, 1.1566 + restoreAfterFinish: true, 1.1567 + afterSetupInternal: function (effect) { 1.1568 + d.makePositioned(effect.element); 1.1569 + d.makePositioned(effect.element.firstChild); 1.1570 + if (/Opera/.test(navigator.userAgent)) { 1.1571 + s.setStyle(effect.element, {top: ''}); 1.1572 + } 1.1573 + elemClip = d.makeClipping(effect.element); 1.1574 + s.setStyle(effect.element, {height: '0px'}); 1.1575 + s.showElement(effect.element); 1.1576 + }, 1.1577 + afterUpdateInternal: function (effect) { 1.1578 + s.setStyle(effect.element.firstChild, 1.1579 + {bottom: (effect.dims[0] - effect.element.clientHeight) + 'px'}); 1.1580 + }, 1.1581 + afterFinishInternal: function (effect) { 1.1582 + d.undoClipping(effect.element, elemClip); 1.1583 + // IE will crash if child is undoPositioned first 1.1584 + if (/MSIE/.test(navigator.userAgent)) { 1.1585 + d.undoPositioned(effect.element); 1.1586 + d.undoPositioned(effect.element.firstChild); 1.1587 + } else { 1.1588 + d.undoPositioned(effect.element.firstChild); 1.1589 + d.undoPositioned(effect.element); 1.1590 + } 1.1591 + s.setStyle(effect.element.firstChild, 1.1592 + {bottom: oldInnerBottom}); 1.1593 + } 1.1594 + }, options || {}); 1.1595 + 1.1596 + return new MochiKit.Visual.Scale(element, 100, options); 1.1597 +}; 1.1598 + 1.1599 +/** @id MochiKit.Visual.slideUp */ 1.1600 +MochiKit.Visual.slideUp = function (element, /* optional */ options) { 1.1601 + /*** 1.1602 + 1.1603 + Slide an element up. 1.1604 + It needs to have the content of the element wrapped in a container 1.1605 + element with fixed height. 1.1606 + 1.1607 + ***/ 1.1608 + var d = MochiKit.DOM; 1.1609 + var b = MochiKit.Base; 1.1610 + var s = MochiKit.Style; 1.1611 + element = d.getElement(element); 1.1612 + if (!element.firstChild) { 1.1613 + throw "MochiKit.Visual.slideUp must be used on a element with a child"; 1.1614 + } 1.1615 + d.removeEmptyTextNodes(element); 1.1616 + var oldInnerBottom = s.getStyle(element.firstChild, 'bottom'); 1.1617 + var elemClip; 1.1618 + options = b.update({ 1.1619 + scaleContent: false, 1.1620 + scaleX: false, 1.1621 + scaleMode: 'box', 1.1622 + scaleFrom: 100, 1.1623 + restoreAfterFinish: true, 1.1624 + beforeStartInternal: function (effect) { 1.1625 + d.makePositioned(effect.element); 1.1626 + d.makePositioned(effect.element.firstChild); 1.1627 + if (/Opera/.test(navigator.userAgent)) { 1.1628 + s.setStyle(effect.element, {top: ''}); 1.1629 + } 1.1630 + elemClip = d.makeClipping(effect.element); 1.1631 + s.showElement(effect.element); 1.1632 + }, 1.1633 + afterUpdateInternal: function (effect) { 1.1634 + s.setStyle(effect.element.firstChild, 1.1635 + {bottom: (effect.dims[0] - effect.element.clientHeight) + 'px'}); 1.1636 + }, 1.1637 + afterFinishInternal: function (effect) { 1.1638 + s.hideElement(effect.element); 1.1639 + d.undoClipping(effect.element, elemClip); 1.1640 + d.undoPositioned(effect.element.firstChild); 1.1641 + d.undoPositioned(effect.element); 1.1642 + s.setStyle(effect.element.firstChild, {bottom: oldInnerBottom}); 1.1643 + } 1.1644 + }, options || {}); 1.1645 + return new MochiKit.Visual.Scale(element, 0, options); 1.1646 +}; 1.1647 + 1.1648 +// Bug in opera makes the TD containing this element expand for a instance 1.1649 +// after finish 1.1650 +/** @id MochiKit.Visual.squish */ 1.1651 +MochiKit.Visual.squish = function (element, /* optional */ options) { 1.1652 + /*** 1.1653 + 1.1654 + Reduce an element and make it disappear. 1.1655 + 1.1656 + ***/ 1.1657 + var d = MochiKit.DOM; 1.1658 + var b = MochiKit.Base; 1.1659 + var elemClip; 1.1660 + options = b.update({ 1.1661 + restoreAfterFinish: true, 1.1662 + beforeSetupInternal: function (effect) { 1.1663 + elemClip = d.makeClipping(effect.element); 1.1664 + }, 1.1665 + afterFinishInternal: function (effect) { 1.1666 + MochiKit.Style.hideElement(effect.element); 1.1667 + d.undoClipping(effect.element, elemClip); 1.1668 + } 1.1669 + }, options || {}); 1.1670 + 1.1671 + return new MochiKit.Visual.Scale(element, /Opera/.test(navigator.userAgent) ? 1 : 0, options); 1.1672 +}; 1.1673 + 1.1674 +/** @id MochiKit.Visual.grow */ 1.1675 +MochiKit.Visual.grow = function (element, /* optional */ options) { 1.1676 + /*** 1.1677 + 1.1678 + Grow an element to its original size. Make it zero-sized before 1.1679 + if necessary. 1.1680 + 1.1681 + ***/ 1.1682 + var d = MochiKit.DOM; 1.1683 + var v = MochiKit.Visual; 1.1684 + var s = MochiKit.Style; 1.1685 + element = d.getElement(element); 1.1686 + options = MochiKit.Base.update({ 1.1687 + direction: 'center', 1.1688 + moveTransition: v.Transitions.sinoidal, 1.1689 + scaleTransition: v.Transitions.sinoidal, 1.1690 + opacityTransition: v.Transitions.full, 1.1691 + scaleContent: true, 1.1692 + scaleFromCenter: false 1.1693 + }, options || {}); 1.1694 + var oldStyle = { 1.1695 + top: element.style.top, 1.1696 + left: element.style.left, 1.1697 + height: element.style.height, 1.1698 + width: element.style.width, 1.1699 + opacity: s.getStyle(element, 'opacity') 1.1700 + }; 1.1701 + 1.1702 + var dims = s.getElementDimensions(element); 1.1703 + var initialMoveX, initialMoveY; 1.1704 + var moveX, moveY; 1.1705 + 1.1706 + switch (options.direction) { 1.1707 + case 'top-left': 1.1708 + initialMoveX = initialMoveY = moveX = moveY = 0; 1.1709 + break; 1.1710 + case 'top-right': 1.1711 + initialMoveX = dims.w; 1.1712 + initialMoveY = moveY = 0; 1.1713 + moveX = -dims.w; 1.1714 + break; 1.1715 + case 'bottom-left': 1.1716 + initialMoveX = moveX = 0; 1.1717 + initialMoveY = dims.h; 1.1718 + moveY = -dims.h; 1.1719 + break; 1.1720 + case 'bottom-right': 1.1721 + initialMoveX = dims.w; 1.1722 + initialMoveY = dims.h; 1.1723 + moveX = -dims.w; 1.1724 + moveY = -dims.h; 1.1725 + break; 1.1726 + case 'center': 1.1727 + initialMoveX = dims.w / 2; 1.1728 + initialMoveY = dims.h / 2; 1.1729 + moveX = -dims.w / 2; 1.1730 + moveY = -dims.h / 2; 1.1731 + break; 1.1732 + } 1.1733 + 1.1734 + var optionsParallel = MochiKit.Base.update({ 1.1735 + beforeSetupInternal: function (effect) { 1.1736 + s.setStyle(effect.effects[0].element, {height: '0px'}); 1.1737 + s.showElement(effect.effects[0].element); 1.1738 + }, 1.1739 + afterFinishInternal: function (effect) { 1.1740 + d.undoClipping(effect.effects[0].element); 1.1741 + d.undoPositioned(effect.effects[0].element); 1.1742 + s.setStyle(effect.effects[0].element, oldStyle); 1.1743 + } 1.1744 + }, options || {}); 1.1745 + 1.1746 + return new v.Move(element, { 1.1747 + x: initialMoveX, 1.1748 + y: initialMoveY, 1.1749 + duration: 0.01, 1.1750 + beforeSetupInternal: function (effect) { 1.1751 + s.hideElement(effect.element); 1.1752 + d.makeClipping(effect.element); 1.1753 + d.makePositioned(effect.element); 1.1754 + }, 1.1755 + afterFinishInternal: function (effect) { 1.1756 + new v.Parallel( 1.1757 + [new v.Opacity(effect.element, { 1.1758 + sync: true, to: 1.0, from: 0.0, 1.1759 + transition: options.opacityTransition 1.1760 + }), 1.1761 + new v.Move(effect.element, { 1.1762 + x: moveX, y: moveY, sync: true, 1.1763 + transition: options.moveTransition 1.1764 + }), 1.1765 + new v.Scale(effect.element, 100, { 1.1766 + scaleMode: {originalHeight: dims.h, 1.1767 + originalWidth: dims.w}, 1.1768 + sync: true, 1.1769 + scaleFrom: /Opera/.test(navigator.userAgent) ? 1 : 0, 1.1770 + transition: options.scaleTransition, 1.1771 + scaleContent: options.scaleContent, 1.1772 + scaleFromCenter: options.scaleFromCenter, 1.1773 + restoreAfterFinish: true 1.1774 + }) 1.1775 + ], optionsParallel 1.1776 + ); 1.1777 + } 1.1778 + }); 1.1779 +}; 1.1780 + 1.1781 +/** @id MochiKit.Visual.shrink */ 1.1782 +MochiKit.Visual.shrink = function (element, /* optional */ options) { 1.1783 + /*** 1.1784 + 1.1785 + Shrink an element and make it disappear. 1.1786 + 1.1787 + ***/ 1.1788 + var d = MochiKit.DOM; 1.1789 + var v = MochiKit.Visual; 1.1790 + var s = MochiKit.Style; 1.1791 + element = d.getElement(element); 1.1792 + options = MochiKit.Base.update({ 1.1793 + direction: 'center', 1.1794 + moveTransition: v.Transitions.sinoidal, 1.1795 + scaleTransition: v.Transitions.sinoidal, 1.1796 + opacityTransition: v.Transitions.none, 1.1797 + scaleContent: true, 1.1798 + scaleFromCenter: false 1.1799 + }, options || {}); 1.1800 + var oldStyle = { 1.1801 + top: element.style.top, 1.1802 + left: element.style.left, 1.1803 + height: element.style.height, 1.1804 + width: element.style.width, 1.1805 + opacity: s.getStyle(element, 'opacity') 1.1806 + }; 1.1807 + 1.1808 + var dims = s.getElementDimensions(element); 1.1809 + var moveX, moveY; 1.1810 + 1.1811 + switch (options.direction) { 1.1812 + case 'top-left': 1.1813 + moveX = moveY = 0; 1.1814 + break; 1.1815 + case 'top-right': 1.1816 + moveX = dims.w; 1.1817 + moveY = 0; 1.1818 + break; 1.1819 + case 'bottom-left': 1.1820 + moveX = 0; 1.1821 + moveY = dims.h; 1.1822 + break; 1.1823 + case 'bottom-right': 1.1824 + moveX = dims.w; 1.1825 + moveY = dims.h; 1.1826 + break; 1.1827 + case 'center': 1.1828 + moveX = dims.w / 2; 1.1829 + moveY = dims.h / 2; 1.1830 + break; 1.1831 + } 1.1832 + var elemClip; 1.1833 + 1.1834 + var optionsParallel = MochiKit.Base.update({ 1.1835 + beforeStartInternal: function (effect) { 1.1836 + elemClip = d.makePositioned(effect.effects[0].element); 1.1837 + d.makeClipping(effect.effects[0].element); 1.1838 + }, 1.1839 + afterFinishInternal: function (effect) { 1.1840 + s.hideElement(effect.effects[0].element); 1.1841 + d.undoClipping(effect.effects[0].element, elemClip); 1.1842 + d.undoPositioned(effect.effects[0].element); 1.1843 + s.setStyle(effect.effects[0].element, oldStyle); 1.1844 + } 1.1845 + }, options || {}); 1.1846 + 1.1847 + return new v.Parallel( 1.1848 + [new v.Opacity(element, { 1.1849 + sync: true, to: 0.0, from: 1.0, 1.1850 + transition: options.opacityTransition 1.1851 + }), 1.1852 + new v.Scale(element, /Opera/.test(navigator.userAgent) ? 1 : 0, { 1.1853 + sync: true, transition: options.scaleTransition, 1.1854 + scaleContent: options.scaleContent, 1.1855 + scaleFromCenter: options.scaleFromCenter, 1.1856 + restoreAfterFinish: true 1.1857 + }), 1.1858 + new v.Move(element, { 1.1859 + x: moveX, y: moveY, sync: true, transition: options.moveTransition 1.1860 + }) 1.1861 + ], optionsParallel 1.1862 + ); 1.1863 +}; 1.1864 + 1.1865 +/** @id MochiKit.Visual.pulsate */ 1.1866 +MochiKit.Visual.pulsate = function (element, /* optional */ options) { 1.1867 + /*** 1.1868 + 1.1869 + Pulse an element between appear/fade. 1.1870 + 1.1871 + ***/ 1.1872 + var d = MochiKit.DOM; 1.1873 + var v = MochiKit.Visual; 1.1874 + var b = MochiKit.Base; 1.1875 + var oldOpacity = MochiKit.Style.getStyle(element, 'opacity'); 1.1876 + options = b.update({ 1.1877 + duration: 3.0, 1.1878 + from: 0, 1.1879 + afterFinishInternal: function (effect) { 1.1880 + MochiKit.Style.setStyle(effect.element, {'opacity': oldOpacity}); 1.1881 + } 1.1882 + }, options || {}); 1.1883 + var transition = options.transition || v.Transitions.sinoidal; 1.1884 + var reverser = b.bind(function (pos) { 1.1885 + return transition(1 - v.Transitions.pulse(pos, options.pulses)); 1.1886 + }, transition); 1.1887 + b.bind(reverser, transition); 1.1888 + return new v.Opacity(element, b.update({ 1.1889 + transition: reverser}, options)); 1.1890 +}; 1.1891 + 1.1892 +/** @id MochiKit.Visual.fold */ 1.1893 +MochiKit.Visual.fold = function (element, /* optional */ options) { 1.1894 + /*** 1.1895 + 1.1896 + Fold an element, first vertically, then horizontally. 1.1897 + 1.1898 + ***/ 1.1899 + var d = MochiKit.DOM; 1.1900 + var v = MochiKit.Visual; 1.1901 + var s = MochiKit.Style; 1.1902 + element = d.getElement(element); 1.1903 + var oldStyle = { 1.1904 + top: element.style.top, 1.1905 + left: element.style.left, 1.1906 + width: element.style.width, 1.1907 + height: element.style.height 1.1908 + }; 1.1909 + var elemClip = d.makeClipping(element); 1.1910 + options = MochiKit.Base.update({ 1.1911 + scaleContent: false, 1.1912 + scaleX: false, 1.1913 + afterFinishInternal: function (effect) { 1.1914 + new v.Scale(element, 1, { 1.1915 + scaleContent: false, 1.1916 + scaleY: false, 1.1917 + afterFinishInternal: function (effect) { 1.1918 + s.hideElement(effect.element); 1.1919 + d.undoClipping(effect.element, elemClip); 1.1920 + s.setStyle(effect.element, oldStyle); 1.1921 + } 1.1922 + }); 1.1923 + } 1.1924 + }, options || {}); 1.1925 + return new v.Scale(element, 5, options); 1.1926 +}; 1.1927 + 1.1928 + 1.1929 +// Compatibility with MochiKit 1.0 1.1930 +MochiKit.Visual.Color = MochiKit.Color.Color; 1.1931 +MochiKit.Visual.getElementsComputedStyle = MochiKit.DOM.computedStyle; 1.1932 + 1.1933 +/* end of Rico adaptation */ 1.1934 + 1.1935 +MochiKit.Visual.__new__ = function () { 1.1936 + var m = MochiKit.Base; 1.1937 + 1.1938 + m.nameFunctions(this); 1.1939 + 1.1940 + this.EXPORT_TAGS = { 1.1941 + ":common": this.EXPORT, 1.1942 + ":all": m.concat(this.EXPORT, this.EXPORT_OK) 1.1943 + }; 1.1944 + 1.1945 +}; 1.1946 + 1.1947 +MochiKit.Visual.EXPORT = [ 1.1948 + "roundElement", 1.1949 + "roundClass", 1.1950 + "tagifyText", 1.1951 + "multiple", 1.1952 + "toggle", 1.1953 + "Parallel", 1.1954 + "Opacity", 1.1955 + "Move", 1.1956 + "Scale", 1.1957 + "Highlight", 1.1958 + "ScrollTo", 1.1959 + "Morph", 1.1960 + "fade", 1.1961 + "appear", 1.1962 + "puff", 1.1963 + "blindUp", 1.1964 + "blindDown", 1.1965 + "switchOff", 1.1966 + "dropOut", 1.1967 + "shake", 1.1968 + "slideDown", 1.1969 + "slideUp", 1.1970 + "squish", 1.1971 + "grow", 1.1972 + "shrink", 1.1973 + "pulsate", 1.1974 + "fold" 1.1975 +]; 1.1976 + 1.1977 +MochiKit.Visual.EXPORT_OK = [ 1.1978 + "Base", 1.1979 + "PAIRS" 1.1980 +]; 1.1981 + 1.1982 +MochiKit.Visual.__new__(); 1.1983 + 1.1984 +MochiKit.Base._exportSymbols(this, MochiKit.Visual);