1318 |
alexandre_ |
1 |
/*
|
|
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
|
|
3 |
All Rights Reserved.
|
|
|
4 |
|
|
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
|
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
|
|
7 |
|
|
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
|
|
9 |
*/
|
|
|
10 |
|
|
|
11 |
dojo.provide("dojo.html.common");
|
|
|
12 |
dojo.require("dojo.lang.common");
|
|
|
13 |
dojo.require("dojo.dom");
|
|
|
14 |
dojo.lang.mixin(dojo.html, dojo.dom);
|
|
|
15 |
dojo.html.body = function () {
|
|
|
16 |
dojo.deprecated("dojo.html.body() moved to dojo.body()", "0.5");
|
|
|
17 |
return dojo.body();
|
|
|
18 |
};
|
|
|
19 |
dojo.html.getEventTarget = function (evt) {
|
|
|
20 |
if (!evt) {
|
|
|
21 |
evt = dojo.global().event || {};
|
|
|
22 |
}
|
|
|
23 |
var t = (evt.srcElement ? evt.srcElement : (evt.target ? evt.target : null));
|
|
|
24 |
while ((t) && (t.nodeType != 1)) {
|
|
|
25 |
t = t.parentNode;
|
|
|
26 |
}
|
|
|
27 |
return t;
|
|
|
28 |
};
|
|
|
29 |
dojo.html.getViewport = function () {
|
|
|
30 |
var _window = dojo.global();
|
|
|
31 |
var _document = dojo.doc();
|
|
|
32 |
var w = 0;
|
|
|
33 |
var h = 0;
|
|
|
34 |
if (dojo.render.html.mozilla) {
|
|
|
35 |
w = _document.documentElement.clientWidth;
|
|
|
36 |
h = _window.innerHeight;
|
|
|
37 |
} else {
|
|
|
38 |
if (!dojo.render.html.opera && _window.innerWidth) {
|
|
|
39 |
w = _window.innerWidth;
|
|
|
40 |
h = _window.innerHeight;
|
|
|
41 |
} else {
|
|
|
42 |
if (!dojo.render.html.opera && dojo.exists(_document, "documentElement.clientWidth")) {
|
|
|
43 |
var w2 = _document.documentElement.clientWidth;
|
|
|
44 |
if (!w || w2 && w2 < w) {
|
|
|
45 |
w = w2;
|
|
|
46 |
}
|
|
|
47 |
h = _document.documentElement.clientHeight;
|
|
|
48 |
} else {
|
|
|
49 |
if (dojo.body().clientWidth) {
|
|
|
50 |
w = dojo.body().clientWidth;
|
|
|
51 |
h = dojo.body().clientHeight;
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
}
|
|
|
56 |
return {width:w, height:h};
|
|
|
57 |
};
|
|
|
58 |
dojo.html.getScroll = function () {
|
|
|
59 |
var _window = dojo.global();
|
|
|
60 |
var _document = dojo.doc();
|
|
|
61 |
var top = _window.pageYOffset || _document.documentElement.scrollTop || dojo.body().scrollTop || 0;
|
|
|
62 |
var left = _window.pageXOffset || _document.documentElement.scrollLeft || dojo.body().scrollLeft || 0;
|
|
|
63 |
return {top:top, left:left, offset:{x:left, y:top}};
|
|
|
64 |
};
|
|
|
65 |
dojo.html.getParentByType = function (node, type) {
|
|
|
66 |
var _document = dojo.doc();
|
|
|
67 |
var parent = dojo.byId(node);
|
|
|
68 |
type = type.toLowerCase();
|
|
|
69 |
while ((parent) && (parent.nodeName.toLowerCase() != type)) {
|
|
|
70 |
if (parent == (_document["body"] || _document["documentElement"])) {
|
|
|
71 |
return null;
|
|
|
72 |
}
|
|
|
73 |
parent = parent.parentNode;
|
|
|
74 |
}
|
|
|
75 |
return parent;
|
|
|
76 |
};
|
|
|
77 |
dojo.html.getAttribute = function (node, attr) {
|
|
|
78 |
node = dojo.byId(node);
|
|
|
79 |
if ((!node) || (!node.getAttribute)) {
|
|
|
80 |
return null;
|
|
|
81 |
}
|
|
|
82 |
var ta = typeof attr == "string" ? attr : new String(attr);
|
|
|
83 |
var v = node.getAttribute(ta.toUpperCase());
|
|
|
84 |
if ((v) && (typeof v == "string") && (v != "")) {
|
|
|
85 |
return v;
|
|
|
86 |
}
|
|
|
87 |
if (v && v.value) {
|
|
|
88 |
return v.value;
|
|
|
89 |
}
|
|
|
90 |
if ((node.getAttributeNode) && (node.getAttributeNode(ta))) {
|
|
|
91 |
return (node.getAttributeNode(ta)).value;
|
|
|
92 |
} else {
|
|
|
93 |
if (node.getAttribute(ta)) {
|
|
|
94 |
return node.getAttribute(ta);
|
|
|
95 |
} else {
|
|
|
96 |
if (node.getAttribute(ta.toLowerCase())) {
|
|
|
97 |
return node.getAttribute(ta.toLowerCase());
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
}
|
|
|
101 |
return null;
|
|
|
102 |
};
|
|
|
103 |
dojo.html.hasAttribute = function (node, attr) {
|
|
|
104 |
return dojo.html.getAttribute(dojo.byId(node), attr) ? true : false;
|
|
|
105 |
};
|
|
|
106 |
dojo.html.getCursorPosition = function (e) {
|
|
|
107 |
e = e || dojo.global().event;
|
|
|
108 |
var cursor = {x:0, y:0};
|
|
|
109 |
if (e.pageX || e.pageY) {
|
|
|
110 |
cursor.x = e.pageX;
|
|
|
111 |
cursor.y = e.pageY;
|
|
|
112 |
} else {
|
|
|
113 |
var de = dojo.doc().documentElement;
|
|
|
114 |
var db = dojo.body();
|
|
|
115 |
cursor.x = e.clientX + ((de || db)["scrollLeft"]) - ((de || db)["clientLeft"]);
|
|
|
116 |
cursor.y = e.clientY + ((de || db)["scrollTop"]) - ((de || db)["clientTop"]);
|
|
|
117 |
}
|
|
|
118 |
return cursor;
|
|
|
119 |
};
|
|
|
120 |
dojo.html.isTag = function (node) {
|
|
|
121 |
node = dojo.byId(node);
|
|
|
122 |
if (node && node.tagName) {
|
|
|
123 |
for (var i = 1; i < arguments.length; i++) {
|
|
|
124 |
if (node.tagName.toLowerCase() == String(arguments[i]).toLowerCase()) {
|
|
|
125 |
return String(arguments[i]).toLowerCase();
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
return "";
|
|
|
130 |
};
|
|
|
131 |
if (dojo.render.html.ie && !dojo.render.html.ie70) {
|
|
|
132 |
if (window.location.href.substr(0, 6).toLowerCase() != "https:") {
|
|
|
133 |
(function () {
|
|
|
134 |
var xscript = dojo.doc().createElement("script");
|
|
|
135 |
xscript.src = "javascript:'dojo.html.createExternalElement=function(doc, tag){ return doc.createElement(tag); }'";
|
|
|
136 |
dojo.doc().getElementsByTagName("head")[0].appendChild(xscript);
|
|
|
137 |
})();
|
|
|
138 |
}
|
|
|
139 |
} else {
|
|
|
140 |
dojo.html.createExternalElement = function (doc, tag) {
|
|
|
141 |
return doc.createElement(tag);
|
|
|
142 |
};
|
|
|
143 |
}
|
|
|
144 |
dojo.html._callDeprecated = function (inFunc, replFunc, args, argName, retValue) {
|
|
|
145 |
dojo.deprecated("dojo.html." + inFunc, "replaced by dojo.html." + replFunc + "(" + (argName ? "node, {" + argName + ": " + argName + "}" : "") + ")" + (retValue ? "." + retValue : ""), "0.5");
|
|
|
146 |
var newArgs = [];
|
|
|
147 |
if (argName) {
|
|
|
148 |
var argsIn = {};
|
|
|
149 |
argsIn[argName] = args[1];
|
|
|
150 |
newArgs.push(args[0]);
|
|
|
151 |
newArgs.push(argsIn);
|
|
|
152 |
} else {
|
|
|
153 |
newArgs = args;
|
|
|
154 |
}
|
|
|
155 |
var ret = dojo.html[replFunc].apply(dojo.html, args);
|
|
|
156 |
if (retValue) {
|
|
|
157 |
return ret[retValue];
|
|
|
158 |
} else {
|
|
|
159 |
return ret;
|
|
|
160 |
}
|
|
|
161 |
};
|
|
|
162 |
dojo.html.getViewportWidth = function () {
|
|
|
163 |
return dojo.html._callDeprecated("getViewportWidth", "getViewport", arguments, null, "width");
|
|
|
164 |
};
|
|
|
165 |
dojo.html.getViewportHeight = function () {
|
|
|
166 |
return dojo.html._callDeprecated("getViewportHeight", "getViewport", arguments, null, "height");
|
|
|
167 |
};
|
|
|
168 |
dojo.html.getViewportSize = function () {
|
|
|
169 |
return dojo.html._callDeprecated("getViewportSize", "getViewport", arguments);
|
|
|
170 |
};
|
|
|
171 |
dojo.html.getScrollTop = function () {
|
|
|
172 |
return dojo.html._callDeprecated("getScrollTop", "getScroll", arguments, null, "top");
|
|
|
173 |
};
|
|
|
174 |
dojo.html.getScrollLeft = function () {
|
|
|
175 |
return dojo.html._callDeprecated("getScrollLeft", "getScroll", arguments, null, "left");
|
|
|
176 |
};
|
|
|
177 |
dojo.html.getScrollOffset = function () {
|
|
|
178 |
return dojo.html._callDeprecated("getScrollOffset", "getScroll", arguments, null, "offset");
|
|
|
179 |
};
|
|
|
180 |
|