📄 html.js
字号:
if(!dojo._hasResource["dojo._base.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.dojo._hasResource["dojo._base.html"] = true;dojo.require("dojo._base.lang");dojo.provide("dojo._base.html");// FIXME: need to add unit tests for all the semi-public methodstry{ document.execCommand("BackgroundImageCache", false, true);}catch(e){ // sane browsers don't have cache "issues"}// =============================// DOM Functions// =============================/*=====dojo.byId = function(id, doc){ // summary: // Returns DOM node with matching `id` attribute or `null` // if not found, similar to "$" function in another library. // If `id` is a DomNode, this function is a no-op. // // id: String|DOMNode // A string to match an HTML id attribute or a reference to a DOM Node // // doc: Document? // Document to work in. Defaults to the current value of // dojo.doc. Can be used to retrieve // node references from other documents.=====*/if(dojo.isIE || dojo.isOpera){ dojo.byId = function(id, doc){ if(dojo.isString(id)){ var _d = doc || dojo.doc; var te = _d.getElementById(id); // attributes.id.value is better than just id in case the // user has a name=id inside a form if(te && te.attributes.id.value == id){ return te; }else{ var eles = _d.all[id]; if(!eles || !eles.length){ return eles; } // if more than 1, choose first with the correct id var i=0; while((te=eles[i++])){ if(te.attributes.id.value == id){ return te; } } } }else{ return id; // DomNode } }}else{ dojo.byId = function(id, doc){ return dojo.isString(id) ? (doc || dojo.doc).getElementById(id) : id; // DomNode }}/*=====}=====*/(function(){ /* dojo.createElement = function(obj, parent, position){ // TODO: need to finish this! } */ var d = dojo; var _destroyContainer = null; dojo.addOnUnload(function(){ _destroyContainer=null; //prevent IE leak }); dojo._destroyElement = function(/*String||DomNode*/node){ // summary: // removes node from its parent, clobbers it and all of its // children. // node: // the element to be destroyed, either as an ID or a reference node = d.byId(node); try{ if(!_destroyContainer){ _destroyContainer = document.createElement("div"); } _destroyContainer.appendChild(node.parentNode ? node.parentNode.removeChild(node) : node); // NOTE: see http://trac.dojotoolkit.org/ticket/2931. This may be a bug and not a feature _destroyContainer.innerHTML = ""; }catch(e){ /* squelch */ } }; dojo.isDescendant = function(/*DomNode|String*/node, /*DomNode|String*/ancestor){ // summary: // Returns true if node is a descendant of ancestor // node: id or node reference to test // ancestor: id or node reference of potential parent to test against try{ node = d.byId(node); ancestor = d.byId(ancestor); while(node){ if(node === ancestor){ return true; // Boolean } node = node.parentNode; } }catch(e){ /* squelch, return false */ } return false; // Boolean }; dojo.setSelectable = function(/*DomNode|String*/node, /*Boolean*/selectable){ // summary: enable or disable selection on a node // node: // id or reference to node // selectable: node = d.byId(node); if(d.isMozilla){ node.style.MozUserSelect = selectable ? "" : "none"; }else if(d.isKhtml){ node.style.KhtmlUserSelect = selectable ? "auto" : "none"; }else if(d.isIE){ node.unselectable = selectable ? "" : "on"; d.query("*", node).forEach(function(descendant){ descendant.unselectable = selectable ? "" : "on"; }); } //FIXME: else? Opera? }; var _insertBefore = function(/*Node*/node, /*Node*/ref){ ref.parentNode.insertBefore(node, ref); return true; // boolean } var _insertAfter = function(/*Node*/node, /*Node*/ref){ // summary: // Try to insert node after ref var pn = ref.parentNode; if(ref == pn.lastChild){ pn.appendChild(node); }else{ return _insertBefore(node, ref.nextSibling); // boolean } return true; // boolean } dojo.place = function(/*String|DomNode*/node, /*String|DomNode*/refNode, /*String|Number*/position){ // summary: // Attempt to insert node into the DOM, choosing from various positioning options. // Returns true if successful, false otherwise. // node: // id or node reference to place relative to refNode // refNode: // id or node reference to use as basis for placement // position: // string noting the position of node relative to refNode or a // number indicating the location in the childNodes collection of // refNode. Accepted string values are: // // * before // * after // * first // * last // // "first" and "last" indicate positions as children of refNode. // FIXME: need to write tests for this!!!! if(!node || !refNode || position === undefined){ return false; // boolean } node = d.byId(node); refNode = d.byId(refNode); if(typeof position == "number"){ var cn = refNode.childNodes; if((position == 0 && cn.length == 0) || cn.length == position){ refNode.appendChild(node); return true; } if(position == 0){ return _insertBefore(node, refNode.firstChild); } return _insertAfter(node, cn[position-1]); } switch(position.toLowerCase()){ case "before": return _insertBefore(node, refNode); // boolean case "after": return _insertAfter(node, refNode); // boolean case "first": if(refNode.firstChild){ return _insertBefore(node, refNode.firstChild); // boolean } // else fallthrough... default: // aka: last refNode.appendChild(node); return true; // boolean } } // Box functions will assume this model. // On IE/Opera, BORDER_BOX will be set if the primary document is in quirks mode. // Can be set to change behavior of box setters. // can be either: // "border-box" // "content-box" (default) dojo.boxModel = "content-box"; // We punt per-node box mode testing completely. // If anybody cares, we can provide an additional (optional) unit // that overrides existing code to include per-node box sensitivity. // Opera documentation claims that Opera 9 uses border-box in BackCompat mode. // but experiments (Opera 9.10.8679 on Windows Vista) indicate that it actually continues to use content-box. // IIRC, earlier versions of Opera did in fact use border-box. // Opera guys, this is really confusing. Opera being broken in quirks mode is not our fault. if(d.isIE /*|| dojo.isOpera*/){ var _dcm = document.compatMode; // client code may have to adjust if compatMode varies across iframes d.boxModel = _dcm == "BackCompat" || _dcm == "QuirksMode" || d.isIE<6 ? "border-box" : "content-box"; // FIXME: remove IE < 6 support? } // ============================= // Style Functions // ============================= // getComputedStyle drives most of the style code. // Wherever possible, reuse the returned object. // // API functions below that need to access computed styles accept an // optional computedStyle parameter. // If this parameter is omitted, the functions will call getComputedStyle themselves. // This way, calling code can access computedStyle once, and then pass the reference to // multiple API functions. /*===== dojo.getComputedStyle = function(node){ // summary: // Returns a "computed style" object. // // description: // Gets a "computed style" object which can be used to gather // information about the current state of the rendered node. // // Note that this may behave differently on different browsers. // Values may have different formats and value encodings across // browsers. // // Note also that this method is expensive. Wherever possible, // reuse the returned object. // // Use the dojo.style() method for more consistent (pixelized) // return values. // // node: DOMNode // A reference to a DOM node. Does NOT support taking an // ID string for speed reasons. // example: // | dojo.getComputedStyle(dojo.byId('foo')).borderWidth; return; // CSS2Properties }=====*/ var gcs, dv = document.defaultView; if(d.isSafari){ gcs = function(/*DomNode*/node){ var s = dv.getComputedStyle(node, null); if(!s && node.style){ node.style.display = ""; s = dv.getComputedStyle(node, null); } return s || {}; }; }else if(d.isIE){ gcs = function(node){ return node.currentStyle; }; }else{ gcs = function(node){ return dv.getComputedStyle(node, null); }; } dojo.getComputedStyle = gcs; if(!d.isIE){ dojo._toPixelValue = function(element, value){ // style values can be floats, client code may want // to round for integer pixels. return parseFloat(value) || 0; } }else{ dojo._toPixelValue = function(element, avalue){ if(!avalue){ return 0; } // on IE7, medium is usually 4 pixels if(avalue=="medium"){ return 4; } // style values can be floats, client code may // want to round this value for integer pixels. if(avalue.slice && (avalue.slice(-2)=='px')){ return parseFloat(avalue); } with(element){ var sLeft = style.left; var rsLeft = runtimeStyle.left; runtimeStyle.left = currentStyle.left; try{ // 'avalue' may be incompatible with style.left, which can cause IE to throw // this has been observed for border widths using "thin", "medium", "thick" constants // those particular constants could be trapped by a lookup // but perhaps there are more style.left = avalue; avalue = style.pixelLeft; }catch(e){ avalue = 0; } style.left = sLeft; runtimeStyle.left = rsLeft; } return avalue; } } var px = d._toPixelValue; // FIXME: there opacity quirks on FF that we haven't ported over. Hrm. /*===== dojo._getOpacity = function(node){ // summary: // Returns the current opacity of the passed node as a // floating-point value between 0 and 1. // node: DomNode // a reference to a DOM node. Does NOT support taking an // ID string for speed reasons. // return: Number between 0 and 1 } =====*/ dojo._getOpacity = d.isIE ? function(node){ try{ return node.filters.alpha.opacity / 100; // Number }catch(e){ return 1; // Number } } : function(node){ return gcs(node).opacity; }; /*===== dojo._setOpacity = function(node, opacity){ // summary: // set the opacity of the passed node portably. Returns the // new opacity of the node. // node: DOMNode // a reference to a DOM node. Does NOT support taking an // ID string for performance reasons. // opacity: Number // A Number between 0 and 1. 0 specifies transparent. // return: Number between 0 and 1 } =====*/ dojo._setOpacity = d.isIE ? function(/*DomNode*/node, /*Number*/opacity){ if(opacity == 1){ // on IE7 Alpha(Filter opacity=100) makes text look fuzzy so remove it altogether (bug #2661) var filterRE = /FILTER:[^;]*;?/i; node.style.cssText = node.style.cssText.replace(filterRE, ""); if(node.nodeName.toLowerCase() == "tr"){ d.query("> td", node).forEach(function(i){ i.style.cssText = i.style.cssText.replace(filterRE, ""); }); } }else{ var o = "Alpha(Opacity="+ opacity * 100 +")"; node.style.filter = o; } if(node.nodeName.toLowerCase() == "tr"){ d.query("> td", node).forEach(function(i){ i.style.filter = o; }); } return opacity; } : function(node, opacity){ return node.style.opacity = opacity; }; var _pixelNamesCache = { left: true, top: true }; var _pixelRegExp = /margin|padding|width|height|max|min|offset/; // |border var _toStyleValue = function(node, type, value){ type = type.toLowerCase(); if(d.isIE && value == "auto"){ if(type == "height"){ return node.offsetHeight; } if(type == "width"){ return node.offsetWidth; } } if(!(type in _pixelNamesCache)){ // if(dojo.isOpera && type == "cssText"){ // FIXME: add workaround for #2855 here // } _pixelNamesCache[type] = _pixelRegExp.test(type); } return _pixelNamesCache[type] ? px(node, value) : value; } var _floatStyle = d.isIE ? "styleFloat" : "cssFloat"; var _floatAliases = { "cssFloat": _floatStyle, "styleFloat": _floatStyle, "float": _floatStyle }; // public API
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -