174 lines
4.7 KiB
JavaScript
Executable File
174 lines
4.7 KiB
JavaScript
Executable File
/*
|
|
function addEvent(evt, condition, action) {
|
|
a = this.event[evt].length;
|
|
this.event[evt][a][0] = condition;
|
|
this.event[evt][a][1] = action;
|
|
return a;
|
|
}
|
|
|
|
//function removeEvent(evt,
|
|
*/
|
|
|
|
function DOMExtension () {
|
|
|
|
function addClassName(className) {
|
|
|
|
var exp = new Array();
|
|
var add = true;
|
|
exp[0] = new RegExp("^" + className + " ", 'g');
|
|
exp[1] = new RegExp("^" + className + "$", 'g');
|
|
exp[2] = new RegExp(" " + className + "$", 'g');
|
|
exp[3] = new RegExp(" " + className + " ", 'g');
|
|
|
|
for (var i = 0; i < exp.length; i++) {
|
|
if (exp[i].test(this.className)) add = false;
|
|
}
|
|
if (add) this.className += ' ' + className;
|
|
}
|
|
|
|
function removeClassName(className) {
|
|
|
|
var exp = new Array();
|
|
var switchto = new Array();
|
|
exp[0] = new RegExp("^" + className + " ", 'g');
|
|
exp[1] = new RegExp("^" + className + "$", 'g');
|
|
exp[2] = new RegExp(" " + className + "$", 'g');
|
|
exp[3] = new RegExp(" " + className + " ", 'g');
|
|
switchto[0] = '';
|
|
switchto[1] = '';
|
|
switchto[2] = '';
|
|
switchto[3] = ' ';
|
|
for (var i = 0; i < exp.length; i++) {
|
|
if (exp[i].test(this.className)) {
|
|
this.className = this.className.replace(exp[i], switchto[i]);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getElementsByClassName(className) {
|
|
|
|
var exp = new Array();
|
|
var add = false;
|
|
exp[0] = new RegExp("^" + className + " ", 'g');
|
|
exp[1] = new RegExp("^" + className + "$", 'g');
|
|
exp[2] = new RegExp(" " + className + "$", 'g');
|
|
exp[3] = new RegExp(" " + className + " ", 'g');
|
|
var a = this.getElementsByTagName('*');
|
|
var b = new Array();
|
|
for(var i = 0; i < a.length; i++) {
|
|
add = false;
|
|
for (var j = 0; j < exp.length; j++) {
|
|
if (exp[j].test(a[i].className)) add = true;
|
|
}
|
|
if (add) b[b.length] = a[i];
|
|
}
|
|
return b;
|
|
}
|
|
|
|
|
|
function getElementsByClassNameI(className) {
|
|
|
|
var exp = new Array();
|
|
var add = false;
|
|
exp[0] = new RegExp("^" + className + " ", 'g');
|
|
exp[1] = new RegExp("^" + className + "$", 'g');
|
|
exp[2] = new RegExp(" " + className + "$", 'g');
|
|
exp[3] = new RegExp(" " + className + " ", 'g');
|
|
var a = this.getElementsByTagName('*');
|
|
var b = new Array();
|
|
for(var i = 0; i < a.length; i++) {
|
|
add = false;
|
|
for (var j = 0; j < exp.length; j++) {
|
|
if (exp[j].test(a[i].className)) add = true;
|
|
}
|
|
if (add) b[b.length] = a[i];
|
|
}
|
|
return b;
|
|
}
|
|
|
|
function hasClassName(className) {
|
|
|
|
var exp = new Array();
|
|
var has = false;
|
|
exp[0] = new RegExp("^" + className + " ", 'g');
|
|
exp[1] = new RegExp("^" + className + "$", 'g');
|
|
exp[2] = new RegExp(" " + className + "$", 'g');
|
|
exp[3] = new RegExp(" " + className + " ", 'g');
|
|
|
|
for (var i = 0; i < exp.length; i++) {
|
|
if (exp[i].test(this.className)) has = true;
|
|
}
|
|
return has;
|
|
}
|
|
|
|
function hasClassNameI(className) {
|
|
|
|
var exp = new Array();
|
|
var has = array();;
|
|
|
|
className = className.split(' ');
|
|
|
|
for (var j in className) {
|
|
|
|
exp[0] = new RegExp("^" + className[i] + " ", 'g');
|
|
exp[1] = new RegExp("^" + className[i] + "$", 'g');
|
|
exp[2] = new RegExp(" " + className[i] + "$", 'g');
|
|
exp[3] = new RegExp(" " + className[i] + " ", 'g');
|
|
for (var i = 0; i < exp.length; i++) {
|
|
if (exp[i].test(this.className)) has[j] = true;
|
|
}
|
|
}
|
|
var tot = true;
|
|
for (var i in has) tot = tot && has;
|
|
return tot;
|
|
}
|
|
|
|
|
|
function getChildElementsByTagName(tagName) {
|
|
var b = new Array();
|
|
var at = this.getElementsByTagName('li');
|
|
for(var i = 0; i < at.length; i++) {
|
|
if( at[i].parentNode == this ) b[b.length] = at[i];
|
|
}
|
|
return b;
|
|
}
|
|
|
|
|
|
function prependChild ( newNode ) {
|
|
|
|
if ( this.childNodes.length )
|
|
return this.insertBefore(newNode, this.childNodes[0]);
|
|
|
|
else return this.appendChild(newNode);
|
|
|
|
}
|
|
|
|
|
|
function insertAfter(newNode, node) {
|
|
if (node.nextSibling) return this.insertBefore(newNode, node.nextSibling);
|
|
else return this.appendChild(newNode);
|
|
}
|
|
|
|
document.getElementsByClassName = getElementsByClassName;
|
|
document.getElementsByClassNameI = getElementsByClassNameI;
|
|
|
|
|
|
/*document..getElementsByClassName = getElementsByClassName;
|
|
document.body.addClassName = addClassName;
|
|
document.body.hasClassName = hasClassName;
|
|
document.body.hasClassNameI = hasClassNameI;
|
|
document.body.removeClassName = removeClassName;
|
|
document.body.getChildElementsByTagName = getChildElementsByTagName;
|
|
document.body.insertAfter = insertAfter;*/
|
|
|
|
HTMLElement.prototype.getElementsByClassName = getElementsByClassName;
|
|
HTMLElement.prototype.addClassName = addClassName;
|
|
HTMLElement.prototype.hasClassName = hasClassName;
|
|
HTMLElement.prototype.hasClassNameI = hasClassNameI;
|
|
HTMLElement.prototype.removeClassName = removeClassName;
|
|
HTMLElement.prototype.getChildElementsByTagName = getChildElementsByTagName;
|
|
HTMLElement.prototype.insertAfter = insertAfter;
|
|
HTMLElement.prototype.prependChild = prependChild;
|
|
} |