2 window
.$ = function(selector
) {
3 if (!selector
.match(/^[.#]?[a-z0-9_-]+$/i))
5 return document
.querySelectorAll(selector
);
7 else if (selector
.substr(0, 1) == '.')
9 return document
.getElementsByClassName(selector
.substr(1));
11 else if (selector
.substr(0, 1) == '#')
13 return document
.getElementById(selector
.substr(1));
17 return document
.getElementsByTagName(selector
);
21 window
.toggleElementVisibility = function(selector
, visibility
)
23 if (!('classList' in document
.documentElement
))
26 if (selector
instanceof Array
)
28 for (var i
= 0; i
< selector
.length
; i
++)
30 toggleElementVisibility(selector
[i
], visibility
);
36 var elements
= $(selector
);
38 for (var i
= 0; i
< elements
.length
; i
++)
41 elements
[i
].classList
.add('hidden');
43 elements
[i
].classList
.remove('hidden');
49 function dateInputFallback()
51 var input
= document
.createElement('input');
52 input
.setAttribute('type', 'date');
54 input
.style
.position
= 'absolute';
55 input
.style
.visibility
= 'hidden';
56 document
.body
.appendChild(input
);
58 // If input type changed or value hasn't been sanitized then
59 // the input type date element is not supported
60 if (input
.type
=== 'text' || input
.value
=== ':-)')
62 var www_url
= document
.body
.getAttribute('data-url') + 'static/';
64 var script
= document
.createElement('script');
65 script
.type
= "text/javascript";
66 script
.src
= www_url
+ 'datepickr.js';
67 document
.head
.appendChild(script
);
69 var link
= document
.createElement('link');
70 link
.type
= 'text/css';
71 link
.rel
= 'stylesheet';
72 link
.href
= www_url
+ 'datepickr.css';
73 document
.head
.appendChild(link
);
76 document
.body
.removeChild(input
);
79 if (document
.addEventListener
)
81 document
.addEventListener("DOMContentLoaded", dateInputFallback
, false);
85 document
.attachEvent("onDOMContentLoaded", dateInputFallback
);