📄 common.js
字号:
/// </remarks>
if (!element) {
throw Error.argumentNull('element');
}
if (!size) {
throw Error.argumentNull('size');
}
// FF respects -moz-box-sizing css extension, so adjust the box size for the border-box
if(this.getCurrentStyle(element, 'MozBoxSizing') == 'border-box' || this.getCurrentStyle(element, 'BoxSizing') == 'border-box') {
var borderBox = this.getBorderBox(element);
var paddingBox = this.getPaddingBox(element);
size = {
width: size.width + borderBox.horizontal + paddingBox.horizontal,
height: size.height + borderBox.vertical + paddingBox.vertical
};
}
element.style.width = size.width.toString() + 'px';
element.style.height = size.height.toString() + 'px';
},
setSize : function(element, size) {
/// <summary>
/// Sets the "border-box" size of an element.
/// </summary>
/// <remarks>
/// The "border-box" is the size of the content area *outside* of the borders and
/// padding of an element. The "border-box" size does not include the margins around
/// the element.
/// </remarks>
/// <param name="element" type="Sys.UI.DomElement">DOM element</param>
/// <param name="size" type="Object">Size of the element (in the form {width,height})</param>
/// <returns />
if (!element) {
throw Error.argumentNull('element');
}
if (!size) {
throw Error.argumentNull('size');
}
var borderBox = this.getBorderBox(element);
var paddingBox = this.getPaddingBox(element);
var contentSize = {
width: size.width - borderBox.horizontal - paddingBox.horizontal,
height: size.height - borderBox.vertical - paddingBox.vertical
};
this.setContentSize(element, contentSize);
},
getBounds : function(element) {
/// <summary>Gets the coordinates, width and height of an element.</summary>
/// <param name="element" domElement="true"/>
/// <returns type="Sys.UI.Bounds">
/// A Bounds object with four fields, x, y, width and height, which contain the pixel coordinates,
/// width and height of the element.
/// </returns>
/// <remarks>
/// Use the CommonToolkitScripts version of getLocation to handle the workaround for IE6. We can
/// remove the below implementation and just call Sys.UI.DomElement.getBounds when the other bug
/// is fixed.
/// </remarks>
var offset = $common.getLocation(element);
return new Sys.UI.Bounds(offset.x, offset.y, element.offsetWidth || 0, element.offsetHeight || 0);
},
setBounds : function(element, bounds) {
/// <summary>
/// Sets the "border-box" bounds of an element
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="bounds" type="Object">
/// Bounds of the element (of the form {x,y,width,height})
/// </param>
/// <remarks>
/// The "border-box" is the size of the content area *outside* of the borders and
/// padding of an element. The "border-box" size does not include the margins around
/// the element.
/// </remarks>
if (!element) {
throw Error.argumentNull('element');
}
if (!bounds) {
throw Error.argumentNull('bounds');
}
this.setSize(element, bounds);
$common.setLocation(element, bounds);
},
getClientBounds : function() {
/// <summary>
/// Gets the width and height of the browser client window (excluding scrollbars)
/// </summary>
/// <returns type="Sys.UI.Bounds">
/// Browser's client width and height
/// </returns>
var clientWidth;
var clientHeight;
switch(Sys.Browser.agent) {
case Sys.Browser.InternetExplorer:
clientWidth = document.documentElement.clientWidth;
clientHeight = document.documentElement.clientHeight;
break;
case Sys.Browser.Safari:
clientWidth = window.innerWidth;
clientHeight = window.innerHeight;
break;
case Sys.Browser.Opera:
clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
break;
default: // Sys.Browser.Firefox, etc.
clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
break;
}
return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
},
getMarginBox : function(element) {
/// <summary>
/// Gets the entire margin box sizes.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <returns type="Object">
/// Element's margin box sizes (of the form {top,left,bottom,right,horizontal,vertical})
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
var box = {
top: this.getMargin(element, AjaxControlToolkit.BoxSide.Top),
right: this.getMargin(element, AjaxControlToolkit.BoxSide.Right),
bottom: this.getMargin(element, AjaxControlToolkit.BoxSide.Bottom),
left: this.getMargin(element, AjaxControlToolkit.BoxSide.Left)
};
box.horizontal = box.left + box.right;
box.vertical = box.top + box.bottom;
return box;
},
getBorderBox : function(element) {
/// <summary>
/// Gets the entire border box sizes.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <returns type="Object">
/// Element's border box sizes (of the form {top,left,bottom,right,horizontal,vertical})
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
var box = {
top: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Top),
right: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Right),
bottom: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Bottom),
left: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Left)
};
box.horizontal = box.left + box.right;
box.vertical = box.top + box.bottom;
return box;
},
getPaddingBox : function(element) {
/// <summary>
/// Gets the entire padding box sizes.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <returns type="Object">
/// Element's padding box sizes (of the form {top,left,bottom,right,horizontal,vertical})
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
var box = {
top: this.getPadding(element, AjaxControlToolkit.BoxSide.Top),
right: this.getPadding(element, AjaxControlToolkit.BoxSide.Right),
bottom: this.getPadding(element, AjaxControlToolkit.BoxSide.Bottom),
left: this.getPadding(element, AjaxControlToolkit.BoxSide.Left)
};
box.horizontal = box.left + box.right;
box.vertical = box.top + box.bottom;
return box;
},
isBorderVisible : function(element, boxSide) {
/// <summary>
/// Gets whether the current border style for an element on a specific boxSide is not 'none'.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="boxSide" type="AjaxControlToolkit.BoxSide">
/// Side of the element
/// </param>
/// <returns type="Boolean">
/// Whether the current border style for an element on a specific boxSide is not 'none'.
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
if(boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) {
throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide'));
}
var styleName = this._borderStyleNames[boxSide];
var styleValue = this.getCurrentStyle(element, styleName);
return styleValue != "none";
},
getMargin : function(element, boxSide) {
/// <summary>
/// Gets the margin thickness of an element on a specific boxSide.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="boxSide" type="AjaxControlToolkit.BoxSide">
/// Side of the element
/// </param>
/// <returns type="Number" integer="true">
/// Margin thickness on the element's specified side
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
if(boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) {
throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide'));
}
var styleName = this._marginWidthNames[boxSide];
var styleValue = this.getCurrentStyle(element, styleName);
try { return this.parsePadding(styleValue); } catch(ex) { return 0; }
},
getBorderWidth : function(element, boxSide) {
/// <summary>
/// Gets the border thickness of an element on a specific boxSide.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="boxSide" type="AjaxControlToolkit.BoxSide">
/// Side of the element
/// </param>
/// <returns type="Number" integer="true">
/// Border thickness on the element's specified side
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
if(boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) {
throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide'));
}
if(!this.isBorderVisible(element, boxSide)) {
return 0;
}
var styleName = this._borderWidthNames[boxSide];
var styleValue = this.getCurrentStyle(element, styleName);
return this.parseBorderWidth(styleValue);
},
getPadding : function(element, boxSide) {
/// <summary>
/// Gets the padding thickness of an element on a specific boxSide.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="boxSide" type="AjaxControlToolkit.BoxSide">
/// Side of the element
/// </param>
/// <returns type="Number" integer="true">
/// Padding on the element's specified side
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
if(boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) {
throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide'));
}
var styleName = this._paddingWidthNames[boxSide];
var styleValue = this.getCurrentStyle(element, styleName);
return this.parsePadding(styleValue);
},
parseBorderWidth : function(borderWidth) {
/// <summary>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -