⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ext-base.js

📁 ext-2.3.0
💻 JS
📖 第 1 页 / 共 5 页
字号:
            noNegatives:        /width|height|opacity|padding/i,            offsetAttribute:  /^((width|height)|(top|left))$/,            defaultUnit:        /width|height|top$|bottom$|left$|right$/i,            offsetUnit:         /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i        },        doMethod: function(attr, start, end) {            return this.method(this.currentFrame, start, end - start, this.totalFrames);        },        setAttribute: function(attr, val, unit) {            if (this.patterns.noNegatives.test(attr)) {                val = (val > 0) ? val : 0;            }            Ext.fly(this.getEl(), '_anim').setStyle(attr, val + unit);        },        getAttribute: function(attr) {            var el = this.getEl();            var val = fly(el).getStyle(attr);            if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) {                return parseFloat(val);            }            var a = this.patterns.offsetAttribute.exec(attr) || [];            var pos = !!( a[3] );            var box = !!( a[2] );            if (box || (fly(el).getStyle('position') == 'absolute' && pos)) {                val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)];            } else {                val = 0;            }            return val;        },        getDefaultUnit: function(attr) {            if (this.patterns.defaultUnit.test(attr)) {                return 'px';            }            return '';        },        animateX : function(callback, scope) {            var f = function() {                this.onComplete.removeListener(f);                if (typeof callback == "function") {                    callback.call(scope || this, this);                }            };            this.onComplete.addListener(f, this);            this.animate();        },        setRuntimeAttribute: function(attr) {            var start;            var end;            var attributes = this.attributes;            this.runtimeAttributes[attr] = {};            var isset = function(prop) {                return (typeof prop !== 'undefined');            };            if (!isset(attributes[attr]['to']) && !isset(attributes[attr]['by'])) {                return false;            }            start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr);            if (isset(attributes[attr]['to'])) {                end = attributes[attr]['to'];            } else if (isset(attributes[attr]['by'])) {                if (start.constructor == Array) {                    end = [];                    for (var i = 0, len = start.length; i < len; ++i) {                        end[i] = start[i] + attributes[attr]['by'][i];                    }                } else {                    end = start + attributes[attr]['by'];                }            }            this.runtimeAttributes[attr].start = start;            this.runtimeAttributes[attr].end = end;            this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr);        },        init: function(el, attributes, duration, method) {            var isAnimated = false;            var startTime = null;            var actualFrames = 0;            el = Ext.getDom(el);            this.attributes = attributes || {};            this.duration = duration || 1;            this.method = method || Ext.lib.Easing.easeNone;            this.useSeconds = true;            this.currentFrame = 0;            this.totalFrames = Ext.lib.AnimMgr.fps;            this.getEl = function() {                return el;            };            this.isAnimated = function() {                return isAnimated;            };            this.getStartTime = function() {                return startTime;            };            this.runtimeAttributes = {};            this.animate = function() {                if (this.isAnimated()) {                    return false;                }                this.currentFrame = 0;                this.totalFrames = ( this.useSeconds ) ? Math.ceil(Ext.lib.AnimMgr.fps * this.duration) : this.duration;                Ext.lib.AnimMgr.registerElement(this);            };            this.stop = function(finish) {                if (finish) {                    this.currentFrame = this.totalFrames;                    this._onTween.fire();                }                Ext.lib.AnimMgr.stop(this);            };            var onStart = function() {                this.onStart.fire();                this.runtimeAttributes = {};                for (var attr in this.attributes) {                    this.setRuntimeAttribute(attr);                }                isAnimated = true;                actualFrames = 0;                startTime = new Date();            };            var onTween = function() {                var data = {                    duration: new Date() - this.getStartTime(),                    currentFrame: this.currentFrame                };                data.toString = function() {                    return (                            'duration: ' + data.duration +                            ', currentFrame: ' + data.currentFrame                            );                };                this.onTween.fire(data);                var runtimeAttributes = this.runtimeAttributes;                for (var attr in runtimeAttributes) {                    this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit);                }                actualFrames += 1;            };            var onComplete = function() {                var actual_duration = (new Date() - startTime) / 1000 ;                var data = {                    duration: actual_duration,                    frames: actualFrames,                    fps: actualFrames / actual_duration                };                data.toString = function() {                    return (                            'duration: ' + data.duration +                            ', frames: ' + data.frames +                            ', fps: ' + data.fps                            );                };                isAnimated = false;                actualFrames = 0;                this.onComplete.fire(data);            };            this._onStart = new Ext.util.Event(this);            this.onStart = new Ext.util.Event(this);            this.onTween = new Ext.util.Event(this);            this._onTween = new Ext.util.Event(this);            this.onComplete = new Ext.util.Event(this);            this._onComplete = new Ext.util.Event(this);            this._onStart.addListener(onStart);            this._onTween.addListener(onTween);            this._onComplete.addListener(onComplete);        }    };    Ext.lib.AnimMgr = new function() {        var thread = null;        var queue = [];        var tweenCount = 0;        this.fps = 1000;        this.delay = 1;        this.registerElement = function(tween) {            queue[queue.length] = tween;            tweenCount += 1;            tween._onStart.fire();            this.start();        };        this.unRegister = function(tween, index) {            tween._onComplete.fire();            index = index || getIndex(tween);            if (index != -1) {                queue.splice(index, 1);            }            tweenCount -= 1;            if (tweenCount <= 0) {                this.stop();            }        };        this.start = function() {            if (thread === null) {                thread = setInterval(this.run, this.delay);            }        };        this.stop = function(tween) {            if (!tween) {                clearInterval(thread);                for (var i = 0, len = queue.length; i < len; ++i) {                    if (queue[0].isAnimated()) {                        this.unRegister(queue[0], 0);                    }                }                queue = [];                thread = null;                tweenCount = 0;            }            else {                this.unRegister(tween);            }        };        this.run = function() {            for (var i = 0, len = queue.length; i < len; ++i) {                var tween = queue[i];                if (!tween || !tween.isAnimated()) {                    continue;                }                if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null)                {                    tween.currentFrame += 1;                    if (tween.useSeconds) {                        correctFrame(tween);                    }                    tween._onTween.fire();                }                else {                    Ext.lib.AnimMgr.stop(tween, i);                }            }        };        var getIndex = function(anim) {            for (var i = 0, len = queue.length; i < len; ++i) {                if (queue[i] == anim) {                    return i;                }            }            return -1;        };        var correctFrame = function(tween) {            var frames = tween.totalFrames;            var frame = tween.currentFrame;            var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames);            var elapsed = (new Date() - tween.getStartTime());            var tweak = 0;            if (elapsed < tween.duration * 1000) {                tweak = Math.round((elapsed / expected - 1) * tween.currentFrame);            } else {                tweak = frames - (frame + 1);            }            if (tweak > 0 && isFinite(tweak)) {                if (tween.currentFrame + tweak >= frames) {                    tweak = frames - (frame + 1);                }                tween.currentFrame += tweak;            }        };    };    Ext.lib.Bezier = new function() {        this.getPosition = function(points, t) {            var n = points.length;            var tmp = [];            for (var i = 0; i < n; ++i) {                tmp[i] = [points[i][0], points[i][1]];            }            for (var j = 1; j < n; ++j) {                for (i = 0; i < n - j; ++i) {                    tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0];                    tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1];                }            }            return [ tmp[0][0], tmp[0][1] ];        };    };    (function() {        Ext.lib.ColorAnim = function(el, attributes, duration, method) {            Ext.lib.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method);        };        Ext.extend(Ext.lib.ColorAnim, Ext.lib.AnimBase);        var Y = Ext.lib;        var superclass = Y.ColorAnim.superclass;        var proto = Y.ColorAnim.prototype;        proto.toString = function() {            var el = this.getEl();            var id = el.id || el.tagName;            return ("ColorAnim " + id);        };        proto.patterns.color = /color$/i;        proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i;        proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i;        proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i;        proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/;        proto.parseColor = function(s) {            if (s.length == 3) {                return s;            }            var c = this.patterns.hex.exec(s);            if (c && c.length == 4) {                return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ];            }            c = this.patterns.rgb.exec(s);            if (c && c.length == 4) {                return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ];            }            c = this.patterns.hex3.exec(s);            if (c && c.length == 4) {                return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ];            }            return null;        };        proto.getAttribute = function(attr) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -