slider-debug.js
来自「国外很不错的一个开源OA系统Group-Office」· JavaScript 代码 · 共 1,153 行 · 第 1/3 页
JS
1,153 行
lock: function() { this.logger.log("locking"); this.thumb.lock(); this.locked = true; }, /** * Unlocks the slider, overrides YAHOO.util.DragDrop * @method unlock */ unlock: function() { this.logger.log("unlocking"); this.thumb.unlock(); this.locked = false; }, /** * Handles mouseup event on the slider background * @method thumbMouseUp * @private */ thumbMouseUp: function() { this.logger.log("bg mouseup"); if (!this.isLocked() && !this.moveComplete) { this.endMove(); } }, /** * Returns a reference to this slider's thumb * @method getThumb * @return {SliderThumb} this slider's thumb */ getThumb: function() { return this.thumb; }, /** * Try to focus the element when clicked so we can add * accessibility features * @method focus * @private */ focus: function() { this.logger.log("focus"); // Focus the background element if possible var el = this.getEl(); if (el.focus) { try { el.focus(); } catch(e) { // Prevent permission denied unhandled exception in FF that can // happen when setting focus while another element is handling // the blur. @TODO this is still writing to the error log // (unhandled error) in FF1.5 with strict error checking on. } } this.verifyOffset(); if (this.isLocked()) { return false; } else { this.onSlideStart(); return true; } }, /** * Event that fires when the value of the slider has changed * @method onChange * @param {int} firstOffset the number of pixels the thumb has moved * from its start position. Normal horizontal and vertical sliders will only * have the firstOffset. Regions will have both, the first is the horizontal * offset, the second the vertical. * @param {int} secondOffset the y offset for region sliders * @deprecated use instance.subscribe("change") instead */ onChange: function (firstOffset, secondOffset) { /* override me */ this.logger.log("onChange: " + firstOffset + ", " + secondOffset); }, /** * Event that fires when the at the beginning of the slider thumb move * @method onSlideStart * @deprecated use instance.subscribe("slideStart") instead */ onSlideStart: function () { /* override me */ this.logger.log("onSlideStart"); }, /** * Event that fires at the end of a slider thumb move * @method onSliderEnd * @deprecated use instance.subscribe("slideEnd") instead */ onSlideEnd: function () { /* override me */ this.logger.log("onSlideEnd"); }, /** * Returns the slider's thumb offset from the start position * @method getValue * @return {int} the current value */ getValue: function () { return this.thumb.getValue(); }, /** * Returns the slider's thumb X offset from the start position * @method getXValue * @return {int} the current horizontal offset */ getXValue: function () { return this.thumb.getXValue(); }, /** * Returns the slider's thumb Y offset from the start position * @method getYValue * @return {int} the current vertical offset */ getYValue: function () { return this.thumb.getYValue(); }, /** * Internal handler for the slider thumb's onChange event * @method handleThumbChange * @private */ handleThumbChange: function () { var t = this.thumb; if (t._isRegion) { t.onChange(t.getXValue(), t.getYValue()); this.fireEvent("change", { x: t.getXValue(), y: t.getYValue() } ); } else { t.onChange(t.getValue()); this.fireEvent("change", t.getValue()); } }, /** * Provides a way to set the value of the slider in code. * @method setValue * @param {int} newOffset the number of pixels the thumb should be * positioned away from the initial start point * @param {boolean} skipAnim set to true to disable the animation * for this move action (but not others). * @param {boolean} force ignore the locked setting and set value anyway * @return {boolean} true if the move was performed, false if it failed */ setValue: function(newOffset, skipAnim, force) { this.logger.log("setValue " + newOffset); if (!this.thumb.available) { this.logger.log("defer setValue until after onAvailble"); this.deferredSetValue = arguments; return false; } if (this.isLocked() && !force) { this.logger.log("Can't set the value, the control is locked"); return false; } if ( isNaN(newOffset) ) { this.logger.log("setValue, Illegal argument: " + newOffset); return false; } var t = this.thumb; var newX, newY; this.verifyOffset(); if (t._isRegion) { return false; } else if (t._isHoriz) { this.onSlideStart(); // this.fireEvent("slideStart"); newX = t.initPageX + newOffset + this.thumbCenterPoint.x; this.moveThumb(newX, t.initPageY, skipAnim); } else { this.onSlideStart(); // this.fireEvent("slideStart"); newY = t.initPageY + newOffset + this.thumbCenterPoint.y; this.moveThumb(t.initPageX, newY, skipAnim); } return true; }, /** * Provides a way to set the value of the region slider in code. * @method setRegionValue * @param {int} newOffset the number of pixels the thumb should be * positioned away from the initial start point (x axis for region) * @param {int} newOffset2 the number of pixels the thumb should be * positioned away from the initial start point (y axis for region) * @param {boolean} skipAnim set to true to disable the animation * for this move action (but not others). * @param {boolean} force ignore the locked setting and set value anyway * @return {boolean} true if the move was performed, false if it failed */ setRegionValue: function(newOffset, newOffset2, skipAnim) { if (!this.thumb.available) { this.logger.log("defer setRegionValue until after onAvailble"); this.deferredSetRegionValue = arguments; return false; } if (this.isLocked() && !force) { this.logger.log("Can't set the value, the control is locked"); return false; } if ( isNaN(newOffset) ) { this.logger.log("setRegionValue, Illegal argument: " + newOffset); return false; } var t = this.thumb; if (t._isRegion) { this.onSlideStart(); var newX = t.initPageX + newOffset + this.thumbCenterPoint.x; var newY = t.initPageY + newOffset2 + this.thumbCenterPoint.y; this.moveThumb(newX, newY, skipAnim); return true; } return false; }, /** * Checks the background position element position. If it has moved from the * baseline position, the constraints for the thumb are reset * @method verifyOffset * @return {boolean} True if the offset is the same as the baseline. */ verifyOffset: function() { var newPos = YAHOO.util.Dom.getXY(this.getEl()); this.logger.log("newPos: " + newPos); if (newPos[0] != this.baselinePos[0] || newPos[1] != this.baselinePos[1]) { this.logger.log("background moved, resetting constraints"); this.thumb.resetConstraints(); this.baselinePos = newPos; return false; } return true; }, /** * Move the associated slider moved to a timeout to try to get around the * mousedown stealing moz does when I move the slider element between the * cursor and the background during the mouseup event * @method moveThumb * @param {int} x the X coordinate of the click * @param {int} y the Y coordinate of the click * @param {boolean} skipAnim don't animate if the move happend onDrag * @private */ moveThumb: function(x, y, skipAnim) { // this.logger.log("move thumb", "warn"); var t = this.thumb; var self = this; if (!t.available) { this.logger.log("thumb is not available yet, aborting move"); return; } this.logger.log("move thumb, x: " + x + ", y: " + y); // this.verifyOffset(); t.setDelta(this.thumbCenterPoint.x, this.thumbCenterPoint.y); var _p = t.getTargetCoord(x, y); var p = [_p.x, _p.y]; this.fireEvent("slideStart"); if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && t._graduated && !skipAnim) { this.logger.log("graduated"); // this.thumb._animating = true; this.lock(); setTimeout( function() { self.moveOneTick(p); }, this.tickPause ); } else if (this.animate && YAHOO.widget.Slider.ANIM_AVAIL && !skipAnim) { this.logger.log("animating to " + p); // this.thumb._animating = true; this.lock(); var oAnim = new YAHOO.util.Motion( t.id, { points: { to: p } }, this.animationDuration, YAHOO.util.Easing.easeOut ); oAnim.onComplete.subscribe( function() { self.endMove(); } ); oAnim.animate(); } else { t.setDragElPos(x, y); // this.fireEvents(); this.endMove(); } }, /** * Move the slider one tick mark towards its final coordinate. Used * for the animation when tick marks are defined * @method moveOneTick * @param {int[]} the destination coordinate * @private */ moveOneTick: function(finalCoord) { var t = this.thumb; var curCoord = YAHOO.util.Dom.getXY(t.getEl()); var tmp; // var thresh = Math.min(t.tickSize + (Math.floor(t.tickSize/2)), 10); // var thresh = 10; // var thresh = t.tickSize + (Math.floor(t.tickSize/2)); var nextCoord = null; if (t._isRegion) { nextCoord = this._getNextX(curCoord, finalCoord); var tmpX = (nextCoord) ? nextCoord[0] : curCoord[0]; nextCoord = this._getNextY([tmpX, curCoord[1]], finalCoord); } else if (t._isHoriz) { nextCoord = this._getNextX(curCoord, finalCoord); } else { nextCoord = this._getNextY(curCoord, finalCoord); } this.logger.log("moveOneTick: " + " finalCoord: " + finalCoord + " curCoord: " + curCoord + " nextCoord: " + nextCoord); if (nextCoord) { // move to the next coord // YAHOO.util.Dom.setXY(t.getEl(), nextCoord); // var el = t.getEl(); // YAHOO.util.Dom.setStyle(el, "left", (nextCoord[0] + this.thumb.deltaSetXY[0]) + "px"); // YAHOO.util.Dom.setStyle(el, "top", (nextCoord[1] + this.thumb.deltaSetXY[1]) + "px"); this.thumb.alignElWithMouse(t.getEl(), nextCoord[0], nextCoord[1]); // check if we are in the final position, if not make a recursive call if (!(nextCoord[0] == finalCoord[0] && nextCoord[1] == finalCoord[1])) { var self = this; setTimeout(function() { self.moveOneTick(finalCoord); }, this.tickPause); } else { this.endMove(); } } else { this.endMove(); } //this.tickPause = Math.round(this.tickPause/2); },
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?