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

📄 kupubasetools.js

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JS
📖 第 1 页 / 共 5 页
字号:
    this.openHlColorChooser = function() {        /* event handler for closing the colorchooser */        if (this.editor.getBrowserName() == "IE") {            this.command = "backcolor";        } else {            this.command = "hilitecolor";        }        this.show();    };    this.chooseColor = function(event) {        /* event handler for choosing the color */        var target = _SARISSA_IS_MOZ ? event.target : event.srcElement;        var cell = this.editor.getNearestParentOfType(target, 'td');        this.editor.execCommand(this.command, cell.getAttribute('bgColor'));        this.hide();            this.editor.logMessage('Color chosen');    };    this.show = function(command) {        /* show the colorchooser */        this.ccwindow.style.display = "block";    };    this.hide = function() {        /* hide the colorchooser */        this.command = null;        this.ccwindow.style.display = "none";    };    this.createColorchooser = function(table) {        /* create the colorchooser table */                var chunks = new Array('00', '33', '66', '99', 'CC', 'FF');        table.setAttribute('id', 'kupu-colorchooser-table');        table.style.borderWidth = '2px';        table.style.borderStyle = 'solid';        table.style.position = 'absolute';        table.style.cursor = 'default';        table.style.display = 'none';        var tbody = document.createElement('tbody');        for (var i=0; i < 6; i++) {            var tr = document.createElement('tr');            var r = chunks[i];            for (var j=0; j < 6; j++) {                var g = chunks[j];                for (var k=0; k < 6; k++) {                    var b = chunks[k];                    var color = '#' + r + g + b;                    var td = document.createElement('td');                    td.setAttribute('bgColor', color);                    td.style.backgroundColor = color;                    td.style.borderWidth = '1px';                    td.style.borderStyle = 'solid';                    td.style.fontSize = '1px';                    td.style.width = '10px';                    td.style.height = '10px';                    var text = document.createTextNode('\u00a0');                    td.appendChild(text);                    tr.appendChild(td);                }            }            tbody.appendChild(tr);        }        table.appendChild(tbody);        return table;    };}ColorchooserTool.prototype = new KupuTool;function PropertyTool(titlefieldid, descfieldid) {    /* The property tool */    this.titlefield = document.getElementById(titlefieldid);    this.descfield = document.getElementById(descfieldid);    this.initialize = function(editor) {        /* attach the event handlers and set the initial values */        this.editor = editor;        addEventHandler(this.titlefield, "change", this.updateProperties, this);        addEventHandler(this.descfield, "change", this.updateProperties, this);                // set the fields        var heads = this.editor.getInnerDocument().getElementsByTagName('head');        if (!heads[0]) {            this.editor.logMessage('No head in document!', 1);        } else {            var head = heads[0];            var titles = head.getElementsByTagName('title');            if (titles.length) {                this.titlefield.value = titles[0].text;            }            var metas = head.getElementsByTagName('meta');            if (metas.length) {                for (var i=0; i < metas.length; i++) {                    var meta = metas[i];                    if (meta.getAttribute('name') &&                             meta.getAttribute('name').toLowerCase() ==                             'description') {                        this.descfield.value = meta.getAttribute('content');                        break;                    }                }            }        }        this.editor.logMessage('Property tool initialized');    };    this.updateProperties = function() {        /* event handler for updating the properties form */        var doc = this.editor.getInnerDocument();        var heads = doc.getElementsByTagName('HEAD');        if (!heads) {            this.editor.logMessage('No head in document!', 1);            return;        }        var head = heads[0];        // set the title        var titles = head.getElementsByTagName('title');        if (!titles) {            var title = doc.createElement('title');            var text = doc.createTextNode(this.titlefield.value);            title.appendChild(text);            head.appendChild(title);        } else {            titles[0].childNodes[0].nodeValue = this.titlefield.value;        }        // let's just fulfill the usecase, not think about more properties        // set the description        var metas = doc.getElementsByTagName('meta');        var descset = 0;        for (var i=0; i < metas.length; i++) {            var meta = metas[i];            if (meta.getAttribute('name') &&                     meta.getAttribute('name').toLowerCase() == 'description') {                meta.setAttribute('content', this.descfield.value);            }        }        if (!descset) {            var meta = doc.createElement('meta');            meta.setAttribute('name', 'description');            meta.setAttribute('content', this.descfield.value);            head.appendChild(meta);        }        this.editor.logMessage('Properties modified');    };}PropertyTool.prototype = new KupuTool;function LinkTool() {    /* Add and update hyperlinks */        this.initialize = function(editor) {        this.editor = editor;        this.editor.logMessage('Link tool initialized');    };        this.createLinkHandler = function(event) {        /* create a link according to a url entered in a popup */        var linkWindow = openPopup('kupupopups/link.html', 300, 200);        linkWindow.linktool = this;        linkWindow.focus();    };    this.updateLink = function (linkel, url, type, name, target, title) {        if (type && type == 'anchor') {            linkel.removeAttribute('href');            linkel.setAttribute('name', name);        } else {            linkel.href = url;            if (linkel.innerHTML == "") {                var doc = this.editor.getInnerDocument();                linkel.appendChild(doc.createTextNode(title || url));            }            linkel.title = title;            if (target && target != '') {                linkel.setAttribute('target', target);            }            else {                linkel.removeAttribute('target');            };            linkel.style.color = this.linkcolor;        };    };    this.formatSelectedLink = function(url, type, name, target, title) {        var currnode = this.editor.getSelectedNode();        // selection inside link        var linkel = this.editor.getNearestParentOfType(currnode, 'A');        if (linkel) {            this.updateLink(linkel, url, type, name, target, title);            return true;        }        if (currnode.nodeType!=1) return false;        // selection contains links        var linkelements = currnode.getElementsByTagName('A');        var selection = this.editor.getSelection();        var containsLink = false;        for (var i = 0; i < linkelements.length; i++) {            linkel = linkelements[i];            if (selection.containsNode(linkel)) {                this.updateLink(linkel, url, type, name, target, title);                containsLink = true;            }        };        return containsLink;    }    // Can create a link in the following circumstances:    //   The selection is inside a link:    //      just update the link attributes.    //   The selection contains links:    //      update the attributes of the contained links    //   No links inside or outside the selection:    //      create a link around the selection    //   No selection:    //      insert a link containing the title    //    // the order of the arguments is a bit odd here because of backward    // compatibility    this.createLink = function(url, type, name, target, title) {        if (!this.formatSelectedLink(url, type, name, target, title)) {            // No links inside or outside.            this.editor.execCommand("CreateLink", url);            if (!this.formatSelectedLink(url, type, name, target, title)) {                // Insert link with no text selected, insert the title                // or URI instead.                var doc = this.editor.getInnerDocument();                linkel = doc.createElement("a");                linkel.setAttribute('href', url);                this.editor.getSelection().replaceWithNode(linkel, true);                this.updateLink(linkel, url, type, name, target, title);            };        }        this.editor.logMessage('Link added');        this.editor.updateState();    };        this.deleteLink = function() {        /* delete the current link */        var currnode = this.editor.getSelectedNode();        var linkel = this.editor.getNearestParentOfType(currnode, 'a');        if (!linkel) {            this.editor.logMessage('Not inside link');            return;        };        while (linkel.childNodes.length) {            linkel.parentNode.insertBefore(linkel.childNodes[0], linkel);        };        linkel.parentNode.removeChild(linkel);                this.editor.logMessage('Link removed');        this.editor.updateState();    };        this.createContextMenuElements = function(selNode, event) {        /* create the 'Create link' or 'Remove link' menu elements */        var ret = new Array();        var link = this.editor.getNearestParentOfType(selNode, 'a');        if (link) {            ret.push(new ContextMenuElement('Delete link', this.deleteLink, this));        } else {            ret.push(new ContextMenuElement('Create link', this.createLinkHandler, this));        };        return ret;    };}LinkTool.prototype = new KupuTool;function LinkToolBox(inputid, buttonid, toolboxid, plainclass, activeclass) {    /* create and edit links */        this.input = document.getElementById(inputid);    this.button = document.getElementById(buttonid);    this.toolboxel = document.getElementById(toolboxid);    this.plainclass = plainclass;    this.activeclass = activeclass;        this.initialize = function(tool, editor) {        /* attach the event handlers */        this.tool = tool;        this.editor = editor;        addEventHandler(this.input, "blur", this.updateLink, this);        addEventHandler(this.button, "click", this.addLink, this);    };    this.updateState = function(selNode) {        /* if we're inside a link, update the input, else empty it */        var linkel = this.editor.getNearestParentOfType(selNode, 'a');        if (linkel) {            // check first before setting a class for backward compatibility            if (this.toolboxel) {                this.toolboxel.className = this.activeclass;            };            this.input.value = linkel.getAttribute('href');        } else {            // check first before setting a class for backward compatibility            if (this.toolboxel) {                this.toolboxel.className = this.plainclass;            };            this.input.value = '';        }    };        this.addLink = function(event) {        /* add a link */        var url = this.input.value;        this.tool.createLink(url);    };        this.updateLink = function() {        /* update the current link */        var currnode = this.editor.getSelectedNode();        var linkel = this.editor.getNearestParentOfType(currnode, 'A');        if (!linkel) {            return;        }        var url = this.input.value;        linkel.setAttribute('href', url);        this.editor.logMessage('Link modified');    };};LinkToolBox.prototype = new LinkToolBox;function ImageTool() {    /* Image tool to add images */        this.initialize = function(editor) {        /* attach the event handlers */        this.editor = editor;        this.editor.logMessage('Image tool initialized');

⌨️ 快捷键说明

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