Fixed formatting issues, removed redundant internal function

This commit is contained in:
Timothy Warren 2011-06-29 11:34:05 -04:00
parent b88da57421
commit d43964583a

109
kis.js
View File

@ -5,7 +5,8 @@
Version 0.1.0 Version 0.1.0
*/ */
(function(){ (function ()
{
"use strict"; "use strict";
@ -15,7 +16,7 @@
return; return;
} }
var $_, $, _sel; var $_, $;
$_ = {}; $_ = {};
@ -28,20 +29,11 @@
*/ */
$ = function (a) $ = function (a)
{ {
if (typeof a !== "string"){ return a;}
var x = document.querySelectorAll(a); var x = document.querySelectorAll(a);
return (x.length === 1) ? x[0] : x; return (x.length === 1) ? x[0] : x;
}; };
/**
* _sel
*
* Return the selector for the string
*/
_sel = function(s)
{
return (typeof s === "string") ? $(s) : s;
};
window.$ = $; window.$ = $;
/** /**
@ -50,6 +42,7 @@
* Object for making ajax requests * Object for making ajax requests
*/ */
(function (){ (function (){
var ajax = { var ajax = {
_do: function (url, data, callback, isPost) _do: function (url, data, callback, isPost)
{ {
@ -58,19 +51,16 @@
callback = function (){}; callback = function (){};
} }
var request = (typeof window.XMLHttpRequest === "function") var request = (typeof window.XMLHttpRequest === "function") ? new XMLHttpRequest() : false;
? new XMLHttpRequest()
: false;
var type = (isPost) ? "POST" : "GET"; var type = (isPost) ? "POST" : "GET";
url += (type === "GET") url += (type === "GET") ? "?" + this._serialize(data, true) : '';
? "?" + this._serialize(data, true)
: '';
request.open(type, url); request.open(type, url);
request.onreadystatechange = function(){ request.onreadystatechange = function ()
{
if (request.readyState === 4) if (request.readyState === 4)
{ {
callback(request.responseText); callback(request.responseText);
@ -93,8 +83,14 @@
for (var name in data) for (var name in data)
{ {
if(!data.hasOwnProperty(name)){ continue; }; if (!data.hasOwnProperty(name))
if(typeof data[name] === "function"){ continue; }; {
continue;
}
if (typeof data[name] === "function")
{
continue;
}
var value = data[name].toString(); var value = data[name].toString();
@ -135,6 +131,7 @@
parse: function (hb) parse: function (hb)
{ {
hb = hb || $_.hb; hb = hb || $_.hb;
var h, i, hString, pairs, pLen, data, y; var h, i, hString, pairs, pLen, data, y;
data = {}; data = {};
@ -234,7 +231,9 @@
}, },
getAll: function () getAll: function ()
{ {
var i, len, data; var i,
len,
data;
len = localStorage.length; len = localStorage.length;
data = {}; data = {};
@ -258,8 +257,8 @@
* Event api wrapper * Event api wrapper
*/ */
(function (){ (function (){
var attach, remove, add_remove, e;
var attach, remove, add_remove, e;
attach = function (sel, event, callback) attach = function (sel, event, callback)
{ {
@ -287,7 +286,7 @@
} }
//Get the DOM object if you give me a selector string //Get the DOM object if you give me a selector string
sel = _sel(sel); sel = $(sel);
//Multiple events? Run recursively! //Multiple events? Run recursively!
event = event.split(" "); event = event.split(" ");
@ -311,16 +310,12 @@
len = sel.length; len = sel.length;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
{ {
(add === true) (add === true) ? attach(sel[i], event, callback) : remove(sel[i], event, callback);
? attach(sel[i], event, callback)
: remove(sel[i], event, callback);
} }
} }
else else
{ {
(add === true) (add === true) ? attach(sel, event, callback) : remove(sel, event, callback);
? attach(sel, event, callback)
: remove(sel, event, callback);
} }
}; };
@ -344,7 +339,7 @@
* *
*/ */
(function (){ (function (){
var d, len; var d;
//Private function for getting/setting attributes //Private function for getting/setting attributes
function _attr(sel, name, value) function _attr(sel, name, value)
@ -390,15 +385,11 @@
//Determine what to do with the attribute //Determine what to do with the attribute
if (typeof value !== "undefined" && value !== null) if (typeof value !== "undefined" && value !== null)
{ {
(doAttr === true) (doAttr === true) ? sel.setAttribute(name, value) : sel[name] = value;
? sel.setAttribute(name, value)
: sel[name] = value;
} }
else if (value === null) else if (value === null)
{ {
(doAttr === true) (doAttr === true) ? sel.removeAttribute(name) : sel[name] = null;
? sel.removeAttribute(name)
: sel[name] = null;
} }
return (typeof value !== "undefined") ? value : oldValue; return (typeof value !== "undefined") ? value : oldValue;
@ -429,7 +420,6 @@
ec = _attr(sel, "class"); ec = _attr(sel, "class");
ec = (typeof ec === "string") ? ec : ''; ec = (typeof ec === "string") ? ec : '';
//Convert class attribute string into array //Convert class attribute string into array
if (typeof ec === "string") if (typeof ec === "string")
{ {
@ -439,7 +429,7 @@
classInd = false; classInd = false;
//Check for the class in the array //Check for the class in the array
for(var i=0;i<len;i++) for (i = 0; i < len; i++)
{ {
if (cs[i] === c) if (cs[i] === c)
{ {
@ -475,7 +465,7 @@
} }
else if (typeof sel.setAttribute !== "undefined") else if (typeof sel.setAttribute !== "undefined")
{ {
sel.setAttribute('class', cName) sel.setAttribute('class', cName);
} }
else else
{ {
@ -497,9 +487,15 @@
var len = sel.length; var len = sel.length;
if(len === 0){ return } if (len === 0)
{
return;
}
if(len === 1){ return callback(sel); } if (len === 1)
{
return callback(sel);
}
for (var x = 0; x < sel.length; x++) for (var x = 0; x < sel.length; x++)
{ {
@ -508,27 +504,30 @@
}, },
addClass: function (sel, c) addClass: function (sel, c)
{ {
sel = _sel(sel); sel = $(sel);
this.each(sel, function(e){ this.each(sel, function (e)
{
_class(e, c, true); _class(e, c, true);
}); });
}, },
removeClass: function (sel, c) removeClass: function (sel, c)
{ {
sel = _sel(sel); sel = $(sel);
this.each(sel, function(e){ this.each(sel, function (e)
{
_class(e, c, false); _class(e, c, false);
}); });
}, },
hide: function (sel) hide: function (sel)
{ {
sel = _sel(sel); sel = $(sel);
if (sel.length > 1) if (sel.length > 1)
{ {
this.each(sel, function(e){ this.each(sel, function (e)
{
e.style.display = "none"; e.style.display = "none";
}); });
} }
@ -543,7 +542,7 @@
}, },
show: function (sel, type) show: function (sel, type)
{ {
sel = _sel(sel); sel = $(sel);
if (typeof type === "undefined") if (typeof type === "undefined")
{ {
@ -552,7 +551,8 @@
if (sel.length > 1) if (sel.length > 1)
{ {
this.each(sel, function(e){ this.each(sel, function (e)
{
e.style.display = type; e.style.display = type;
}); });
} }
@ -563,9 +563,7 @@
}, },
attr: function (sel, name, value) attr: function (sel, name, value)
{ {
var oldVal; sel = $(sel);
sel = _sel(sel);
//Make sure you don't try to get a bunch of elements //Make sure you don't try to get a bunch of elements
if (sel.length > 1 && typeof value === "undefined") if (sel.length > 1 && typeof value === "undefined")
@ -576,7 +574,8 @@
} }
else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though
{ {
this.each(sel, function(e){ this.each(sel, function (e)
{
_attr(e, name, value); _attr(e, name, value);
}); });
} }
@ -590,4 +589,4 @@
window.$_.dom = d; window.$_.dom = d;
}()); }());
})(); }());