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

📄 ssmoz.debug.js

📁 经典编程900例(C语言),主要是C基础知识
💻 JS
字号:
//! Script# Mozilla Compat Layer
//! Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//! http://projects.nikhilk.net
//!

function __loadCompat(w) {
    w.Debug = function() {
    };
    w.Debug._fail = function(message) {
        throw new Error(message);
    };
    w.Debug.writeln = function(text) {
        if (window.console) {
            window.console.debug(text);
        }
    };

    w.__getNonTextNode = function(node) {
        try {
            while (node && (node.nodeType != 1)) {
                node = node.parentNode;
            }
        }
        catch (ex) {
            node = null;
        }
        return node;
    };
    
    w.__getLocation = function(e) {
        var loc = {x : 0, y : 0};
        while (e) {
            loc.x += e.offsetLeft;
            loc.y += e.offsetTop;
            e = e.offsetParent;
        }
        return loc;
    }
}

function _loadMozillaCompat(w) {

    w.navigate = function(url) {
        window.setTimeout('window.location = "' + url + '";', 0);
    };

    var attachEventProxy = function(eventName, eventHandler) {
        eventHandler._mozillaEventHandler = function(e) {
            window.event = e;
            eventHandler();
            return e.returnValue;
        };
        this.addEventListener(eventName.slice(2), eventHandler._mozillaEventHandler, false);
    };

    var detachEventProxy = function (eventName, eventHandler) {
        if (eventHandler._mozillaEventHandler) {
            var mozillaEventHandler = eventHandler._mozillaEventHandler;
            delete eventHandler._mozillaEventHandler;
            
            this.removeEventListener(eventName.slice(2), mozillaEventHandler, false);
        }
    };

    w.attachEvent = attachEventProxy;
    w.detachEvent = detachEventProxy;
    w.HTMLDocument.prototype.attachEvent = attachEventProxy;
    w.HTMLDocument.prototype.detachEvent = detachEventProxy;
    w.HTMLElement.prototype.attachEvent = attachEventProxy;
    w.HTMLElement.prototype.detachEvent = detachEventProxy;

    w.Event.prototype.__defineGetter__('srcElement', function() {
        // __getNonTextNode(this.target) is the expected implementation.
        // However script.load has target set to the Document object... so we
        // need to throw in currentTarget as well.
        return __getNonTextNode(this.target) || this.currentTarget;
    });
    w.Event.prototype.__defineGetter__('cancelBubble', function() {
        return this._bubblingCanceled || false;
    });
    w.Event.prototype.__defineSetter__('cancelBubble', function(v) {
        if (v) {
            this._bubblingCanceled = true;
            this.stopPropagation();
        }
    });
    w.Event.prototype.__defineGetter__('returnValue', function() {
        return !this._cancelDefault;
    });
    w.Event.prototype.__defineSetter__('returnValue', function(v) {
        if (!v) {
            this._cancelDefault = true;
            this.preventDefault();
        }
    });
    w.Event.prototype.__defineGetter__('fromElement', function () {
        var n;
        if (this.type == 'mouseover') {
            n = this.relatedTarget;
        }
        else if (this.type == 'mouseout') {
            n = this.target;
        }
        return __getNonTextNode(n);
    });
    w.Event.prototype.__defineGetter__('toElement', function () {
        var n;
        if (this.type == 'mouseout') {
            n = this.relatedTarget;
        }
        else if (this.type == 'mouseover') {
            n = this.target;
        }
        return __getNonTextNode(n);
    });
    w.Event.prototype.__defineGetter__('button', function() {
        return (this.which == 1) ? 1 : (this.which == 3) ? 2 : 0
    });
    w.Event.prototype.__defineGetter__('offsetX', function() {
        return window.pageXOffset + this.clientX - __getLocation(this.srcElement).x;
    });
    w.Event.prototype.__defineGetter__('offsetY', function() {
        return window.pageYOffset + this.clientY - __getLocation(this.srcElement).y;
    });

    w.HTMLElement.prototype.__defineGetter__('parentElement', function() {
        return this.parentNode;
    });
    w.HTMLElement.prototype.__defineGetter__('children', function() {
        var children = [];
        var childCount = this.childNodes.length;
        for (var i = 0; i < childCount; i++) {
            var childNode = this.childNodes[i];
            if (childNode.nodeType == 1) {
                children.push(childNode);
            }
        }
        return children;
    });
    w.HTMLElement.prototype.__defineGetter__('innerText', function() {    
        try {
            return this.textContent
        } 
        catch (ex) {
            var text = '';
            for (var i=0; i < this.childNodes.length; i++) {
                if (this.childNodes[i].nodeType == 3) {
                    text += this.childNodes[i].textContent;
                }
            }
            return str;
        }
    });
    w.HTMLElement.prototype.__defineSetter__('innerText', function(v) {
        var textNode = document.createTextNode(v);
        this.innerHTML = '';
        this.appendChild(textNode);
    });
    w.HTMLElement.prototype.__defineGetter__('currentStyle', function() {
        return window.getComputedStyle(this, null);
    });
    w.HTMLElement.prototype.__defineGetter__('runtimeStyle', function() {
        return window.getOverrideStyle(this, null);
    });
    w.HTMLElement.prototype.removeNode = function(b) {
        return this.parentNode.removeChild(this)
    };
    w.HTMLElement.prototype.contains = function(el) {
        while (el != null && el != this) {
            el = el.parentNode;
        }
        return (el!=null)
    };

    w.HTMLStyleElement.prototype.__defineGetter__('styleSheet', function() {
        return this.sheet;
    });
    w.CSSStyleSheet.prototype.__defineGetter__('rules', function() {
        return this.cssRules;
    });
    w.CSSStyleSheet.prototype.addRule = function(selector, style, index) {
        this.insertRule(selector + '{' + style + '}', index);
    };
    w.CSSStyleSheet.prototype.removeRule = function(index) {
        this.deleteRule(index);
    };
    w.CSSStyleDeclaration.prototype.__defineGetter__('styleFloat', function() {
        return this.cssFloat;
    });
    w.CSSStyleDeclaration.prototype.__defineSetter__('styleFloat', function(v) {
        this.cssFloat = v;
    });
    DocumentFragment.prototype.getElementById = function(id) {
        var nodeQueue = [];
        var childNodes = this.childNodes;
        var node;
        var c;
        
        for (c = 0; c < childNodes.length; c++) {
            node = childNodes[c];
            if (node.nodeType == 1) {
                nodeQueue.push(node);
            }
        }

        while (nodeQueue.length) {
            node = nodeQueue.dequeue();
            if (node.id == id) {
                return node;
            }
            childNodes = node.childNodes;
            if (childNodes.length != 0) {
                for (c = 0; c < childNodes.length; c++) {
                    node = childNodes[c];
                    if (node.nodeType == 1) {
                        nodeQueue.push(node);
                    }
                }
            }
        }

        return null;
    };

    DocumentFragment.prototype.getElementsByTagName = function(tagName) {
        var elements = [];
        var nodeQueue = [];
        var childNodes = this.childNodes;
        var node;
        var c;

        for (c = 0; c < childNodes.length; c++) {
            node = childNodes[c];
            if (node.nodeType == 1) {
                nodeQueue.push(node);
            }
        }

        while (nodeQueue.length) {
            node = nodeQueue.dequeue();
            if (node.tagName == tagName) {
                elements.add(node);
            }
            childNodes = node.childNodes;
            if (childNodes.length != 0) {
                for (c = 0; c < childNodes.length; c++) {
                    node = childNodes[c];
                    if (node.nodeType == 1) {
                        nodeQueue.push(node);
                    }
                }
            }
        }

        return elements;
    };

    DocumentFragment.prototype.createElement = function(tagName) {
        return document.createElement(tagName);
    };

    var selectNodes = function(doc, path, contextNode) {
        contextNode = contextNode ? contextNode : doc;
        var xpath = new XPathEvaluator();
        var result = xpath.evaluate(path, contextNode,
                                    doc.createNSResolver(doc.documentElement),
                                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

        var nodeList = new Array(result.snapshotLength);
        for(var i = 0; i < result.snapshotLength; i++) {
            nodeList[i] = result.snapshotItem(i);
        }

        return nodeList;
    };

    var selectSingleNode = function(doc, path, contextNode) {
        path += '[1]';
        var nodes = selectNodes(doc, path, contextNode);
        if (nodes.length != 0) {
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i]) {
                    return nodes[i];
                }
            }
        }
        return null;
    };

    w.XMLDocument.prototype.selectNodes = function(path, contextNode) {
        return selectNodes(this, path, contextNode);
    };

    w.XMLDocument.prototype.selectSingleNode = function(path, contextNode) {
        return selectSingleNode(this, path, contextNode);
    };

    w.XMLDocument.prototype.transformNode = function(xsl) {
        var xslProcessor = new XSLTProcessor();
        xslProcessor.importStylesheet(xsl);

        var ownerDocument = document.implementation.createDocument("", "", null);
        var transformedDoc = xslProcessor.transformToDocument(this);
        
        return transformedDoc.xml;
    };

    Node.prototype.selectNodes = function(path) {
        var doc = this.ownerDocument;
        return doc.selectNodes(path, this);
    };

    Node.prototype.selectSingleNode = function(path) {
        var doc = this.ownerDocument;
        return doc.selectSingleNode(path, this);
    };

    Node.prototype.__defineGetter__('baseName', function() {
        return this.localName;
    });

    Node.prototype.__defineGetter__('text', function() {
        return this.textContent;
    });
    Node.prototype.__defineSetter__('text', function(value) {
        this.textContent = value;
    });

    Node.prototype.__defineGetter__('xml', function() {
        return (new XMLSerializer()).serializeToString(this);
    });
}

function _loadSafariCompat(w) {

    window["HTMLHtmlElement"] = document.createElement("html").constructor;

    function HTMLElement() {
    }

    HTMLElement.prototype = HTMLHtmlElement.__proto__.__proto__;
    var HTMLDocument = document.constructor;
    var Text = document.createTextNode("").constructor;
    Node = Text;

    var attachEventProxy = function(eventName, eventHandler) {
        eventHandler.__safariEventHandler = function(e) {
            // Somehow Safari raises a keyboard event twice when an arrow key is 
            // pressed. We really only want to raise it once.
            // REVIEW: We should really find a better way to do this.
            if (!this.__eventTimeStamp) {
                this.__eventTimeStamp = e.timeStamp;
            }
            else {
                if ((e.timeStamp - this.__eventTimeStamp) < 20) {
                    return null;
                }
                this.__eventTimeStamp = e.timeStamp;
            }
            
            var compatEvent = {};
            for (var a in e) {
                compatEvent[a] = e[a];
            }
            compatEvent.srcElement = __getNonTextNode(compatEvent.srcElement);
            window.event = compatEvent;
            eventHandler();
            e.returnValue = compatEvent.returnValue;
            return e.returnValue;
        };
        this.addEventListener(eventName.slice(2), eventHandler.__safariEventHandler, false);
    };

    var detachEventProxy = function(eventName, eventHandler) {
        if (eventHandler.__safariEventHandler) {
            var safariEventHandler = eventHandler.__safariEventHandler;
            delete eventHandler.__safariEventHandler;
            
            this.removeEventListener(eventName.slice(2), safariEventHandler, false);
        }
    };
    
    w.attachEvent = attachEventProxy;
    w.detachEvent = detachEventProxy;
    HTMLDocument.prototype.attachEvent = attachEventProxy;
    HTMLDocument.prototype.detachEvent = detachEventProxy;
    HTMLElement.prototype.attachEvent = attachEventProxy;
    HTMLElement.prototype.detachEvent = detachEventProxy;
    
    Node.prototype.getElementById = function(id) {
        var nodeQueue = [];
        var childNodes = this.childNodes;
        var node;
        var c;
        
        for (c = 0; c < childNodes.length; c++) {
            node = childNodes[c];
            if (node.nodeType == 1) {
                nodeQueue.push(node);
            }
        }
        
        while (nodeQueue.length) {
            node = nodeQueue.dequeue();
            if (node.id == id) {
                return node;
            }
            childNodes = node.childNodes;
            if (childNodes.length != 0) {
                for (c = 0; c < childNodes.length; c++) {
                    node = childNodes[c];
                    if (node.nodeType == 1) {
                        nodeQueue.push(node);
                    }
                }
            }
        }
        
        return null;
    };
}

__loadCompat(window);
if (window.navigator.userAgent.indexOf('Safari') >= 0) {
    _loadSafariCompat(window);
}
else {
    _loadMozillaCompat(window);
}

⌨️ 快捷键说明

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