📄 kupudrawers.js
字号:
/***************************************************************************** * * Copyright (c) 2003-2004 Kupu Contributors. All rights reserved. * * This software is distributed under the terms of the Kupu * License. See LICENSE.txt for license text. For a list of Kupu * Contributors see CREDITS.txt. * *****************************************************************************/// $Id: kupudrawers.js,v 1.1 2005/03/26 20:31:36 svieujot Exp $function DrawerTool() { /* a tool to open and fill drawers this tool has to (and should!) only be instantiated once */ this.drawers = {}; this.current_drawer = null; this.initialize = function(editor) { this.editor = editor; // this essentially makes the drawertool a singleton window.drawertool = this; }; this.registerDrawer = function(id, drawer) { this.drawers[id] = drawer; drawer.initialize(this.editor, this); }; this.openDrawer = function(id) { /* open a drawer */ if (this.current_drawer) { this.closeDrawer(); }; if (this.editor.getBrowserName() == 'IE') { this.editor._saveSelection(); } var drawer = this.drawers[id]; drawer.createContent(); this.current_drawer = drawer; }; this.updateState = function(selNode) { if (this.current_drawer) { this.closeDrawer(); }; }; this.closeDrawer = function() { if (!this.current_drawer) { return; }; this.current_drawer.hide(); this.current_drawer = null; }; this.getDrawerEnv = function(iframe_win) { var drawer = null; for (var id in this.drawers) { var ldrawer = this.drawers[id]; // Note that we require drawers to provide us with an // element property! if (ldrawer.element.contentWindow == iframe_win) { drawer = ldrawer; }; }; if (!drawer) { this.editor.logMessage("Drawer not found", 1); return; }; return { 'drawer': drawer, 'drawertool': this, 'tool': drawer.tool }; };};DrawerTool.prototype = new KupuTool;function Drawer(elementid, tool) { /* base prototype for drawers */ this.element = document.getElementById(elementid); this.tool = tool; this.initialize = function(editor, drawertool) { this.editor = editor; this.drawertool = drawertool; }; this.createContent = function() { /* fill the drawer with some content */ // here's where any intelligence and XSLT transformation and such // is done this.element.style.display = 'block'; if (this.editor.getBrowserName() == 'IE') { this.element.focus(); } }; this.hide = function() { this.element.style.display = 'none'; };};function LinkDrawer(elementid, tool) { /* Link drawer */ this.element = document.getElementById(elementid); this.tool = tool; this.createContent = function() { /* display the drawer */ var currnode = this.editor.getSelectedNode(); var linkel = this.editor.getNearestParentOfType(currnode, 'a'); var input = document.getElementById('kupu-linkdrawer-input'); input.value = ""; this.preview(); if (linkel) { input.value = linkel.getAttribute('href'); } else { input.value = 'http://'; }; this.element.style.display = 'block'; if (this.editor.getBrowserName() == 'IE') { this.element.focus(); } }; this.save = function() { /* add or modify a link */ var input = document.getElementById('kupu-linkdrawer-input'); var url = input.value; var target = '_self'; if (this.target) target = this.target; this.tool.createLink(url, null, null, target); input.value = ''; // XXX when reediting a link, the drawer does not close for // some weird reason. BUG! Close the drawer manually until we // find a fix: this.drawertool.closeDrawer(); }; this.preview = function() { var input = document.getElementById('kupu-linkdrawer-input'); var preview = document.getElementById('kupu-linkdrawer-preview'); preview.src = input.value; if (this.editor.getBrowserName() == 'IE') { preview.width = "800"; preview.height = "365"; preview.style.zoom = "60%"; }; } this.preview_loaded = function() { var input = document.getElementById('kupu-linkdrawer-input'); var preview = document.getElementById('kupu-linkdrawer-preview'); if (input.value != preview.src) { input.value = preview.src; } }};LinkDrawer.prototype = new Drawer;function TableDrawer(elementid, tool) { /* Table drawer */ this.element = document.getElementById(elementid); this.tool = tool; this.addpanelid = 'kupu-tabledrawer-addtable'; this.editpanelid = 'kupu-tabledrawer-edittable'; this.addpanel = document.getElementById(this.addpanelid); this.editpanel = document.getElementById(this.editpanelid); this.createContent = function() { var selNode = this.editor.getSelectedNode(); if (this.editor.config.table_classes) { var classselect = document.getElementById('kupu-tabledrawer-classchooser'); var classes = this.editor.config.table_classes['class']; while (classselect.hasChildNodes()) { classselect.removeChild(classselect.firstChild); }; for (var i=0; i < classes.length; i++) { var classname = classes[i]; var option = document.createElement('option'); var content = document.createTextNode(classname); option.appendChild(content); option.setAttribute('value', classname); classselect.appendChild(option); }; }; var table = this.editor.getNearestParentOfType(selNode, 'table'); if (!table) { // show add table drawer show = this.addpanel; hide = this.editpanel; } else { // show edit table drawer show = this.editpanel; hide = this.addpanel; var align = this.tool._getColumnAlign(selNode); var alignselect = document.getElementById('kupu-tabledrawer-alignchooser'); selectSelectItem(alignselect, align); var classselect = document.getElementById('kupu-tabledrawer-classchooser'); selectSelectItem(classselect, table.className); }; hide.style.display = 'none'; show.style.display = 'block'; this.element.style.display = 'block'; if (this.editor.getBrowserName() == 'IE') { this.element.focus(); } }; this.createTable = function() { var rows = document.getElementById('kupu-tabledrawer-newrows').value; var cols = document.getElementById('kupu-tabledrawer-newcols').value; var style = document.getElementById('kupu-tabledrawer-classchooser').value; var add_header = document.getElementById('kupu-tabledrawer-makeheader').checked; this.tool.createTable(parseInt(rows), parseInt(cols), add_header, style); this.drawertool.closeDrawer(); };};TableDrawer.prototype = new Drawer;function LibraryDrawer(tool, xsluri, libsuri, searchuri) { /* a drawer that loads XSLT and XML from the server and converts the XML to XHTML for the drawer using the XSLT there are 2 types of XML file loaded from the server: the first contains a list of 'libraries', partitions for the data items, and the second a list of data items for a certain library all XML loading is done async, since sync loading can freeze Mozilla */ this.init = function(tool, xsluri, libsuri, searchuri) { /* This method is there to thin out the constructor and to be able to inherit it in sub-prototypes. Don't confuse this method with the component initializer (initialize()). */ // these are used in the XSLT. Maybe they should be // parameterized or something, but we depend on so many other // things implicitly anyway... this.drawerid = 'kupu-librarydrawer'; this.librariespanelid = 'kupu-librariespanel'; this.resourcespanelid = 'kupu-resourcespanel'; this.propertiespanelid = 'kupu-propertiespanel'; this.tool = tool; this.element = document.getElementById(this.drawerid); this.xsluri = xsluri; this.libsuri = libsuri; this.searchuri = searchuri; // marker that gets set when a new image has been uploaded this.newimages = null; // the following vars will be available after this.initialize() // has been called // this will be filled by this._libXslCallback() this.xsl = null; // this will be filled by this.loadLibraries(), which is called // somewhere further down the chain starting with // this._libsXslCallback() this.xmldata = null; }; this.init(tool, xsluri, libsuri, searchuri); this.initialize = function(editor, drawertool) { this.editor = editor; this.drawertool = drawertool; // load the xsl and the initial xml var wrapped_callback = new ContextFixer(this._libsXslCallback, this); this._loadXML(this.xsluri, wrapped_callback.execute); }; /*** bootstrapping ***/ this._libsXslCallback = function(dom) { /* callback for when the xsl for the libs is loaded this is called on init and since the initial libs need to be loaded as well (and everything is async with callbacks so there's no way to wait until the XSL is loaded) this will also make the first loadLibraries call */ this.xsl = dom;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -