Added start of util module, removed ..dom.children function

This commit is contained in:
Timothy Warren 2011-10-20 17:31:29 -04:00
parent c15fff3b4b
commit db76e16393
7 changed files with 130 additions and 150 deletions

View File

@ -146,6 +146,18 @@ functions:
Set: $_(selector).dom.css(property, value);
Get: $_(selector).dom.css(property);
### Util: Array and string manipulation functions ###
** functions:**
* object_keys: Gets the name of the properties of an object
$_.util.object_keys(object);
* object_values: Gets the values of the top-level members of an object
$_.util.object_values(object);

View File

@ -27,11 +27,11 @@
if (typeof a !== "string" || typeof a === "undefined"){ return a;}
//Pick the quickest method for each kind of selector
if(a.match(/^#([\w\-]+$)/))
if (a.match(/^#([\w\-]+$)/))
{
return document.getElementById(a.split('#')[1]);
}
else if(a.match(/^([\w\-]+)$/))
else if (a.match(/^([\w\-]+)$/))
{
x = document.getElementsByTagName(a);
}
@ -62,6 +62,9 @@
{
sel = (typeof s !== "object") ? $(s) : s;
}
// Add the selector to the prototype
$_.prototype.el = sel;
// Make a copy before adding properties
var self = dcopy($_);
@ -478,45 +481,6 @@
console.log("Property " + prop + " nor an equivalent seems to exist");
}
function _sel_filter(filter, curr_sel)
{
var i,
len = curr_sel.length,
matches = [];
//Filter by tag
if(filter.match(tag_reg))
{
for(i=0;i<len;i++)
{
if(curr_sel[i].tagName.toLowerCase() == filter.toLowerCase())
{
matches.push(curr_sel[i]);
}
}
}
else if(filter.match(class_reg))
{
//Remove the .
filter = filter.replace(".", "");
for(i=0;i<len;i++)
{
if(curr_sel[i].classList.contains(filter))
{
matches.push(curr_sel[i]);
}
}
}
else
{
console.log(filter+" is not a valid filter");
}
return (matches.length == 1) ? matches[0] : matches;
}
// --------------------------------------------------------------------------
d = {
@ -604,30 +568,6 @@
$_.each(function (e){
_css(e, prop, val);
});
},
children: function(filter)
{
//Return the children directly, if there is no filter
if(typeof filter === "undefined")
{
return $_(this.el.children);
}
var childs = (typeof this.el.children !== "undefined") ? this.el.children : this.el;
if($_.type(filter) !== "string")
{
return $_(filter);
}
else if(filter.match(/#([\w\-]+$)/))
{
return $_($_.$(filter));
}
else
{
var filtered = _sel_filter(filter, childs);
return $_(filtered);
}
}
};
@ -859,6 +799,49 @@
// --------------------------------------------------------------------------
/**
* Util Object
*
* Various object and string manipulation functions
*/
(function(){
var u = {
object_keys: function(o)
{
var keys = [],
key;
for(key in o)
{
if(o.hasOwnProperty(key))
{
keys.push(key);
}
}
return keys;
},
object_values: function(o)
{
var vals = [],
prop;
for(prop in o)
{
vals.push(o[prop]);
}
return vals;
}
};
//Add it to the $_ object
$_.ext('util', u);
}());
// --------------------------------------------------------------------------
/**
* Event object
*

35
kis-min.js vendored
View File

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

View File

@ -284,45 +284,6 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
console.log("Property " + prop + " nor an equivalent seems to exist");
}
function _sel_filter(filter, curr_sel)
{
var i,
len = curr_sel.length,
matches = [];
//Filter by tag
if(filter.match(tag_reg))
{
for(i=0;i<len;i++)
{
if(curr_sel[i].tagName.toLowerCase() == filter.toLowerCase())
{
matches.push(curr_sel[i]);
}
}
}
else if(filter.match(class_reg))
{
//Remove the .
filter = filter.replace(".", "");
for(i=0;i<len;i++)
{
if(curr_sel[i].classList.contains(filter))
{
matches.push(curr_sel[i]);
}
}
}
else
{
console.log(filter+" is not a valid filter");
}
return (matches.length == 1) ? matches[0] : matches;
}
// --------------------------------------------------------------------------
d = {
@ -410,30 +371,6 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
$_.each(function (e){
_css(e, prop, val);
});
},
children: function(filter)
{
//Return the children directly, if there is no filter
if(typeof filter === "undefined")
{
return $_(this.el.children);
}
var childs = (typeof this.el.children !== "undefined") ? this.el.children : this.el;
if($_.type(filter) !== "string")
{
return $_(filter);
}
else if(filter.match(/#([\w\-]+$)/))
{
return $_($_.$(filter));
}
else
{
var filtered = _sel_filter(filter, childs);
return $_(filtered);
}
}
};

View File

@ -27,11 +27,11 @@
if (typeof a !== "string" || typeof a === "undefined"){ return a;}
//Pick the quickest method for each kind of selector
if(a.match(/^#([\w\-]+$)/))
if (a.match(/^#([\w\-]+$)/))
{
return document.getElementById(a.split('#')[1]);
}
else if(a.match(/^([\w\-]+)$/))
else if (a.match(/^([\w\-]+)$/))
{
x = document.getElementsByTagName(a);
}
@ -62,6 +62,9 @@
{
sel = (typeof s !== "object") ? $(s) : s;
}
// Add the selector to the prototype
$_.prototype.el = sel;
// Make a copy before adding properties
var self = dcopy($_);

40
src/util.js Normal file
View File

@ -0,0 +1,40 @@
/**
* Util Object
*
* Various object and string manipulation functions
*/
(function(){
var u = {
object_keys: function(o)
{
var keys = [],
key;
for(key in o)
{
if(o.hasOwnProperty(key))
{
keys.push(key);
}
}
return keys;
},
object_values: function(o)
{
var vals = [],
prop;
for(prop in o)
{
vals.push(o[prop]);
}
return vals;
}
};
//Add it to the $_ object
$_.ext('util', u);
}());

View File

@ -177,7 +177,7 @@
equal($test.dom.css("display"), "block", "Getting CSS");
});
test("Children", function(){
/*test("Children", function(){
var $test = $_("section");
var ele = $("section");
var ele2 = $_("section aside").el;
@ -186,6 +186,12 @@
equal($_("section").dom.children('#r14').el, document.getElementById('r14'), "Finds id");
equal($_("section").dom.children("aside").el, ele2, "Finds children by tag name");
equal($_("section aside").dom.children(".child").el, $_("#classChild .child").el, "Finds children by class");
});
});*/
// --------------------------------------------------------------------------
module("util");
}());