📄 sliderbehavior.js
字号:
if(isInputElement) {
this._boundControl.value = value;
}
else if(this._boundControl) {
this._boundControl.innerHTML = value;
}
}
}
},
// _getBoundsInternal
// This function swaps the x and y coordinates to use the same logic
// for both the horizontal and vertical slider.
//
_getBoundsInternal : function(element) {
var bounds = $common.getBounds(element);
// This function checks whether width and height are defined
// for the DOM element passed as an argument.
function hasSize() {
return bounds.width > 0 && bounds.height > 0;
}
// If we weren't able to compute the size, let's try getting it from CSS.
// For example, if the slider has a containing element with display:none, then
// the size computed will always be zero. Note: in Opera, the width parsed from CSS is always 0.
if(!hasSize()) {
bounds.width = parseInt($common.getCurrentStyle(element, 'width'));
bounds.height = parseInt($common.getCurrentStyle(element, 'height'));
if(!hasSize()) {
// If size is still invalid, let's try temporary adding the element
// as a child of the BODY element.
var tempNode = element.cloneNode(true);
tempNode.visibility = 'hidden';
document.body.appendChild(tempNode);
bounds.width = parseInt($common.getCurrentStyle(tempNode, 'width'));
bounds.height = parseInt($common.getCurrentStyle(tempNode, 'height'));
document.body.removeChild(tempNode);
// If size is still invalid, then give up.
if(!hasSize()) {
throw Error.argument('element size', AjaxControlToolkit.Resources.Slider_NoSizeProvided);
}
}
}
if(this._orientation == AjaxControlToolkit.SliderOrientation.Vertical) {
bounds = { x : bounds.y,
y : bounds.x,
height : bounds.width,
width : bounds.height,
right : bounds.right,
bottom : bounds.bottom,
location : {x:bounds.y, y:bounds.x},
size : {width:bounds.height, height:bounds.width}
};
}
return bounds;
},
// _getRailBounds
// This method returns the slider's rail bounds.
//
_getRailBounds : function() {
var bounds = this._getBoundsInternal(this._railElement);
return bounds;
},
// _getHandleBounds
// This method returns the slider's handle bounds.
//
_getHandleBounds : function() {
return this._getBoundsInternal(this._handle);
},
// _initializeDragHandle
// Initializes the invisible drag handle used to obtain
// an horizontal or vertical drag effect with the ASP.NET AJAX framework.
//
_initializeDragHandle : function() {
var dh = this._dragHandle = document.createElement('DIV');
dh.style.position = 'absolute';
dh.style.width = '1px';
dh.style.height = '1px';
dh.style.overflow = 'hidden';
dh.style.zIndex = '999';
dh.style.background = 'none';
document.body.appendChild(this._dragHandle);
},
// _resetDragHandle
// This method is called to reset the invisible drag handle to its
// default position.
//
_resetDragHandle : function() {
var handleBounds = $common.getBounds(this._handle);
$common.setLocation(this._dragHandle, {x:handleBounds.x, y:handleBounds.y});
},
// _initializeHandlers
// This method creates the event handlers and attach them to the
// corresponding events.
//
_initializeHandlers : function() {
this._selectstartHandler = Function.createDelegate(this, this._onSelectStart);
this._mouseupHandler = Function.createDelegate(this, this._onMouseUp);
$addHandler(document, 'mouseup', this._mouseupHandler);
$addHandlers(this._handle,
{
'mousedown': this._onMouseDown,
'dragstart': this._IEDragDropHandler,
'drag': this._IEDragDropHandler,
'dragend': this._IEDragDropHandler
},
this);
$addHandlers(this._railElement,
{
'click': this._onRailClick
},
this);
},
_disposeHandlers : function() {
$clearHandlers(this._handle);
$clearHandlers(this._railElement);
$removeHandler(document, 'mouseup', this._mouseupHandler);
this._mouseupHandler = null;
this._selectstartHandler = null;
},
// startDragDrop
// Tells the DragDropManager to start a drag and drop operation.
//
startDragDrop : function(dragVisual) {
this._resetDragHandle();
AjaxControlToolkit.SliderDragDropManagerInternal.startDragDrop(this, dragVisual, null);
},
// _onMouseDown
// Handles the slider's handle mousedown event.
//
_onMouseDown : function(evt) {
window._event = evt;
evt.preventDefault();
if(!AjaxControlToolkit.SliderBehavior.DropPending) {
AjaxControlToolkit.SliderBehavior.DropPending = this;
$addHandler(document, 'selectstart', this._selectstartHandler);
this._selectstartPending = true;
this.startDragDrop(this._dragHandle);
}
},
// _onMouseUp
// Handles the document's mouseup event.
//
_onMouseUp : function(evt) {
var srcElement = evt.target;
if(AjaxControlToolkit.SliderBehavior.DropPending == this) {
AjaxControlToolkit.SliderBehavior.DropPending = null;
if(this._selectstartPending) {
$removeHandler(document, 'selectstart', this._selectstartHandler);
}
}
},
// _onRailClick
// Handles the rail element's click event.
_onRailClick : function(evt) {
if(evt.target == this._railElement) {
this._animationPending = true;
this._onRailClicked(evt);
}
},
// _IEDragDropHandler
// This method handles the drag events raised by Internet Explorer,
// preventing the default behaviors since we are using the
// GenericDragDropManager
//
_IEDragDropHandler : function(evt) {
evt.preventDefault();
},
// _onSelectStart
// Handles the document's selectstart event.
//
_onSelectStart : function(evt) {
evt.preventDefault();
},
// _calcValue
// This function computes the slider's value.
//
_calcValue : function(value, mouseOffset) {
var val;
if(value != null) {
if(!Number.isInstanceOfType(value)) {
try {
value = parseFloat(value);
} catch(ex) {
value = Number.NaN;
}
}
if(isNaN(value)) {
value = this._minimum;
}
val = (value < this._minimum) ? this._minimum
: (value > this._maximum) ? this._maximum
: value;
}
else {
var _minimum = this._minimum;
var _maximum = this._maximum;
var handleBounds = this._getHandleBounds();
var sliderBounds = this._getRailBounds();
var handleX = (mouseOffset) ? mouseOffset - handleBounds.width / 2
: handleBounds.x - sliderBounds.x;
var extent = sliderBounds.width - handleBounds.width;
var percent = handleX / extent;
val = (handleX == 0) ? _minimum
: (handleX == (sliderBounds.width - handleBounds.width)) ? _maximum
: _minimum + percent * (_maximum - _minimum);
}
if(this._steps > 0) {
val = this._getNearestStepValue(val);
}
val = (val < this._minimum) ? this._minimum
: (val > this._maximum) ? this._maximum
: val;
this._isUpdatingInternal = true;
this.set_Value(val);
this._isUpdatingInternal = false;
return val;
},
// _setHandleOffset
// This function computes the handle's offset corresponding
// to a given value.
//
_setHandleOffset : function(value, playHandleAnimation) {
var _minimum = this._minimum;
var _maximum = this._maximum;
var handleBounds = this._getHandleBounds();
var sliderBounds = this._getRailBounds();
var extent = _maximum - _minimum;
var fraction = (value - _minimum) / extent;
var hypOffset = Math.round(fraction * (sliderBounds.width - handleBounds.width));
var offset = (value == _minimum) ? 0
: (value == _maximum) ? (sliderBounds.width - handleBounds.width)
: hypOffset;
if(playHandleAnimation) {
this._handleAnimation.set_startValue(handleBounds.x - sliderBounds.x);
this._handleAnimation.set_endValue(offset);
this._handleAnimation.set_propertyKey((this._isHorizontal) ? 'left' : 'top');
this._handleAnimation.play();
this._animationPending = false;
}
else {
if(this._isHorizontal) {
this._handle.style.left = offset + 'px';
}
else {
this._handle.style.top = offset + 'px';
}
}
},
// _getNearestStepValue
// This function computes the current value for a "discrete" slider.
//
_getNearestStepValue : function(value) {
if(this._steps == 0) return value;
var extent = this._maximum - this._minimum;
if (extent == 0) return value;
var delta = extent / (this._steps - 1);
return Math.round(value / delta) * delta;
},
// _onHandleReleased
// This function is invoked when the slider's handle is released.
//
_onHandleReleased : function() {
if(this._raiseChangeOnlyOnMouseUp) {
this._fireTextBoxChangeEvent();
}
this._raiseEvent('slideEnd');
},
// _onRailClicked
// This function is invoked when the slider's rail is clicked.
//
_onRailClicked : function(evt) {
// Compute the pointer's offset.
var handleBounds = this._getHandleBounds();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -