📄 common.js
字号:
/// Parses a border-width string into a pixel size
/// </summary>
/// <param name="borderWidth" type="String" mayBeNull="true">
/// Type of border ('thin','medium','thick','inherit',px unit,null,'')
/// </param>
/// <returns type="Number" integer="true">
/// Number of pixels in the border-width
/// </returns>
if (!this._borderThicknesses) {
// Populate the borderThicknesses lookup table
var borderThicknesses = { };
var div0 = document.createElement('div');
div0.style.visibility = 'hidden';
div0.style.position = 'absolute';
div0.style.fontSize = '1px';
document.body.appendChild(div0)
var div1 = document.createElement('div');
div1.style.height = '0px';
div1.style.overflow = 'hidden';
div0.appendChild(div1);
var base = div0.offsetHeight;
div1.style.borderTop = 'solid black';
div1.style.borderTopWidth = 'thin';
borderThicknesses['thin'] = div0.offsetHeight - base;
div1.style.borderTopWidth = 'medium';
borderThicknesses['medium'] = div0.offsetHeight - base;
div1.style.borderTopWidth = 'thick';
borderThicknesses['thick'] = div0.offsetHeight - base;
div0.removeChild(div1);
document.body.removeChild(div0);
this._borderThicknesses = borderThicknesses;
}
if (borderWidth) {
switch(borderWidth) {
case 'thin':
case 'medium':
case 'thick':
return this._borderThicknesses[borderWidth];
case 'inherit':
return 0;
}
var unit = this.parseUnit(borderWidth);
Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidBorderWidthUnit, unit.type));
return unit.size;
}
return 0;
},
parsePadding : function(padding) {
/// <summary>
/// Parses a padding string into a pixel size
/// </summary>
/// <param name="padding" type="String" mayBeNull="true">
/// Padding to parse ('inherit',px unit,null,'')
/// </param>
/// <returns type="Number" integer="true">
/// Number of pixels in the padding
/// </returns>
if(padding) {
if(padding == 'inherit') {
return 0;
}
var unit = this.parseUnit(padding);
Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidPaddingUnit, unit.type));
return unit.size;
}
return 0;
},
parseUnit : function(value) {
/// <summary>
/// Parses a unit string into a unit object
/// </summary>
/// <param name="value" type="String" mayBeNull="true">
/// Value to parse (of the form px unit,% unit,em unit,...)
/// </param>
/// <returns type="Object">
/// Parsed unit (of the form {size,type})
/// </returns>
if (!value) {
throw Error.argumentNull('value');
}
value = value.trim().toLowerCase();
var l = value.length;
var s = -1;
for(var i = 0; i < l; i++) {
var ch = value.substr(i, 1);
if((ch < '0' || ch > '9') && ch != '-' && ch != '.' && ch != ',') {
break;
}
s = i;
}
if(s == -1) {
throw Error.create(AjaxControlToolkit.Resources.Common_UnitHasNoDigits);
}
var type;
var size;
if(s < (l - 1)) {
type = value.substring(s + 1).trim();
} else {
type = 'px';
}
size = parseFloat(value.substr(0, s + 1));
if(type == 'px') {
size = Math.floor(size);
}
return {
size: size,
type: type
};
},
getElementOpacity : function(element) {
/// <summary>
/// Get the element's opacity
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Element
/// </param>
/// <returns type="Number">
/// Opacity of the element
/// </returns>
if (!element) {
throw Error.argumentNull('element');
}
var hasOpacity = false;
var opacity;
if (element.filters) {
var filters = element.filters;
if (filters.length !== 0) {
var alphaFilter = filters['DXImageTransform.Microsoft.Alpha'];
if (alphaFilter) {
opacity = alphaFilter.opacity / 100.0;
hasOpacity = true;
}
}
}
else {
opacity = this.getCurrentStyle(element, 'opacity', 1);
hasOpacity = true;
}
if (hasOpacity === false) {
return 1.0;
}
return parseFloat(opacity);
},
setElementOpacity : function(element, value) {
/// <summary>
/// Set the element's opacity
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Element
/// </param>
/// <param name="value" type="Number">
/// Opacity of the element
/// </param>
if (!element) {
throw Error.argumentNull('element');
}
if (element.filters) {
var filters = element.filters;
var createFilter = true;
if (filters.length !== 0) {
var alphaFilter = filters['DXImageTransform.Microsoft.Alpha'];
if (alphaFilter) {
createFilter = false;
alphaFilter.opacity = value * 100;
}
}
if (createFilter) {
element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (value * 100) + ')';
}
}
else {
element.style.opacity = value;
}
},
getVisible : function(element) {
/// <summary>
/// Check if an element is visible
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Element
/// </param>
/// <returns type="Boolean" mayBeNull="false">
/// True if the element is visible, false otherwise
/// </returns>
// Note: reference to CommonToolkitScripts must be left intact (i.e. don't
// replace with 'this') because this function will be aliased
return (element &&
("none" != $common.getCurrentStyle(element, "display")) &&
("hidden" != $common.getCurrentStyle(element, "visibility")));
},
setVisible : function(element, value) {
/// <summary>
/// Check if an element is visible
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Element
/// </param>
/// <param name="value" type="Boolean" mayBeNull="false">
/// True to make the element visible, false to hide it
/// </param>
// Note: reference to CommonToolkitScripts must be left intact (i.e. don't
// replace with 'this') because this function will be aliased
if (element && value != $common.getVisible(element)) {
if (value) {
if (element.style.removeAttribute) {
element.style.removeAttribute("display");
} else {
element.style.removeProperty("display");
}
} else {
element.style.display = 'none';
}
element.style.visibility = value ? 'visible' : 'hidden';
}
},
resolveFunction : function(value) {
/// <summary>
/// Returns a function reference that corresponds to the provided value
/// </summary>
/// <param name="value" type="Object">
/// The value can either be a Function, the name of a function (that can be found using window['name']),
/// or an expression that evaluates to a function.
/// </param>
/// <returns type="Function">
/// Reference to the function, or null if not found
/// </returns>
if (value) {
if (value instanceof Function) {
return value;
} else if (String.isInstanceOfType(value) && value.length > 0) {
var func;
if ((func = window[value]) instanceof Function) {
return func;
} else if ((func = eval(value)) instanceof Function) {
return func;
}
}
}
return null;
},
addCssClasses : function(element, classNames) {
/// <summary>
/// Adds multiple css classes to a DomElement
/// </summary>
/// <param name="element" type="Sys.UI.DomElement">The element to modify</param>
/// <param name="classNames" type="Array">The class names to add</param>
for(var i = 0; i < classNames.length; i++) {
Sys.UI.DomElement.addCssClass(element, classNames[i]);
}
},
removeCssClasses : function(element, classNames) {
/// <summary>
/// Removes multiple css classes to a DomElement
/// </summary>
/// <param name="element" type="Sys.UI.DomElement">The element to modify</param>
/// <param name="classNames" type="Array">The class names to remove</param>
for(var i = 0; i < classNames.length; i++) {
Sys.UI.DomElement.removeCssClass(element, classNames[i]);
}
},
setStyle : function(element, style) {
/// <summary>
/// Sets the style of the element using the supplied style template object
/// </summary>
/// <param name="element" type="Sys.UI.DomElement">The element to modify</param>
/// <param name="style" type="Object">The template</param>
$common.applyProperties(element.style, style);
},
removeHandlers : function(element, events) {
/// <summary>
/// Removes a set of event handlers from an element
/// </summary>
/// <param name="element" type="Sys.UI.DomElement">The element to modify</param>
/// <param name="events" type="Object">The template object that contains event names and delegates</param>
/// <remarks>
/// This is NOT the same as $clearHandlers which removes all delegates from a DomElement. This rather removes select delegates
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -