author | Dan |
Sat, 01 Mar 2008 18:54:33 -0500 | |
changeset 464 | 8063eace5b67 |
parent 458 | c433348f3628 |
child 501 | 9367161b2457 |
permissions | -rw-r--r-- |
1 | 1 |
// Some additional DHTML functions |
2 |
||
3 |
function fetch_offset(obj) { |
|
4 |
var left_offset = obj.offsetLeft; |
|
5 |
var top_offset = obj.offsetTop; |
|
6 |
while ((obj = obj.offsetParent) != null) { |
|
7 |
left_offset += obj.offsetLeft; |
|
8 |
top_offset += obj.offsetTop; |
|
9 |
} |
|
10 |
return { 'left' : left_offset, 'top' : top_offset }; |
|
11 |
} |
|
12 |
||
13 |
function fetch_dimensions(o) { |
|
14 |
var w = o.offsetWidth; |
|
15 |
var h = o.offsetHeight; |
|
16 |
return { 'w' : w, 'h' : h }; |
|
17 |
} |
|
18 |
||
19 |
function findParentForm(o) |
|
20 |
{ |
|
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
21 |
if ( o.tagName == 'FORM' ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
22 |
return o; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
23 |
while(true) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
24 |
{ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
25 |
o = o.parentNode; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
26 |
if ( !o ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
27 |
return false; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
28 |
if ( o.tagName == 'FORM' ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
29 |
return o; |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
30 |
} |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
31 |
return false; |
1 | 32 |
} |
33 |
||
34 |
function ajaxReverseDNS(o, text) |
|
35 |
{ |
|
36 |
if(text) var ipaddr = text; |
|
37 |
else var ipaddr = o.innerHTML; |
|
38 |
rDnsObj = o; |
|
39 |
rDnsBannerObj = bannerOn('Retrieving reverse DNS info...'); |
|
40 |
ajaxGet(stdAjaxPrefix+'&_mode=rdns&ip='+ipaddr, function() { |
|
407
35d94240a197
Mass-fixed all AJAX functions to also check the HTTP status code before parsing the response
Dan
parents:
372
diff
changeset
|
41 |
if ( ajax.readyState == 4 && ajax.status == 200 ) |
1 | 42 |
{ |
43 |
off = fetch_offset(rDnsObj); |
|
44 |
dim = fetch_dimensions(rDnsObj); |
|
45 |
right = off['left'] + dim['w']; |
|
46 |
top = off['top'] + dim['h']; |
|
47 |
var thediv = document.createElement('div'); |
|
48 |
thediv.className = 'info-box'; |
|
49 |
thediv.style.margin = '0'; |
|
50 |
thediv.style.position = 'absolute'; |
|
51 |
thediv.style.top = top + 'px'; |
|
52 |
thediv.style.display = 'none'; |
|
53 |
thediv.style.zIndex = getHighestZ() + 2; |
|
54 |
thediv.id = 'mdgDynamic_rDnsInfoDiv_'+Math.floor(Math.random() * 1000000); |
|
55 |
thediv.innerHTML = '<b>Reverse DNS:</b><br />'+ajax.responseText+' <a href="#" onclick="elem = document.getElementById(\''+thediv.id+'\'); elem.innerHTML = \'\'; elem.style.display = \'none\';return false;">Close</a>'; |
|
56 |
var body = document.getElementsByTagName('body'); |
|
57 |
body = body[0]; |
|
58 |
bannerOff(rDnsBannerObj); |
|
59 |
body.appendChild(thediv); |
|
60 |
thediv.style.display = 'block'; |
|
61 |
left = fetch_dimensions(thediv); |
|
62 |
thediv.style.display = 'none'; |
|
63 |
left = right - left['w']; |
|
64 |
thediv.style.left = left + 'px'; |
|
65 |
thediv.style.display = 'block'; |
|
66 |
fadeInfoBoxes(); |
|
67 |
} |
|
68 |
}); |
|
69 |
} |
|
70 |
||
71 |
function bannerOn(text) |
|
72 |
{ |
|
73 |
darken(true); |
|
74 |
var thediv = document.createElement('div'); |
|
75 |
thediv.className = 'mdg-comment'; |
|
76 |
thediv.style.padding = '0'; |
|
77 |
thediv.style.marginLeft = '0'; |
|
78 |
thediv.style.position = 'absolute'; |
|
79 |
thediv.style.display = 'none'; |
|
80 |
thediv.style.padding = '4px'; |
|
81 |
thediv.style.fontSize = '14pt'; |
|
82 |
thediv.id = 'mdgDynamic_bannerDiv_'+Math.floor(Math.random() * 1000000); |
|
83 |
thediv.innerHTML = text; |
|
84 |
||
85 |
var body = document.getElementsByTagName('body'); |
|
86 |
body = body[0]; |
|
87 |
body.appendChild(thediv); |
|
88 |
body.style.cursor = 'wait'; |
|
89 |
||
90 |
thediv.style.display = 'block'; |
|
91 |
dim = fetch_dimensions(thediv); |
|
92 |
thediv.style.display = 'none'; |
|
93 |
bdim = { 'w' : getWidth(), 'h' : getHeight() }; |
|
94 |
so = getScrollOffset(); |
|
95 |
||
40
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
96 |
var left = (bdim['w'] / 2) - ( dim['w'] / 2 ); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
97 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
98 |
var top = (bdim['h'] / 2); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
99 |
top = top - ( dim['h'] / 2 ); |
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
100 |
|
723bb7acf914
Fixed a lot of bugs with Safari and Konqueror; improved Opera compatibility
Dan
parents:
9
diff
changeset
|
101 |
top = top + so; |
1 | 102 |
|
103 |
thediv.style.top = top + 'px'; |
|
104 |
thediv.style.left = left + 'px'; |
|
105 |
||
106 |
thediv.style.display = 'block'; |
|
107 |
||
108 |
return thediv.id; |
|
109 |
} |
|
110 |
||
111 |
function bannerOff(id) |
|
112 |
{ |
|
113 |
e = document.getElementById(id); |
|
114 |
if(!e) return; |
|
115 |
e.innerHTML = ''; |
|
116 |
e.style.display = 'none'; |
|
117 |
var body = document.getElementsByTagName('body'); |
|
118 |
body = body[0]; |
|
119 |
body.style.cursor = 'default'; |
|
120 |
enlighten(true); |
|
121 |
} |
|
122 |
||
123 |
function disableUnload(message) |
|
124 |
{ |
|
125 |
if(typeof message != 'string') message = 'You may want to save your changes first.'; |
|
440 | 126 |
window._unloadmsg = message; |
127 |
window.onbeforeunload = function(e) |
|
128 |
{ |
|
129 |
if ( !e ) |
|
130 |
e = window.event; |
|
131 |
e.returnValue = window._unloadmsg; |
|
132 |
} |
|
1 | 133 |
} |
134 |
||
135 |
function enableUnload() |
|
136 |
{ |
|
440 | 137 |
window._unloadmsg = null; |
138 |
window.onbeforeunload = null; |
|
1 | 139 |
} |
140 |
||
141 |
/** |
|
142 |
* Gets the highest z-index of all divs in the document |
|
143 |
* @return integer |
|
144 |
*/ |
|
145 |
function getHighestZ() |
|
146 |
{ |
|
147 |
z = 0; |
|
148 |
var divs = document.getElementsByTagName('div'); |
|
149 |
for(var i = 0; i < divs.length; i++) |
|
150 |
{ |
|
151 |
if(divs[i].style.zIndex > z) z = divs[i].style.zIndex; |
|
152 |
} |
|
153 |
return z; |
|
154 |
} |
|
155 |
||
156 |
function isKeyPressed(event) |
|
157 |
{ |
|
158 |
if (event.shiftKey==1) |
|
159 |
{ |
|
160 |
shift = true; |
|
161 |
} |
|
162 |
else |
|
163 |
{ |
|
164 |
shift = false; |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
function moveDiv(div, newparent) |
|
169 |
{ |
|
170 |
var backup = div; |
|
171 |
var oldparent = div.parentNode; |
|
172 |
oldparent.removeChild(div); |
|
173 |
newparent.appendChild(backup); |
|
174 |
} |
|
175 |
||
176 |
function readCookie(name) {var nameEQ = name + "=";var ca = document.cookie.split(';');for(var i=0;i < ca.length;i++){var c = ca[i];while (c.charAt(0)==' ') c = c.substring(1,c.length);if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);}return null;} |
|
177 |
function createCookie(name,value,days){if (days){var date = new Date();date.setTime(date.getTime()+(days*24*60*60*1000));var expires = "; expires="+date.toGMTString();}else var expires = "";document.cookie = name+"="+value+expires+"; path=/";} |
|
178 |
function eraseCookie(name) {createCookie(name,"",-1);} |
|
179 |
||
180 |
var busyBannerID; |
|
181 |
function goBusy(msg) |
|
182 |
{ |
|
183 |
if(!msg) msg = 'Please wait...'; |
|
184 |
body = document.getElementsByTagName('body'); |
|
185 |
body = body[0]; |
|
186 |
body.style.cursor = 'wait'; |
|
187 |
busyBannerID = bannerOn(msg); |
|
188 |
} |
|
189 |
||
190 |
function unBusy() |
|
191 |
{ |
|
192 |
body = document.getElementsByTagName('body'); |
|
193 |
body = body[0]; |
|
194 |
body.style.cursor = 'default'; |
|
195 |
bannerOff(busyBannerID); |
|
196 |
} |
|
197 |
||
198 |
function setAjaxLoading() |
|
199 |
{ |
|
200 |
if ( document.getElementById('ajaxloadicon') ) |
|
201 |
{ |
|
200
63fddf1335d9
Nothing real special. The AJAX loading icon can be changed using the Javascript variable ajax_load_icon in header.tpl.
Dan
parents:
176
diff
changeset
|
202 |
document.getElementById('ajaxloadicon').src=ajax_load_icon; |
1 | 203 |
} |
204 |
} |
|
205 |
||
206 |
function unsetAjaxLoading() |
|
207 |
{ |
|
208 |
if ( document.getElementById('ajaxloadicon') ) |
|
209 |
{ |
|
210 |
document.getElementById('ajaxloadicon').src=scriptPath + '/images/spacer.gif'; |
|
211 |
} |
|
212 |
} |
|
213 |
||
214 |
/* |
|
215 |
* Search boxes |
|
216 |
*/ |
|
217 |
||
218 |
function buildSearchBoxes() |
|
219 |
{ |
|
220 |
var divs = document.getElementsByTagName('*'); |
|
221 |
var boxes = new Array(); |
|
222 |
for ( var i = 0; i < divs.length; i++ ) |
|
223 |
{ |
|
224 |
if ( divs[i].className) |
|
225 |
{ |
|
226 |
if ( divs[i].className.substr(0, 9) == 'searchbox' ) |
|
227 |
{ |
|
228 |
boxes.push(divs[i]); |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
for ( var i = 0; i < boxes.length; i++ ) |
|
233 |
{ |
|
234 |
if ( boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/) ) |
|
235 |
{ |
|
236 |
var width = boxes[i].className.match(/^searchbox\[([0-9]+)px\]$/); |
|
237 |
width = parseInt(width[1]); |
|
238 |
} |
|
239 |
else |
|
240 |
{ |
|
241 |
var width = 120; |
|
242 |
} |
|
243 |
createSearchBox(boxes[i], width); |
|
244 |
} |
|
245 |
} |
|
246 |
||
247 |
function createSearchBox(parent, width) |
|
248 |
{ |
|
249 |
if ( typeof(parent) != 'object') |
|
250 |
{ |
|
251 |
alert('BUG: createSearchBox(): parent is not an object'); |
|
252 |
return false; |
|
253 |
} |
|
254 |
//parent.style.padding = '0px'; |
|
255 |
//parent.style.textAlign = 'center'; |
|
256 |
parent.style.width = width + 'px'; |
|
257 |
var submit = document.createElement('div'); |
|
258 |
submit.onclick = function() { searchFormSubmit(this); }; |
|
259 |
submit.className = 'js-search-submit'; |
|
260 |
var input = document.createElement('input'); |
|
261 |
input.className = 'js-search-box'; |
|
262 |
input.value = 'Search'; |
|
263 |
input.name = 'q'; |
|
264 |
input.style.width = ( width - 28 ) + 'px'; |
|
265 |
input.onfocus = function() { if ( this.value == 'Search' ) this.value = ''; }; |
|
266 |
input.onblur = function() { if ( this.value == '' ) this.value = 'Search'; }; |
|
267 |
parent.appendChild(input); |
|
268 |
var off = fetch_offset(input); |
|
269 |
var top = off['top'] + 'px'; |
|
270 |
var left = ( parseInt(off['left']) + ( width - 24 ) ) + 'px'; |
|
271 |
submit.style.top = top; |
|
272 |
submit.style.left = left; |
|
273 |
parent.appendChild(submit); |
|
274 |
} |
|
275 |
||
276 |
function searchFormSubmit(obj) |
|
277 |
{ |
|
278 |
var input = obj.previousSibling; |
|
279 |
if ( input.value == 'Search' || input.value == '' ) |
|
280 |
return false; |
|
281 |
var p = obj; |
|
282 |
while(true) |
|
283 |
{ |
|
284 |
p = p.parentNode; |
|
285 |
if ( !p ) |
|
286 |
break; |
|
287 |
if ( typeof(p.tagName) != 'string' ) |
|
288 |
break; |
|
289 |
else if ( p.tagName.toLowerCase() == 'form' ) |
|
290 |
{ |
|
291 |
p.submit(); |
|
292 |
} |
|
293 |
else if ( p.tagName.toLowerCase() == 'body' ) |
|
294 |
{ |
|
295 |
break; |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
/* |
|
301 |
* AJAX login box (experimental) |
|
436
242353360e37
Added support for Diffie-Hellman key exchange during login. w00t!
Dan
parents:
426
diff
changeset
|
302 |
* Moved / rewritten in login.js |
1 | 303 |
*/ |
304 |
||
436
242353360e37
Added support for Diffie-Hellman key exchange during login. w00t!
Dan
parents:
426
diff
changeset
|
305 |
// Included only for API-compatibility |
1 | 306 |
function ajaxPromptAdminAuth(call_on_ok, level) |
307 |
{ |
|
436
242353360e37
Added support for Diffie-Hellman key exchange during login. w00t!
Dan
parents:
426
diff
changeset
|
308 |
ajaxLogonInit(call_on_ok, level); |
1 | 309 |
} |
310 |
||
311 |
// This code is in the public domain. Feel free to link back to http://jan.moesen.nu/ |
|
312 |
function sprintf() |
|
313 |
{ |
|
314 |
if (!arguments || arguments.length < 1 || !RegExp) |
|
315 |
{ |
|
316 |
return; |
|
317 |
} |
|
318 |
var str = arguments[0]; |
|
319 |
var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/; |
|
320 |
var a = b = [], numSubstitutions = 0, numMatches = 0; |
|
321 |
while (a = re.exec(str)) |
|
322 |
{ |
|
323 |
var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4]; |
|
324 |
var pPrecision = a[5], pType = a[6], rightPart = a[7]; |
|
325 |
||
326 |
//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision); |
|
327 |
||
328 |
numMatches++; |
|
329 |
if (pType == '%') |
|
330 |
{ |
|
331 |
subst = '%'; |
|
332 |
} |
|
333 |
else |
|
334 |
{ |
|
335 |
numSubstitutions++; |
|
336 |
if (numSubstitutions >= arguments.length) |
|
337 |
{ |
|
338 |
alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).'); |
|
339 |
} |
|
340 |
var param = arguments[numSubstitutions]; |
|
341 |
var pad = ''; |
|
342 |
if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1); |
|
343 |
else if (pPad) pad = pPad; |
|
344 |
var justifyRight = true; |
|
345 |
if (pJustify && pJustify === "-") justifyRight = false; |
|
346 |
var minLength = -1; |
|
347 |
if (pMinLength) minLength = parseInt(pMinLength); |
|
348 |
var precision = -1; |
|
349 |
if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1)); |
|
350 |
var subst = param; |
|
351 |
if (pType == 'b') subst = parseInt(param).toString(2); |
|
352 |
else if (pType == 'c') subst = String.fromCharCode(parseInt(param)); |
|
353 |
else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0; |
|
354 |
else if (pType == 'u') subst = Math.abs(param); |
|
355 |
else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param); |
|
356 |
else if (pType == 'o') subst = parseInt(param).toString(8); |
|
357 |
else if (pType == 's') subst = param; |
|
358 |
else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase(); |
|
359 |
else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase(); |
|
360 |
} |
|
361 |
str = leftpart + subst + rightPart; |
|
362 |
} |
|
363 |
return str; |
|
364 |
} |
|
365 |
||
74
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
366 |
/** |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
367 |
* Insert a DOM object _after_ the specified child. |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
368 |
* @param object Parent node |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
369 |
* @param object Node to insert |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
370 |
* @param object Node to insert after |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
371 |
*/ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
372 |
|
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
373 |
function insertAfter(parent, baby, bigsister) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
374 |
{ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
375 |
try |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
376 |
{ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
377 |
if ( parent.childNodes[parent.childNodes.length-1] == bigsister ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
378 |
parent.appendChild(baby); |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
379 |
else |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
380 |
parent.insertBefore(baby, bigsister.nextSibling); |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
381 |
} |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
382 |
catch(e) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
383 |
{ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
384 |
alert(e.toString()); |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
385 |
if ( window.console ) |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
386 |
{ |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
387 |
// Firebug support |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
388 |
window.console.warn(e); |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
389 |
} |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
390 |
} |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
391 |
} |
68469a95658d
Various bugfixes and cleanups, too much to remember... see the diffs for what got changed :-)
Dan
parents:
60
diff
changeset
|
392 |
|
125
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
393 |
/** |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
394 |
* Validates an e-mail address. |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
395 |
* @param string E-mail address |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
396 |
* @return bool |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
397 |
*/ |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
398 |
|
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
399 |
function validateEmail(email) |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
400 |
{ |
295
f948557af068
Add warning in installer for PHP < 5.2.0; hopefully fix validation of e-mail addresses with dashes
Dan
parents:
281
diff
changeset
|
401 |
return ( email.match(/^(?:[\w\d_-]+\.?)+@((?:(?:[\w\d_-]\-?)+\.)+\w{2,4}|localhost)$/) ) ? true : false; |
125
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
402 |
} |
fb31c951d3a2
Fixed some rather major bugs in the registration system, this will need a release followup
Dan
parents:
85
diff
changeset
|
403 |
|
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
404 |
/** |
348
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
405 |
* Validates a username. |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
406 |
* @param string Username to test |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
407 |
* @return bool |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
408 |
*/ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
409 |
|
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
410 |
function validateUsername(username) |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
411 |
{ |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
412 |
var regex = new RegExp('^[^<>&\?\'"%\n\r/]+$', ''); |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
413 |
return ( username.match(regex) ) ? true : false; |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
414 |
} |
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
415 |
|
87e08a6e4fec
Welcome to the new Enano installer. Much distance still to be covered but the basics are there.
Dan
parents:
340
diff
changeset
|
416 |
/** |
334
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
417 |
* Equivalent of PHP's time() |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
418 |
* @return int |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
419 |
*/ |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
420 |
|
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
421 |
function unix_time() |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
422 |
{ |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
423 |
return parseInt((new Date()).getTime()/1000); |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
424 |
} |
c72b545f1304
More localization work. Resolved major issue with JSON parser not parsing files over ~50KB. Switched JSON parser to the one from the Zend Framework (BSD licensed). Forced to split enano.json into five different files.
Dan
parents:
326
diff
changeset
|
425 |
|
420
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
426 |
/* |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
427 |
* Utility functions, moved from windows.js |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
428 |
*/ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
429 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
430 |
// getElementWidth() and getElementHeight() |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
431 |
// Source: http://www.aspandjavascript.co.uk/javascript/javascript_api/get_element_width_height.asp |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
432 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
433 |
function getElementHeight(Elem) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
434 |
if (ns4) |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
435 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
436 |
var elem = getObjNN4(document, Elem); |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
437 |
return elem.clip.height; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
438 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
439 |
else |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
440 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
441 |
if(document.getElementById) |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
442 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
443 |
var elem = document.getElementById(Elem); |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
444 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
445 |
else if (document.all) |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
446 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
447 |
var elem = document.all[Elem]; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
448 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
449 |
if (op5) |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
450 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
451 |
xPos = elem.style.pixelHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
452 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
453 |
else |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
454 |
{ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
455 |
xPos = elem.offsetHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
456 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
457 |
return xPos; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
458 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
459 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
460 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
461 |
function getElementWidth(Elem) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
462 |
if (ns4) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
463 |
var elem = getObjNN4(document, Elem); |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
464 |
return elem.clip.width; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
465 |
} else { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
466 |
if(document.getElementById) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
467 |
var elem = document.getElementById(Elem); |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
468 |
} else if (document.all){ |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
469 |
var elem = document.all[Elem]; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
470 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
471 |
if (op5) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
472 |
xPos = elem.style.pixelWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
473 |
} else { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
474 |
xPos = elem.offsetWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
475 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
476 |
return xPos; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
477 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
478 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
479 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
480 |
function getHeight() { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
481 |
var myHeight = 0; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
482 |
if( typeof( window.innerWidth ) == 'number' ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
483 |
myHeight = window.innerHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
484 |
} else if( document.documentElement && |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
485 |
( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
486 |
myHeight = document.documentElement.clientHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
487 |
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
488 |
myHeight = document.body.clientHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
489 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
490 |
return myHeight; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
491 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
492 |
|
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
493 |
function getWidth() { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
494 |
var myWidth = 0; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
495 |
if( typeof( window.innerWidth ) == 'number' ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
496 |
myWidth = window.innerWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
497 |
} else if( document.documentElement && |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
498 |
( document.documentElement.clientWidth || document.documentElement.clientWidth ) ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
499 |
myWidth = document.documentElement.clientWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
500 |
} else if( document.body && ( document.body.clientWidth || document.body.clientWidth ) ) { |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
501 |
myWidth = document.body.clientWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
502 |
} |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
503 |
return myWidth; |
301f546688d1
Re-enabled, debugged, and optimized Javascript compression code
Dan
parents:
413
diff
changeset
|
504 |
} |
426 | 505 |
|
506 |
/** |
|
507 |
* Sanitizes a page URL string so that it can safely be stored in the database. |
|
508 |
* @param string Page ID to sanitize |
|
509 |
* @return string Cleaned text |
|
510 |
*/ |
|
511 |
||
512 |
function sanitize_page_id(page_id) |
|
513 |
{ |
|
514 |
// Remove character escapes |
|
515 |
page_id = dirtify_page_id(page_id); |
|
516 |
||
517 |
var regex = new RegExp('[A-Za-z0-9\\[\\]\./:;\(\)@_-]', 'g'); |
|
518 |
pid_clean = page_id.replace(regex, 'X'); |
|
519 |
var pid_dirty = []; |
|
520 |
for ( var i = 0; i < pid_clean.length; i++ ) |
|
521 |
pid_dirty[i] = pid_clean.substr(i, 1); |
|
522 |
||
523 |
for ( var i = 0; i < pid_dirty.length; i++ ) |
|
524 |
{ |
|
525 |
var char = pid_dirty[i]; |
|
526 |
if ( char == 'X' ) |
|
527 |
continue; |
|
528 |
var cid = char.charCodeAt(0); |
|
529 |
cid = cid.toString(16).toUpperCase(); |
|
530 |
if ( cid.length < 2 ) |
|
531 |
{ |
|
532 |
cid = '0' + cid; |
|
533 |
} |
|
534 |
pid_dirty[i] = "." + cid; |
|
535 |
} |
|
536 |
||
537 |
var pid_chars = []; |
|
538 |
for ( var i = 0; i < page_id.length; i++ ) |
|
539 |
pid_chars[i] = page_id.substr(i, 1); |
|
540 |
||
541 |
var page_id_cleaned = ''; |
|
542 |
||
543 |
for ( var id in pid_chars ) |
|
544 |
{ |
|
545 |
var char = pid_chars[id]; |
|
546 |
if ( pid_dirty[id] == 'X' ) |
|
547 |
page_id_cleaned += char; |
|
548 |
else |
|
549 |
page_id_cleaned += pid_dirty[id]; |
|
550 |
} |
|
551 |
||
552 |
return page_id_cleaned; |
|
553 |
} |
|
554 |
||
555 |
/** |
|
556 |
* Removes character escapes in a page ID string |
|
557 |
* @param string Page ID string to dirty up |
|
558 |
* @return string |
|
559 |
*/ |
|
560 |
||
561 |
function dirtify_page_id(page_id) |
|
562 |
{ |
|
563 |
// First, replace spaces with underscores |
|
564 |
page_id = page_id.replace(/ /g, '_'); |
|
565 |
||
566 |
var matches = page_id.match(/\.[A-Fa-f0-9][A-Fa-f0-9]/g); |
|
567 |
||
568 |
if ( matches != null ) |
|
569 |
{ |
|
570 |
for ( var i = 0; i < matches.length; i++ ) |
|
571 |
{ |
|
572 |
var match = matches[i]; |
|
573 |
var byt = (match.substr(1)).toUpperCase(); |
|
574 |
var code = eval("0x" + byt); |
|
575 |
var regex = new RegExp('\\.' + byt, 'g'); |
|
576 |
page_id = page_id.replace(regex, String.fromCharCode(code)); |
|
577 |
} |
|
578 |
} |
|
579 |
||
580 |
return page_id; |
|
581 |
} |