annotate Blast output page example_files/utils.js @ 21:9596fea636bb

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