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