annotate Blast output page example trimmed_files/utils.js @ 20:53cd304c5f26

Add index for multiple results; fix layout of query ruler for edge case The query ruler did not layout nicely if the last segment was too short to contain the text. For very short last segments the text is now displayed after the ruler.
author Jan Kanis <jan.code@jankanis.nl>
date Wed, 14 May 2014 16:20:29 +0200
parents ffe82516a83c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
1 // $Id: utils.js,v 1.4 2014/02/26 14:47:32 zaretska Exp $
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
2
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
3 utils = {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
4
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
5 KeyCode_TAB: 9,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
6 KeyCode_DELETE: 46,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
7 KeyCode_BACKSPACE: 8,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
8 KeyCode_LEFT_ARROW: 37,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
9 KeyCode_RIGHT_ARROW: 39,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
10 KeyCode_HOME: 36,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
11 KeyCode_END: 35,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
12 KeyCode_PAGE_UP: 33,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
13 KeyCode_PAGE_DOWN: 34,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
14 KeyCode_UP_ARROW: 38,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
15 KeyCode_DOWN_ARROW: 40,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
16 KeyCode_ESC: 27,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
17 KeyCode_ENTER: 13,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
18 KeyCode_SPACE: 32,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
19 KeyCode_SHIFT_KEY: 16,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
20 KeyCode_CTRL_KEY: 17,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
21 KeyCode_ALT_KEY: 18,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
22 KeyCode_LEFT_MS_WINDOWS_KEY: 91,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
23 KeyCode_RIGHT_MS_WINDOWS_KEY: 92,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
24 KeyCode_MS_MENU_KEY: 93,
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
25
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
26 isObject: function(a) { return (a && typeof a == 'object'); },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
27
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
28 isArray: function(a) { return this.isObject(a) && a.constructor == Array; },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
29
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
30 insertInHtml: function(text, obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
31 if (document.all) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
32 obj.innerHTML += text;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
33 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
34 var range = document.createRange();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
35 range.setStartAfter(obj);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
36 var docFrag = range.createContextualFragment(text);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
37 obj.appendChild(docFrag);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
38 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
39
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
40 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
41
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
42 replaceInHtml: function(text, obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
43 if (document.all) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
44 obj.innerHTML = text;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
45 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
46 while (obj.hasChildNodes()) obj.removeChild(obj.firstChild);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
47 var range = document.createRange();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
48 range.setStartAfter(obj);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
49 var docFrag = range.createContextualFragment(text);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
50 obj.appendChild(docFrag);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
51 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
52 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
53
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
54
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
55 getTargetObj: function(eEvent) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
56 var oTarget;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
57 var e = eEvent || window.event;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
58 if (e == null) return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
59 if (e.srcElement == null) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
60 oTarget = e.target;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
61 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
62 oTarget = e.srcElement;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
63 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
64 while ( oTarget && oTarget.nodeType != 1 ) oTarget = oTarget.parentNode;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
65 return oTarget;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
66 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
67
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
68
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
69
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
70
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
71 getParent: function(obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
72 if (obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
73 var result = obj.parentNode;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
74 while (result && result.nodeType != 1) result = result.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
75 if (result) return result;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
76 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
77 return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
78 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
79
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
80 getFirstChild: function(obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
81 if (obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
82 var result = obj.firstChild;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
83 while (result && result.nodeType != 1) result = result.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
84 if (result) return result;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
85 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
86 return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
87 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
88
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
89 getNextSibling: function(obj, tagName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
90 if (obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
91 var result = obj.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
92 if (tagName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
93 var tn = tagName.toUpperCase();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
94 while (result && result.tagName != tn) result = result.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
95 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
96 while (result && result.nodeType != 1) result = result.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
97 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
98 return result;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
99 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
100 return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
101 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
102
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
103 getPreviousSibling: function(obj, tagName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
104 if (obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
105 var result = obj.previousSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
106 if (tagName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
107 var tn = tagName.toUpperCase();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
108 while (result && result.tagName != tn) result = result.previousSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
109 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
110 while (result && result.nodeType != 1) result = result.previousSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
111 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
112 return result;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
113 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
114 return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
115 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
116
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
117 removeChildren: function(oObj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
118 if (!oObj || typeof oObj != "object") return;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
119 while(oObj.hasChildNodes()) oObj.removeChild(oObj.firstChild)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
120 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
121
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
122 insertAfter: function(parent, node, referenceNode) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
123 parent.insertBefore(node, referenceNode.nextSibling);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
124 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
125
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
126 nextItem: function(item, nodeName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
127 if (item == null) return;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
128 var next = item.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
129 while (next != null) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
130 if (next.nodeName == nodeName) return next;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
131 next = next.nextSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
132 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
133 return null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
134 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
135
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
136 previousItem: function(item, nodeName) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
137 var previous = item.previousSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
138 while (previous != null) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
139 if (previous.nodeName == nodeName) return previous;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
140 previous = previous.previousSibling;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
141 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
142 return null
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
143 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
144
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
145 moveBefore: function(item1, item2) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
146 var parent = item1.parentNode;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
147 parent.removeChild(item1);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
148 parent.insertBefore(item1, item2);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
149 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
150
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
151 moveAfter: function(item1, item2) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
152 var parent = item1.parentNode;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
153 parent.removeChild(item1);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
154 parent.insertBefore(item1, item2 ? item2.nextSibling : null);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
155 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
156
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
157
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
158
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
159
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
160 createCookie: function(name, value, days) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
161 if (days) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
162 var date = new Date();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
163 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
164 var expires = '; expires=' + date.toGMTString();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
165 } else expires = '';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
166 document.cookie = name + '=' + value + expires + '; path=/';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
167 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
168
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
169 readCookie: function(name) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
170 var nameEQ = name + '=';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
171 var ca = document.cookie.split(';');
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
172 for (var i = 0; i < ca.length; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
173 var c = ca[i];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
174 while (c.charAt(0)==' ') c = c.substring(1, c.length);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
175 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
176 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
177 return "";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
178 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
179
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
180 eraseCookie: function(name) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
181 document.cookie = name + "=null; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=nih.gov; path=/";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
182 document.cookie = name + "; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=nih.gov; path=/";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
183 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
184
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
185 addClass: function(element, className) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
186 if (!this.hasClass(element, className)) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
187 if (element.className) element.className += " " + className;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
188 else element.className = className;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
189 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
190 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
191
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
192 removeClass: function(element, className) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
193 var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
194 element.className = element.className.replace(regexp, "$2");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
195 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
196
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
197 hasClass: function(element, className) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
198 var regexp = new RegExp("(^|\\s)" + className + "(\\s|$)");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
199 return regexp.test(element.className);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
200 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
201
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
202
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
203 getXY: function (obj){
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
204 /*
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
205 +------------- w ----
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
206 | (x,y)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
207 |
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
208 h
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
209 |
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
210 */
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
211 var b={x:0, y:0, w:obj.offsetWidth, h:obj.offsetHeight};
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
212
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
213 if (obj.offsetParent) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
214 while(obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
215 b.x += obj.offsetLeft;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
216 b.y += obj.offsetTop;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
217 obj = obj.offsetParent;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
218 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
219 } else if (obj.x) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
220 b.x = obj.x;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
221 b.y = obj.y;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
222 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
223 return b;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
224 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
225
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
226 /* Based on ppk (untested) */
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
227 getEventXY: function(e) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
228 var xpos = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
229 var ypos = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
230 e = e || window.event;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
231 xpos = e.pageX || (e.clientX + document.body.scrollLeft +
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
232 document.documentElement.scrollLeft);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
233 ypos = e.pageY || (e.clientY + document.body.scrollTop +
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
234 document.documentElement.scrollTop);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
235 return {x: xpos, y: ypos};
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
236 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
237
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
238 drawText: function (sText, sId, add) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
239 if (!sId) sId = "debug";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
240 var obj = document.getElementById(sId);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
241 if (obj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
242 if (add)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
243 this.insertInHtml("<br/>" + sText, obj);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
244 else
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
245 this.replaceInHtml(sText, obj);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
246 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
247 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
248
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
249
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
250 selectRange: function (oObj /*:object*/, iStart /*:int*/, iLength /*:int*/) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
251 if (!(oObj && oObj.value)) return;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
252
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
253 if (oObj.createTextRange) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
254 //use text ranges for Internet Explorer
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
255 var oRange = oObj.createTextRange();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
256 oRange.moveStart("character", iStart);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
257 oRange.moveEnd("character", iLength - oObj.value.length);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
258 oRange.select();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
259 } else if (oObj.setSelectionRange) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
260 //use setSelectionRange() for Mozilla
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
261 oObj.setSelectionRange(iStart, iLength);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
262 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
263 //set focus back to the textbox
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
264 oObj.focus();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
265 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
266
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
267 getSelection: function() {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
268 var text = "";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
269 if (window.getSelection) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
270 text += window.getSelection();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
271 } else if (document.getSelection) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
272 text += document.getSelection();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
273 } else if (document.selection){ //IE
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
274 text += document.selection.createRange().text;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
275 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
276 return text;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
277 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
278
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
279
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
280
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
281
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
282 // http://ejohn.org/apps/jselect/event.html
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
283 addEvent: function(obj, type, fn, b) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
284 if (obj.attachEvent) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
285 var name = "" + type + fn;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
286 // name = name.substring(0, name.indexOf("\n")); // IE This doesn't work
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
287 obj["e" + name] = fn;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
288 obj[name] = function(){ obj["e" + name](window.event);}
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
289 obj.attachEvent("on" + type, obj[name]);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
290 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
291 obj.addEventListener(type, fn, b);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
292 return true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
293 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
294 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
295
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
296
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
297 removeEvent: function(obj, type, fn, b) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
298 if (obj.detachEvent) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
299 var name = "" + type + fn;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
300 // name = name.substring(0, name.indexOf("\n")); //IE This doesn't work
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
301 if ("function" == typeof obj[name]) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
302 obj.detachEvent("on" + type, obj[name]);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
303 obj[name] = null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
304 obj["e" + name] = null;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
305 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
306 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
307 obj.removeEventListener(type, fn, b);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
308 return true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
309 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
310 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
311
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
312 noBubbleEvent: function(e) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
313 if (e && e.stopPropagation) e.stopPropagation();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
314 else window.event.cancelBubble = true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
315 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
316
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
317 targetEvent: function(e) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
318 if (e.srcElement == null) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
319 return e.target;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
320 } else {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
321 return window.event.srcElement;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
322 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
323 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
324
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
325 preventDefault: function(e) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
326 if (e.preventDefault) e.preventDefault();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
327 else window.event.returnValue = false;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
328 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
329
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
330 relatedTarget: function(e) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
331 if (!e) var e = window.event;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
332 if (e.relatedTarget) return e.relatedTarget;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
333 else if (e.toElement) return e.toElement;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
334 else if (e.fromElement) return e.fromElement;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
335 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
336
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
337 readStyle: function(element, property) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
338 if (element.style[property]) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
339 return element.style[property];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
340 } else if (element.currentStyle) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
341 return element.currentStyle[property];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
342 } else if (document.defaultView && document.defaultView.getComputedStyle) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
343 var style = document.defaultView.getComputedStyle(element, null);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
344 if (style) return style.getPropertyValue(property);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
345 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
346 return "";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
347 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
348
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
349
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
350 printObj: function (oObj, iLevel) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
351 var s = "";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
352 var sIdent = "";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
353 if (!iLevel) iLevel = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
354 for (var i = 0; i < iLevel; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
355 sIdent += "__";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
356 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
357 for (var i in oObj) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
358 var ss = [];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
359 if ("string" == typeof oObj[i]) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
360 ss = oObj[i].split("<");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
361 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
362 s += sIdent + " " + i + " : [" + (typeof oObj[i]) + "] : " + ss.join("&lt;") + "<br/>";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
363 // if (oObj[i] && "object" == typeof oObj[i] && iLevel < 2) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
364 // s+= "<br/>-----" + typeof oObj[i] + " --- " + iLevel + "</br>";
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
365 // s += this.printObj(oObj[i], iLevel + 1);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
366 // }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
367 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
368 return s;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
369 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
370
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
371 jsLoader: {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
372 sBase: "", /* Base is this directory */
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
373 oLoaded: [],
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
374 load: function (aScripts) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
375
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
376 var oS = document.getElementsByTagName("script");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
377 var k = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
378 for (var j = 0; j < oS.length; j++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
379 if (oS[j].src == "") continue;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
380 this.oLoaded[k++] = oS[j].src;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
381 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
382
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
383 var oHead = document.getElementsByTagName("head")[0];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
384
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
385 for (var i = 0; i < aScripts.length; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
386 var sNewSrc = this.sBase + aScripts[i];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
387 var oS = document.getElementsByTagName("script");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
388 var b = true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
389 for (var j = 0; j < this.oLoaded.length; j++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
390 if (sNewSrc == this.oLoaded[j]) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
391 // alert(sNewSrc + " : already loaded");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
392 b = false;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
393 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
394 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
395
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
396 if (b) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
397 var oScript = document.createElement("script");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
398 oScript.src = sNewSrc;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
399 oScript.setAttribute("type", "text/javascript");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
400 oHead.appendChild(oScript);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
401 this.oLoaded[this.oLoaded.length] = sNewSrc;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
402 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
403 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
404 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
405 },
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
406
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
407 // Create an id that doesn't exist in this document
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
408 createNewId: function()
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
409 {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
410 var newid = null
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
411
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
412 while (!newid || document.getElementById(newid)) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
413 newid = "XID" + Math.round(Math.random() * 65536).toString(16)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
414 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
415 return newid
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
416 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
417
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
418 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
419
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
420
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
421 String.prototype.trimSpaces = function(trimMode) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
422 // 0 = trim begin and end
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
423 // 1 = trim begin only
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
424 // 2 = trim after only
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
425
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
426 var targetString = this;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
427 var iPos = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
428 if (!trimMode) trimMode = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
429
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
430 if (trimMode==0 || trimMode==1) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
431 if (targetString.charAt(iPos)==" ") {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
432 while(targetString.charAt(iPos)==" ") iPos++;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
433 targetString = targetString.substr(iPos);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
434 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
435 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
436
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
437 iPos = targetString.length-1;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
438 if (trimMode==0 || trimMode==2) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
439 if (targetString.charAt(iPos) == " ") {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
440 while(targetString.charAt(iPos) == " ") iPos--;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
441 targetString = targetString.substr(0, iPos + 1);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
442 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
443 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
444 return targetString;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
445 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
446
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
447
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
448
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
449
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
450 /* Shortcuts */
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
451
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
452 // Get elements by Id's
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
453 function $() {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
454 var elements = new Array();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
455
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
456 for (var i = 0; i < arguments.length; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
457 var element = arguments[i];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
458 if (typeof element == 'string')
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
459 element = document.getElementById(element);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
460
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
461 if (arguments.length == 1)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
462 return element;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
463
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
464 elements.push(element);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
465 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
466
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
467 return elements;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
468 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
469
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
470 // Get elements by AttributeValue for Attributename
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
471 // http://www.dustindiaz.com/top-ten-javascript/ (but has some errors)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
472 function $C(attrValue, attrName, node, tag) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
473 //alert([attrValue, attrName, node, tag])
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
474 if ("*" == attrValue) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
475 return $AN(attrName, node, tag);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
476 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
477 var oElements = new Array();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
478 if (!node) node = document;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
479 if (!tag) tag = '*';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
480 if (!attrName) attrName = 'class';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
481
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
482 var els = node.getElementsByTagName(tag);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
483 var elsLen = els.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
484 var pattern = new RegExp("(^|\\s)" + attrValue + "(\\s|$)");
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
485 var j = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
486 for (i = 0; i < elsLen; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
487 if (attrName == "class" && pattern.test(els[i].className)) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
488 // IE behavior
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
489 // oElements.push(els[i]);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
490 oElements[j++] = els[i];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
491 } else if (pattern.test(els[i].getAttribute(attrName))) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
492 oElements[j++] = els[i];
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
493 // oElements.push(els[i]);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
494 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
495 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
496 return oElements;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
497 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
498
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
499
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
500 function $AN(attrName, node, tag) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
501 var oElements = new Array();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
502 if (node == null) node = document;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
503 if (tag == null)tag = '*';
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
504 var els = node.getElementsByTagName(tag);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
505 for (i = 0; i < els.length; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
506 if (els[i].getAttribute(attrName) != null) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
507 oElements.push(els[i]);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
508 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
509 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
510 return oElements;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
511 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
512
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
513 function dump(aMessage) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
514 var consoleService = Components.classes["@mozilla.org/consoleservice;1"]
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
515 .getService(Components.interfaces.nsIConsoleService);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
516 consoleService.logStringMessage(aMessage);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
517 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
518
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
519
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
520 // forEach iterators from Dean Edwards: http://dean.edwards.name/weblog/2006/07/enum/
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
521 // generic enumeration
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
522 Function.prototype.forEach = function(object, block, context) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
523 for (var key in object) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
524 if (typeof this.prototype[key] == "undefined") {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
525 block.call(context, object[key], key, object);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
526 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
527 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
528 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
529
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
530 // globally resolve forEach enumeration
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
531 var forEach = function(object, block, context) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
532 if (object) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
533 var resolve = Object; // default
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
534 if (object instanceof Function) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
535 // functions have a "length" property
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
536 resolve = Function;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
537 } else if (object.forEach instanceof Function) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
538 // the object implements a custom forEach method so use that
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
539 object.forEach(block, context);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
540 return;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
541 } else if (typeof object.length == "number") {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
542 // the object is array-like
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
543 resolve = Array;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
544 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
545 resolve.forEach(object, block, context);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
546 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
547 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
548
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
549 //
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
550 // Update Array class to JS 1.5 if not yet there.
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
551 //
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
552
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
553 // array-like enumeration
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
554 if (!Array.forEach) { // mozilla already supports this
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
555 Array.forEach = function(object, block, context) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
556 for (var i = 0; i < object.length; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
557 block.call(context, object[i], i, object);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
558 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
559 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
560 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
561
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
562 if (!Array.prototype.indexOf)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
563 Array.prototype.indexOf = function(item, startIndex) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
564 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
565 if (startIndex == null)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
566 startIndex = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
567 else if (startIndex < 0) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
568 startIndex += len;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
569 if (startIndex < 0)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
570 startIndex = 0;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
571 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
572 for (var i = startIndex; i < len; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
573 var val = this[i] || this.charAt && this.charAt(i);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
574 if (val == item)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
575 return i;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
576 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
577 return -1;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
578 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
579
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
580 if (!Array.prototype.lastIndexOf)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
581 Array.prototype.lastIndexOf = function(item, startIndex) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
582 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
583 if (startIndex == null || startIndex >= len)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
584 startIndex = len - 1;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
585 else if (startIndex < 0)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
586 startIndex += len;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
587 for (var i = startIndex; i >= 0; i--) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
588 var val = this[i] || this.charAt && this.charAt(i);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
589 if (val == item)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
590 return i;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
591 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
592 return -1;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
593 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
594
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
595 if (!Array.prototype.map)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
596 Array.prototype.map = function(func, thisVal) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
597 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
598 var ret = new Array(len);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
599 for (var i = 0; i < len; i++)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
600 ret[i] = func.call(thisVal, this[i] || this.charAt && this.charAt(i), i, this);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
601 return ret;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
602 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
603
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
604 if (!Array.prototype.filter)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
605 Array.prototype.filter = function(func, thisVal) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
606 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
607 var ret = new Array();
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
608 for (var i = 0; i < len; i++) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
609 var val = this[i] || this.charAt && this.charAt(i);
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
610 if(func.call(thisVal, val, i, this))
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
611 ret[ret.length] = val;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
612 }
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
613 return ret;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
614 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
615
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
616 if (!Array.prototype.every)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
617 Array.prototype.every = function(func, thisVal) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
618 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
619 for (var i = 0; i < len; i++)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
620 if (!func.call(thisVal, this[i] || this.charAt && this.charAt(i), i, this))
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
621 return false;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
622 return true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
623 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
624
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
625 if (!Array.prototype.some)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
626 Array.prototype.some = function(func, thisVal) {
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
627 var len = this.length;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
628 for (var i = 0; i < len; i++)
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
629 if (func.call(thisVal, this[i] || this.charAt && this.charAt(i), i, this))
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
630 return true;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
631 return false;
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
632 };
ffe82516a83c add trimmed down html example
Jan Kanis <jan.code@jankanis.nl>
parents:
diff changeset
633