slider-debug.js

来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 1,153 行 · 第 1/3 页

JS
1,153
字号
    /**     * Returns the next X tick value based on the current coord and the target coord.     * @method _getNextX     * @private     */    _getNextX: function(curCoord, finalCoord) {        this.logger.log("getNextX: " + curCoord + ", " + finalCoord);        var t = this.thumb;        var thresh;        var tmp = [];        var nextCoord = null;        if (curCoord[0] > finalCoord[0]) {            thresh = t.tickSize - this.thumbCenterPoint.x;            tmp = t.getTargetCoord( curCoord[0] - thresh, curCoord[1] );            nextCoord = [tmp.x, tmp.y];        } else if (curCoord[0] < finalCoord[0]) {            thresh = t.tickSize + this.thumbCenterPoint.x;            tmp = t.getTargetCoord( curCoord[0] + thresh, curCoord[1] );            nextCoord = [tmp.x, tmp.y];        } else {            // equal, do nothing        }        return nextCoord;    },    /**     * Returns the next Y tick value based on the current coord and the target coord.     * @method _getNextY     * @private     */    _getNextY: function(curCoord, finalCoord) {        var t = this.thumb;        var thresh;        var tmp = [];        var nextCoord = null;        if (curCoord[1] > finalCoord[1]) {            thresh = t.tickSize - this.thumbCenterPoint.y;            tmp = t.getTargetCoord( curCoord[0], curCoord[1] - thresh );            nextCoord = [tmp.x, tmp.y];        } else if (curCoord[1] < finalCoord[1]) {            thresh = t.tickSize + this.thumbCenterPoint.y;            tmp = t.getTargetCoord( curCoord[0], curCoord[1] + thresh );            nextCoord = [tmp.x, tmp.y];        } else {            // equal, do nothing        }        return nextCoord;    },    /**     * Resets the constraints before moving the thumb.     * @method b4MouseDown     * @private     */    b4MouseDown: function(e) {        this.thumb.autoOffset();        this.thumb.resetConstraints();    },    /**     * Handles the mousedown event for the slider background     * @method onMouseDown     * @private     */    onMouseDown: function(e) {        // this.resetConstraints(true);        // this.thumb.resetConstraints(true);        if (! this.isLocked() && this.backgroundEnabled) {            var x = YAHOO.util.Event.getPageX(e);            var y = YAHOO.util.Event.getPageY(e);            this.logger.log("bg mousedown: " + x + "," + y);            this.focus();            this.moveThumb(x, y);        }    },    /**     * Handles the onDrag event for the slider background     * @method onDrag     * @private     */    onDrag: function(e) {        if (! this.isLocked()) {            var x = YAHOO.util.Event.getPageX(e);            var y = YAHOO.util.Event.getPageY(e);            this.moveThumb(x, y, true);        }    },    /**     * Fired when the slider movement ends     * @method endMove     * @private     */    endMove: function () {        // this._animating = false;        this.unlock();        this.moveComplete = true;        this.fireEvents();    },    /**     * Fires the change event if the value has been changed.  Ignored if we are in     * the middle of an animation as the event will fire when the animation is     * complete     * @method fireEvents     * @private     */    fireEvents: function () {        var t = this.thumb;        // this.logger.log("FireEvents: " + t._isRegion);        t.cachePosition();        if (! this.isLocked()) {            if (t._isRegion) {                this.logger.log("region");                var newX = t.getXValue();                var newY = t.getYValue();                if (newX != this.previousX || newY != this.previousY) {                    // this.logger.log("Firing onchange");                    this.onChange(newX, newY);                    this.fireEvent("change", { x: newX, y: newY });                }                this.previousX = newX;                this.previousY = newY;            } else {                var newVal = t.getValue();                if (newVal != this.previousVal) {                    this.logger.log("Firing onchange: " + newVal);                    this.onChange( newVal );                    this.fireEvent("change", newVal);                }                this.previousVal = newVal;            }            if (this.moveComplete) {                this.onSlideEnd();                this.fireEvent("slideEnd");                this.moveComplete = false;            }        }    },    /**     * Slider toString     * @method toString     * @return {string} string representation of the instance     */    toString: function () {        return ("Slider (" + this.type +") " + this.id);    }});YAHOO.augment(YAHOO.widget.Slider, YAHOO.util.EventProvider);/** * A drag and drop implementation to be used as the thumb of a slider. * @class SliderThumb * @extends YAHOO.util.DD * @constructor * @param {String} id the id of the slider html element * @param {String} sGroup the group of related DragDrop items * @param {int} iLeft the number of pixels the element can move left * @param {int} iRight the number of pixels the element can move right * @param {int} iUp the number of pixels the element can move up * @param {int} iDown the number of pixels the element can move down * @param {int} iTickSize optional parameter for specifying that the element * should move a certain number pixels at a time. */YAHOO.widget.SliderThumb = function(id, sGroup, iLeft, iRight, iUp, iDown, iTickSize) {    if (id) {        this.init(id, sGroup);        /**         * The id of the thumbs parent HTML element (the slider background         * element).         * @property parentElId         * @type string         */        this.parentElId = sGroup;    }    //this.removeInvalidHandleType("A");    this.logger = new YAHOO.widget.LogWriter(this.toString());    /**     * Overrides the isTarget property in YAHOO.util.DragDrop     * @property isTarget     * @private     */    this.isTarget = false;    /**     * The tick size for this slider     * @property tickSize     * @type int     * @private     */    this.tickSize = iTickSize;    /**     * Informs the drag and drop util that the offsets should remain when     * resetting the constraints.  This preserves the slider value when     * the constraints are reset     * @property maintainOffset     * @type boolean     * @private     */    this.maintainOffset = true;    this.initSlider(iLeft, iRight, iUp, iDown, iTickSize);    /**     * Turns off the autoscroll feature in drag and drop     * @property scroll     * @private     */    this.scroll = false;};YAHOO.extend(YAHOO.widget.SliderThumb, YAHOO.util.DD, {    /**     * The (X and Y) difference between the thumb location and its parent     * (the slider background) when the control is instantiated.     * @property startOffset     * @type [int, int]     */    startOffset: null,    /**     * Flag used to figure out if this is a horizontal or vertical slider     * @property _isHoriz     * @type boolean     * @private     */    _isHoriz: false,    /**     * Cache the last value so we can check for change     * @property _prevVal     * @type int     * @private     */    _prevVal: 0,    /**     * The slider is _graduated if there is a tick interval defined     * @property _graduated     * @type boolean     * @private     */    _graduated: false,    /**     * Returns the difference between the location of the thumb and its parent.     * @method getOffsetFromParent     * @param {[int, int]} parentPos Optionally accepts the position of the parent     * @type [int, int]     */    getOffsetFromParent: function(parentPos) {        var myPos = YAHOO.util.Dom.getXY(this.getEl());        var ppos  = parentPos || YAHOO.util.Dom.getXY(this.parentElId);        return [ (myPos[0] - ppos[0]), (myPos[1] - ppos[1]) ];    },    /**     * Set up the slider, must be called in the constructor of all subclasses     * @method initSlider     * @param {int} iLeft the number of pixels the element can move left     * @param {int} iRight the number of pixels the element can move right     * @param {int} iUp the number of pixels the element can move up     * @param {int} iDown the number of pixels the element can move down     * @param {int} iTickSize the width of the tick interval.     */    initSlider: function (iLeft, iRight, iUp, iDown, iTickSize) {        this.setXConstraint(iLeft, iRight, iTickSize);        this.setYConstraint(iUp, iDown, iTickSize);        if (iTickSize && iTickSize > 1) {            this._graduated = true;        }        this._isHoriz  = (iLeft || iRight);        this._isVert   = (iUp   || iDown);        this._isRegion = (this._isHoriz && this._isVert);    },    /**     * Clear's the slider's ticks     * @method clearTicks     */    clearTicks: function () {        YAHOO.widget.SliderThumb.superclass.clearTicks.call(this);        this._graduated = false;    },    /**     * Gets the current offset from the element's start position in     * pixels.     * @method getValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved from the start position.     */    getValue: function () {        if (!this.available) { return 0; }        var val = (this._isHoriz) ? this.getXValue() : this.getYValue();        this.logger.log("getVal: " + val);        return val;    },    /**     * Gets the current X offset from the element's start position in     * pixels.     * @method getXValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved horizontally from the start position.     */    getXValue: function () {        if (!this.available) { return 0; }        var newOffset = this.getOffsetFromParent();        return (newOffset[0] - this.startOffset[0]);    },    /**     * Gets the current Y offset from the element's start position in     * pixels.     * @method getYValue     * @return {int} the number of pixels (positive or negative) the     * slider has moved vertically from the start position.     */    getYValue: function () {        if (!this.available) { return 0; }        var newOffset = this.getOffsetFromParent();        return (newOffset[1] - this.startOffset[1]);    },    /**     * Thumb toString     * @method toString     * @return {string} string representation of the instance     */    toString: function () {        return "SliderThumb " + this.id;    },    /**     * The onchange event for the handle/thumb is delegated to the YAHOO.widget.Slider     * instance it belongs to.     * @method onChange     * @private     */    onChange: function (x, y) {    }});if ("undefined" == typeof YAHOO.util.Anim) {    YAHOO.widget.Slider.ANIM_AVAIL = false;}

⌨️ 快捷键说明

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