Readme formatting, and start of DOM .children function

This commit is contained in:
Timothy Warren 2011-07-26 15:29:30 -04:00
parent f8350e516a
commit 1c014459df
2 changed files with 339 additions and 259 deletions

View File

@ -16,7 +16,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
* Function: `$_(selector).module.function(params);` * Function: `$_(selector).module.function(params);`
## Official Modules: ## ## Official Modules: ##
**Global**: Core functions ###Global###: Core functions
properties: properties:
@ -39,7 +39,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
Adds 'zip' function to $_. Adds 'zip' function to $_.
**Ajax**: simple, jQuery-like ajax functions ###Ajax###: simple, jQuery-like ajax functions
functions: functions:
@ -51,7 +51,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
Use: Use:
$_.post(url, data_object, callback); $_.post(url, data_object, callback);
**QS**: querystring parsing and serialization for hashbang strings, and pushState urls ###QS###: querystring parsing and serialization for hashbang strings, and pushState urls
functions: functions:
@ -67,7 +67,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
Use: Use:
$_.qs.get(key); $_.qs.get(key);
**Store**: localstorage wrapper with automatic data serialization ###Store###: localstorage wrapper with automatic data serialization
functions: functions:
@ -84,7 +84,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
$_.store.getAll(); $_.store.getAll();
**Event**: wrapper for applying events to DOM objects ###Event###: wrapper for applying events to DOM objects
functions: functions:
@ -96,9 +96,9 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
Use: Use:
$_(selector).event.remove(event, callback); $_(selector).event.remove(event, callback);
**DOM**: Dom manipulation module ###DOM###: Dom manipulation module
function: functions:
*addClass: *addClass:
Use: Use:
@ -130,7 +130,7 @@ Browser support: IE8+, Latest versions of Firefox, Chrome, Safari, Opera
*css: Sets css styles on the selected element(s) *css: Sets css styles on the selected element(s)
Use: Use:
Set: $_(selector).dom.css(property, value); Set: $_(selector).dom.css(property, value);
Get: $_(selector).dom.css(property);

View File

@ -1,10 +1,3 @@
/**
* Dom manipulation object
*
*/
(function (){
var d;
/* /*
* classList.js: Cross-browser full element.classList implementation. * classList.js: Cross-browser full element.classList implementation.
* 2011-06-15 * 2011-06-15
@ -161,6 +154,18 @@
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/**
* Dom manipulation object
*
*/
(function (){
var d, tag_reg, id_reg, class_reg;
tag_reg = /^([\w\-]+)$/;
id_reg = /#([\w\-]+$)/;
class_reg = /\.([\w\-]+)$/;
//Private function for getting/setting attributes //Private function for getting/setting attributes
function _attr(sel, name, value) function _attr(sel, name, value)
{ {
@ -280,6 +285,62 @@
console.log("Property " + prop + " nor an equivalent seems to exist"); console.log("Property " + prop + " nor an equivalent seems to exist");
} }
function _sel_filter(filter, curr_sel)
{
var i,
len = curr_sel.length,
matches = [];
if(typeof filter !== "string")
{
return filter;
}
//Filter by tag
if(filter.match(tag_reg))
{
for(i=0;i<len;i++)
{
if(curr_sell[i].tagName.toLowerCase() == filter.toLowerCase())
{
matches.push(curr_sel[i]);
}
}
}
else if(filter.match(class_reg))
{
for(i=0;i<len;i++)
{
if(curr_sel[i].classList.contains(filter))
{
matches.push(curr_sel[i]);
}
}
}
else if(filter.match(id_reg))
{
return document.getElementById(filter);
}
else
{
console.log(filter+" is not a valid filter");
}
return (matches.length === 1) ? matches[0] : matches;
}
function _set_sel(sel)
{
for(var i in $_)
{
if(typeof $_[i] === "object")
{
$_[i].el = sel;
}
}
}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
d = { d = {
@ -367,6 +428,25 @@
$_.each(function (e){ $_.each(function (e){
_css(e, prop, val); _css(e, prop, val);
}); });
},
children: function(filter)
{
var sel;
if(typeof sel === "undefined")
{
sel = this.el.children;
}
else
{
sel = _sel_filter(filter, this.el.children);
}
//Update the $_ object to reflect the new selector
_set_sel(sel);
//Return the $_ object for chaining
return $_
} }
}; };