📄 common.js
字号:
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.
/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxTimer.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
// Add common toolkit scripts here. To consume the scripts on a control add
//
// [RequiredScript(typeof(CommonToolkitScripts))]
// public class SomeExtender : ...
//
// to the controls extender class declaration.
Type.registerNamespace('AjaxControlToolkit');
AjaxControlToolkit.BoxSide = function() {
/// <summary>
/// The BoxSide enumeration describes the sides of a DOM element
/// </summary>
/// <field name="Top" type="Number" integer="true" static="true" />
/// <field name="Right" type="Number" integer="true" static="true" />
/// <field name="Bottom" type="Number" integer="true" static="true" />
/// <field name="Left" type="Number" integer="true" static="true" />
}
AjaxControlToolkit.BoxSide.prototype = {
Top : 0,
Right : 1,
Bottom : 2,
Left : 3
}
AjaxControlToolkit.BoxSide.registerEnum("AjaxControlToolkit.BoxSide", false);
AjaxControlToolkit._CommonToolkitScripts = function() {
/// <summary>
/// The _CommonToolkitScripts class contains functionality utilized across a number
/// of controls (but not universally)
/// </summary>
/// <remarks>
/// You should not create new instances of _CommonToolkitScripts. Instead you should use the shared instance CommonToolkitScripts (or AjaxControlToolkit.CommonToolkitScripts).
/// </remarks>
}
AjaxControlToolkit._CommonToolkitScripts.prototype = {
// The order of these lookup tables is directly linked to the BoxSide enum defined above
_borderStyleNames : ["borderTopStyle","borderRightStyle","borderBottomStyle","borderLeftStyle"],
_borderWidthNames : ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
_paddingWidthNames : ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"],
_marginWidthNames : ["marginTop", "marginRight", "marginBottom", "marginLeft"],
getCurrentStyle : function(element, attribute, defaultValue) {
/// <summary>
/// CommonToolkitScripts.getCurrentStyle is used to compute the value of a style attribute on an
/// element that is currently being displayed. This is especially useful for scenarios where
/// several CSS classes and style attributes are merged, or when you need information about the
/// size of an element (such as its padding or margins) that is not exposed in any other fashion.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Live DOM element to check style of
/// </param>
/// <param name="attribute" type="String">
/// The style attribute's name is expected to be in a camel-cased form that you would use when
/// accessing a JavaScript property instead of the hyphenated form you would use in a CSS
/// stylesheet (i.e. it should be "backgroundColor" and not "background-color").
/// </param>
/// <param name="defaultValue" type="Object" mayBeNull="true" optional="true">
/// In the event of a problem (i.e. a null element or an attribute that cannot be found) we
/// return this object (or null if none if not specified).
/// </param>
/// <returns type="Object">
/// Current style of the element's attribute
/// </returns>
var currentValue = null;
if (element) {
if (element.currentStyle) {
currentValue = element.currentStyle[attribute];
} else if (document.defaultView && document.defaultView.getComputedStyle) {
var style = document.defaultView.getComputedStyle(element, null);
if (style) {
currentValue = style[attribute];
}
}
if (!currentValue && element.style.getPropertyValue) {
currentValue = element.style.getPropertyValue(attribute);
}
else if (!currentValue && element.style.getAttribute) {
currentValue = element.style.getAttribute(attribute);
}
}
if ((!currentValue || currentValue == "" || typeof(currentValue) === 'undefined')) {
if (typeof(defaultValue) != 'undefined') {
currentValue = defaultValue;
}
else {
currentValue = null;
}
}
return currentValue;
},
getInheritedBackgroundColor : function(element) {
/// <summary>
/// CommonToolkitScripts.getInheritedBackgroundColor provides the ability to get the displayed
/// background-color of an element. In most cases calling CommonToolkitScripts.getCurrentStyle
/// won't do the job because it will return "transparent" unless the element has been given a
/// specific background color. This function will walk up the element's parents until it finds
/// a non-transparent color. If we get all the way to the top of the document or have any other
/// problem finding a color, we will return the default value '#FFFFFF'. This function is
/// especially important when we're using opacity in IE (because ClearType will make text look
/// horrendous if you fade it with a transparent background color).
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Live DOM element to get the background color of
/// </param>
/// <returns type="String">
/// Background color of the element
/// </returns>
if (!element) return '#FFFFFF';
var background = this.getCurrentStyle(element, 'backgroundColor');
try {
while (!background || background == '' || background == 'transparent' || background == 'rgba(0, 0, 0, 0)') {
element = element.parentNode;
if (!element) {
background = '#FFFFFF';
} else {
background = this.getCurrentStyle(element, 'backgroundColor');
}
}
} catch(ex) {
background = '#FFFFFF';
}
return background;
},
getLocation : function(element) {
/// <summary>Gets the coordinates of a DOM element.</summary>
/// <param name="element" domElement="true"/>
/// <returns type="Sys.UI.Point">
/// A Point object with two fields, x and y, which contain the pixel coordinates of the element.
/// </returns>
// workaround for an issue in getLocation where it will compute the location of the document element.
// this will return an offset if scrolled.
//
if (element === document.documentElement) {
return new Sys.UI.Point(0,0);
}
// Workaround for IE6 bug in getLocation (also required patching getBounds - remove that fix when this is removed)
if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) {
if (element.window === element || element.nodeType === 9 || !element.getClientRects || !element.getBoundingClientRect) return new Sys.UI.Point(0,0);
// Get the first bounding rectangle in screen coordinates
var screenRects = element.getClientRects();
if (!screenRects || !screenRects.length) {
return new Sys.UI.Point(0,0);
}
var first = screenRects[0];
// Delta between client coords and screen coords
var dLeft = 0;
var dTop = 0;
var inFrame = false;
try {
inFrame = element.ownerDocument.parentWindow.frameElement;
} catch(ex) {
// If accessing the frameElement fails, a frame is probably in a different
// domain than its parent - and we still want to do the calculation below
inFrame = true;
}
// If we're in a frame, get client coordinates too so we can compute the delta
if (inFrame) {
// Get the bounding rectangle in client coords
var clientRect = element.getBoundingClientRect();
if (!clientRect) {
return new Sys.UI.Point(0,0);
}
// Find the minima in screen coords
var minLeft = first.left;
var minTop = first.top;
for (var i = 1; i < screenRects.length; i++) {
var r = screenRects[i];
if (r.left < minLeft) {
minLeft = r.left;
}
if (r.top < minTop) {
minTop = r.top;
}
}
// Compute the delta between screen and client coords
dLeft = minLeft - clientRect.left;
dTop = minTop - clientRect.top;
}
// Subtract 2px, the border of the viewport (It can be changed in IE6 by applying a border style to the HTML element,
// but this is not supported by ASP.NET AJAX, and it cannot be changed in IE7.), and also subtract the delta between
// screen coords and client coords
var ownerDocument = element.document.documentElement;
return new Sys.UI.Point(first.left - 2 - dLeft + ownerDocument.scrollLeft, first.top - 2 - dTop + ownerDocument.scrollTop);
}
return Sys.UI.DomElement.getLocation(element);
},
setLocation : function(element, point) {
/// <summary>
/// Sets the current location for an element.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="point" type="Object">
/// Point object (of the form {x,y})
/// </param>
/// <remarks>
/// This method does not attempt to set the positioning mode of an element.
/// The position is relative from the elements nearest position:relative or
/// position:absolute element.
/// </remarks>
Sys.UI.DomElement.setLocation(element, point.x, point.y);
},
getContentSize : function(element) {
/// <summary>
/// Gets the "content-box" size of an element.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <returns type="Object">
/// Size of the element (in the form {width,height})
/// </returns>
/// <remarks>
/// The "content-box" is the size of the content area *inside* of the borders and
/// padding of an element. The "content-box" size does not include the margins around
/// the element.
/// </remarks>
if (!element) {
throw Error.argumentNull('element');
}
var size = this.getSize(element);
var borderBox = this.getBorderBox(element);
var paddingBox = this.getPaddingBox(element);
return {
width : size.width - borderBox.horizontal - paddingBox.horizontal,
height : size.height - borderBox.vertical - paddingBox.vertical
}
},
getSize : function(element) {
/// <summary>
/// Gets the "border-box" size of an element.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <returns type="Object">
/// Size of the element (in the form {width,height})
/// </returns>
/// <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');
}
return {
width: element.offsetWidth,
height: element.offsetHeight
};
},
setContentSize : function(element, size) {
/// <summary>
/// Sets the "content-box" size of an element.
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// DOM element
/// </param>
/// <param name="size" type="Object">
/// Size of the element (in the form {width,height})
/// </param>
/// <remarks>
/// The "content-box" is the size of the content area *inside* of the borders and
/// padding of an element. The "content-box" size does not include the margins around
/// the element.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -