Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
DOM=function(){function b(c){if(c&&typeof c==="string"){c=document.getElementById(c)}return c||null}function a(e,c,d,i,g){var f=b(e)[i||d],h=g?[]:null;while(f){if(f.nodeType===1&&(!c||f.tagName.toLowerCase()===c)){if(!g){return f}h.push(f)}f=f[d]}return h}return{get:b,walk:a,getPrevious:function(d,c){return a(d,c,"previousSibling")},getAllPrevious:function(d,c){return a(d,c,"previousSibling",null,true)},getNext:function(d,c){return a(d,c,"nextSibling")},getAllNext:function(d,c){return a(d,c,"nextSibling",null,true)},getFirst:function(d,c){return a(d,c,"nextSibling","firstChild")},getLast:function(d,c){return a(d,c,"previousSibling","lastChild")},getParent:function(d,c){return a(d,c,"parentNode")},getParents:function(d,c){return a(d,c,"parentNode",null,true)},getChildren:function(d,c){return a(d,c,"nextSibling","firstChild",true)},dispose:function(c){c=b(c);return(c.parentNode)?c.parentNode.removeChild(c):c}}}();
/**
* Simple DOM traversing copied from MooTools.
*/
DOM = function () {
function get(id) {
if (id && typeof id === 'string') {
id = document.getElementById(id);
}
return id || null;
}
function walk(element, tag, walk, start, all) {
var el = get(element)[start || walk], elements = all ? [] : null;
while (el) {
if (el.nodeType === 1 && (!tag || el.tagName.toLowerCase() === tag)) {
if (!all) {
return el;
}
elements.push(el);
}
el = el[walk];
}
return elements;
}
return {
// Get the element by its id
get: get,
walk: walk,
// Returns the previousSibling of the Element (excluding text nodes).
getPrevious: function (el, tag) {
return walk(el, tag, 'previousSibling');
},
// Like getPrevious, but returns a collection of all the matched previousSiblings.
getAllPrevious: function (el, tag) {
return walk(el, tag, 'previousSibling', null, true);
},
// As getPrevious, but tries to find the nextSibling (excluding text nodes).
getNext: function (el, tag) {
return walk(el, tag, 'nextSibling');
},
// Like getNext, but returns a collection of all the matched nextSiblings.
getAllNext: function (el, tag) {
return walk(el, tag, 'nextSibling', null, true);
},
// Works as getPrevious, but tries to find the firstChild (excluding text nodes).
getFirst: function (el, tag) {
return walk(el, tag, 'nextSibling', 'firstChild');
},
// Works as getPrevious, but tries to find the lastChild.
getLast: function (el, tag) {
return walk(el, tag, 'previousSibling', 'lastChild');
},
// Works as getPrevious, but tries to find the parentNode.
getParent: function (el, tag) {
return walk(el, tag, 'parentNode');
},
// Like getParent, but returns a collection of all the matched parentNodes up the tree.
getParents: function (el, tag) {
return walk(el, tag, 'parentNode', null, true);
},
// Returns all the Element's children (excluding text nodes).
getChildren: function (el, tag) {
return walk(el, tag, 'nextSibling', 'firstChild', true);
},
// Removes the Element from the DOM.
dispose: function (el) {
el = get(el);
return (el.parentNode) ? el.parentNode.removeChild(el) : el;
}
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.