]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dom-prop.js.uncompressed.js
1 define("dojo/dom-prop", ["exports", "./_base/kernel", "./sniff", "./_base/lang", "./dom", "./dom-style", "./dom-construct", "./_base/connect"],
2 function(exports
, dojo
, has
, lang
, dom
, style
, ctr
, conn
){
6 // This module defines the core dojo DOM properties API.
7 // Indirectly depends on dojo.empty() and dojo.toDom().
9 // TODOC: summary not showing up in output, see https://github.com/csnover/js-doc-parse/issues/42
11 // =============================
12 // Element properties Functions
13 // =============================
15 // helper to connect events
16 var _evtHdlrMap
= {}, _ctr
= 0, _attrId
= dojo
._scopeName
+ "attrid";
19 // properties renamed to avoid clashes with reserved words
22 // properties written as camelCase
26 frameborder
: "frameBorder",
28 valuetype
: "valueType"
31 exports
.get = function getProp(/*DOMNode|String*/ node
, /*String*/ name
){
33 // Gets a property on an HTML element.
35 // Handles normalized getting of properties on DOM nodes.
37 // node: DOMNode|String
38 // id or reference to the element to get the property on
40 // the name of the property to get.
42 // the value of the requested property or its default value
45 // | // get the current value of the "foo" property on a node
46 // | dojo.getProp(dojo.byId("nodeId"), "foo");
47 // | // or we can just pass the id:
48 // | dojo.getProp("nodeId", "foo");
50 node
= dom
.byId(node
);
51 var lc
= name
.toLowerCase(), propName
= exports
.names
[lc
] || name
;
52 return node
[propName
]; // Anything
55 exports
.set = function setProp(/*DOMNode|String*/ node
, /*String|Object*/ name
, /*String?*/ value
){
57 // Sets a property on an HTML element.
59 // Handles normalized setting of properties on DOM nodes.
61 // When passing functions as values, note that they will not be
62 // directly assigned to slots on the node, but rather the default
63 // behavior will be removed and the new behavior will be added
64 // using `dojo.connect()`, meaning that event handler properties
65 // will be normalized and that some caveats with regards to
66 // non-standard behaviors for onsubmit apply. Namely that you
67 // should cancel form submission using `dojo.stopEvent()` on the
68 // passed event object instead of returning a boolean value from
69 // the handler itself.
70 // node: DOMNode|String
71 // id or reference to the element to set the property on
72 // name: String|Object
73 // the name of the property to set, or a hash object to set
74 // multiple properties at once.
76 // The value to set for the property
81 // | // use prop() to set the tab index
82 // | dojo.setProp("nodeId", "tabIndex", 3);
86 // Set multiple values at once, including event handlers:
87 // | dojo.setProp("formId", {
90 // | "method": "POST",
91 // | "onsubmit": function(e){
92 // | // stop submitting the form. Note that the IE behavior
93 // | // of returning true or false will have no effect here
94 // | // since our handler is connect()ed to the built-in
95 // | // onsubmit behavior and so we need to use
96 // | // dojo.stopEvent() to ensure that the submission
97 // | // doesn't proceed.
98 // | dojo.stopEvent(e);
100 // | // submit the form with Ajax
101 // | dojo.xhrPost({ form: "formId" });
106 // Style is s special case: Only set with an object hash of styles
107 // | dojo.setProp("someNode",{
110 // | width:"200px", height:"100px", color:"#000"
115 // Again, only set style as an object hash of styles:
116 // | var obj = { color:"#fff", backgroundColor:"#000" };
117 // | dojo.setProp("someNode", "style", obj);
119 // | // though shorter to use `dojo.style()` in this case:
120 // | dojo.style("someNode", obj);
122 node
= dom
.byId(node
);
123 var l
= arguments
.length
;
124 if(l
== 2 && typeof name
!= "string"){ // inline'd type check
125 // the object form of setter: the 2nd argument is a dictionary
127 exports
.set(node
, x
, name
[x
]);
129 return node
; // DomNode
131 var lc
= name
.toLowerCase(), propName
= exports
.names
[lc
] || name
;
132 if(propName
== "style" && typeof value
!= "string"){ // inline'd type check
133 // special case: setting a style
134 style
.set(node
, value
);
135 return node
; // DomNode
137 if(propName
== "innerHTML"){
138 // special case: assigning HTML
139 // the hash lists elements with read-only innerHTML on IE
140 if(has("ie") && node
.tagName
.toLowerCase() in {col
: 1, colgroup
: 1,
141 table
: 1, tbody
: 1, tfoot
: 1, thead
: 1, tr
: 1, title
: 1}){
143 node
.appendChild(ctr
.toDom(value
, node
.ownerDocument
));
145 node
[propName
] = value
;
147 return node
; // DomNode
149 if(lang
.isFunction(value
)){
150 // special case: assigning an event handler
152 var attrId
= node
[_attrId
];
155 node
[_attrId
] = attrId
;
157 if(!_evtHdlrMap
[attrId
]){
158 _evtHdlrMap
[attrId
] = {};
160 var h
= _evtHdlrMap
[attrId
][propName
];
166 delete node
[propName
];
169 // ensure that event objects are normalized, etc.
171 //_evtHdlrMap[attrId][propName] = on(node, propName, value);
172 _evtHdlrMap
[attrId
][propName
] = conn
.connect(node
, propName
, value
);
174 node
[propName
] = null;
176 return node
; // DomNode
178 node
[propName
] = value
;
179 return node
; // DomNode