📄 html.js
字号:
*/dojo.html.hasClass = function(node, classname){ return dojo.lang.inArray(dojo.html.getClasses(node), classname);}/** * Adds the specified class to the beginning of the class list on the * passed node. This gives the specified class the highest precidence * when style cascading is calculated for the node. Returns true or * false; indicating success or failure of the operation, respectively. */dojo.html.prependClass = function(node, classStr){ classStr += " " + dojo.html.getClass(node); return dojo.html.setClass(node, classStr);}/** * Adds the specified class to the end of the class list on the * passed &node;. Returns &true; or &false; indicating success or failure. */dojo.html.addClass = function(node, classStr){ if (dojo.html.hasClass(node, classStr)) { return false; } classStr = dojo.string.trim(dojo.html.getClass(node) + " " + classStr); return dojo.html.setClass(node, classStr);}/** * Clobbers the existing list of classes for the node, replacing it with * the list given in the 2nd argument. Returns true or false * indicating success or failure. */dojo.html.setClass = function(node, classStr){ node = dojo.byId(node); var cs = new String(classStr); try{ if(typeof node.className == "string"){ node.className = cs; }else if(node.setAttribute){ node.setAttribute("class", classStr); node.className = cs; }else{ return false; } }catch(e){ dojo.debug("dojo.html.setClass() failed", e); } return true;}/** * Removes the className from the node;. Returns * true or false indicating success or failure. */ dojo.html.removeClass = function(node, classStr, allowPartialMatches){ var classStr = dojo.string.trim(new String(classStr)); try{ var cs = dojo.html.getClasses(node); var nca = []; if(allowPartialMatches){ for(var i = 0; i<cs.length; i++){ if(cs[i].indexOf(classStr) == -1){ nca.push(cs[i]); } } }else{ for(var i=0; i<cs.length; i++){ if(cs[i] != classStr){ nca.push(cs[i]); } } } dojo.html.setClass(node, nca.join(" ")); }catch(e){ dojo.debug("dojo.html.removeClass() failed", e); } return true;}/** * Replaces 'oldClass' and adds 'newClass' to node */dojo.html.replaceClass = function(node, newClass, oldClass) { dojo.html.removeClass(node, oldClass); dojo.html.addClass(node, newClass);}// Enum type for getElementsByClass classMatchType arg:dojo.html.classMatchType = { ContainsAll : 0, // all of the classes are part of the node's class (default) ContainsAny : 1, // any of the classes are part of the node's class IsOnly : 2 // only all of the classes are part of the node's class}/** * Returns an array of nodes for the given classStr, children of a * parent, and optionally of a certain nodeType */dojo.html.getElementsByClass = function(classStr, parent, nodeType, classMatchType, useNonXpath){ parent = dojo.byId(parent) || document; var classes = classStr.split(/\s+/g); var nodes = []; if( classMatchType != 1 && classMatchType != 2 ) classMatchType = 0; // make it enum var reClass = new RegExp("(\\s|^)((" + classes.join(")|(") + "))(\\s|$)"); var candidateNodes = []; if(!useNonXpath && document.evaluate) { // supports dom 3 xpath var xpath = "//" + (nodeType || "*") + "[contains("; if(classMatchType != dojo.html.classMatchType.ContainsAny){ xpath += "concat(' ',@class,' '), ' " + classes.join(" ') and contains(concat(' ',@class,' '), ' ") + " ')]"; }else{ xpath += "concat(' ',@class,' '), ' " + classes.join(" ')) or contains(concat(' ',@class,' '), ' ") + " ')]"; } var xpathResult = document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null); var result = xpathResult.iterateNext(); while(result){ try{ candidateNodes.push(result); result = xpathResult.iterateNext(); }catch(e){ break; } } return candidateNodes; }else{ if(!nodeType){ nodeType = "*"; } candidateNodes = parent.getElementsByTagName(nodeType); var node, i = 0; outer: while(node = candidateNodes[i++]){ var nodeClasses = dojo.html.getClasses(node); if(nodeClasses.length == 0){ continue outer; } var matches = 0; for(var j = 0; j < nodeClasses.length; j++){ if(reClass.test(nodeClasses[j])){ if(classMatchType == dojo.html.classMatchType.ContainsAny){ nodes.push(node); continue outer; }else{ matches++; } }else{ if(classMatchType == dojo.html.classMatchType.IsOnly){ continue outer; } } } if(matches == classes.length){ if( (classMatchType == dojo.html.classMatchType.IsOnly)&& (matches == nodeClasses.length)){ nodes.push(node); }else if(classMatchType == dojo.html.classMatchType.ContainsAll){ nodes.push(node); } } } return nodes; }}dojo.html.getElementsByClassName = dojo.html.getElementsByClass;/** * Returns the mouse position relative to the document (not the viewport). * For example, if you have a document that is 10000px tall, * but your browser window is only 100px tall, * if you scroll to the bottom of the document and call this function it * will return {x: 0, y: 10000} */dojo.html.getCursorPosition = function(e){ e = e || window.event; var cursor = {x:0, y:0}; if(e.pageX || e.pageY){ cursor.x = e.pageX; cursor.y = e.pageY; }else{ var de = document.documentElement; var db = document.body; cursor.x = e.clientX + ((de||db)["scrollLeft"]) - ((de||db)["clientLeft"]); cursor.y = e.clientY + ((de||db)["scrollTop"]) - ((de||db)["clientTop"]); } return cursor;}dojo.html.overElement = function(element, e){ element = dojo.byId(element); var mouse = dojo.html.getCursorPosition(e); with(dojo.html){ var top = getAbsoluteY(element, true); var bottom = top + getInnerHeight(element); var left = getAbsoluteX(element, true); var right = left + getInnerWidth(element); } return (mouse.x >= left && mouse.x <= right && mouse.y >= top && mouse.y <= bottom);}dojo.html.setActiveStyleSheet = function(title){ var i = 0, a, els = document.getElementsByTagName("link"); while (a = els[i++]) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")){ a.disabled = true; if (a.getAttribute("title") == title) { a.disabled = false; } } }}dojo.html.getActiveStyleSheet = function(){ var i = 0, a, els = document.getElementsByTagName("link"); while (a = els[i++]) { if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) { return a.getAttribute("title"); } } return null;}dojo.html.getPreferredStyleSheet = function(){ var i = 0, a, els = document.getElementsByTagName("link"); while (a = els[i++]) { if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) { return a.getAttribute("title"); } } return null;}dojo.html.body = function(){ // Note: document.body is not defined for a strict xhtml document return document.body || document.getElementsByTagName("body")[0];}/** * Like dojo.dom.isTag, except case-insensitive**/dojo.html.isTag = function(node /* ... */) { node = dojo.byId(node); if(node && node.tagName) { var arr = dojo.lang.map(dojo.lang.toArray(arguments, 1), function(a) { return String(a).toLowerCase(); }); return arr[ dojo.lang.find(node.tagName.toLowerCase(), arr) ] || ""; } return "";}dojo.html.copyStyle = function(target, source){ // work around for opera which doesn't have cssText, and for IE which fails on setAttribute if(dojo.lang.isUndefined(source.style.cssText)){ target.setAttribute("style", source.getAttribute("style")); }else{ target.style.cssText = source.style.cssText; } dojo.html.addClass(target, dojo.html.getClass(source));}dojo.html._callExtrasDeprecated = function(inFunc, args) { var module = "dojo.html.extras"; dojo.deprecated("dojo.html." + inFunc, "moved to " + module, "0.4"); dojo["require"](module); // weird syntax to fool list-profile-deps (build) return dojo.html[inFunc].apply(dojo.html, args);}dojo.html.createNodesFromText = function() { return dojo.html._callExtrasDeprecated('createNodesFromText', arguments);}dojo.html.gravity = function() { return dojo.html._callExtrasDeprecated('gravity', arguments);}dojo.html.placeOnScreen = function() { return dojo.html._callExtrasDeprecated('placeOnScreen', arguments);}dojo.html.placeOnScreenPoint = function() { return dojo.html._callExtrasDeprecated('placeOnScreenPoint', arguments);}dojo.html.renderedTextContent = function() { return dojo.html._callExtrasDeprecated('renderedTextContent', arguments);}dojo.html.BackgroundIframe = function() { return dojo.html._callExtrasDeprecated('BackgroundIframe', arguments);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -