📄 style.js
字号:
// summary // work around for opera which doesn't have cssText, and for IE which fails on setAttribute if(!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.getUnitValue = function(/* HTMLElement */node, /* string */cssSelector, /* boolean? */autoIsZero){ // summary // Get the value of passed selector, with the specific units used var s = dojo.html.getComputedStyle(node, cssSelector); if((!s)||((s == 'auto')&&(autoIsZero))){ return { value: 0, units: 'px' }; // object } // FIXME: is regex inefficient vs. parseInt or some manual test? var match = s.match(/(\-?[\d.]+)([a-z%]*)/i); if (!match){return dojo.html.getUnitValue.bad;} return { value: Number(match[1]), units: match[2].toLowerCase() }; // object}dojo.html.getUnitValue.bad = { value: NaN, units: '' };dojo.html.getPixelValue = function(/* HTMLElement */node, /* string */cssSelector, /* boolean? */autoIsZero){ // summary // Get the value of passed selector in pixels. var result = dojo.html.getUnitValue(node, cssSelector, autoIsZero); // FIXME: there is serious debate as to whether or not this is the right solution if(isNaN(result.value)){ return 0; // integer } // FIXME: code exists for converting other units to px (see Dean Edward's IE7) // but there are cross-browser complexities if((result.value)&&(result.units != 'px')){ return NaN; // integer } return result.value; // integer}dojo.html.setPositivePixelValue = function(/* HTMLElement */node, /* string */selector, /* integer */value){ // summary // Attempt to set the value of selector on node as a positive pixel value. if(isNaN(value)){return false;} node.style[selector] = Math.max(0, value) + 'px'; return true; // boolean}dojo.html.styleSheet = null;// FIXME: this is a really basic stub for adding and removing cssRules, but// it assumes that you know the index of the cssRule that you want to add // or remove, making it less than useful. So we need something that can // search for the selector that you you want to remove.dojo.html.insertCssRule = function(/* string */selector, /* string */declaration, /* integer? */index) { // summary // Attempt to insert declaration as selector on the internal stylesheet; if index try to set it there. if (!dojo.html.styleSheet) { if (document.createStyleSheet) { // IE dojo.html.styleSheet = document.createStyleSheet(); } else if (document.styleSheets[0]) { // rest // FIXME: should create a new style sheet here // fall back on an exsiting style sheet dojo.html.styleSheet = document.styleSheets[0]; } else { return null; // integer } // fail } if (arguments.length < 3) { // index may == 0 if (dojo.html.styleSheet.cssRules) { // W3 index = dojo.html.styleSheet.cssRules.length; } else if (dojo.html.styleSheet.rules) { // IE index = dojo.html.styleSheet.rules.length; } else { return null; // integer } // fail } if (dojo.html.styleSheet.insertRule) { // W3 var rule = selector + " { " + declaration + " }"; return dojo.html.styleSheet.insertRule(rule, index); // integer } else if (dojo.html.styleSheet.addRule) { // IE return dojo.html.styleSheet.addRule(selector, declaration, index); // integer } else { return null; // integer } // fail}dojo.html.removeCssRule = function(/* integer? */index){ // summary // Attempt to remove the rule at index. if(!dojo.html.styleSheet){ dojo.debug("no stylesheet defined for removing rules"); return false; } if(dojo.render.html.ie){ if(!index){ index = dojo.html.styleSheet.rules.length; dojo.html.styleSheet.removeRule(index); } }else if(document.styleSheets[0]){ if(!index){ index = dojo.html.styleSheet.cssRules.length; } dojo.html.styleSheet.deleteRule(index); } return true; // boolean}dojo.html._insertedCssFiles = []; // cache container needed because IE reformats cssText when added to DOMdojo.html.insertCssFile = function(/* string */URI, /* HTMLDocument? */doc, /* boolean? */checkDuplicates, /* boolean */fail_ok){ // summary // calls css by XmlHTTP and inserts it into DOM as <style [widgetType="widgetType"]> *downloaded cssText*</style> if(!URI){ return; } if(!doc){ doc = document; } var cssStr = dojo.hostenv.getText(URI, false, fail_ok); if(cssStr===null){ return; } cssStr = dojo.html.fixPathsInCssText(cssStr, URI); if(checkDuplicates){ var idx = -1, node, ent = dojo.html._insertedCssFiles; for(var i = 0; i < ent.length; i++){ if((ent[i].doc == doc) && (ent[i].cssText == cssStr)){ idx = i; node = ent[i].nodeRef; break; } } // make sure we havent deleted our node if(node){ var styles = doc.getElementsByTagName("style"); for(var i = 0; i < styles.length; i++){ if(styles[i] == node){ return; } } // delete this entry dojo.html._insertedCssFiles.shift(idx, 1); } } var style = dojo.html.insertCssText(cssStr, doc); dojo.html._insertedCssFiles.push({'doc': doc, 'cssText': cssStr, 'nodeRef': style}); // insert custom attribute ex dbgHref="../foo.css" usefull when debugging in DOM inspectors, no? if(style && djConfig.isDebug){ style.setAttribute("dbgHref", URI); } return style; // HTMLStyleElement}dojo.html.insertCssText = function(/* string */cssStr, /* HTMLDocument? */doc, /* string? */URI){ // summary // Attempt to insert CSS rules into the document through inserting a style element // DomNode Style = insertCssText(String ".dojoMenu {color: green;}"[, DomDoc document, dojo.uri.Uri Url ]) if(!cssStr){ return; // HTMLStyleElement } if(!doc){ doc = document; } if(URI){// fix paths in cssStr cssStr = dojo.html.fixPathsInCssText(cssStr, URI); } var style = doc.createElement("style"); style.setAttribute("type", "text/css"); // IE is b0rken enough to require that we add the element to the doc // before changing it's properties var head = doc.getElementsByTagName("head")[0]; if(!head){ // must have a head tag dojo.debug("No head tag in document, aborting styles"); return; // HTMLStyleElement }else{ head.appendChild(style); } if(style.styleSheet){// IE var setFunc = function(){ try{ style.styleSheet.cssText = cssStr; }catch(e){ dojo.debug(e); } }; if(style.styleSheet.disabled){ setTimeout(setFunc, 10); }else{ setFunc(); } }else{ // w3c var cssText = doc.createTextNode(cssStr); style.appendChild(cssText); } return style; // HTMLStyleElement}dojo.html.fixPathsInCssText = function(/* string */cssStr, /* string */URI){ // summary // usage: cssText comes from dojoroot/src/widget/templates/Foobar.css // it has .dojoFoo { background-image: url(images/bar.png);} then uri should point to dojoroot/src/widget/templates/ if(!cssStr || !URI){ return; } var match, str = "", url = "", urlChrs = "[\\t\\s\\w\\(\\)\\/\\.\\\\'\"-:#=&?~]+"; var regex = new RegExp('url\\(\\s*('+urlChrs+')\\s*\\)'); var regexProtocol = /(file|https?|ftps?):\/\//; regexTrim = new RegExp("^[\\s]*(['\"]?)("+urlChrs+")\\1[\\s]*?$"); if(dojo.render.html.ie55 || dojo.render.html.ie60){ var regexIe = new RegExp("AlphaImageLoader\\((.*)src\=['\"]("+urlChrs+")['\"]"); // TODO: need to decide how to handle relative paths and AlphaImageLoader see #1441 // current implementation breaks on build with intern_strings while(match = regexIe.exec(cssStr)){ url = match[2].replace(regexTrim, "$2"); if(!regexProtocol.exec(url)){ url = (new dojo.uri.Uri(URI, url).toString()); } str += cssStr.substring(0, match.index) + "AlphaImageLoader(" + match[1] + "src='" + url + "'"; cssStr = cssStr.substr(match.index + match[0].length); } cssStr = str + cssStr; str = ""; } while(match = regex.exec(cssStr)){ url = match[1].replace(regexTrim, "$2"); if(!regexProtocol.exec(url)){ url = (new dojo.uri.Uri(URI, url).toString()); } str += cssStr.substring(0, match.index) + "url(" + url + ")"; cssStr = cssStr.substr(match.index + match[0].length); } return str + cssStr; // string}dojo.html.setActiveStyleSheet = function(/* string */title){ // summary // Activate style sheet with specified title. var i = 0, a, els = dojo.doc().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(){ // summary // return the title of the currently active stylesheet var i = 0, a, els = dojo.doc().getElementsByTagName("link"); while (a = els[i++]) { if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled ){ return a.getAttribute("title"); // string } } return null; // string}dojo.html.getPreferredStyleSheet = function(){ // summary // Return the preferred stylesheet title (i.e. link without alt attribute) var i = 0, a, els = dojo.doc().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"); // string } } return null; // string}dojo.html.applyBrowserClass = function(/* HTMLElement */node){ // summary // Applies pre-set class names based on browser & version to the passed node. // Modified version of Morris' CSS hack. var drh=dojo.render.html; var classes = { dj_ie: drh.ie, dj_ie55: drh.ie55, dj_ie6: drh.ie60, dj_ie7: drh.ie70, dj_iequirks: drh.ie && drh.quirks, dj_opera: drh.opera, dj_opera8: drh.opera && (Math.floor(dojo.render.version)==8), dj_opera9: drh.opera && (Math.floor(dojo.render.version)==9), dj_khtml: drh.khtml, dj_safari: drh.safari, dj_gecko: drh.mozilla }; // no dojo unsupported browsers for(var p in classes){ if(classes[p]){ dojo.html.addClass(node, p); } }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -