Added object_merge function and tests

This commit is contained in:
Timothy Warren 2011-10-24 12:24:10 -04:00
parent 69ee39623d
commit 1237ea511e
13 changed files with 1040 additions and 1936 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
kis-custom.js
kis-custom-min.js
combine-build.php
test.html

View File

@ -8,11 +8,13 @@
//The name of the source folder
$folder = "src";
$src_folder = "{$folder}/modules";
$core_folder = "{$folder}/core";
$files = array();
//Get all the source files
if($dir = opendir($folder))
if($dir = opendir($src_folder))
{
while(($file = readdir($dir)) !== FALSE)
{
@ -26,37 +28,20 @@ if($dir = opendir($folder))
closedir($dir);
}
//Define files that aren't modules
$special_files = array(
'core.js',
);
//Filter out special files
$src_files = array_diff($files, $special_files);
//Start with the core
$new_file = file_get_contents($folder."/core.js") . "\n";
$new_file = file_get_contents($core_folder."/core.js") . "\n";
//Add the opening of the function for the modules
$new_file .= "\n// --------------------------------------------------------------------------\n\n";
//Add the modules
foreach($src_files as $f)
foreach($files as $f)
{
$farray = file($folder."/".$f, FILE_IGNORE_NEW_LINES);
$farray = file($src_folder."/".$f, FILE_IGNORE_NEW_LINES);
$flen = count($farray);
//Indent each module 1 tab, for neatness
for($i=0;$i<$flen;$i++)
{
if($farray[$i] == ""){ continue; }
$farray[$i] = "\t".$farray[$i];
}
$module = implode("\n", $farray);
$new_file .= "\n\t// --------------------------------------------------------------------------\n\n".$module."\n";
$new_file .= "\n// --------------------------------------------------------------------------\n\n".$module."\n";
}
@ -71,7 +56,7 @@ curl_setopt($ch, CURLOPT_POSTFIELDS, 'output_info=compiled_code&output_format=te
$output = curl_exec($ch);
curl_close($ch);
file_put_contents("kis-min.js", $output);
file_put_contents("kis-custom-min.js", $output);
//Display the output on-screen too

1801
kis-all.js

File diff suppressed because it is too large Load Diff

17
kis-min.js vendored
View File

@ -2,19 +2,20 @@
c;a.el=c;return a};f=function(a){var d;if(typeof a!=="undefined"){if(typeof Object.create!=="undefined")return Object.create(a);d=typeof a;if(!(d!=="object"&&d!=="function"))return d=function(){},d.prototype=a,new d}};b.ext=function(a,d){d.el=c;b[a]=d};b.ext("each",function(a){if(typeof c.length!=="undefined"&&c!==window){var d=c.length;if(d!==0)for(var b,e=0;e<d;e++)b=c.item(e)?c.item(e):c[e],a(b)}else a(c)});b.type=function(a){return function(){return a&&a!==this}.call(a)?(typeof a).toLowerCase():
{}.toString.call(a).match(/\s([a-z|A-Z]+)/)[1].toLowerCase()};b=window.$_=window.$_||b;b.$=e;if(typeof window.console==="undefined")window.console={log:function(){}};if(typeof String.prototype.trim==="undefined")String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")}}})();
typeof document!=="undefined"&&!("classList"in document.createElement("a"))&&function(b){var b=(b.HTMLElement||b.Element).prototype,e=Object,f=String.prototype.trim||function(){return this.replace(/^\s+|\s+$/g,"")},c=Array.prototype.indexOf||function(a){for(var d=0,c=this.length;d<c;d++)if(d in this&&this[d]===a)return d;return-1},a=function(a,d){this.name=a;this.code=DOMException[a];this.message=d},d=function(d,b){if(b==="")throw new a("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new a("INVALID_CHARACTER_ERR",
"String contains an invalid character");return c.call(d,b)},l=function(a){for(var d=f.call(a.className),d=d?d.split(/\s+/):[],c=0,b=d.length;c<b;c++)this.push(d[c]);this._updateClassName=function(){a.className=this.toString()}},g=l.prototype=[],j=function(){return new l(this)};a.prototype=Error.prototype;g.item=function(a){return this[a]||null};g.contains=function(a){a+="";return d(this,a)!==-1};g.add=function(a){a+="";d(this,a)===-1&&(this.push(a),this._updateClassName())};g.remove=function(a){a+=
"";a=d(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};g.toggle=function(a){a+="";d(this,a)===-1?this.add(a):this.remove(a)};g.toString=function(){return this.join(" ")};if(e.defineProperty){g={get:j,enumerable:true,configurable:true};try{e.defineProperty(b,"classList",g)}catch(h){if(h.number===-2146823252)g.enumerable=false,e.defineProperty(b,"classList",g)}}else e.prototype.__defineGetter__&&b.__defineGetter__("classList",j)}(self);
"String contains an invalid character");return c.call(d,b)},h=function(a){for(var d=f.call(a.className),d=d?d.split(/\s+/):[],c=0,b=d.length;c<b;c++)this.push(d[c]);this._updateClassName=function(){a.className=this.toString()}},g=h.prototype=[],l=function(){return new h(this)};a.prototype=Error.prototype;g.item=function(d){return this[d]||null};g.contains=function(a){a+="";return d(this,a)!==-1};g.add=function(a){a+="";d(this,a)===-1&&(this.push(a),this._updateClassName())};g.remove=function(a){a+=
"";a=d(this,a);a!==-1&&(this.splice(a,1),this._updateClassName())};g.toggle=function(a){a+="";d(this,a)===-1?this.add(a):this.remove(a)};g.toString=function(){return this.join(" ")};if(e.defineProperty){g={get:l,enumerable:true,configurable:true};try{e.defineProperty(b,"classList",g)}catch(j){if(j.number===-2146823252)g.enumerable=false,e.defineProperty(b,"classList",g)}}else e.prototype.__defineGetter__&&b.__defineGetter__("classList",l)}(self);
(function(){function b(c,a,d){var b,e;if(typeof c.hasAttribute!=="undefined")c.hasAttribute(a)&&(b=c.getAttribute(a)),e=true;else if(typeof c[a]!=="undefined")b=c[a],e=false;else if(a==="class"&&typeof c.className!=="undefined")a="className",b=c.className,e=false;if(typeof b==="undefined"&&(typeof d==="undefined"||d===null))console.log(d),console.log(c),console.log("Element does not have the selected attribute");else{if(typeof d==="undefined")return b;typeof d!=="undefined"&&d!==null?e===true?c.setAttribute(a,
d):c[a]=d:d===null&&(e===true?c.removeAttribute(a):delete c[a]);return typeof d!=="undefined"?d:b}}function e(c){return c.replace(/(\-[a-z])/g,function(a){return a.toUpperCase().replace("-","")})}function f(c,a,d){var b,a=e(a);b={outerHeight:"offsetHeight",outerWidth:"offsetWidth",top:"posTop"};if(typeof d==="undefined"&&c.style[a]!=="undefined")return c.style[a];else if(typeof d==="undefined"&&c.style[b[a]]!=="undefined")return c.style[b[a]];typeof c.style[a]!=="undefined"?c.style[a]=d:c.style[b[a]]?
c.style[b[a]]=d:console.log("Property "+a+" nor an equivalent seems to exist")}$_.ext("dom",{addClass:function(c){$_.each(function(a){a.classList.add(c)})},removeClass:function(c){$_.each(function(a){a.classList.remove(c)})},hide:function(){this.css("display","none")},show:function(c){typeof c==="undefined"&&(c="block");this.css("display",c)},attr:function(c,a){var d=this.el;if(d.length>1&&typeof a==="undefined")console.log(d),console.log("Must be a singular element");else if(d.length>1&&typeof a!==
"undefined")$_.each(function(d){return b(d,c,a)});else return b(d,c,a)},text:function(c){var a,d,b;b=this.el;d=typeof b.innerText!=="undefined"?"innerText":typeof b.textContent!=="undefined"?"textContent":"innerHTML";a=b[d];return typeof c!=="undefined"?b[d]=c:a},css:function(b,a){if(typeof a==="undefined")return f(this.el,b);$_.each(function(d){f(d,b,a)})}})})();
"undefined")$_.each(function(d){return b(d,c,a)});else return b(d,c,a)},text:function(c){var a,d,b;b=this.el;d=typeof b.innerText!=="undefined"?"innerText":typeof b.textContent!=="undefined"?"textContent":"innerHTML";a=b[d];return typeof c!=="undefined"?b[d]=c:a},css:function(c,a){if(typeof a==="undefined")return f(this.el,c);$_.each(function(d){f(d,c,a)})}})})();
(function(){$_.ext("store",{get:function(b){return JSON.parse(localStorage.getItem(b))},set:function(b,e){typeof e!=="string"&&(e=JSON.stringify(e));localStorage.setItem(b,e)},remove:function(b){localStorage.removeItem(b)},getAll:function(){var b,e,f;e=localStorage.length;f={};for(b=0;b<e;b++){var c=localStorage.key(b),a=localStorage.getItem(c);f[c]=a}return f}})})();
(function(){$_.hb=history.pushState?false:true;$_.ext("qs",{parse:function(b){var b=b||$_.hb,e,f,c,a;c={};if(b===true)b=location.hash.split("#!/"),b=b.length>1?b[1]:"";else if(b===false||b===void 0)b=window.location.search.substring(1);else return false;e=b.split("&");f=e.length;for(b=0;b<f;b++){a=e[b].split("=");if(a.length<2)break;c[a[0]]=a[1]}return c},set:function(b,e,f){var f=f||$_.hb,c=this.parse(f);b!==void 0&&e!==void 0&&(c[b]=e);var b=[],a;for(a in c)c.hasOwnProperty(a)&&b.push(a+"="+c[a]);
c=b.join("&");if(f===true)c="!/"+c,location.hash=c;return c},get:function(b,e){var e=e||$_.hb,f=this.parse(e);return f[b]?f[b]:""}})})();var $_=$_||window.$_;
c=b.join("&");if(f===true)c="!/"+c,location.hash=c;return c},get:function(b,e){var e=e||$_.hb,f=this.parse(e);return f[b]?f[b]:""}})})();
(function(){var b={_do:function(b,f,c,a){typeof c==="undefined"&&(c=function(){});var d=typeof window.XMLHttpRequest!=="undefined"?new XMLHttpRequest:false,a=a?"POST":"GET";b+=a==="GET"?"?"+this._serialize(f):"";d.open(a,b);d.onreadystatechange=function(){d.readyState===4&&c(d.responseText)};a==="POST"?(d.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),d.send(this._serialize(f))):d.send(null)},_serialize:function(b){var f=[],c;for(c in b)if(b.hasOwnProperty(c)&&typeof b[c]!==
"function"){var a=b[c].toString();c=encodeURIComponent(c);a=encodeURIComponent(a);f.push(c+"="+a)}return f.join("&")}};$_.ext("get",function(e,f,c){b._do(e,f,c,false)});$_.ext("post",function(e,f,c){b._do(e,f,c,true)})})();
(function(){$_.ext("util",{object_keys:function(b){var e=[],f;for(f in b)b.hasOwnProperty(f)&&e.push(f);return e},object_values:function(b){var e=[],f;for(f in b)e.push(b[f]);return e},object_merge:function(){},reverse_key_sort:function(b){var e=[],f=0,c={},a,d,e=this.object_keys(b);e.sort(function(a,d){var b=parseFloat(d),c=parseFloat(a),e=b+""===d,f=c+""===a;if(e&&f)return b>c?1:b<c?-1:0;else if(e&&!f)return 1;else if(!e&&f)return-1;return d>a?1:d<a?-1:0});f=e.length;for(a=0;a<f;a++)d=e[a],c[d]=
b[d];return c},str_trans:function(){}})})();
(function(){$_.ext("util",{reverse_key_sort:function(b){var e=[],f=0,c={},a,e=this.object_keys(b);e.sort(function(a,b){var c=parseFloat(b),e=parseFloat(a),f=c+""===b,i=e+""===a;if(f&&i)return c>e?1:c<e?-1:0;else if(f&&!i)return 1;else if(!f&&i)return-1;return b>a?1:b<a?-1:0});f=e.length;for(a=0;a<f;a++)c[e[a]]=b[e[a]];return c},object_keys:function(b){var e=[],f;for(f in b)b.hasOwnProperty(f)&&e.push(f);return e},object_values:function(b){var e=[],f;for(f in b)e.push(b[f]);return e},array_combine:function(b,
e){var f={},c,a=0;$_.type(b)!=="array"&&(b=this.object_values(b));$_.type(e)!=="array"&&(e=this.object_values(e));c=b.length;if(c!==e.length)return console.log("Object combine requires two arrays of the same size"),false;for(a=0;a<c;a++)f[b[a]]=e[a];return f},object_merge:function(){var b=Array.prototype.slice.call(arguments),e=b.length,f={},c,a=0,d,h,g;c=true;for(d=0;d<e;d++)if($_.type(b[d])!=="array"){c=false;break}if(c){f=[];for(d=0;d<e;d++)f=f.contact(b[d]);return f}for(d=0,g=0;d<e;d++)if(c=b[d],
$_.type(c)=="array")for(h=0,a=c.length;h<a;h++)f[g++]=c[h];else for(h in c)c.hasOwnProperty(h)&&(parseInt(h,10)+""===h?f[g++]=c[h]:f[h]=c[h]);return f},str_trans:function(){},str_replace:function(){}})})();
(function(){var b,e,f,c,a;typeof document.addEventListener!=="undefined"?(b=function(a,b,c){typeof a.addEventListener!=="undefined"&&a.addEventListener(b,c,false)},e=function(a,b,c){typeof a.removeEventListener!=="undefined"&&a.removeEventListener(b,c,false)}):typeof document.attachEvent!=="undefined"&&(b=function(a,b,c){var d;function f(){c.apply(arguments)}typeof a.attachEvent!=="undefined"?(e(b,c),a.attachEvent("on"+b,f),d=a.KIS_0_3_0=a.KIS_0_3_0||{},a=d,a.listeners=a.listeners||{},a.listeners[b]=
a.listeners[b]||[],a.listeners[b].push({callback:c,listener:f})):console.log("Failed to attach event:"+b+" on "+a)},e=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var e=a.KIS_0_3_0;if(e&&e.listeners&&e.listeners[b])for(var f=e.listeners[b],k=f.length,i=0;i<k;i++)if(f[i].callback===c){a.detachEvent("on"+b,f[i].listener);f.splice(i,1);f.length===0&&delete e.listeners[b];break}}});f=function(a,c,g,j){var h,k;if(typeof a==="undefined")return console.log(arguments),console.log(c),false;if(c.match(/^([\w\-]+)$/))j===
true?b(a,c,g):e(a,c,g);else{c=c.split(" ");k=c.length;for(h=0;h<k;h++)f(a,c[h],g,j)}};c=function(a,b,c){f(a,c,function(){a=$_.$(a)},true)};a=function(a,b,e){c(document.documentElement,a,b,e)};$_.ext("event",{add:function(a,b){$_.each(function(c){f(c,a,b,true)})},remove:function(a,b){$_.each(function(c){f(c,a,b,false)})},live:function(b,c){$_.each(function(e){a(e,b,c)})},delegate:function(a,b,e){$_.each(function(f){c(f,a,b,e)})}})})();
a.listeners[b]||[],a.listeners[b].push({callback:c,listener:f})):console.log("Failed to attach event:"+b+" on "+a)},e=function(a,b,c){if(typeof a.detachEvent!=="undefined"){var e=a.KIS_0_3_0;if(e&&e.listeners&&e.listeners[b])for(var f=e.listeners[b],i=f.length,k=0;k<i;k++)if(f[k].callback===c){a.detachEvent("on"+b,f[k].listener);f.splice(k,1);f.length===0&&delete e.listeners[b];break}}});f=function(a,c,g,l){var j,i;if(typeof a==="undefined")return console.log(arguments),console.log(c),false;if(c.match(/^([\w\-]+)$/))l===
true?b(a,c,g):e(a,c,g);else{c=c.split(" ");i=c.length;for(j=0;j<i;j++)f(a,c[j],g,l)}};c=function(a,b,c){f(a,c,function(){a=$_.$(a)},true)};a=function(a,b,e){c(document.documentElement,a,b,e)};$_.ext("event",{add:function(a,b){$_.each(function(c){f(c,a,b,true)})},remove:function(a,b){$_.each(function(c){f(c,a,b,false)})},live:function(b,c){$_.each(function(e){a(e,b,c)})},delegate:function(a,b,e){$_.each(function(f){c(f,a,b,e)})}})})();

View File

@ -1,379 +0,0 @@
/*
* classList.js: Cross-browser full element.classList implementation.
* 2011-06-15
*
* By Eli Grey, http://eligrey.com
* Public Domain.
* NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
*/
if (typeof document !== "undefined" && !("classList" in document.createElement("a")))
{
(function (view){
var classListProp = "classList",
protoProp = "prototype",
elemCtrProto = (view.HTMLElement || view.Element)[protoProp],
objCtr = Object,
strTrim = String[protoProp].trim ||
function ()
{
return this.replace(/^\s+|\s+$/g, "");
},
arrIndexOf = Array[protoProp].indexOf ||
function (item)
{
var
i = 0,
len = this.length;
for (; i < len; i++)
{
if (i in this && this[i] === item)
{
return i;
}
}
return -1;
}
// Vendors: please allow content code to instantiate DOMExceptions
,
DOMEx = function (type, message)
{
this.name = type;
this.code = DOMException[type];
this.message = message;
},
checkTokenAndGetIndex = function (classList, token)
{
if (token === "")
{
throw new DOMEx("SYNTAX_ERR", "An invalid or illegal string was specified");
}
if (/\s/.test(token))
{
throw new DOMEx("INVALID_CHARACTER_ERR", "String contains an invalid character");
}
return arrIndexOf.call(classList, token);
},
ClassList = function (elem)
{
var
trimmedClasses = strTrim.call(elem.className),
classes = trimmedClasses ? trimmedClasses.split(/\s+/) : [],
i = 0,
len = classes.length;
for (; i < len; i++)
{
this.push(classes[i]);
}
this._updateClassName = function ()
{
elem.className = this.toString();
};
},
classListProto = ClassList[protoProp] = [],
classListGetter = function ()
{
return new ClassList(this);
};
// Most DOMException implementations don't allow calling DOMException's toString()
// on non-DOMExceptions. Error's toString() is sufficient here.
DOMEx[protoProp] = Error[protoProp];
classListProto.item = function (i)
{
return this[i] || null;
};
classListProto.contains = function (token)
{
token += "";
return checkTokenAndGetIndex(this, token) !== -1;
};
classListProto.add = function (token)
{
token += "";
if (checkTokenAndGetIndex(this, token) === -1)
{
this.push(token);
this._updateClassName();
}
};
classListProto.remove = function (token)
{
token += "";
var index = checkTokenAndGetIndex(this, token);
if (index !== -1)
{
this.splice(index, 1);
this._updateClassName();
}
};
classListProto.toggle = function (token)
{
token += "";
if (checkTokenAndGetIndex(this, token) === -1)
{
this.add(token);
}
else
{
this.remove(token);
}
};
classListProto.toString = function ()
{
return this.join(" ");
};
if (objCtr.defineProperty)
{
var classListPropDesc = {
get: classListGetter,
enumerable: true,
configurable: true
};
try
{
objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
}
catch (ex)
{ // IE 8 doesn't support enumerable:true
if (ex.number === -0x7FF5EC54)
{
classListPropDesc.enumerable = false;
objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);
}
}
}
else if (objCtr[protoProp].__defineGetter__)
{
elemCtrProto.__defineGetter__(classListProp, classListGetter);
}
}(self));
}
// --------------------------------------------------------------------------
/**
* Dom manipulation object
*
*/
(function (){
var d, tag_reg, class_reg;
tag_reg = /^([\w\-]+)$/;
class_reg = /\.([\w\-]+)$/;
//Private function for getting/setting attributes
function _attr(sel, name, value)
{
var oldVal, doAttr;
//Get the value of the attribute, if it exists
if (typeof sel.hasAttribute !== "undefined")
{
if (sel.hasAttribute(name))
{
oldVal = sel.getAttribute(name);
}
doAttr = true;
}
else if (typeof sel[name] !== "undefined")
{
oldVal = sel[name];
doAttr = false;
}
else if (name === "class" && typeof sel.className !== "undefined") //className attribute
{
name = "className";
oldVal = sel.className;
doAttr = false;
}
//Well, I guess that attribute doesn't exist
if (typeof oldVal === "undefined" && (typeof value === "undefined" || value === null))
{
console.log(value);
console.log(sel);
console.log("Element does not have the selected attribute");
return;
}
//No value to set? Return the current value
if (typeof value === "undefined")
{
return oldVal;
}
//Determine what to do with the attribute
if (typeof value !== "undefined" && value !== null)
{
if(doAttr === true)
{
sel.setAttribute(name, value);
}
else
{
sel[name] = value;
}
}
else if (value === null)
{
if(doAttr === true)
{
sel.removeAttribute(name);
}
else
{
delete sel[name];
}
}
return (typeof value !== "undefined") ? value : oldVal;
}
function _toCamel(s)
{
return s.replace(/(\-[a-z])/g, function($1){
return $1.toUpperCase().replace('-','');
});
}
function _css(sel, prop, val)
{
var equi;
//Camel-case
prop = _toCamel(prop);
//Equivalent properties for 'special' browsers
equi = {
outerHeight: "offsetHeight",
outerWidth: "offsetWidth",
top: "posTop"
};
//If you don't define a value, try returning the existing value
if(typeof val === "undefined" && sel.style[prop] !== "undefined")
{
return sel.style[prop];
}
else if(typeof val === "undefined" && sel.style[equi[prop]] !== "undefined")
{
return sel.style[equi[prop]];
}
//Let's try the easy way first
if(typeof sel.style[prop] !== "undefined")
{
sel.style[prop] = val;
//Short circuit
return;
}
else if(sel.style[equi[prop]])
{
sel.style[equi[prop]] = val;
return;
}
//No matches? Well, lets log it for now
console.log("Property " + prop + " nor an equivalent seems to exist");
}
// --------------------------------------------------------------------------
d = {
addClass: function (c)
{
$_.each(function (e){
e.classList.add(c);
});
},
removeClass: function (c)
{
$_.each(function (e){
e.classList.remove(c);
});
},
hide: function ()
{
this.css('display', 'none');
},
show: function (type)
{
if (typeof type === "undefined")
{
type = "block";
}
this.css("display", type);
},
attr: function (name, value)
{
var sel = this.el;
//Make sure you don't try to get a bunch of elements
if (sel.length > 1 && typeof value === "undefined")
{
console.log(sel);
console.log("Must be a singular element");
return;
}
else if (sel.length > 1 && typeof value !== "undefined") //You can set a bunch, though
{
$_.each(function (e){
return _attr(e, name, value);
});
}
else //Normal behavior
{
return _attr(sel, name, value);
}
},
text: function (value)
{
var oldValue, set, type, sel;
sel = this.el;
set = (typeof value !== "undefined") ? true : false;
type = (typeof sel.innerText !== "undefined")
? "innerText"
: (typeof sel.textContent !== "undefined")
? "textContent"
: "innerHTML";
oldValue = sel[type];
if(set)
{
sel[type] = value;
return value;
}
else
{
return oldValue;
}
},
css: function (prop, val)
{
//Return the current value if a value is not set
if(typeof val === "undefined")
{
return _css(this.el, prop);
}
$_.each(function (e){
_css(e, prop, val);
});
}
};
$_.ext('dom', d);
}());

View File

@ -1,91 +0,0 @@
/**
* Qs
*
* Object for encoding and decoding querystrings and hashbang strings
*/
(function (){
$_.hb = (history.pushState) ? false : true;
var qs = {
parse: function (hb)
{
hb = hb || $_.hb;
var h, i, hString, pairs, pLen, data, y;
data = {};
if (hb === true)
{
h = location.hash.split('#!/');
hString = (h.length > 1) ? h[1] : '';
}
else if (hb === false || hb === undefined)
{
hString = window.location.search.substring(1);
}
else
{
return false;
}
pairs = hString.split('&');
pLen = pairs.length;
for (i = 0; i < pLen; i++)
{
y = pairs[i].split('=');
if (y.length < 2)
{
return data;
}
data[y[0]] = y[1];
}
return data;
},
set: function (key, value, hb)
{
hb = hb || $_.hb;
var pairs = this.parse(hb);
if (key !== undefined && value !== undefined)
{
pairs[key] = value;
}
var vars = [];
for (var x in pairs)
{
if (pairs.hasOwnProperty(x))
{
vars.push(x + '=' + pairs[x]);
}
}
var qs = vars.join('&');
if (hb === true)
{
qs = '!/' + qs;
location.hash = qs;
}
return qs;
},
get: function (key, hb)
{
hb = hb || $_.hb;
var pairs = this.parse(hb);
return (pairs[key]) ? pairs[key] : '';
}
};
$_.ext('qs', qs);
}());

View File

@ -1,78 +0,0 @@
/**
* Ajax
*
* Object for making ajax requests
*/
(function (){
var ajax = {
_do: function (url, data, callback, isPost)
{
if (typeof callback === "undefined")
{
callback = function (){};
}
var request = (typeof window.XMLHttpRequest !== "undefined")
? new XMLHttpRequest()
: false;
var type = (isPost) ? "POST" : "GET";
url += (type === "GET") ? "?"+this._serialize(data) : '';
request.open(type, url);
request.onreadystatechange = function ()
{
if (request.readyState === 4)
{
callback(request.responseText);
}
};
if (type === "POST")
{
request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
request.send(this._serialize(data));
}
else
{
request.send(null);
}
},
_serialize: function (data)
{
var pairs = [];
for (var name in data)
{
if (!data.hasOwnProperty(name))
{
continue;
}
if (typeof data[name] === "function")
{
continue;
}
var value = data[name].toString();
name = encodeURIComponent(name);
value = encodeURIComponent(value);
pairs.push(name + "=" + value);
}
return pairs.join("&");
}
};
$_.ext('get', function (url, data, callback){
ajax._do(url, data, callback, false);
});
$_.ext('post', function (url, data, callback){
ajax._do(url, data, callback, true);
});
}());

View File

@ -1,184 +0,0 @@
/**
Kis JS Keep It Simple JS Library
Copyright Timothy J. Warren
License Public Domain
Version 0.3.0
*/
(function (){
"use strict";
//Browser requirements check
if (!document.querySelectorAll)
{
return;
}
var $_, $, dcopy, sel;
/**
* $
*
* Simple DOM selector function
*/
$ = function (a)
{
var x;
if (typeof a !== "string" || typeof a === "undefined"){ return a;}
//Pick the quickest method for each kind of selector
if (a.match(/^#([\w\-]+$)/))
{
return document.getElementById(a.split('#')[1]);
}
else if (a.match(/^([\w\-]+)$/))
{
x = document.getElementsByTagName(a);
}
else
{
x = document.querySelectorAll(a);
}
//Return the single object if applicable
return (x.length === 1) ? x[0] : x;
};
/**
* $_
*
* Constructor function
*/
$_ = function(s)
{
//Have documentElement be default selector, just in case
if(typeof s === "undefined")
{
sel = (typeof $_.el !== "undefined")
? $_.el
: document.documentElement;
}
else
{
sel = (typeof s !== "object") ? $(s) : s;
}
// Add the selector to the prototype
$_.prototype.el = sel;
// Make a copy before adding properties
var self = dcopy($_);
// Give sel to each extension.
for(var i in self)
{
if(typeof self[i] === "object")
{
self[i].el = sel;
}
}
self.el = sel;
return self;
};
/**
* Deep copy/prototypical constructor function
*/
dcopy = function(obj)
{
var type, F;
if(typeof obj === "undefined")
{
return;
}
if(typeof Object.create !== "undefined")
{
return Object.create(obj);
}
type = typeof obj;
if(type !== "object" && type !== "function")
{
return;
}
F = function(){};
F.prototype = obj;
return new F();
};
//Function to add to $_ object, and get sel
$_.ext = function(name, obj)
{
obj.el = sel;
$_[name] = obj;
};
//Selector iteration
$_.ext('each', function (callback)
{
if(typeof sel.length !== "undefined" && sel !== window)
{
var len = sel.length;
if (len === 0)
{
return;
}
var selx;
for (var x = 0; x < len; x++)
{
selx = (sel.item(x)) ? sel.item(x) : sel[x];
callback(selx);
}
}
else
{
callback(sel);
}
});
//Type retriever
$_.type = function(obj)
{
if((function() {return obj && (obj !== this)}).call(obj))
{
//fallback on 'typeof' for truthy primitive values
return (typeof obj).toLowerCase();
}
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
//Set global variables
$_ = window.$_ = window.$_ || $_;
$_.$ = $;
//console.log polyfill
if(typeof window.console === "undefined")
{
window.console = {
log:function(){}
};
}
/**
* String trim function polyfill
*/
if(typeof String.prototype.trim === "undefined")
{
String.prototype.trim = function(){
return this.replace(/^\s+|\s+$/g, "");
};
}
}());

View File

@ -1,177 +0,0 @@
/**
* Event object
*
* Event api wrapper
*/
(function (){
// Property name for expandos on DOM objects
var kis_expando = "KIS_0_3_0";
var attach, remove, add_remove, e, attach_delegate, attach_live;
// Define the proper attach and remove functions
// based on browser support
if(typeof document.addEventListener !== "undefined")
{
attach = function (sel, event, callback)
{
if (typeof sel.addEventListener !== "undefined")
{
sel.addEventListener(event, callback, false);
}
};
remove = function (sel, event, callback)
{
if (typeof sel.removeEventListener !== "undefined")
{
sel.removeEventListener(event, callback, false);
}
};
}
//typeof function doesn't work in IE where attachEvent is available: brute force it
else if(typeof document.attachEvent !== "undefined")
{
attach = function (sel, event, callback)
{
function listener () {
// Internet Explorer fails to correctly set the 'this' object
// for event listeners, so we need to set it ourselves.
callback.apply(arguments);
}
if (typeof sel.attachEvent !== "undefined")
{
remove(event, callback); // Make sure we don't have duplicate listeners
sel.attachEvent("on" + event, listener);
// Store our listener so we can remove it later
var expando = sel[kis_expando] = sel[kis_expando] || {};
expando.listeners = expando.listeners || {};
expando.listeners[event] = expando.listeners[event] || [];
expando.listeners[event].push({
callback: callback,
listener: listener
});
}
else
{
console.log("Failed to attach event:"+event+" on "+sel);
}
};
remove = function (sel, event, callback)
{
if(typeof sel.detachEvent !== "undefined")
{
var expando = sel[kis_expando];
if (expando && expando.listeners
&& expando.listeners[event])
{
var listeners = expando.listeners[event];
var len = listeners.length;
for (var i=0; i<len; i++)
{
if (listeners[i].callback === callback)
{
sel.detachEvent("on" + event, listeners[i].listener);
listeners.splice(i, 1);
if(listeners.length === 0)
{
delete expando.listeners[event];
}
return;
}
}
}
}
};
}
add_remove = function (sel, event, callback, add)
{
var i, len;
if(typeof sel === "undefined")
{
console.log(arguments);
console.log(event);
return false;
}
//Multiple events? Run recursively!
if (!event.match(/^([\w\-]+)$/))
{
event = event.split(" ");
len = event.length;
for (i = 0; i < len; i++)
{
add_remove(sel, event[i], callback, add);
}
return;
}
if(add === true)
{
attach(sel, event, callback);
}
else
{
remove(sel, event, callback);
}
};
attach_delegate = function(sel, target, event, callback)
{
//Attach the listener to the parent object
add_remove(sel, event, function(e){
//Get the live version of the target selector
sel = $_.$(sel);
//todo: fire target callback when event bubbles from target
}, true);
};
attach_live = function(target, event, callback)
{
attach_delegate(document.documentElement, target, event, callback);
};
// --------------------------------------------------------------------------
e = {
add: function (event, callback)
{
$_.each(function(e){
add_remove(e, event, callback, true);
});
},
remove: function (event, callback)
{
$_.each(function(e){
add_remove(e, event, callback, false);
});
},
live: function (event, callback)
{
$_.each(function(e){
attach_live(e, event, callback);
});
},
delegate: function(target, event, callback)
{
$_.each(function(e){
attach_delegate(e, target, event, callback);
});
}
};
$_.ext('event', e);
}());

View File

@ -1,2 +0,0 @@
//Fix $_ is not defined errors
var $_ = $_ || window.$_;

View File

@ -1,44 +0,0 @@
/**
* Store object
*
* Wrapper for localstorage data serialization
*/
(function (){
var store = {
get: function (key)
{
return JSON.parse(localStorage.getItem(key));
},
set: function (key, value)
{
if (typeof value !== "string")
{
value = JSON.stringify(value);
}
localStorage.setItem(key, value);
},
remove: function (key)
{
localStorage.removeItem(key);
},
getAll: function ()
{
var i,
len,
data;
len = localStorage.length;
data = {};
for (i = 0; i < len; i++)
{
var name = localStorage.key(i);
var value = localStorage.getItem(name);
data[name] = value;
}
return data;
}
};
$_.ext('store', store);
}());

View File

@ -1,97 +0,0 @@
/**
* Util Object
*
* Various object and string manipulation functions
*/
(function(){
var u = {
object_keys: function(o)
{
var keys = [],
k;
for(k in o)
{
if(o.hasOwnProperty(k))
{
keys.push(k);
}
}
return keys;
},
object_values: function(o)
{
var vals = [],
prop;
for(prop in o)
{
vals.push(o[prop]);
}
return vals;
},
object_merge: function()
{
},
reverse_key_sort: function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i,
k,
x;
//Extract the keys
keys = this.object_keys(o);
//Sort the keys
keys.sort(function (b, a) {
var aFloat = parseFloat(a),
bFloat = parseFloat(b),
aNumeric = aFloat + '' === a,
bNumeric = bFloat + '' === b;
if (aNumeric && bNumeric)
{
return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
}
else if (aNumeric && !bNumeric)
{
return 1;
}
else if (!aNumeric && bNumeric)
{
return -1;
}
return a > b ? 1 : a < b ? -1 : 0;
});
//cache object/array size
num_keys = keys.length;
//Recreate the object/array
for(i=0; i < num_keys; i++)
{
k = keys[i];
new_o[k] = o[k];
}
return new_o;
},
str_trans: function(string, from, to)
{
}
};
//Add it to the $_ object
$_.ext('util', u);
}());

View File

@ -214,6 +214,45 @@
});
test("Array combine", function(){
expect(3);
var keys_5 = ["a", "u", "i", "e", "o"];
var keys_obj = {
"x": 2,
"a": 4,
"q": 3,
"r": 1,
"p": "q"
};
var vals_5 = [1, 5, 3, 2, 4];
var vals_4 = [3, 6, 2, 7];
var obj_combined = {
2:1,
4:5,
3:3,
1:2,
"q":4
};
var combined = {
"a":1,
"u":5,
"i":3,
"e":2,
"o":4
};
equal($_.util.array_combine(keys_5, vals_4), false, "Can't combine arrays of different sizes");
deepEqual($_.util.array_combine(keys_obj, vals_5), obj_combined, "Combine with keys as object");
deepEqual($_.util.array_combine(keys_5, vals_5), combined, "Properly combines arrays");
});
test("Reverse Key Sort", function(){
expect(2);
@ -237,6 +276,41 @@
deepEqual($_.util.reverse_key_sort(test_o), test_sorted, "Object sort");
deepEqual($_.util.object_values($_.util.reverse_key_sort(test_array)), test_array_sorted, "Array Sort");
});
test("Object Merge", function(){
expect(2);
var arr1 = {
"color": "red",
0: 2,
1: 4
},
arr2 = {
0: "a",
1: "b",
"color": "green",
"shape": "trapezoid",
2: 4
},
res1 = {
"color": "green",
0: 2,
1: 4,
2: "a",
3: "b",
"shape": "trapezoid",
4: 4
},
arr3 = [],
arr4 = {
1:'value',
},
res2 = {0:'value'};
deepEqual($_.util.object_merge(arr1, arr2), res1, "Merge objects with numeric and test keys");
deepEqual($_.util.object_merge(arr3, arr4), res2, "Merged object has reordered keys");
});