⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 common.js

📁 WAPmo手机网站管理平台是一款创建与管理维护WAP网站的的软件产品
💻 JS
字号:
if (/gecko/i.test(window.navigator.userAgent))
{
    Event.prototype.__defineGetter__("srcElement", function()
    {
        var node = this.target;
        while (node.nodeType != 1) node = node.parentNode;
        return node;
    });
    Event.prototype.__defineGetter__("fromElement", function()
    {
        var node = null;
        if (this.type == "mouseover")
        {
            node = this.relatedTarget;
        }
        else if (this.type == "mouseout")
        {
            node = this.target;
        }
        while (node && node.nodeType != 1) node = node.parentNode;
        return node;
    });
    Event.prototype.__defineGetter__("toElement", function()
    {
        var node = null;
        if (this.type == "mouseover")
        {
            node = this.target;
        }
        else if (this.type == "mouseout")
        {
            node = this.relatedTarget;
        }
        while (node && node.nodeType != 1) node = node.parentNode;
        return node;
    });
    Event.prototype.__defineGetter__("offsetX", function()
    {
        return this.layerX;
    });
    Event.prototype.__defineGetter__("offsetY", function()
    {
        return this.layerY;
    });
    Event.prototype.__defineSetter__("returnValue", function(b)
    {
        if (!b) this.preventDefault();
        return b;
    });
    Event.prototype.__defineSetter__("cancelBubble", function(b)
    {
        if (b) this.stopPropagation();
        return b;
    });
    HTMLElement.prototype.__defineGetter__("innerText", function()
    {
        return this.textContent;
    });
    HTMLElement.prototype.__defineSetter__("innerText", function(str)
    {
        this.textContent = str;
    });
    window.constructor.prototype.__defineGetter__("event", function()
    {
        var obj = arguments.callee.caller;
        var ev;
        while(obj != null)
        {
            ev = obj.arguments[0];
            if(ev && (ev.constructor == Event || ev.constructor == MouseEvent)) return ev;
            obj = obj.caller;
        }
        return null;
    });
    HTMLElement.prototype.__defineGetter__("canHaveChildren", function()
    {
        switch (this.tagName)
        {
        case "AREA":
        case "BASE":
        case "BASEFONT":
        case "COL":
        case "FRAME":
        case "HR":
        case "IMG":
        case "BR":
        case "INPUT":
        case "ISINDEX":
        case "LINK":
        case "META":
        case "PARAM":
        return false;
        }
        return true;
    });
    HTMLElement.prototype.__defineGetter__("outerHTML", function()
    {
        var attr, attrs = this.attributes;
        var str = "<" + this.tagName;
        for (var i = 0; i < attrs.length; i++)
        {
            attr = attrs[i];
            if (attr.specified)
                str += " " + attr.name + '="' + attr.value + '"';
        }
        if (!this.canHaveChildren) return str + ">";
        return str + ">" + this.innerHTML + "</" + this.tagName + ">";
    });
    HTMLElement.prototype.__defineSetter__("outerHTML", function(str)
    {
        var rag = this.ownerDocument.createRange();
        rag.setStartBefore(this);
        var ctx = r.createContextualFragment(str);
        this.parentNode.replaceChild(ctx, this);
        return str;
    });
    Window.prototype.attachEvent = HTMLDocument.prototype.attachEvent = HTMLElement.prototype.attachEvent = function(handle, func)
    {
        this.addEventListener(handle.substr(2), func, false);
    };
    Window.prototype.detachEvent = HTMLDocument.prototype.detachEvent = HTMLElement.prototype.detachEvent = function(handle, func)
    {
        this.removeEventListener(handle.substr(2), func, false);
    };
}

if (!window.XMLHttpRequest)
{
    window.XMLHttpRequest = function()
    {
        return new ActiveXObject("Microsoft.XMLHTTP");
    };
}

function $(id)
{
    return document.getElementById(id);
}

function getOffset(obj)
{
    var x = obj.offsetLeft;
    var y = obj.offsetTop;
    var r = obj.offsetWidth;
    var b = obj.offsetHeight;
    while((obj = obj.offsetParent) != null)
    {
        x += obj.offsetLeft;
        y += obj.offsetTop;
    }
    r += x;
    b += y;
    return({"left" : x, "top" : y, "right" : r, "bottom" : b});
}

function AddListener(obj, handle, func)
{
    var argv = Array.prototype.slice.call(arguments, 3);
    var newFunc = function()
    {
        func.apply(null, argv);
    };
    obj.attachEvent(handle, newFunc);
}

function AddInterval(func, ms)
{
    var argv = Array.prototype.slice.call(arguments, 2);
    var newFunc = function()
    {
        func.apply(null, argv);
    };
    return window.setInterval(newFunc, ms);
}

function AppendText(obj, str)
{
    if (document.selection)
    {
        obj.focus();
        var ptr = document.selection.createRange();
        ptr.text = str;
    }
    else
    {
        obj.focus();
        obj.value = obj.value.substring(0, obj.selectionStart) + str + obj.value.substring(obj.selectionEnd);
    }
}

var PopupMenu = function(id, w)
{
    this.id = id;
    this.width = w;
    this.element = $(id);
    this.list = [];
    this.intel = null;
};

PopupMenu.prototype.add = function(text, dest)
{
    this.list.push([text, dest]);
};

PopupMenu.prototype.start = function()
{
    var core = this;
    if (core.element == null) return false;
    core.element.onmouseover = function()
    {
        core.clearInterval();
        var div = $(core.id + "Div");
        if (div == null)
        {
            div = document.createElement("DIV");
            div.id = core.id + "Div";
            div.className = "CMenu";
            div.style.width = core.width + "px";
            for (var i = 0; i < core.list.length; i++)
            {
                div.appendChild(core.Item(core.list[i][0], core.list[i][1]));
            }
            document.body.appendChild(div);
        }
        div.style.display = "";
        div.style.zIndex = 1;
        var offset = getOffset(core.element);
        if (offset.left + div.offsetWidth > document.body.clientWidth)
        {
            div.style.left = (offset.right - div.offsetWidth) + "px";
        }
        else
        {
            div.style.left = offset.left + "px";
        }
        div.style.top = offset.bottom + "px";
    };
    core.element.onmouseout = function()
    {
        core.setInterval();
    };
}

PopupMenu.prototype.OnMouseOver = function(me)
{
    var div = $(me.id + "Div");
    if (div == null)
    {
        div = document.createElement("DIV");
        div.id = me.id + "Div";
        div.className = "CMenu";
        for (var i = 0; i < me.list.length; i++)
        {
            div.appendChild(me.Item(me.list[i][0], me.list[i][1]));
        }
        document.body.appendChild(div);
    }
    div.style.display = "";
    div.style.zIndex = 1;
    var offset = getOffset(me.element);
    div.style.left = offset.left + "px";
    div.style.top = offset.bottom + "px";
};

PopupMenu.prototype.Item = function(text, dest)
{
    var core = this;
    var div = document.createElement("DIV");
    div.id = core.id + "Item"
    div.className = "CMenuItem";
    div.innerHTML = text;
    div.onclick = function()
    {
        if (typeof dest == "function")
        {
            dest();
        }
        else
        {
            location.href = dest;
        }
    };
    div.onmouseover = function()
    {
        this.className = "CMenuItemOver";
        core.clearInterval();
    };
    div.onmouseout = function()
    {
        this.className = "CMenuItem";
        core.setInterval();
    };
    return div;
};

PopupMenu.prototype.setInterval = function()
{
    var core = this;
    core.intel = AddInterval(core.close, 100, core);
};

PopupMenu.prototype.clearInterval = function()
{
    var core = this;
    if (core.intel)
    {
        window.clearInterval(core.intel);
        core.intel = null;
    }
};

PopupMenu.prototype.close = function(core)
{
    var div = $(core.id + "Div");
    if (div) div.style.display = "none";
    core.clearInterval();
};

var ImageCombox = function(name, w, h)
{
    var core = this;
    core.state = false;
    core.index = 0;
    core.option = null;
    core.com = document.createElement("INPUT");
    core.com.type = "hidden";
    core.com.name = name;
    core.list = [];
    core.box = document.createElement("TABLE");
    core.box.cellPadding = "0";
    core.box.cellSpacing = "0";
    core.box.width = (w + 15) + "px";
    core.box.height = h + "px";
    core.box.style.border = "1px solid #000000";
    var tr = core.box.insertRow(0);
    var td = tr.insertCell(0);
    td.width = w + "px";
    core.img = document.createElement("IMG");
    core.img.border = "0px";
    core.img.align = "absMiddle";
    td.appendChild(core.img);
    td = tr.insertCell(1);
    td.width = "15px";
    td.style.backgroundColor = "#D6D3CE";
    td.style.textAlign = "center";
    td.style.cursor = "default";
    core.arr = document.createElement("IMG");
    core.arr.border = "0px";
    core.arr.align = "absMiddle";
    core.arr.src = "images/arrow_down.gif";
    core.img.onclick = td.onclick = function()
    {
        if (core.option == null)
        {
            var offset = getOffset(core.box);
            core.option = document.createElement("DIV");
            core.option.id = name + "_option";
            core.option.style.position = "absolute";
            core.option.style.border = "1px solid #000000";
            core.option.style.width = (w + 17) + "px";
            core.option.style.height = (h * 3) + "px";
            core.option.style.zIndex = 999;
            core.option.style.left = offset.left + "px";
            core.option.style.top = offset.bottom + "px";
            core.option.style.backgroundColor = "#FFFFFF";
            core.option.style.overflowX = "hidden";
            core.option.style.overflowY = "auto";
            var table = document.createElement("TABLE");
            table.style.border = "0";
            table.cellPadding = "0";
            table.cellSpacing = "0";
            table.width = w;
            for (var i = 0; i < core.list.length; i++)
            {
                var tr = table.insertRow(i);
                var td = tr.insertCell(0);
                var img = document.createElement("IMG");
                img.border = "0";
                img.align = "absMiddle";
                img.src = core.list[i].src;
                img.value = i;
                img.onclick = function()
                {
                    core.choose(this.value);
                }
                td.appendChild(img);
            }
            core.option.appendChild(table);
            document.body.appendChild(core.option);
        }
        core.option.style.display = (core.state ? "none" : "");
        core.state = (core.state == false);
    };
    td.appendChild(core.arr);
};

ImageCombox.prototype.add = function(src, val)
{
    var core = this;
    core.list.push({"src" : src, "value" : val});
};

ImageCombox.prototype.create = function(pid)
{
    var core = this;
    $(pid).appendChild(core.box);
    $(pid).parentNode.appendChild(core.com);
};

ImageCombox.prototype.choose = function(x)
{
    var core = this;
    core.index = x;
    core.img.src = core.list[core.index].src;
    core.com.value = core.list[core.index].value;
    core.state = false;
    if (core.option) core.option.style.display = "none";
};

var ImageTable = function(name, w, h, rows, cells, padding)
{
    var core = this;
    core.name = name;
    core.imgWidth = w;
    core.imgHeight = h;
    core.rows = rows;
    core.cells = cells;
    core.padding = padding;
    core.page = 1;
    core.pageSize = core.rows * core.cells;
    core.list = [];
    core.div = null;
    core.table = null;
};

ImageTable.prototype.add = function(src, val)
{
    var core = this;
    core.list.push({"src" : src, "value" : val});
};

ImageTable.prototype.open = function(page)
{
    var core = this;
    core.page = page;
    if (core.div == null)
    {
        var div = core.div = document.createElement("DIV");
        var tab = core.table = document.createElement("TABLE");
        div.className = "imagetable";
        tab.cellPadding = core.padding;
        tab.cellSpacing = "0";
        tab.border = "0";
        tab.style.width = "100%";
        div.appendChild(tab);
    }
    else
    {
        var div = core.div;
        var tab = core.table;
        while (tab.hasChildNodes())
        {
            tab.removeChild(tab.childNodes.item(0));
        }
    }
    var x = (core.page - 1) * core.pageSize;
    for (var i = 0; i < core.rows; i++)
    {
        var tr = tab.insertRow(i);
        for (var k = 0; k < core.cells; k++)
        {
            var td = tr.insertCell(k);
            td.width = parseInt(100 / core.cells) + "%";
            if (x < core.list.length)
            {
                var img = document.createElement("IMG");
                img.src = core.list[x].src;
                img.value = core.list[x++].value;
                eval("img.onclick = " + core.name + "_onclick");
                td.appendChild(img);
            }
        }
    }
    var tr = tab.insertRow(i);
    var td = tr.insertCell(0);
    td.colSpan = core.cells;
    td.className = "imagetablepages";
    core.pages = parseInt(core.list.length / core.pageSize);
    core.pages += (core.list.length % core.pageSize == 0 ? 0 : 1);
    for (var i = 1; i <= core.pages; i++)
    {
        var pg = document.createElement("DIV");
        pg.innerHTML = i;
        pg.onclick = function()
        {
            core.open(this.innerHTML);
        }
        td.appendChild(pg);
    }
};

ImageTable.prototype.make = function(id)
{
    var core = this;
    var obj = $(id);
    if (obj) obj.appendChild(core.div);
}


function debug(str)
{
    var div = $("Debug");
    if (div == null)
    {
        div = document.createElement("DIV");
        div.id = "Debug";
        div.style.position = "absolute";
        div.style.fontSize = "12px";
        div.style.fontFamily = "Arial";
        div.style.zIndex = 999;
        div.style.overflow = "auto";
        div.style.width = "200px";
        div.style.height = "300px";
        div.style.left = (document.body.offsetWidth - 200) + "px";
        div.style.top = "0px";
        div.style.border = "1px solid #000000";
        div.style.backgroundColor = "#F0F0F0";
        document.body.appendChild(div);
    }
    div.innerHTML += str + "<br/>";
};

function insertText(obj, str)
{
    if (document.selection)
    {
        obj.focus();
        var ptr = document.selection.createRange();
        ptr.text = str;
    }
    else
    {
        obj.value = obj.value.substring(0, obj.selectionStart) + str + obj.value.substring(obj.selectionEnd);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -