Updated selector function to add context, privitized reverse_key_sort function in util module

This commit is contained in:
Timothy Warren 2011-10-31 11:56:59 -04:00
parent 2cefaa19aa
commit d1f1af40ae
9 changed files with 145 additions and 154 deletions

1
.gitignore vendored
View File

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

View File

@ -149,7 +149,7 @@ functions:
### Util: Array and string manipulation functions ###
** functions: **
**functions:**
* object_keys: Gets the name of the properties of an object

View File

@ -21,23 +21,25 @@
*
* Simple DOM selector function
*/
$ = function (a)
$ = function (a, context)
{
var x;
var x, c;
if (typeof a !== "string" || typeof a === "undefined"){ return a;}
//Check for a context of a specific element, otherwise, just run on the document
c = (typeof context === 'object' && context.nodeType === 1)
? context
: document;
//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);
x = c.querySelectorAll(a);
}
//Return the single object if applicable
@ -54,6 +56,7 @@
//Have documentElement be default selector, just in case
if(typeof s === "undefined")
{
//Defines a "global" selector for that instance
sel = (typeof $_.el !== "undefined")
? $_.el
: document.documentElement;
@ -157,7 +160,7 @@
}
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
};
//Set global variables
$_ = window.$_ = window.$_ || $_;
@ -799,52 +802,53 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
"use strict";
var u = {
reverse_key_sort: function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
var
reverse_key_sort = function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
//Extract the keys
keys = this.object_keys(o);
//Extract the keys
keys = u.object_keys(o);
//Sort the keys
keys.sort(function (b, a) {
var aFloat = parseFloat(a),
bFloat = parseFloat(b),
aNumeric = aFloat + '' === a,
bNumeric = bFloat + '' === b;
//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++)
if (aNumeric && bNumeric)
{
new_o[keys[i]] = o[keys[i]];
return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
}
else if (aNumeric && !bNumeric)
{
return 1;
}
else if (!aNumeric && bNumeric)
{
return -1;
}
return new_o;
},
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++)
{
new_o[keys[i]] = o[keys[i]];
}
return new_o;
},
u = {
object_keys: function(o)
{
var keys = [],
@ -1003,7 +1007,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
{
// Sort the keys in descending order for better
// replacement functionality
from = this.reverse_key_sort(from);
from = reverse_key_sort(from);
for(f in from)
{
@ -1035,19 +1039,11 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
stry = str.charAt(i+1);
for(j=0; j < from_len; j++)
{
/*if(from_len !== to_len)
if(strx == from.charAt(j))
{
//Double check matches when the strings are different lengths
match = true;
break;
}
else
{*/
if(strx == from.charAt(j))
{
match = true;
break;
}
//}
}
}
else

44
kis-min.js vendored
View File

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

View File

@ -21,23 +21,25 @@
*
* Simple DOM selector function
*/
$ = function (a)
$ = function (a, context)
{
var x;
var x, c;
if (typeof a !== "string" || typeof a === "undefined"){ return a;}
//Check for a context of a specific element, otherwise, just run on the document
c = (typeof context === 'object' && context.nodeType === 1)
? context
: document;
//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);
x = c.querySelectorAll(a);
}
//Return the single object if applicable
@ -54,6 +56,7 @@
//Have documentElement be default selector, just in case
if(typeof s === "undefined")
{
//Defines a "global" selector for that instance
sel = (typeof $_.el !== "undefined")
? $_.el
: document.documentElement;
@ -157,7 +160,7 @@
}
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
};
//Set global variables
$_ = window.$_ = window.$_ || $_;

View File

@ -8,52 +8,53 @@
"use strict";
var u = {
reverse_key_sort: function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
var
reverse_key_sort = function(o)
{
//Define some variables
var keys = [],
num_keys = 0,
new_o = {},
i;
//Extract the keys
keys = this.object_keys(o);
//Extract the keys
keys = u.object_keys(o);
//Sort the keys
keys.sort(function (b, a) {
var aFloat = parseFloat(a),
bFloat = parseFloat(b),
aNumeric = aFloat + '' === a,
bNumeric = bFloat + '' === b;
//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++)
if (aNumeric && bNumeric)
{
new_o[keys[i]] = o[keys[i]];
return aFloat > bFloat ? 1 : aFloat < bFloat ? -1 : 0;
}
else if (aNumeric && !bNumeric)
{
return 1;
}
else if (!aNumeric && bNumeric)
{
return -1;
}
return new_o;
},
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++)
{
new_o[keys[i]] = o[keys[i]];
}
return new_o;
},
u = {
object_keys: function(o)
{
var keys = [],
@ -212,7 +213,7 @@
{
// Sort the keys in descending order for better
// replacement functionality
from = this.reverse_key_sort(from);
from = reverse_key_sort(from);
for(f in from)
{
@ -244,19 +245,11 @@
stry = str.charAt(i+1);
for(j=0; j < from_len; j++)
{
/*if(from_len !== to_len)
if(strx == from.charAt(j))
{
//Double check matches when the strings are different lengths
match = true;
break;
}
else
{*/
if(strx == from.charAt(j))
{
match = true;
break;
}
//}
}
}
else

View File

@ -1,5 +1,5 @@
/**
* QUnit - A JavaScript Unit Testing Framework
* QUnit 1.2.0pre - A JavaScript Unit Testing Framework
*
* http://docs.jquery.com/QUnit
*

View File

@ -6,8 +6,6 @@
* Copyright (c) 2011 John Resig, Jörn Zaefferer
* Dual licensed under the MIT (MIT-LICENSE.txt)
* or GPL (GPL-LICENSE.txt) licenses.
* Pulled Live from Git Fri Oct 21 15:55:01 UTC 2011
* Last Commit: ee156923cdb01820e35e6bb579d5cf6bf55736d4
*/
(function(window) {

View File

@ -1,5 +1,5 @@
(function(){
//"use strict";
"use strict";
//Selector test function
function $(a)
@ -253,7 +253,7 @@
});
test("Reverse Key Sort", function(){
/*test("Reverse Key Sort", function(){
expect(2);
var test_o = {
@ -275,7 +275,7 @@
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);