Skip to content

Instantly share code, notes, and snippets.

@zela
zela / handlers (DOM0).js
Created March 18, 2011 12:25
handle handlers to event in unobtrusive way (DOM0)
/** Universal function for unobtrusive adding event handler to element.
* It doesn't replace yet binded handler, for example in the tag.
* It returns value of the new handler, so values of previous handlers
* will be replaced.
*
* Arguments:
* element: target HTML element of binding,
* event: string with name of the event, for example, 'onclick',
* newHandler: function to be binded.
**/
@zela
zela / Navigator object overview.js
Created March 18, 2011 12:21
Navigator object overview (adress bar version)
javascript:var b="Browser Overview: \n";for(var p in navigator){b+=p+": "+navigator[p]+"\n"};alert(b);
@zela
zela / node text constants for IE6.js
Created March 18, 2011 12:20
node text constants for IE6
if (!window.Node) {
var Node = {
ELEMENT_NODE: 1,
ATTRIBUTE_NODE: 2,
TEXT_NODE: 3,
COMMENT_NODE: 8,
DOCUMENT_NODE: 9,
DOCUMENT_FRAGMENT_NODE: 11
}
}
@zela
zela / totally unobstrusive module.js
Created March 18, 2011 12:18
totally unobstrusive module
(function(){
if (window.addEventListener) window.addEventListener("load", init, false);
else if (window.attachEvent) window.attachEvent("onload", init);
function init(){}
})();
@zela
zela / url parser.js
Created March 18, 2011 12:14
url parser
function parseURL(url){
var l = document.createElement("a");
l.href = url;
// output object
var o = {
// parts of parsed URL
hash: l.hash,
host: l.host,
hostname: l.hostname,
href:l.href,
@zela
zela / factorial.js
Created March 18, 2011 11:56
factorial
function factorial(n) {
return n === 0 ? 1 : n <= 2 ? n : n * factorial(n - 1);
};