new oz.js
--HG-- extra : convert_revision : svn%3Ab267cdba-c1da-11dd-874b-8bacd04a0a74/trunk%4067
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* (c) 2008 Ondrej Zara, 1.1 */
|
/* (c) 2007 - now() Ondrej Zara, 1.3 */
|
||||||
var OZ = {
|
var OZ = {
|
||||||
$:function(x) { return typeof(x) == "string" ? document.getElementById(x) : x; },
|
$:function(x) { return typeof(x) == "string" ? document.getElementById(x) : x; },
|
||||||
opera:!!window.opera,
|
opera:!!window.opera,
|
||||||
@@ -9,19 +9,17 @@ var OZ = {
|
|||||||
Event:{
|
Event:{
|
||||||
_id:0,
|
_id:0,
|
||||||
_cache:{},
|
_cache:{},
|
||||||
_standard:["click","dblclick","mousedown","mouseup","mouseover","mouseout","mousemove","keypress","keydown","keyup",
|
|
||||||
"load","unload","abort","error","resize","scroll","select","change","submit","reset","focus","blur"],
|
|
||||||
add:function(elm,event,cb) {
|
add:function(elm,event,cb) {
|
||||||
var id = OZ.Event._id++;
|
var id = OZ.Event._id++;
|
||||||
var element = OZ.$(elm);
|
var element = OZ.$(elm);
|
||||||
var fnc = cb;
|
var fnc = cb;
|
||||||
if (OZ.Event._standard.indexOf(event) != -1) {
|
if (element) {
|
||||||
if (document.addEventListener) {
|
if (element.addEventListener) {
|
||||||
element.addEventListener(event,fnc,false);
|
element.addEventListener(event,fnc,false);
|
||||||
} else if (document.attachEvent) {
|
} else if (element && element.attachEvent) {
|
||||||
fnc = function() { return cb.apply(elm,arguments); }
|
fnc = function() { return cb.apply(elm,arguments); }
|
||||||
element.attachEvent("on"+event,fnc);
|
element.attachEvent("on"+event,fnc);
|
||||||
} else { return false; }
|
}
|
||||||
}
|
}
|
||||||
OZ.Event._cache[id] = [element,event,fnc];
|
OZ.Event._cache[id] = [element,event,fnc];
|
||||||
return id;
|
return id;
|
||||||
@@ -29,11 +27,12 @@ var OZ = {
|
|||||||
remove:function(id) {
|
remove:function(id) {
|
||||||
var e = OZ.Event._cache[id];
|
var e = OZ.Event._cache[id];
|
||||||
if (!e) { return; }
|
if (!e) { return; }
|
||||||
if (OZ.Event._standard.indexOf(e[1]) != -1) {
|
var elm = e[0];
|
||||||
if (document.removeEventListener) {
|
if (elm) {
|
||||||
e[0].removeEventListener(e[1],e[2],false);
|
if (elm.removeListener) {
|
||||||
} else if (document.detachEvent) {
|
elm.removeEventListener(e[1],e[2],false);
|
||||||
e[0].detachEvent("on"+e[1],e[2]);
|
} else if (elm && elm.detachEvent) {
|
||||||
|
elm.detachEvent("on"+e[1],e[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete OZ.Event._cache[id];
|
delete OZ.Event._cache[id];
|
||||||
@@ -47,7 +46,7 @@ var OZ = {
|
|||||||
var init = arguments.callee.prototype.init;
|
var init = arguments.callee.prototype.init;
|
||||||
if (init) { init.apply(this,arguments); }
|
if (init) { init.apply(this,arguments); }
|
||||||
};
|
};
|
||||||
c.inherit = function(parent) {
|
c.implement = function(parent) {
|
||||||
for (var p in parent.prototype) { this.prototype[p] = parent.prototype[p]; }
|
for (var p in parent.prototype) { this.prototype[p] = parent.prototype[p]; }
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
@@ -133,18 +132,22 @@ var OZ = {
|
|||||||
return [x,y];
|
return [x,y];
|
||||||
},
|
},
|
||||||
hasClass:function(node, className) {
|
hasClass:function(node, className) {
|
||||||
var arr = OZ.$(node).className.toString().split(" ");
|
var cn = OZ.$(node).className;
|
||||||
|
var arr = (cn ? cn.split(" ") : []);
|
||||||
return (arr.indexOf(className) != -1);
|
return (arr.indexOf(className) != -1);
|
||||||
},
|
},
|
||||||
addClass:function(node,className) {
|
addClass:function(node,className) {
|
||||||
if (OZ.DOM.hasClass(node, className)) { return; }
|
if (OZ.DOM.hasClass(node, className)) { return; }
|
||||||
var arr = OZ.$(node).className.toString().split(" ");
|
var cn = OZ.$(node).className;
|
||||||
|
var arr = (cn ? cn.split(" ") : []);
|
||||||
arr.push(className);
|
arr.push(className);
|
||||||
OZ.$(node).className = arr.join(" ");
|
OZ.$(node).className = arr.join(" ");
|
||||||
},
|
},
|
||||||
removeClass:function(node, className) {
|
removeClass:function(node, className) {
|
||||||
if (!OZ.DOM.hasClass(node, className)) { return; }
|
if (!OZ.DOM.hasClass(node, className)) { return; }
|
||||||
var arr = OZ.$(node).className.toString().split(" ").filter(function($){ return $ != className; });
|
var cn = OZ.$(node).className;
|
||||||
|
var arr = (cn ? cn.split(" ") : []);
|
||||||
|
var arr = arr.filter(function($){ return $ != className; });
|
||||||
OZ.$(node).className = arr.join(" ");
|
OZ.$(node).className = arr.join(" ");
|
||||||
},
|
},
|
||||||
append:function() {
|
append:function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user