Added dom module and docs

This commit is contained in:
Timothy Warren 2011-06-21 10:43:31 -04:00
parent a8e6f00692
commit 416ceba451
2 changed files with 86 additions and 2 deletions

View File

@ -61,7 +61,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
**Event**: wrapper for applying events to DOM objects
function:
functions:
*Add:
Use:
@ -70,6 +70,18 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
*Remove
Use:
$_.event.remove(selector, event, callback);
**DOM**: Dom manipulation module
function:
*addClass:
Use:
$_.dom.addClass(selector, className);
*RemoveClass:
Use:
$_.dom.removeClass(selector, className);

74
kis.js
View File

@ -209,7 +209,7 @@
},
set: function(key, value)
{
if(typeof value === "object")
if(typeof value !== "string")
{
value = JSON.stringify(value);
}
@ -345,4 +345,76 @@
}());
/**
* Dom manipulation object
*
*/
(function(){
var d, c, cs, len;
function _get(sel, c)
{
c = sel.className;
if(typeof c === "string")
{
var cs = c.split(" ");
var len = cs.length;
for(var i=0;i<len;i++)
{
if(cs[i] === c)
{
return [cs, i];
}
}
}
return [[], false];
}
d = {
addClass: function(sel, c)
{
if(typeof sel === "string")
{
sel = $(sel);
}
var x, classInd, cs;
x = _get(sel, c);
classInd = (x[1] != false || x[1] === 0) ? x[1] : false;
cs = (x[0]) ? x[0] : [];
if(classInd !== false)
{
cs.push(c);
console.log(cs.join(" "));
sel.className = cs.join(" ");
}
},
removeClass: function(sel, c)
{
if(typeof sel === "string")
{
sel = $(sel);
}
var x, classInd, cs;
x = _get(sel, c);
classInd = (x[1] != false || x[1] === 0) ? x[1] : false;
cs = (x[0]) ? x[0] : [];
if(classInd !== false)
{
cs.splice(classInd, 1);
sel.className = cs.join(" ");
}
}
};
window.$_.dom= d;
}());
})();