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

📄 kupueditor.js

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JS
📖 第 1 页 / 共 2 页
字号:
            return false;        };        var parent = nearest.parentNode;        while (nearest.childNodes.length) {            var child = nearest.firstChild;            child = nearest.removeChild(child);            parent.insertBefore(child, nearest);        };        parent.removeChild(nearest);    };    this.getDocument = function() {        /* returns a reference to the document object that wraps the iframe */        return this.document;    };    this.getInnerDocument = function() {        /* returns a reference to the window.document object of the iframe */        return this.getDocument().getDocument();    };    this.insertNodeAtSelection = function(insertNode, selectNode) {        /* insert a newly created node into the document */        if (!this._initialized) {            this.logMessage('Editor not initialized yet!');            return;        };        this.content_changed = true;        var browser = this.getBrowserName();        if (browser != "IE") {            this.focusDocument();        };                var ret = this.getSelection().replaceWithNode(insertNode, selectNode);                if (browser == 'IE') {            this._saveSelection();        };        return ret;    };    this.focusDocument = function() {        this.getDocument().getWindow().focus();    }    this.logMessage = function(message, severity) {        /* log a message using the logger, severity can be 0 (message, default), 1 (warning) or 2 (error) */        this.log.log(message, severity);    };    this.registerContentChanger = function(element) {        /* set this.content_changed to true (marking the content changed) when the             element's onchange is called        */        addEventHandler(element, 'change', function() {this.content_changed = true;}, this);    };        // helper methods    this.getBrowserName = function() {        /* returns either 'Mozilla' (for Mozilla, Firebird, Netscape etc.) or 'IE' */        if (_SARISSA_IS_MOZ) {            return "Mozilla";        } else if (_SARISSA_IS_IE) {            return "IE";        } else {            throw "Browser not supported!";        }    };        this.handleSaveResponse = function(request, redirect) {        if (request.status != '200' && request.status != '204'){            alert('Error saving your data.\nResponse status: ' +                   request.status +                   '.\nCheck your server log for more information.')            window.status = "Error saving document"        } else if (redirect) { // && (!request.status || request.status == '200' || request.status == '204'))            window.document.location = redirect;            this.content_changed = false;        } else {            // clear content_changed before reloadSrc so saveOnPart is not triggered            this.content_changed = false;            if (this.config.reload_after_save) {                this.reloadSrc();            };            // we're done so we can start editing again            window.status= "Document saved";        };        this._initialized = true;    };    // private methods    this._addEventHandler = addEventHandler;    this._saveCallback = function(request, redirect) {        /* callback for Sarissa */        if (request.readyState == 4) {            this.handleSaveResponse(request, redirect)        };    };        this.reloadSrc = function() {        /* reload the src, called after a save when reload_src is set to true */        // XXX Broken!!!        /*        if (this.getBrowserName() == "Mozilla") {            this.getInnerDocument().designMode = "Off";        }        */        // XXX call reloadSrc() which has a workaround, reloads the full page        // instead of just the iframe...        this.getDocument().reloadSource();        if (this.getBrowserName() == "Mozilla") {            this.getInnerDocument().designMode = "On";        };        /*        var selNode = this.getSelectedNode();        this.updateState(selNode);        */    };    this._initializeEventHandlers = function() {        /* attache the event handlers to the iframe */        // Initialize DOM2Event compatibility        // XXX should come back and change to passing in an element        this._addEventHandler(this.getInnerDocument(), "click", this.updateStateHandler, this);        this._addEventHandler(this.getInnerDocument(), "dblclick", this.updateStateHandler, this);        this._addEventHandler(this.getInnerDocument(), "keyup", this.updateStateHandler, this);        this._addEventHandler(this.getInnerDocument(), "keyup", function() {this.content_changed = true}, this);        this._addEventHandler(this.getInnerDocument(), "mouseup", this.updateStateHandler, this);    };    this._setDesignModeWhenReady = function() {        /* Rather dirty polling loop to see if Mozilla is done doing it's            initialization thing so design mode can be set.        */        this._designModeSetAttempts++;        if (this._designModeSetAttempts > 25) {            alert('Couldn\'t set design mode. Kupu will not work on this browser.');            return;        };        var success = false;        try {            this._setDesignMode();            success = true;        } catch (e) {            // register a function to the timer_instance because             // window.setTimeout can't refer to 'this'...            timer_instance.registerFunction(this, this._setDesignModeWhenReady, 100);        };        if (success) {            // provide an 'afterInit' method on KupuEditor.prototype            // for additional bootstrapping (after editor init)            if (this.afterInit) {                this.afterInit();            };        };    };    this._setDesignMode = function() {        this.getInnerDocument().designMode = "On";        this.execCommand("undo");        // note the negation: the argument doesn't work as expected...        this._initialized = true;    };    this._saveSelection = function() {        /* Save the selection, works around a problem with IE where the          selection in the iframe gets lost. We only save if the current          selection in the document */        if (this._isDocumentSelected()) {            var currange = this.getInnerDocument().selection.createRange();            this._previous_range = currange;        };    };    this._restoreSelection = function() {        /* re-selects the previous selection in IE. We only restore if the         current selection is not in the document.*/        if (this._previous_range && !this._isDocumentSelected()) {            try {                this._previous_range.select();            } catch (e) {                this.logMessage('Error placing back selection');            };        };    };    this._isDocumentSelected = function() {        var editable_body = this.getInnerDocument().getElementsByTagName('body')[0];        try {            var selrange = this.getInnerDocument().selection.createRange();        } catch(e) {            return false;        }        var someelement = selrange.parentElement ? selrange.parentElement() : selrange.item(0);        while (someelement.nodeName.toLowerCase() != 'body') {            someelement = someelement.parentNode;        };                return someelement == editable_body;    };    this._clearSelection = function() {        /* clear the last stored selection */        this._previous_range = null;    };    this._filterContent = function(documentElement) {        /* pass the content through all the filters */        // first copy all nodes to a Sarissa document so it's usable        var xhtmldoc = Sarissa.getDomDocument();        var doc = this._convertToSarissaNode(xhtmldoc, documentElement);        // now pass it through all filters        for (var i=0; i < this.filters.length; i++) {            var doc = this.filters[i].filter(xhtmldoc, doc);        };        // fix some possible structural problems, such as an empty or missing head, title        // or script or textarea tags without closing tag...        this._fixXML(doc, xhtmldoc);        return doc;    };    this.getXMLBody = function(transform) {        var bodies = transform.getElementsByTagName('body');        var data = '';        for (var i = 0; i < bodies.length; i++) {            data += bodies[i].xml;        }        return data;    };    this.getHTMLBody = function() {        var doc = this.getInnerDocument();        var docel = doc.documentElement;        var bodies = docel.getElementsByTagName('body');        var data = '';        for (var i = 0; i < bodies.length; i++) {            data += bodies[i].innerHTML;        }        return data;    };    // If we have multiple bodies this needs to remove the extras.    this.setHTMLBody = function(text) {        var bodies = this.getInnerDocument().documentElement.getElementsByTagName('body');        for (var i = 0; i < bodies.length-1; i++) {            bodies[i].parentNode.removeChild(bodies[i]);        }        bodies[bodies.length-1].innerHTML = text;    };    this._fixXML = function(doc, document) {        /* fix some structural problems in the XML that make it invalid XTHML */        // find if we have a head and title, and if not add them        var heads = doc.getElementsByTagName('head');        var titles = doc.getElementsByTagName('title');        if (!heads.length) {            // assume we have a body, guess Kupu won't work without one anyway ;)            var body = doc.getElementsByTagName('body')[0];            var head = document.createElement('head');            body.parentNode.insertBefore(head, body);            var title = document.createElement('title');            var titletext = document.createTextNode('');            head.appendChild(title);            title.appendChild(titletext);        } else if (!titles.length) {            var head = heads[0];            var title = document.createElement('title');            var titletext = document.createTextNode('');            head.appendChild(title);            title.appendChild(titletext);        };        // create a closing element for all elements that require one in XHTML        var dualtons = new Array('a', 'abbr', 'acronym', 'address', 'applet',                                     'b', 'bdo', 'big', 'blink', 'blockquote',                                     'button', 'caption', 'center', 'cite',                                     'comment', 'del', 'dfn', 'dir', 'div',                                    'dl', 'dt', 'em', 'embed', 'fieldset',                                    'font', 'form', 'frameset', 'h1', 'h2',                                    'h3', 'h4', 'h5', 'h6', 'i', 'iframe',                                    'ins', 'kbd', 'label', 'legend', 'li',                                    'listing', 'map', 'marquee', 'menu',                                    'multicol', 'nobr', 'noembed', 'noframes',                                    'noscript', 'object', 'ol', 'optgroup',                                    'option', 'p', 'pre', 'q', 's', 'script',                                    'select', 'small', 'span', 'strike',                                     'strong', 'style', 'sub', 'sup', 'table',                                    'tbody', 'td', 'textarea', 'tfoot',                                    'th', 'thead', 'title', 'tr', 'tt', 'u',                                    'ul', 'xmp');        // XXX I reckon this is *way* slow, can we use XPath instead or        // something to speed this up?        for (var i=0; i < dualtons.length; i++) {            var elname = dualtons[i];            var els = doc.getElementsByTagName(elname);            for (var j=0; j < els.length; j++) {                var el = els[j];                if (!el.hasChildNodes()) {                    var child = document.createTextNode('');                    el.appendChild(child);                };            };        };    };    this.xhtmlvalid = new XhtmlValidation(this);    this._convertToSarissaNode = function(ownerdoc, htmlnode) {        /* Given a string of non-well-formed HTML, return a string of            well-formed XHTML.           This function works by leveraging the already-excellent HTML            parser inside the browser, which generally can turn a pile            of crap into a DOM.  We iterate over the HTML DOM, appending            new nodes (elements and attributes) into a node.           The primary problems this tries to solve for crappy HTML: mixed            element names, elements that open but don't close,            and attributes that aren't in quotes.  This can also be adapted            to filter out tags that you don't want and clean up inline styles.           Inspired by Guido, adapted by Paul from something in usenet.           Tag and attribute tables added by Duncan        */        return this.xhtmlvalid._convertToSarissaNode(ownerdoc, htmlnode);    };    this._fixupSingletons = function(xml) {        return xml.replace(/<([^>]+)\/>/g, "<$1 />");    }    this._serializeOutputToString = function(transform) {        // XXX need to fix this.  Sometimes a spurious "\n\n" text         // node appears in the transform, which breaks the Moz         // serializer on .xml                    if (this.config.strict_output) {            var contents =  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' +                             '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n' +                             '<html xmlns="http://www.w3.org/1999/xhtml">' +                             transform.getElementsByTagName("head")[0].xml +                            transform.getElementsByTagName("body")[0].xml +                            '</html>';        } else {            var contents = '<html>' +                             transform.getElementsByTagName("head")[0].xml +                            transform.getElementsByTagName("body")[0].xml +                            '</html>';        };        if (this.config.compatible_singletons) {            contents = this._fixupSingletons(contents);        };                return contents;    };    this.getFullEditor = function() {        var fulleditor = this.getDocument().getEditable();        while (!/kupu-fulleditor/.test(fulleditor.className)) {            fulleditor = fulleditor.parentNode;        }        return fulleditor;    }    // Control the className and hence the style for the whole editor.    this.setClass = function(name) {        this.getFullEditor().className += ' '+name;    }        this.clearClass = function(name) {        var fulleditor = this.getFullEditor();        fulleditor.className = fulleditor.className.replace(' '+name, '');    }}

⌨️ 快捷键说明

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