📄 slider.js
字号:
case 0x25: h -= this.keyIncrement; break; // up case 0x26: v -= this.keyIncrement; break; // right case 0x27: h += this.keyIncrement; break; // down case 0x28: v += this.keyIncrement; break; // home case 0x24: h = t.leftConstraint; v = t.topConstraint; break; // end case 0x23: h = t.rightConstraint; v = t.bottomConstraint; break; default: changeValue = false; } if (changeValue) { if (t._isRegion) { this.setRegionValue(h, v, true); } else { var newVal = (t._isHoriz) ? h : v; this.setValue(newVal, true); } Event.stopEvent(e); } } }, /** * Initialization that sets up the value offsets once the elements are ready * @method setStartSliderState */ setStartSliderState: function() { this.setThumbCenterPoint(); /** * The basline position of the background element, used * to determine if the background has moved since the last * operation. * @property baselinePos * @type [int, int] */ this.baselinePos = YAHOO.util.Dom.getXY(this.getEl()); this.thumb.startOffset = this.thumb.getOffsetFromParent(this.baselinePos); if (this.thumb._isRegion) { if (this.deferredSetRegionValue) { this.setRegionValue.apply(this, this.deferredSetRegionValue); this.deferredSetRegionValue = null; } else { this.setRegionValue(0, 0, true, true, true); } } else { if (this.deferredSetValue) { this.setValue.apply(this, this.deferredSetValue); this.deferredSetValue = null; } else { this.setValue(0, true, true, true); } } }, /** * When the thumb is available, we cache the centerpoint of the element so * we can position the element correctly when the background is clicked * @method setThumbCenterPoint */ setThumbCenterPoint: function() { var el = this.thumb.getEl(); if (el) { /** * The center of the slider element is stored so we can * place it in the correct position when the background is clicked. * @property thumbCenterPoint * @type {"x": int, "y": int} */ this.thumbCenterPoint = { x: parseInt(el.offsetWidth/2, 10), y: parseInt(el.offsetHeight/2, 10) }; } }, /** * Locks the slider, overrides YAHOO.util.DragDrop * @method lock */ lock: function() { this.thumb.lock(); this.locked = true; }, /** * Unlocks the slider, overrides YAHOO.util.DragDrop * @method unlock */ unlock: function() { this.thumb.unlock(); this.locked = false; }, /** * Handles mouseup event on the thumb * @method thumbMouseUp * @private */ thumbMouseUp: function() { if (!this.isLocked() && !this.moveComplete) { this.endMove(); } }, onMouseUp: function() { if (this.backgroundEnabled && !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.valueChangeSource = this.SOURCE_UI_EVENT; // 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._slideStart(); 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 */ }, /** * 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 */ }, /** * Event that fires at the end of a slider thumb move * @method onSliderEnd * @deprecated use instance.subscribe("slideEnd") instead */ onSlideEnd: function () { /* override me */ }, /** * 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) { if (!this._silent) { t.onChange(t.getXValue(), t.getYValue()); this.fireEvent("change", { x: t.getXValue(), y: t.getYValue() } ); } } else { if (!this._silent) { 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 * @param {boolean} silent when true, do not fire events * @return {boolean} true if the move was performed, false if it failed */ setValue: function(newOffset, skipAnim, force, silent) { this._silent = silent; this.valueChangeSource = this.SOURCE_SET_VALUE; if (!this.thumb.available) { this.deferredSetValue = arguments; return false; } if (this.isLocked() && !force) { return false; } if ( isNaN(newOffset) ) { return false; } var t = this.thumb; t.lastOffset = [newOffset, newOffset]; var newX, newY; this.verifyOffset(true); if (t._isRegion) { return false; } else if (t._isHoriz) { this._slideStart(); // this.fireEvent("slideStart"); newX = t.initPageX + newOffset + this.thumbCenterPoint.x; this.moveThumb(newX, t.initPageY, skipAnim); } else { this._slideStart(); // 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 * @param {boolean} silent when true, do not fire events * @return {boolean} true if the move was performed, false if it failed */ setRegionValue: function(newOffset, newOffset2, skipAnim, force, silent) { this._silent = silent; this.valueChangeSource = this.SOURCE_SET_VALUE; if (!this.thumb.available) { this.deferredSetRegionValue = arguments; return false; } if (this.isLocked() && !force) { return false; } if ( isNaN(newOffset) ) { return false; } var t = this.thumb; t.lastOffset = [newOffset, newOffset2]; this.verifyOffset(true); if (t._isRegion) { this._slideStart(); 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 * @param checkPos {boolean} check the position instead of using cached value * @method verifyOffset * @return {boolean} True if the offset is the same as the baseline. */ verifyOffset: function(checkPos) { var xy = YAHOO.util.Dom.getXY(this.getEl()), t = this.thumb; if (xy) { if (xy[0] != this.baselinePos[0] || xy[1] != this.baselinePos[1]) { // Reset background this.setInitPosition(); this.baselinePos = xy; // Reset thumb t.initPageX = this.initPageX + t.startOffset[0]; t.initPageY = this.initPageY + t.startOffset[1]; //t.deltaSetXY = [-this.initPageX,-this.initPageY]; t.deltaSetXY = null; //this.resetConstraints(); this.resetThumbConstraints(); return false; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -