MIT-style license.
Takashi Mizohata beatak@nydd.org
2008 [nydd](http://code.nydd.org/).
[nydd jslib](http://code.nydd.org/).
Everything is worthwhile / if the soul isn’t small.
| DOMUtility | MIT-style license. |
| Functions | |
| isDOMNode | Detetect DOM Element or not. |
| removeAllChildren | Remove all child nodes. |
| addCSS | Add css safely. |
| addCSSHover | Shortcut for addCSS with css name “hover” |
| removeCSS | [FIX ME] It there are multiple name added on the element, it should remove everything. |
| removeCSSHover | Shortcut for removeCSS with css name “hover” |
| defer | [FIX ME] not completely done yet. |
| waitUntilVariable | Fires function after the given name is ready on global scope. |
| waitUntilImgLoaded | Fires function after the given DOM Element <img> is ready. |
| findInUpstream | Find a DOMNode on upstream side (parent side) by the given criteria. |
DOMUtility.isDOMNode = function ( obj )
Detetect DOM Element or not. It is using object detection methodology based on [DOM Core Level 1](http://www.w3.org
static
| obj | instance of DOM Element |
if (DOMUtility.isDOMNode(document)) ...
(Boolean)
DOMUtility.removeAllChildren = function ( parent )
Remove all child nodes. It will not take care of garbage collection. If some of child elements has Event handler and registered in Event chain, this may occur a memory leak. Use with caution.
static
| parent | instance of DOM Element |
DOMUtility.removeAllChildren(document.body))
undefined
DOMUtility.addCSS = function ( elm, name, regex )
Add css safely. If the given css name is already on the element, it will not add more.
static
| elm | instance of DOM Element |
| name | (String) name of css |
| regex | [option] (Regex) just for optimization purpose. |
DOMUtility.addCSS(document.body, ‘good’));
(Boolean) true if this affects to elm.
DOMUtility.removeCSS = function ( elm, name, regex )
[FIX ME] It there are multiple name added on the element, it should remove everything. Remove css safely.
static
| elm | instance of DOM Element |
| name | (String) name of css |
| regex | [option] (Regex) just for optimization purpose. |
DOMUtility.removeCSS(document.body, ‘good’));
Array.prototype.vacuum(). See Array
(Boolean) true if this affects element.
DOMUtility.defer = function ( targets, func )
[FIX ME] not completely done yet. Fires function after the given element(s) is ready. It only works with <img> and String. Maybe I’d like to work with Script elements as well.
static
| targets | jQuery object, or String |
| func | (Function) be fired when all targets are ready. |
DOMUtility.defer($(‘img.logo’), function(){alert(‘done’)});
(Boolean) true, if it sets correctly; Otherwise false.
DOMUtility.waitUntilVariable = function ( word, callback )
Fires function after the given name is ready on global scope.
static
| word | (String) expected variable name |
| callback | (Function) be fired when word is ready. |
DOMUtility.waitUntilVariable(‘myvar’, function(){alert(‘done’)});
undefined
DOMUtility.waitUntilImgLoaded = function ( elmImg, callback )
Fires function after the given DOM Element <img> is ready.
static
| elmImg | (DOM Element) image element |
| callback | (Function) be fired when word is ready. |
DOMUtility.waitUntilImgLoaded(document.getElementById(‘logo’), function(){alert(‘done’)});
undefined
DOMUtility.findInUpstream = function ( dom, obj )
Find a DOMNode on upstream side (parent side) by the given criteria. If nothing hits, will return null.
static
| dom | DOM Element |
| obj | object represents criteria. |
hit = DOMUtility.findInUpstream(dom_child, {‘nodeName’: ‘address’})
(DOMNode) or null.
Detetect DOM Element or not.
DOMUtility.isDOMNode = function ( obj )
Remove all child nodes.
DOMUtility.removeAllChildren = function ( parent )
Add css safely.
DOMUtility.addCSS = function ( elm, name, regex )
Shortcut for addCSS with css name “hover”
DOMUtility.addCSSHover = function ( elm )
[FIX ME] It there are multiple name added on the element, it should remove everything.
DOMUtility.removeCSS = function ( elm, name, regex )
Shortcut for removeCSS with css name “hover”
DOMUtility.removeCSSHover = function ( elm )
[FIX ME] not completely done yet.
DOMUtility.defer = function ( targets, func )
Fires function after the given name is ready on global scope.
DOMUtility.waitUntilVariable = function ( word, callback )
Fires function after the given DOM Element img is ready.
DOMUtility.waitUntilImgLoaded = function ( elmImg, callback )
Find a DOMNode on upstream side (parent side) by the given criteria.
DOMUtility.findInUpstream = function ( dom, obj )