]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/dom.js.uncompressed.js
1 define("dojo/dom", ["./sniff", "./_base/window"],
6 // FIXME: need to add unit tests for all the semi-public methods
10 document
.execCommand("BackgroundImageCache", false, true);
12 // sane browsers don't have cache "issues"
16 // =============================
18 // =============================
23 // This module defines the core dojo DOM API.
27 dom
.byId = function(id
, doc
){
28 if(typeof id
!= "string"){
31 var _d
= doc
|| win
.doc
, te
= id
&& _d
.getElementById(id
);
32 // attributes.id.value is better than just id in case the
33 // user has a name=id inside a form
34 if(te
&& (te
.attributes
.id
.value
== id
|| te
.id
== id
)){
37 var eles
= _d
.all
[id
];
38 if(!eles
|| eles
.nodeName
){
41 // if more than 1, choose first with the correct id
43 while((te
= eles
[i
++])){
44 if((te
.attributes
&& te
.attributes
.id
&& te
.attributes
.id
.value
== id
) || te
.id
== id
){
51 dom
.byId = function(id
, doc
){
52 // inline'd type check.
53 // be sure to return null per documentation, to match IE branch.
54 return ((typeof id
== "string") ? (doc
|| win
.doc
).getElementById(id
) : id
) || null; // DOMNode
58 dom.byId = function(id, doc){
60 // Returns DOM node with matching `id` attribute or falsy value (ex: null or undefined)
61 // if not found. If `id` is a DomNode, this function is a no-op.
64 // A string to match an HTML id attribute or a reference to a DOM Node
67 // Document to work in. Defaults to the current value of
68 // dojo.doc. Can be used to retrieve
69 // node references from other documents.
72 // Look up a node by ID:
73 // | var n = dojo.byId("foo");
76 // Check if a node exists, and use it.
77 // | var n = dojo.byId("bar");
78 // | if(n){ doStuff() ... }
81 // Allow string or DomNode references to be passed to a custom function:
82 // | var foo = function(nodeOrId){
83 // | nodeOrId = dojo.byId(nodeOrId);
84 // | // ... more stuff
89 dom
.isDescendant = function(/*DOMNode|String*/ node
, /*DOMNode|String*/ ancestor
){
91 // Returns true if node is a descendant of ancestor
92 // node: DOMNode|String
93 // string id or node reference to test
94 // ancestor: DOMNode|String
95 // string id or node reference of potential parent to test against
98 // Test is node id="bar" is a descendant of node id="foo"
99 // | if(dojo.isDescendant("bar", "foo")){ ... }
102 node
= dom
.byId(node
);
103 ancestor
= dom
.byId(ancestor
);
105 if(node
== ancestor
){
106 return true; // Boolean
108 node
= node
.parentNode
;
110 }catch(e
){ /* squelch, return false */ }
111 return false; // Boolean
115 // TODO: do we need setSelectable in the base?
117 // Add feature test for user-select CSS property
118 // (currently known to work in all but IE < 10 and Opera)
119 has
.add("css-user-select", function(global
, doc
, element
){
120 // Avoid exception when dom.js is loaded in non-browser environments
121 if(!element
){ return false; }
123 var style
= element
.style
;
124 var prefixes
= ["Khtml", "O", "ms", "Moz", "Webkit"],
129 // Iterate prefixes from most to least likely
131 if(typeof style
[name
] !== "undefined"){
132 // Supported; return property name
135 }while(i
-- && (name
= prefixes
[i
] + "UserSelect"));
137 // Not supported if we didn't return before now
142 dom.setSelectable = function(node, selectable){
144 // Enable or disable selection on a node
145 // node: DOMNode|String
146 // id or reference to node
147 // selectable: Boolean
148 // state to put the node in. false indicates unselectable, true
151 // Make the node id="bar" unselectable
152 // | dojo.setSelectable("bar");
154 // Make the node id="bar" selectable
155 // | dojo.setSelectable("bar", true);
159 var cssUserSelect
= has("css-user-select");
160 dom
.setSelectable
= cssUserSelect
? function(node
, selectable
){
161 // css-user-select returns a (possibly vendor-prefixed) CSS property name
162 dom
.byId(node
).style
[cssUserSelect
] = selectable
? "" : "none";
163 } : function(node
, selectable
){
164 node
= dom
.byId(node
);
166 // (IE < 10 / Opera) Fall back to setting/removing the
167 // unselectable attribute on the element and all its children
168 var nodes
= node
.getElementsByTagName("*"),
172 node
.removeAttribute("unselectable");
174 nodes
[i
].removeAttribute("unselectable");
177 node
.setAttribute("unselectable", "on");
179 nodes
[i
].setAttribute("unselectable", "on");