Fixed a minor issue with ajax module, removed unused variables, added Camelcase to css function, and added String.trim polyfill

This commit is contained in:
Timothy Warren 2011-07-11 13:11:06 -04:00
parent 9014a081ab
commit f3963925a3

44
kis.js
View File

@ -20,6 +20,16 @@
var $_, $;
/**
* String trim function polyfill
*/
if(typeof String.prototype.trim === "undefined")
{
String.prototype.trim = function(){
return this.replace(/^\s+|\s+$/g, "");
};
}
/**
* $
*
@ -39,6 +49,10 @@
{
x = document.getElementsByTagName(a);
}
else if(a.match(/^\.([\w\-]+)$/) && document.getElementsByClassName !== "undefined")
{
x = document.getElementsByClassName(a);
}
else
{
x = document.querySelectorAll(a);
@ -86,7 +100,7 @@
$_.each = function (callback)
{
var sel = $_.el
var sel = $_.el;
//Don't try to iterate over the window object
if(sel === window || typeof sel === "undefined")
@ -142,7 +156,9 @@
var type = (isPost) ? "POST" : "GET";
url += (type === "GET") ? "?" + this._serialize(data, true) : '';
var d = (data.length > 0) ? "?"+this._serialize(data, true) : '';
url += (type === "GET") ? d : '';
request.open(type, url);
@ -426,10 +442,10 @@
add_remove = function (event, callback, add)
{
var i, len, selx;
var i, len;
//Get the DOM object
var sel = $_.el
var sel = $_.el;
if(arguments.length === 4)
{
@ -496,7 +512,7 @@
//Private function for getting/setting attributes
function _attr(sel, name, value)
{
var oldVal, doAttr, i;
var oldVal, doAttr;
//Get the value of the attribute, if it exists
if (typeof sel.hasAttribute !== "undefined")
@ -639,11 +655,19 @@
}
function _toCamel(s)
{
return s.replace(/(\-[a-z])/g, function($1){
return $1.toUpperCase().replace('-','');
});
}
function _css(sel, prop, val)
{
var equi;
//Todo: camelCase things like border-left to borderLeft
//Camel-case
prop = _toCamel(prop);
//Let's try the easy way first
if(typeof sel.style[prop] !== "undefined")
@ -679,16 +703,12 @@
d = {
addClass: function (c)
{
var sel = $_.el
$_.each(function (e){
_class(e, c, true);
});
},
removeClass: function (c)
{
var sel = $_.el
$_.each(function (e){
_class(e, c, false);
});
@ -708,7 +728,7 @@
},
attr: function (name, value)
{
var sel = $_.el
var sel = $_.el;
//Make sure you don't try to get a bunch of elements
if (sel.length > 1 && typeof value === "undefined")
@ -732,7 +752,7 @@
{
var oldValue, set, type, sel;
var sel = $_.el
sel = $_.el;
set = (typeof value !== "undefined") ? true : false;