⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 element.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*
 * Isomorphic SmartClient
 * Version 6.5 (2008-04-30)
 * Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
 * "SmartClient" is a trademark of Isomorphic Software, Inc.
 *
 * licensing@smartclient.com
 *
 * http://smartclient.com/license
 */
 //>	@class	Element//// Helper class containing methods for direct DOM interaction. Note that even if // +link{isc, isc_useSimpleNames} is true, this class is not available in the global scope// as <code>window.Element</code> - to access it developers must always use // <code>isc.Element</code>////  @treeLocation Client Reference/Foundation//  @visibility internal//<// Currently has no exposed methods - Developers typically will only need to interact with // higher level canvas methodsisc.ClassFactory.defineClass("Element", null, null, true);isc.Element.addClassMethods({// --------------------------------------------------------------------------------------------// DOM Access / Manipulation//>	@classMethod	Element.get()//		Like the DOM method document.getElementById(), but works in all supported browsers.//<get : function (id, doc) {    doc = doc || this.getDocument();    if (isc.Browser.isDOM) return doc.getElementById(id);},// _getElementFromSelection()// Determine which DOM element contains the current selection.// 'doc' param allows caller to pass in a pointer to the document element - (may be document// element from some frame/iframe - if not specifed the main page document is used)._getElementFromSelection : function (doc) {        if (!doc) doc = document;        if (isc.Browser.isIE) {        var selection = doc.selection,            type = selection.type.toLowerCase(),            isText = (type == "text" || type == "none");                    if (!selection) return null;                    // If it's a text range use the 'parentElement()' method to determine what element        // contains the text.        // NOTE: an empty selection will be reported as type "None", but can be used to create        // a zero char text range, so we treat it like a "Text" selection.        if (isText) {            var range = selection.createRange();            return range ? range.parentElement() : null;        // If it's a control range, we can get at the elements in the control range        // by index.    Iterate through the elements and find the common ancester.                } else {              // If this is a control range             // We're interested in the first common ancestor of the elements            var range = selection.createRange(),                commonParent;            for (var i = 0; i < range.length; i++) {                if (!commonParent) {                    commonParent = range(i).parentElement;                                } else {                    // To determine whether the element is contained by the common parent,                     // we're creating a textRange from both elements and using the inRange                    // method.                    while (!commonParent.contains(range(i))) {                        commonParent = commonParent.parentElement;                    }                }                             }            return commonParent;        }    }},// helpers for createAbsoluteElement_insertAfterBodyStart : window.isc_insertAfterBodyStart,_globalInsertionMarker : "isc_global_insertion_marker",getInsertionMarkerHTML : function () {    return "<span id='"+this._globalInsertionMarker+"' style='display:none'></span>";},getInsertionMarker : function () {    return document.getElementById(this._globalInsertionMarker);},// create a new, absolutely positioned element, after page load_$afterBegin : "afterBegin",_$afterEnd : "afterEnd",_$beforeBegin: "beforeBegin",_$beforeEnd : "beforeEnd",createAbsoluteElement : function (html, targetWindow) {    var wd = targetWindow || this.getWindow(),                 body = this.getDocumentBody(true);            //>DEBUG    // if there's no body tag, we bail    if (body == null && !isc.Element.noBodyTagMessageShown) {        isc.Element.noBodyTagMessageShown = true;        var msg ="Error: Attempt to write content into a page outside the BODY tag.  Isomorphic " +            "SmartClient requires this tag be present and all widgets be written out inside " +            "it.\r" +            "Please ensure your file has a BODY tag and any code to draw SmartClient widgets " +            "is enclosed in this tag."            ;        //alert(msg);        this.logError(msg);        return;    }    //<DEBUG        // safety valve - use a global var to switch back to our previous rendering mode - set    // window.isc_insertAfterBodyStart to enable this rendering mode.    if (this._insertAfterBodyStart) {        return isc.Element.insertAdjacentHTML(body, this._$afterBegin, html, true);    }    if (isc.Browser.isIE) {        if (!this._insertionMarker) {            if (body.childNodes.length < 2) {                // empty body or body with just one element, in either case insert afterBegin                // of the body on the assumption that the one element may not be closed.                isc.Element.insertAdjacentHTML(body, this._$afterBegin, this.getInsertionMarkerHTML());            } else {                // insert right before the last element                //                // If the last element is a text node, spin back through the siblings until we                // find one that isn't a text node because calling                // textNode.insertAdjacentHTML() results in a "no such method" in IE                //                // One natural way in which such text elements get created is by the use of an                // <INPUT> element with no enclosing <FORM> tag, right at the end of the page.                var node = body.lastChild;                while (node && node.nodeType == 3) node = node.previousSibling;                if (node != null) {                    isc.Element.insertAdjacentHTML(node, this._$beforeBegin,                                                   this.getInsertionMarkerHTML());                } else {                    // all nodes of the body are text nodes, insert after body begin                    isc.Element.insertAdjacentHTML(body, this._$afterBegin, this.getInsertionMarkerHTML());                }            }            this._insertionMarker = this.getInsertionMarker();        }        return isc.Element.insertAdjacentHTML(this._insertionMarker, this._$afterEnd, html, true);                } else {        return isc.Element.insertAdjacentHTML(body, this._$beforeEnd, html, true);    }},// emulate IE's insertAdjacentHTML on any fully DOM-compliant browserinsertAdjacentHTML : function (element, where, html, singleElement) {    // handle string element IDs    if (isc.isA.String(element)) element = isc.Element.get(element);    //>DEBUG    if (!element) this.logWarn("insertAdjacentHTML: element is null for where: '" + where +                                 "' with html: " + html);    //<DEBUG    if (isc.Browser.isIE || isc.Browser.isOpera) {        // in IE it's supported natively        element.insertAdjacentHTML(where, html);        return;    }    //this.logWarn("inserting at element: " + this.echoLeaf(element) +     //             " at position " + where + ", html: " + this.echoLeaf(html));        var newElement;    if (singleElement) {        var wrapper = element.ownerDocument.createElement("DIV");        wrapper.innerHTML = html;        newElement = wrapper.firstChild;    } else {        // create a document fragment from the HTML        var range = element.ownerDocument.createRange();        range.setStartBefore(element);        newElement = range.createContextualFragment(html);    }    // insert it into the given parent    switch (where){    case "beforeBegin":        element.parentNode.insertBefore(newElement, element)		break;    case "afterBegin":		element.insertBefore(newElement, element.firstChild);		break;	case "beforeEnd":		element.appendChild(newElement);		break;	case "afterEnd":		if (element.nextSibling) element.parentNode.insertBefore(newElement, element.nextSibling);		else element.parentNode.appendChild(newElement);		break;	}    if (singleElement) return newElement;},// clear the element passed in (removing it's HTML from the DOM)clear : function (element) {    if (element == null) return;         if (isc.Page.isLoaded() && isc.Browser.isIE) {        element.outerHTML = isc.emptyString;        return;    }    if (element.parentNode) {        element.parentNode.removeChild(element);    } else {                //>DEBUG        isc.Log.logWarn("element parentNode null"); //<DEBUG        element.innerHTML = "";    }},	// ----------------------------------------------------------------------------------------// Deriving sizing/positioning + margins etc information from HTML elements// ----------------------------------------------------------------------------------------// As with Canvii, these methods will work with the size of the HTML element, INCLUDING any// margins wherever appropriate.// This means:// - getOffsetLeft(element) / getOffsetTop(element) return the offset top / left of the element's//   margin, rather than of the element itself// - getVisibleWidth(element) / getVisibleHeight(element) return the height / width of the element//   including top and bottom margins.// helper: Does this element adhere to the border-box model or the content-box model for sizing?isBorderBox : function (element) {    if (!element) return;    if (!isc.Browser.isMoz) return isc.Browser.isBorderBox;        return (element.style.MozBoxSizing == "border-box");},// Return the scrollHeight (scrollable height) for the element.getScrollHeight : function (element) {    if (element == null) return 0;        var height = ((element.scrollHeight!= null && element.scrollHeight != "undefined")                                                 ? element.scrollHeight : element.offsetHeight);        var largestBottom = this._getPositionedChildrenBottom(element);    return largestBottom > height ? largestBottom : height;},// get the largest bottom coordinate for any explicitly positioned DOM children of this element_getPositionedChildrenBottom : function (element) {    if (element.childNodes == null) return 0;    var largest = 0,        // constants for determining whether a DOM node is an element.                  elementType = document.ELEMENT_NODE || 1,        debug = this.logIsDebugEnabled("sizing");    for (var i = 0; i < element.childNodes.length; i++) {        var child = element.childNodes.item(i);                // ignore anything that isn't an element (only elements report any size information)        if (child.nodeType != elementType) continue;                var childPosition = isc.Element.getComputedStyleAttribute(child, "position");                // get the top coordinate of the child        var childTop = 0;        if (childPosition == isc.Canvas.ABSOLUTE || childPosition == isc.Canvas.RELATIVE) {            childTop += isc.Element.getOffsetTop(child);        } else {            // inline content ("position" property unset).  We don't inspect this because the            // scrollWidth reported by the element includes inline content            continue;        }                var canvas = child.getAttribute("eventProxy"),            childVisibleHeight;        if (canvas != null &&             !isc.isAn.emptyString(canvas) &&             !window[canvas]._retrievingScrollHeight &&            isc.isA.Function(window[canvas].getVisibleHeight))         {            childVisibleHeight = window[canvas].getVisibleHeight();        } else {            // For regular DOM elements call isc.Element.getVisibleHeight(element) instead            childVisibleHeight = isc.Element.getVisibleHeight(child);        }                var childBottom = childTop + childVisibleHeight;        // Notes:        // - the 'visibleHeight' is the height of this child, including any margins.        //   if this (parent) is scrollable, and the child is absolutely positioned, we         //   natively can't scroll to the right/bottom margin, so deduct this from the reported

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -