testing/mochitest/MochiKit/Visual.js

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

mercurial