Misc cleanup

This commit is contained in:
Timothy Warren 2012-03-29 11:48:11 -04:00
parent 51dccdeaf9
commit 04e8f2e3c7
2 changed files with 43 additions and 42 deletions

View File

@ -11,7 +11,7 @@
if (typeof document !== "undefined" && !("classList" in document.createElement("a"))) if (typeof document !== "undefined" && !("classList" in document.createElement("a")))
{ {
(function (view){ (function (view){
var classListProp = "classList", var classListProp = "classList",
protoProp = "prototype", protoProp = "prototype",
elemCtrProto = (view.HTMLElement || view.Element)[protoProp], elemCtrProto = (view.HTMLElement || view.Element)[protoProp],
@ -167,7 +167,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
/** /**
* DOM * DOM
* *
* Dom manipulation module * Dom manipulation module
*/ */
(function (){ (function (){
@ -175,7 +175,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
"use strict"; "use strict";
var d; var d;
//Private function for getting/setting attributes/properties //Private function for getting/setting attributes/properties
function _attr(sel, name, value) function _attr(sel, name, value)
{ {
@ -209,7 +209,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
console.log(value); console.log(value);
console.log(sel); console.log(sel);
console.log("Element does not have the selected attribute"); console.log("Element does not have the selected attribute");
return; return null;
} }
//No value to set? Return the current value //No value to set? Return the current value
@ -228,7 +228,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
else else
{ {
sel[name] = value; sel[name] = value;
} }
} }
else if (value === null) else if (value === null)
{ {
@ -239,12 +239,12 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
else else
{ {
delete sel[name]; delete sel[name];
} }
} }
return (typeof value !== "undefined") ? value : oldVal; return (typeof value !== "undefined") ? value : oldVal;
} }
/** /**
* Change css property name to it's * Change css property name to it's
* javascript camel case equivalent * javascript camel case equivalent
@ -259,7 +259,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
function _css(sel, prop, val) function _css(sel, prop, val)
{ {
var equi; var equi;
//Camel-case //Camel-case
prop = _toCamel(prop); prop = _toCamel(prop);
@ -269,8 +269,8 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
outerWidth: "offsetWidth", outerWidth: "offsetWidth",
top: "posTop" top: "posTop"
}; };
//If you don't define a value, try returning the existing value //If you don't define a value, try returning the existing value
if(typeof val === "undefined" && sel.style[prop] !== "undefined") if(typeof val === "undefined" && sel.style[prop] !== "undefined")
{ {
@ -287,23 +287,23 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
sel.style[prop] = val; sel.style[prop] = val;
//Short circuit //Short circuit
return; return null;
} }
else if(sel.style[equi[prop]]) else if(sel.style[equi[prop]])
{ {
sel.style[equi[prop]] = val; sel.style[equi[prop]] = val;
return; return null;
} }
//No matches? Well, lets log it for now //No matches? Well, lets log it for now
console.log("Property " + prop + " nor an equivalent seems to exist"); console.log("Property " + prop + " nor an equivalent seems to exist");
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* DOM * DOM
* *
* Dom manipulation module * Dom manipulation module
* @namespace * @namespace
* @memberOf $_ * @memberOf $_
@ -313,7 +313,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
/** /**
* Adds a class to the element(s) specified by the current * Adds a class to the element(s) specified by the current
* selector * selector
* *
* @name addClass * @name addClass
* @memberOf $_.dom * @memberOf $_.dom
* @function * @function
@ -328,7 +328,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
/** /**
* Removes a class from the element(s) specified by the current * Removes a class from the element(s) specified by the current
* selector * selector
* *
* @name removeClass * @name removeClass
* @memberOf $_.dom * @memberOf $_.dom
* @function * @function
@ -342,7 +342,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
}, },
/** /**
* Hides the element(s) specified by the current selector * Hides the element(s) specified by the current selector
* *
* @name hide * @name hide
* @memberOf $_.dom * @memberOf $_.dom
* @function * @function
@ -352,11 +352,11 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
this.css('display', 'none'); this.css('display', 'none');
}, },
/** /**
* Shows the element(s) specified by the current selector. * Shows the element(s) specified by the current selector.
* if type is specified, the element will have it's style * if type is specified, the element will have it's style
* property set to "display:[your type]". If type is not * property set to "display:[your type]". If type is not
* specified, the element is set to "display:block". * specified, the element is set to "display:block".
* *
* @name show * @name show
* @memberOf $_.dom * @memberOf $_.dom
* @function * @function
@ -372,8 +372,8 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
this.css("display", type); this.css("display", type);
}, },
/** /**
* Sets attributes on element(s) specified by the current * Sets attributes on element(s) specified by the current
* selector, or, if name is not specified, returns the * selector, or, if name is not specified, returns the
* value of the attribute of the element specified by the * value of the attribute of the element specified by the
* current selector. * current selector.
* *
@ -409,7 +409,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
}, },
/** /**
* Sets or retrieves the text content of the element * Sets or retrieves the text content of the element
* specified by the current selector. If a value is * specified by the current selector. If a value is
* passed, it will set that value on the current element, * passed, it will set that value on the current element,
* otherwise it will return the value of the current element * otherwise it will return the value of the current element
* *
@ -423,11 +423,11 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
text: function (value) text: function (value)
{ {
var oldValue, set, type, sel; var oldValue, set, type, sel;
sel = this.el; sel = this.el;
set = (typeof value !== "undefined") ? true : false; set = (typeof value !== "undefined") ? true : false;
type = (typeof sel.textContent !== "undefined") type = (typeof sel.textContent !== "undefined")
? "textContent" ? "textContent"
: (typeof sel.innerText !== "undefined") : (typeof sel.innerText !== "undefined")
@ -435,7 +435,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
: "innerHTML"; : "innerHTML";
oldValue = sel[type]; oldValue = sel[type];
if(set) if(set)
{ {
sel[type] = value; sel[type] = value;
@ -448,7 +448,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
}, },
/** /**
* Sets or retrieves a css property of the element * Sets or retrieves a css property of the element
* specified by the current selector. If a value is * specified by the current selector. If a value is
* passed, it will set that value on the current element, * passed, it will set that value on the current element,
* otherwise it will return the value of the css property * otherwise it will return the value of the css property
* on the current element * on the current element
@ -468,14 +468,14 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
{ {
return _css(this.el, prop); return _css(this.el, prop);
} }
$_.each(function (e){ $_.each(function (e){
_css(e, prop, val); _css(e, prop, val);
}); });
}, },
/** /**
* Adds to the innerHTML of the current element, after the last child. * Adds to the innerHTML of the current element, after the last child.
* *
* @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element * @example $_("ul").dom.append("<li></li>") adds an li element to the end of the selected ul element
* @name append * @name append
* @memberOf $_.dom * @memberOf $_.dom
@ -495,7 +495,7 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
}, },
/** /**
* Adds to the innerHTML of the selected element, before the current children * Adds to the innerHTML of the selected element, before the current children
* *
* @name prepend * @name prepend
* @memberOf $_.dom * @memberOf $_.dom
* @function * @function
@ -524,17 +524,17 @@ if (typeof document !== "undefined" && !("classList" in document.createElement("
*/ */
html: function(htm) html: function(htm)
{ {
if(typeof htm !== "undefined") if(typeof htm !== "undefined")
{ {
this.el.innerHTML = htm; this.el.innerHTML = htm;
} }
//If the parameter is undefined, just return the current value //If the parameter is undefined, just return the current value
return this.el.innerHTML; return this.el.innerHTML;
} }
}; };
$_.ext('dom', d); $_.ext('dom', d);
}()); }());

View File

@ -6,7 +6,7 @@
(function (){ (function (){
"use strict"; "use strict";
// Don't bother even defining the object if the XMLHttpRequest isn't available // Don't bother even defining the object if the XMLHttpRequest isn't available
if(typeof window.XMLHttpRequest === "undefined") if(typeof window.XMLHttpRequest === "undefined")
{ {
@ -16,9 +16,9 @@
var ajax = { var ajax = {
_do: function (url, data, callback, isPost) _do: function (url, data, callback, isPost)
{ {
var type, var type,
request = new XMLHttpRequest(); request = new XMLHttpRequest();
if (typeof callback === "undefined") if (typeof callback === "undefined")
{ {
/** /**
@ -30,7 +30,7 @@
type = (isPost) ? "POST" : "GET"; type = (isPost) ? "POST" : "GET";
url += (type === "GET") ? "?"+this._serialize(data) : ''; url += (type === "GET") ? "?"+this._serialize(data) : '';
request.open(type, url); request.open(type, url);
request.onreadystatechange = function () request.onreadystatechange = function ()
@ -82,7 +82,7 @@
/** /**
* Sends a GET type ajax request * Sends a GET type ajax request
* *
* @name get * @name get
* @function * @function
* @memberOf $_ * @memberOf $_
@ -93,10 +93,10 @@
$_.ext('get', function (url, data, callback){ $_.ext('get', function (url, data, callback){
ajax._do(url, data, callback, false); ajax._do(url, data, callback, false);
}); });
/** /**
* Sends a POST type ajax request * Sends a POST type ajax request
* *
* @name post * @name post
* @function * @function
* @memberOf $_ * @memberOf $_
@ -107,4 +107,5 @@
$_.ext('post', function (url, data, callback){ $_.ext('post', function (url, data, callback){
ajax._do(url, data, callback, true); ajax._do(url, data, callback, true);
}); });
}()); }());