mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-06 22:29:44 +08:00
35 lines
927 B
JavaScript
35 lines
927 B
JavaScript
(function(ionic) {
|
|
ionic.DomUtil = {
|
|
getChildIndex: function(element) {
|
|
return Array.prototype.slice.call(element.parentNode.children).indexOf(element);
|
|
},
|
|
swapNodes: function(src, dest) {
|
|
dest.parentNode.insertBefore(src, dest);
|
|
},
|
|
/**
|
|
* {returns} the closest parent matching the className
|
|
*/
|
|
getParentWithClass: function(e, className) {
|
|
while(e.parentNode) {
|
|
if(e.parentNode.classList && e.parentNode.classList.contains(className)) {
|
|
return e.parentNode;
|
|
}
|
|
e = e.parentNode;
|
|
}
|
|
return null;
|
|
},
|
|
/**
|
|
* {returns} the closest parent or self matching the className
|
|
*/
|
|
getParentOrSelfWithClass: function(e, className) {
|
|
while(e) {
|
|
if(e.classList && e.classList.contains(className)) {
|
|
return e;
|
|
}
|
|
e = e.parentNode;
|
|
}
|
|
return null;
|
|
}
|
|
};
|
|
})(window.ionic);
|