html.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. define("dojo/_base/html", ["./kernel", "../dom", "../dom-style", "../dom-attr", "../dom-prop", "../dom-class", "../dom-construct", "../dom-geometry"], function(dojo, dom, style, attr, prop, cls, ctr, geom){
  2. // module:
  3. // dojo/dom
  4. // summary:
  5. // This module is a stub for the core dojo DOM API.
  6. // mix-in dom
  7. dojo.byId = dom.byId;
  8. dojo.isDescendant = dom.isDescendant;
  9. dojo.setSelectable = dom.setSelectable;
  10. // mix-in dom-attr
  11. dojo.getAttr = attr.get;
  12. dojo.setAttr = attr.set;
  13. dojo.hasAttr = attr.has;
  14. dojo.removeAttr = attr.remove;
  15. dojo.getNodeProp = attr.getNodeProp;
  16. dojo.attr = function(node, name, value){
  17. // summary:
  18. // Gets or sets an attribute on an HTML element.
  19. // description:
  20. // Handles normalized getting and setting of attributes on DOM
  21. // Nodes. If 2 arguments are passed, and a the second argument is a
  22. // string, acts as a getter.
  23. //
  24. // If a third argument is passed, or if the second argument is a
  25. // map of attributes, acts as a setter.
  26. //
  27. // When passing functions as values, note that they will not be
  28. // directly assigned to slots on the node, but rather the default
  29. // behavior will be removed and the new behavior will be added
  30. // using `dojo.connect()`, meaning that event handler properties
  31. // will be normalized and that some caveats with regards to
  32. // non-standard behaviors for onsubmit apply. Namely that you
  33. // should cancel form submission using `dojo.stopEvent()` on the
  34. // passed event object instead of returning a boolean value from
  35. // the handler itself.
  36. // node: DOMNode|String
  37. // id or reference to the element to get or set the attribute on
  38. // name: String|Object
  39. // the name of the attribute to get or set.
  40. // value: String?
  41. // The value to set for the attribute
  42. // returns:
  43. // when used as a getter, the value of the requested attribute
  44. // or null if that attribute does not have a specified or
  45. // default value;
  46. //
  47. // when used as a setter, the DOM node
  48. //
  49. // example:
  50. // | // get the current value of the "foo" attribute on a node
  51. // | dojo.attr(dojo.byId("nodeId"), "foo");
  52. // | // or we can just pass the id:
  53. // | dojo.attr("nodeId", "foo");
  54. //
  55. // example:
  56. // | // use attr() to set the tab index
  57. // | dojo.attr("nodeId", "tabIndex", 3);
  58. // |
  59. //
  60. // example:
  61. // Set multiple values at once, including event handlers:
  62. // | dojo.attr("formId", {
  63. // | "foo": "bar",
  64. // | "tabIndex": -1,
  65. // | "method": "POST",
  66. // | "onsubmit": function(e){
  67. // | // stop submitting the form. Note that the IE behavior
  68. // | // of returning true or false will have no effect here
  69. // | // since our handler is connect()ed to the built-in
  70. // | // onsubmit behavior and so we need to use
  71. // | // dojo.stopEvent() to ensure that the submission
  72. // | // doesn't proceed.
  73. // | dojo.stopEvent(e);
  74. // |
  75. // | // submit the form with Ajax
  76. // | dojo.xhrPost({ form: "formId" });
  77. // | }
  78. // | });
  79. //
  80. // example:
  81. // Style is s special case: Only set with an object hash of styles
  82. // | dojo.attr("someNode",{
  83. // | id:"bar",
  84. // | style:{
  85. // | width:"200px", height:"100px", color:"#000"
  86. // | }
  87. // | });
  88. //
  89. // example:
  90. // Again, only set style as an object hash of styles:
  91. // | var obj = { color:"#fff", backgroundColor:"#000" };
  92. // | dojo.attr("someNode", "style", obj);
  93. // |
  94. // | // though shorter to use `dojo.style()` in this case:
  95. // | dojo.style("someNode", obj);
  96. if(arguments.length == 2){
  97. return attr[typeof name == "string" ? "get" : "set"](node, name);
  98. }
  99. return attr.set(node, name, value);
  100. };
  101. // mix-in dom-class
  102. dojo.hasClass = cls.contains;
  103. dojo.addClass = cls.add;
  104. dojo.removeClass = cls.remove;
  105. dojo.toggleClass = cls.toggle;
  106. dojo.replaceClass = cls.replace;
  107. // mix-in dom-construct
  108. dojo._toDom = dojo.toDom = ctr.toDom;
  109. dojo.place = ctr.place;
  110. dojo.create = ctr.create;
  111. dojo.empty = function(node){ ctr.empty(node); };
  112. dojo._destroyElement = dojo.destroy = function(node){ ctr.destroy(node); };
  113. // mix-in dom-geometry
  114. dojo._getPadExtents = dojo.getPadExtents = geom.getPadExtents;
  115. dojo._getBorderExtents = dojo.getBorderExtents = geom.getBorderExtents;
  116. dojo._getPadBorderExtents = dojo.getPadBorderExtents = geom.getPadBorderExtents;
  117. dojo._getMarginExtents = dojo.getMarginExtents = geom.getMarginExtents;
  118. dojo._getMarginSize = dojo.getMarginSize = geom.getMarginSize;
  119. dojo._getMarginBox = dojo.getMarginBox = geom.getMarginBox;
  120. dojo.setMarginBox = geom.setMarginBox;
  121. dojo._getContentBox = dojo.getContentBox = geom.getContentBox;
  122. dojo.setContentSize = geom.setContentSize;
  123. dojo._isBodyLtr = dojo.isBodyLtr = geom.isBodyLtr;
  124. dojo._docScroll = dojo.docScroll = geom.docScroll;
  125. dojo._getIeDocumentElementOffset = dojo.getIeDocumentElementOffset = geom.getIeDocumentElementOffset;
  126. dojo._fixIeBiDiScrollLeft = dojo.fixIeBiDiScrollLeft = geom.fixIeBiDiScrollLeft;
  127. dojo.position = geom.position;
  128. dojo.marginBox = function marginBox(/*DomNode|String*/node, /*Object?*/box){
  129. // summary:
  130. // Getter/setter for the margin-box of node.
  131. // description:
  132. // Getter/setter for the margin-box of node.
  133. // Returns an object in the expected format of box (regardless
  134. // if box is passed). The object might look like:
  135. // `{ l: 50, t: 200, w: 300: h: 150 }`
  136. // for a node offset from its parent 50px to the left, 200px from
  137. // the top with a margin width of 300px and a margin-height of
  138. // 150px.
  139. // node:
  140. // id or reference to DOM Node to get/set box for
  141. // box:
  142. // If passed, denotes that dojo.marginBox() should
  143. // update/set the margin box for node. Box is an object in the
  144. // above format. All properties are optional if passed.
  145. // example:
  146. // Retrieve the margin box of a passed node
  147. // | var box = dojo.marginBox("someNodeId");
  148. // | console.dir(box);
  149. //
  150. // example:
  151. // Set a node's margin box to the size of another node
  152. // | var box = dojo.marginBox("someNodeId");
  153. // | dojo.marginBox("someOtherNode", box);
  154. return box ? geom.setMarginBox(node, box) : geom.getMarginBox(node); // Object
  155. };
  156. dojo.contentBox = function contentBox(/*DomNode|String*/node, /*Object?*/box){
  157. // summary:
  158. // Getter/setter for the content-box of node.
  159. // description:
  160. // Returns an object in the expected format of box (regardless if box is passed).
  161. // The object might look like:
  162. // `{ l: 50, t: 200, w: 300: h: 150 }`
  163. // for a node offset from its parent 50px to the left, 200px from
  164. // the top with a content width of 300px and a content-height of
  165. // 150px. Note that the content box may have a much larger border
  166. // or margin box, depending on the box model currently in use and
  167. // CSS values set/inherited for node.
  168. // While the getter will return top and left values, the
  169. // setter only accepts setting the width and height.
  170. // node:
  171. // id or reference to DOM Node to get/set box for
  172. // box:
  173. // If passed, denotes that dojo.contentBox() should
  174. // update/set the content box for node. Box is an object in the
  175. // above format, but only w (width) and h (height) are supported.
  176. // All properties are optional if passed.
  177. return box ? geom.setContentSize(node, box) : geom.getContentBox(node); // Object
  178. };
  179. dojo.coords = function(/*DomNode|String*/node, /*Boolean?*/includeScroll){
  180. // summary:
  181. // Deprecated: Use position() for border-box x/y/w/h
  182. // or marginBox() for margin-box w/h/l/t.
  183. // Returns an object representing a node's size and position.
  184. //
  185. // description:
  186. // Returns an object that measures margin-box (w)idth/(h)eight
  187. // and absolute position x/y of the border-box. Also returned
  188. // is computed (l)eft and (t)op values in pixels from the
  189. // node's offsetParent as returned from marginBox().
  190. // Return value will be in the form:
  191. //| { l: 50, t: 200, w: 300: h: 150, x: 100, y: 300 }
  192. // Does not act as a setter. If includeScroll is passed, the x and
  193. // y params are affected as one would expect in dojo.position().
  194. dojo.deprecated("dojo.coords()", "Use dojo.position() or dojo.marginBox().");
  195. node = dom.byId(node);
  196. var s = style.getComputedStyle(node), mb = geom.getMarginBox(node, s);
  197. var abs = geom.position(node, includeScroll);
  198. mb.x = abs.x;
  199. mb.y = abs.y;
  200. return mb; // Object
  201. };
  202. // mix-in dom-prop
  203. dojo.getProp = prop.get;
  204. dojo.setProp = prop.set;
  205. dojo.prop = function(/*DomNode|String*/node, /*String|Object*/name, /*String?*/value){
  206. // summary:
  207. // Gets or sets a property on an HTML element.
  208. // description:
  209. // Handles normalized getting and setting of properties on DOM
  210. // Nodes. If 2 arguments are passed, and a the second argument is a
  211. // string, acts as a getter.
  212. //
  213. // If a third argument is passed, or if the second argument is a
  214. // map of attributes, acts as a setter.
  215. //
  216. // When passing functions as values, note that they will not be
  217. // directly assigned to slots on the node, but rather the default
  218. // behavior will be removed and the new behavior will be added
  219. // using `dojo.connect()`, meaning that event handler properties
  220. // will be normalized and that some caveats with regards to
  221. // non-standard behaviors for onsubmit apply. Namely that you
  222. // should cancel form submission using `dojo.stopEvent()` on the
  223. // passed event object instead of returning a boolean value from
  224. // the handler itself.
  225. // node:
  226. // id or reference to the element to get or set the property on
  227. // name:
  228. // the name of the property to get or set.
  229. // value:
  230. // The value to set for the property
  231. // returns:
  232. // when used as a getter, the value of the requested property
  233. // or null if that attribute does not have a specified or
  234. // default value;
  235. //
  236. // when used as a setter, the DOM node
  237. //
  238. // example:
  239. // | // get the current value of the "foo" property on a node
  240. // | dojo.prop(dojo.byId("nodeId"), "foo");
  241. // | // or we can just pass the id:
  242. // | dojo.prop("nodeId", "foo");
  243. //
  244. // example:
  245. // | // use prop() to set the tab index
  246. // | dojo.prop("nodeId", "tabIndex", 3);
  247. // |
  248. //
  249. // example:
  250. // Set multiple values at once, including event handlers:
  251. // | dojo.prop("formId", {
  252. // | "foo": "bar",
  253. // | "tabIndex": -1,
  254. // | "method": "POST",
  255. // | "onsubmit": function(e){
  256. // | // stop submitting the form. Note that the IE behavior
  257. // | // of returning true or false will have no effect here
  258. // | // since our handler is connect()ed to the built-in
  259. // | // onsubmit behavior and so we need to use
  260. // | // dojo.stopEvent() to ensure that the submission
  261. // | // doesn't proceed.
  262. // | dojo.stopEvent(e);
  263. // |
  264. // | // submit the form with Ajax
  265. // | dojo.xhrPost({ form: "formId" });
  266. // | }
  267. // | });
  268. //
  269. // example:
  270. // Style is s special case: Only set with an object hash of styles
  271. // | dojo.prop("someNode",{
  272. // | id:"bar",
  273. // | style:{
  274. // | width:"200px", height:"100px", color:"#000"
  275. // | }
  276. // | });
  277. //
  278. // example:
  279. // Again, only set style as an object hash of styles:
  280. // | var obj = { color:"#fff", backgroundColor:"#000" };
  281. // | dojo.prop("someNode", "style", obj);
  282. // |
  283. // | // though shorter to use `dojo.style()` in this case:
  284. // | dojo.style("someNode", obj);
  285. if(arguments.length == 2){
  286. return prop[typeof name == "string" ? "get" : "set"](node, name);
  287. }
  288. // setter
  289. return prop.set(node, name, value);
  290. };
  291. // mix-in dom-style
  292. dojo.getStyle = style.get;
  293. dojo.setStyle = style.set;
  294. dojo.getComputedStyle = style.getComputedStyle;
  295. dojo.__toPixelValue = dojo.toPixelValue = style.toPixelValue;
  296. dojo.style = function(node, name, value){
  297. // summary:
  298. // Accesses styles on a node. If 2 arguments are
  299. // passed, acts as a getter. If 3 arguments are passed, acts
  300. // as a setter.
  301. // description:
  302. // Getting the style value uses the computed style for the node, so the value
  303. // will be a calculated value, not just the immediate node.style value.
  304. // Also when getting values, use specific style names,
  305. // like "borderBottomWidth" instead of "border" since compound values like
  306. // "border" are not necessarily reflected as expected.
  307. // If you want to get node dimensions, use `dojo.marginBox()`,
  308. // `dojo.contentBox()` or `dojo.position()`.
  309. // node: DOMNode|String
  310. // id or reference to node to get/set style for
  311. // name: String?|Object?
  312. // the style property to set in DOM-accessor format
  313. // ("borderWidth", not "border-width") or an object with key/value
  314. // pairs suitable for setting each property.
  315. // value: String?
  316. // If passed, sets value on the node for style, handling
  317. // cross-browser concerns. When setting a pixel value,
  318. // be sure to include "px" in the value. For instance, top: "200px".
  319. // Otherwise, in some cases, some browsers will not apply the style.
  320. // returns:
  321. // when used as a getter, return the computed style of the node if passing in an ID or node,
  322. // or return the normalized, computed value for the property when passing in a node and a style property
  323. // example:
  324. // Passing only an ID or node returns the computed style object of
  325. // the node:
  326. // | dojo.style("thinger");
  327. // example:
  328. // Passing a node and a style property returns the current
  329. // normalized, computed value for that property:
  330. // | dojo.style("thinger", "opacity"); // 1 by default
  331. //
  332. // example:
  333. // Passing a node, a style property, and a value changes the
  334. // current display of the node and returns the new computed value
  335. // | dojo.style("thinger", "opacity", 0.5); // == 0.5
  336. //
  337. // example:
  338. // Passing a node, an object-style style property sets each of the values in turn and returns the computed style object of the node:
  339. // | dojo.style("thinger", {
  340. // | "opacity": 0.5,
  341. // | "border": "3px solid black",
  342. // | "height": "300px"
  343. // | });
  344. //
  345. // example:
  346. // When the CSS style property is hyphenated, the JavaScript property is camelCased.
  347. // font-size becomes fontSize, and so on.
  348. // | dojo.style("thinger",{
  349. // | fontSize:"14pt",
  350. // | letterSpacing:"1.2em"
  351. // | });
  352. //
  353. // example:
  354. // dojo.NodeList implements .style() using the same syntax, omitting the "node" parameter, calling
  355. // dojo.style() on every element of the list. See: `dojo.query()` and `dojo.NodeList()`
  356. // | dojo.query(".someClassName").style("visibility","hidden");
  357. // | // or
  358. // | dojo.query("#baz > div").style({
  359. // | opacity:0.75,
  360. // | fontSize:"13pt"
  361. // | });
  362. switch(arguments.length){
  363. case 1:
  364. return style.get(node);
  365. case 2:
  366. return style[typeof name == "string" ? "get" : "set"](node, name);
  367. }
  368. // setter
  369. return style.set(node, name, value);
  370. };
  371. return dojo;
  372. });