| | 38 | // quirks mode cookies -- http://www.quirksmode.org/js/cookies.html |
| | 39 | createCookie: function(name,value,days) { |
| | 40 | if (days) { |
| | 41 | var date = new Date(); |
| | 42 | date.setTime(date.getTime()+(days*24*60*60*1000)); |
| | 43 | var expires = "; expires="+date.toGMTString(); |
| | 44 | } |
| | 45 | else var expires = ""; |
| | 46 | document.cookie = name+"="+value+expires+"; path=/"; |
| | 47 | }, |
| | 48 | |
| | 49 | el: { |
| | 50 | byId: function(id) { |
| | 51 | return document.getElementById(id); |
| | 52 | }, |
| | 53 | |
| | 54 | firstChild: function(element, nodeName) { |
| | 55 | if (typeof element == 'string') |
| | 56 | element = HIM.el.byId(element); |
| | 57 | if (!element) |
| | 58 | return; |
| | 59 | for (var i=0; i<element.childNodes.length; i++) { |
| | 60 | if (element.childNodes.item(i).nodeName && |
| | 61 | element.childNodes.item(i).nodeName.toLowerCase() == nodeName.toLowerCase()) |
| | 62 | return element.childNodes.item(i); |
| | 63 | } |
| | 64 | }, |
| | 65 | |
| | 66 | hide: function(el) { |
| | 67 | if (typeof el == 'string') // asume id given |
| | 68 | el = HIM.el.byId(el); |
| | 69 | el.style.display = 'none'; |
| | 70 | }, |
| | 71 | |
| | 72 | next: function(element, nodeName) { |
| | 73 | // searches for next sibling with given nodeName for element |
| | 74 | return this._sibling('next', element, nodeName); |
| | 75 | }, |
| | 76 | |
| | 77 | parentNode: function(element, nodeName) { |
| | 78 | if (typeof element == 'string') |
| | 79 | element = HIM.el.byId(element); |
| | 80 | if (!element) |
| | 81 | return; |
| | 82 | var parent = element.parentNode; |
| | 83 | while (parent.nodeName.toLowerCase() != nodeName.toLowerCase() && |
| | 84 | parent.parentNode) |
| | 85 | parent = parent.parentNode; |
| | 86 | if (parent.nodeName && parent.nodeName.toLowerCase() == nodeName.toLowerCase()) |
| | 87 | return parent; |
| | 88 | return; |
| | 89 | }, |
| | 90 | |
| | 91 | prev: function(element, nodeName) { |
| | 92 | // search for previous sibling with given nodeName for element |
| | 93 | return this._sibling('prev', element, nodeName); |
| | 94 | }, |
| | 95 | |
| | 96 | show: function(el) { |
| | 97 | if (typeof el == 'string') // asume id given |
| | 98 | el = HIM.el.byId(el); |
| | 99 | el.style.display = ''; |
| | 100 | }, |
| | 101 | |
| | 102 | toggle: function(el, activateFun, deactivateFun) { |
| | 103 | if (typeof el == 'string') // asume id given |
| | 104 | el = HIM.el.byId(el); |
| | 105 | if (el.style.display == 'none') { |
| | 106 | this.show(el); |
| | 107 | if (activateFun && typeof activateFun == 'function') |
| | 108 | activateFun(); |
| | 109 | } else { |
| | 110 | this.hide(el); |
| | 111 | if (deactivateFun && typeof deactivateFun == 'function') |
| | 112 | deactivateFun(); |
| | 113 | } |
| | 114 | }, |
| | 115 | |
| | 116 | _sibling: function(dir, element, nodeName) { |
| | 117 | if (typeof element == 'string') |
| | 118 | element = HIM.el.byId(element); |
| | 119 | if (!element) |
| | 120 | return; |
| | 121 | dir = (dir == 'next')?'nextSibling':'previousSibling'; |
| | 122 | var sibling = element[dir]; |
| | 123 | if (!sibling || !sibling.nodeName) |
| | 124 | return; |
| | 125 | if (nodeName && typeof nodeName == 'string' && nodeName != '') { |
| | 126 | nodeName = nodeName.toLowerCase(); |
| | 127 | while (sibling.nodeName.toLowerCase() != nodeName && sibling[dir]) |
| | 128 | sibling = sibling[dir]; |
| | 129 | if (sibling.nodeName.toLowerCase() != nodeName) |
| | 130 | return; |
| | 131 | } |
| | 132 | return sibling; |
| | 133 | } |
| | 134 | }, |
| | 135 | |
| | 136 | fromJSON: function (str) { |
| | 137 | try { |
| | 138 | return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test( |
| | 139 | str.replace(/"(\\.|[^"\\])*"/g, ''))) && |
| | 140 | eval('(' + str + ')'); |
| | 141 | } catch (e) { |
| | 142 | return false; |
| | 143 | } |
| | 144 | }, |
| | 145 | |
| 78 | | |
| 79 | | hide: function(el) { |
| 80 | | if (typeof el == 'string') // asume id given |
| 81 | | el = HIM.el.byId(el); |
| 82 | | el.style.display = 'none'; |
| 83 | | }, |
| 84 | | |
| 85 | | show: function(el) { |
| 86 | | if (typeof el == 'string') // asume id given |
| 87 | | el = HIM.el.byId(el); |
| 88 | | el.style.display = ''; |
| 89 | | }, |
| 90 | | |
| 91 | | toggle: function(el, activateFun, deactivateFun) { |
| 92 | | if (typeof el == 'string') // asume id given |
| 93 | | el = HIM.el.byId(el); |
| 94 | | if (el.style.display == 'none') { |
| 95 | | this.show(el); |
| 96 | | if (activateFun && typeof activateFun == 'function') |
| 97 | | activateFun(); |
| 98 | | } else { |
| 99 | | this.hide(el); |
| 100 | | if (deactivateFun && typeof deactivateFun == 'function') |
| 101 | | deactivateFun(); |
| | 204 | s = { |
| | 205 | array: function (x) { |
| | 206 | var a = ['['], b, f, i, l = x.length, v; |
| | 207 | for (i = 0; i < l; i += 1) { |
| | 208 | v = x[i]; |
| | 209 | f = s[typeof v]; |
| | 210 | if (f) { |
| | 211 | try { |
| | 212 | v = f(v); |
| | 213 | if (typeof v == 'string') { |
| | 214 | if (b) { |
| | 215 | a[a.length] = ','; |
| | 216 | } |
| | 217 | a[a.length] = v; |
| | 218 | b = true; |
| | 219 | } |
| | 220 | } catch(e) { |
| | 221 | } |
| | 222 | } |
| | 223 | } |
| | 224 | a[a.length] = ']'; |
| | 225 | return a.join(''); |
| | 226 | }, |
| | 227 | 'boolean': function (x) { |
| | 228 | return String(x); |
| | 229 | }, |
| | 230 | 'null': function (x) { |
| | 231 | return "null"; |
| | 232 | }, |
| | 233 | number: function (x) { |
| | 234 | return isFinite(x) ? String(x) : 'null'; |
| | 235 | }, |
| | 236 | object: function (x) { |
| | 237 | if (x) { |
| | 238 | if (x instanceof Array) { |
| | 239 | return s.array(x); |
| | 240 | } |
| | 241 | var a = ['{'], b, f, i, v; |
| | 242 | for (i in x) { |
| | 243 | if (x.hasOwnProperty(i)) { |
| | 244 | v = x[i]; |
| | 245 | f = s[typeof v]; |
| | 246 | if (f) { |
| | 247 | try { |
| | 248 | v = f(v); |
| | 249 | if (typeof v == 'string') { |
| | 250 | if (b) { |
| | 251 | a[a.length] = ','; |
| | 252 | } |
| | 253 | a.push(s.string(i), ':', v); |
| | 254 | b = true; |
| | 255 | } |
| | 256 | } catch(e) { |
| | 257 | } |
| | 258 | } |
| | 259 | } |
| | 260 | } |
| | 261 | |
| | 262 | a[a.length] = '}'; |
| | 263 | return a.join(''); |
| | 264 | } |
| | 265 | return 'null'; |
| | 266 | }, |
| | 267 | string: function (x) { |
| | 268 | if (/["\\\x00-\x1f]/.test(x)) { |
| | 269 | x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) { |
| | 270 | var c = m[b]; |
| | 271 | if (c) { |
| | 272 | return c; |
| | 273 | } |
| | 274 | c = b.charCodeAt(); |
| | 275 | return '\\u00' + |
| | 276 | Math.floor(c / 16).toString(16) + |
| | 277 | (c % 16).toString(16); |
| | 278 | }); |
| | 279 | } |
| | 280 | return '"' + x + '"'; |
| 103 | | }, |
| 104 | | |
| 105 | | next: function(element, nodeName) { |
| 106 | | // searches for next sibling with given nodeName for element |
| 107 | | return this._sibling('next', element, nodeName); |
| 108 | | }, |
| 109 | | |
| 110 | | prev: function(element, nodeName) { |
| 111 | | // search for previous sibling with given nodeName for element |
| 112 | | return this._sibling('prev', element, nodeName); |
| 113 | | }, |
| 114 | | |
| 115 | | _sibling: function(dir, element, nodeName) { |
| 116 | | if (typeof element == 'string') |
| 117 | | element = HIM.el.byId(element); |
| 118 | | if (!element) |
| 119 | | return; |
| 120 | | dir = (dir == 'next')?'nextSibling':'previousSibling'; |
| 121 | | var sibling = element[dir]; |
| 122 | | if (!sibling || !sibling.nodeName) |
| 123 | | return; |
| 124 | | if (nodeName && typeof nodeName == 'string' && nodeName != '') { |
| 125 | | nodeName = nodeName.toLowerCase(); |
| 126 | | while (sibling.nodeName.toLowerCase() != nodeName && sibling[dir]) |
| 127 | | sibling = sibling[dir]; |
| 128 | | if (sibling.nodeName.toLowerCase() != nodeName) |
| 129 | | return; |
| 130 | | } |
| 131 | | return sibling; |
| 132 | | }, |
| 133 | | |
| 134 | | firstChild: function(element, nodeName) { |
| 135 | | if (typeof element == 'string') |
| 136 | | element = HIM.el.byId(element); |
| 137 | | if (!element) |
| 138 | | return; |
| 139 | | for (var i=0; i<element.childNodes.length; i++) { |
| 140 | | if (element.childNodes.item(i).nodeName && |
| 141 | | element.childNodes.item(i).nodeName.toLowerCase() == nodeName.toLowerCase()) |
| 142 | | return element.childNodes.item(i); |
| 143 | | } |
| 144 | | }, |
| 145 | | |
| 146 | | parentNode: function(element, nodeName) { |
| 147 | | if (typeof element == 'string') |
| 148 | | element = HIM.el.byId(element); |
| 149 | | if (!element) |
| 150 | | return; |
| 151 | | var parent = element.parentNode; |
| 152 | | while (parent.nodeName.toLowerCase() != nodeName.toLowerCase() && |
| 153 | | parent.parentNode) |
| 154 | | parent = parent.parentNode; |
| 155 | | if (parent.nodeName && parent.nodeName.toLowerCase() == nodeName.toLowerCase()) |
| 156 | | return parent; |
| 157 | | return; |
| | 282 | }; |
| | 283 | |
| | 284 | switch (typeof(obj)) { |
| | 285 | case 'object': |
| | 286 | return s.object(obj); |
| | 287 | case 'array': |
| | 288 | return s.array(obj); |
| | 289 | |