📄 layout.js
字号:
/* Copyright (c) 2004-2006, The Dojo Foundation All Rights Reserved. Licensed under the Academic Free License version 2.1 or above OR the modified BSD license. For more information on Dojo licensing, see: http://dojotoolkit.org/community/licensing.shtml*/dojo.provide("dojo.html.layout");dojo.require("dojo.html.common");dojo.require("dojo.html.style");dojo.require("dojo.html.display");dojo.html.sumAncestorProperties = function(/* HTMLElement */node, /* string */prop){ // summary // Returns the sum of the passed property on all ancestors of node. node = dojo.byId(node); if(!node){ return 0; } // FIXME: throw an error? var retVal = 0; while(node){ if(dojo.html.getComputedStyle(node, 'position') == 'fixed'){ return 0; } var val = node[prop]; if(val){ retVal += val - 0; if(node==dojo.body()){ break; }// opera and khtml #body & #html has the same values, we only need one value } node = node.parentNode; } return retVal; // integer}dojo.html.setStyleAttributes = function(/* HTMLElement */node, /* string */attributes) { // summary // allows a dev to pass a string similar to what you'd pass in style="", and apply it to a node. node = dojo.byId(node); var splittedAttribs=attributes.replace(/(;)?\s*$/, "").split(";"); for(var i=0; i<splittedAttribs.length; i++){ var nameValue=splittedAttribs[i].split(":"); var name=nameValue[0].replace(/\s*$/, "").replace(/^\s*/, "").toLowerCase(); var value=nameValue[1].replace(/\s*$/, "").replace(/^\s*/, ""); switch(name){ case "opacity": dojo.html.setOpacity(node, value); break; case "content-height": dojo.html.setContentBox(node, {height: value}); break; case "content-width": dojo.html.setContentBox(node, {width: value}); break; case "outer-height": dojo.html.setMarginBox(node, {height: value}); break; case "outer-width": dojo.html.setMarginBox(node, {width: value}); break; default: node.style[dojo.html.toCamelCase(name)]=value; } } }dojo.html.boxSizing = { MARGIN_BOX: "margin-box", BORDER_BOX: "border-box", PADDING_BOX: "padding-box", CONTENT_BOX: "content-box"};dojo.html.getAbsolutePosition = dojo.html.abs = function(/* HTMLElement */node, /* boolean? */includeScroll, /* string? */boxType){ // summary // Gets the absolute position of the passed element based on the document itself. node = dojo.byId(node, node.ownerDocument); var ret = { x: 0, y: 0 }; var bs = dojo.html.boxSizing; if(!boxType) { boxType = bs.CONTENT_BOX; } var nativeBoxType = 2; //BORDER box var targetBoxType; switch(boxType){ case bs.MARGIN_BOX: targetBoxType = 3; break; case bs.BORDER_BOX: targetBoxType = 2; break; case bs.PADDING_BOX: default: targetBoxType = 1; break; case bs.CONTENT_BOX: targetBoxType = 0; break; } var h = dojo.render.html; var db = document["body"]||document["documentElement"]; if(h.ie){ with(node.getBoundingClientRect()){ ret.x = left-2; ret.y = top-2; } }else if(document.getBoxObjectFor){ // mozilla nativeBoxType = 1; //getBoxObjectFor return padding box coordinate try{ var bo = document.getBoxObjectFor(node); ret.x = bo.x - dojo.html.sumAncestorProperties(node, "scrollLeft"); ret.y = bo.y - dojo.html.sumAncestorProperties(node, "scrollTop"); }catch(e){ // squelch } }else{ if(node["offsetParent"]){ var endNode; // in Safari, if the node is an absolutely positioned child of // the body and the body has a margin the offset of the child // and the body contain the body's margins, so we need to end // at the body if( (h.safari)&& (node.style.getPropertyValue("position") == "absolute")&& (node.parentNode == db)){ endNode = db; }else{ endNode = db.parentNode; } //TODO: set correct nativeBoxType for safari/konqueror if(node.parentNode != db){ var nd = node; if(dojo.render.html.opera){ nd = db; } ret.x -= dojo.html.sumAncestorProperties(nd, "scrollLeft"); ret.y -= dojo.html.sumAncestorProperties(nd, "scrollTop"); } var curnode = node; do{ var n = curnode["offsetLeft"]; //FIXME: ugly hack to workaround the submenu in //popupmenu2 does not shown up correctly in opera. //Someone have a better workaround? if(!h.opera || n>0){ ret.x += isNaN(n) ? 0 : n; } var m = curnode["offsetTop"]; ret.y += isNaN(m) ? 0 : m; curnode = curnode.offsetParent; }while((curnode != endNode)&&(curnode != null)); }else if(node["x"]&&node["y"]){ ret.x += isNaN(node.x) ? 0 : node.x; ret.y += isNaN(node.y) ? 0 : node.y; } } // account for document scrolling! if(includeScroll){ var scroll = dojo.html.getScroll(); ret.y += scroll.top; ret.x += scroll.left; } var extentFuncArray=[dojo.html.getPaddingExtent, dojo.html.getBorderExtent, dojo.html.getMarginExtent]; if(nativeBoxType > targetBoxType){ for(var i=targetBoxType;i<nativeBoxType;++i){ ret.y += extentFuncArray[i](node, 'top'); ret.x += extentFuncArray[i](node, 'left'); } }else if(nativeBoxType < targetBoxType){ for(var i=targetBoxType;i>nativeBoxType;--i){ ret.y -= extentFuncArray[i-1](node, 'top'); ret.x -= extentFuncArray[i-1](node, 'left'); } } ret.top = ret.y; ret.left = ret.x; return ret; // object}dojo.html.isPositionAbsolute = function(/* HTMLElement */node){ // summary // Returns true if the element is absolutely positioned. return (dojo.html.getComputedStyle(node, 'position') == 'absolute'); // boolean}dojo.html._sumPixelValues = function(/* HTMLElement */node, selectors, autoIsZero){ var total = 0; for(var x=0; x<selectors.length; x++){ total += dojo.html.getPixelValue(node, selectors[x], autoIsZero); } return total;}dojo.html.getMargin = function(/* HTMLElement */node){ // summary // Returns the width and height of the passed node's margin return { width: dojo.html._sumPixelValues(node, ["margin-left", "margin-right"], (dojo.html.getComputedStyle(node, 'position') == 'absolute')), height: dojo.html._sumPixelValues(node, ["margin-top", "margin-bottom"], (dojo.html.getComputedStyle(node, 'position') == 'absolute')) }; // object}dojo.html.getBorder = function(/* HTMLElement */node){ // summary // Returns the width and height of the passed node's border return { width: dojo.html.getBorderExtent(node, 'left') + dojo.html.getBorderExtent(node, 'right'), height: dojo.html.getBorderExtent(node, 'top') + dojo.html.getBorderExtent(node, 'bottom') }; // object}dojo.html.getBorderExtent = function(/* HTMLElement */node, /* string */side){ // summary // returns the width of the requested border return (dojo.html.getStyle(node, 'border-' + side + '-style') == 'none' ? 0 : dojo.html.getPixelValue(node, 'border-' + side + '-width')); // integer}dojo.html.getMarginExtent = function(/* HTMLElement */node, /* string */side){ // summary // returns the width of the requested margin return dojo.html._sumPixelValues(node, ["margin-" + side], dojo.html.isPositionAbsolute(node)); // integer}dojo.html.getPaddingExtent = function(/* HTMLElement */node, /* string */side){ // summary // Returns the width of the requested padding return dojo.html._sumPixelValues(node, ["padding-" + side], true); // integer}dojo.html.getPadding = function(/* HTMLElement */node){ // summary // Returns the width and height of the passed node's padding return { width: dojo.html._sumPixelValues(node, ["padding-left", "padding-right"], true), height: dojo.html._sumPixelValues(node, ["padding-top", "padding-bottom"], true)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -