Annotation of kupuMPIWG/common/kupusourceedit.js, revision 1.1

1.1     ! dwinter     1: /*****************************************************************************
        !             2:  *
        !             3:  * Copyright (c) 2003-2005 Kupu Contributors. All rights reserved.
        !             4:  *
        !             5:  * This software is distributed under the terms of the Kupu
        !             6:  * License. See LICENSE.txt for license text. For a list of Kupu
        !             7:  * Contributors see CREDITS.txt.
        !             8:  *
        !             9:  *****************************************************************************/
        !            10: 
        !            11: // $Id$
        !            12: 
        !            13: 
        !            14: function SourceEditTool(sourcebuttonid, sourceareaid) {
        !            15:     /* Source edit tool to edit document's html source */
        !            16:     this.sourceButton = getFromSelector(sourcebuttonid);
        !            17:     this.sourcemode = false;
        !            18:     this._currently_editing = null;
        !            19: 
        !            20:     this.getSourceArea = function() {
        !            21:         return getFromSelector(sourceareaid);
        !            22:     }
        !            23: 
        !            24:     this.cancelSourceMode = function() {
        !            25:         if (this._currently_editing) {
        !            26:             this.switchSourceEdit(null, true);
        !            27:         }
        !            28:     }
        !            29:     this.updateState = this.cancelSourceMode;
        !            30: 
        !            31:     this.initialize = function(editor) {
        !            32:         /* attach the event handlers */
        !            33:         this.editor = editor;
        !            34:         this._fixTabIndex(this.sourceButton);
        !            35:         addEventHandler(this.sourceButton, "click", this.switchSourceEdit, this);
        !            36:         this.editor.logMessage(_('Source edit tool initialized'));
        !            37:     };
        !            38:  
        !            39:     this.switchSourceEdit = function(event, nograb) {
        !            40:         var kupu = this.editor;
        !            41:         var docobj = this._currently_editing||kupu.getDocument();
        !            42:         var editorframe = docobj.getEditable();
        !            43:         var sourcearea = this.getSourceArea();
        !            44:         var kupudoc = docobj.getDocument();
        !            45:         var sourceClass = 'kupu-sourcemode';
        !            46:     
        !            47:         if (!this.sourcemode) {
        !            48:             if (window.drawertool) {
        !            49:                 window.drawertool.closeDrawer();
        !            50:             }
        !            51:             if (/on/i.test(kupudoc.designMode)) {
        !            52:                 kupudoc.designMode = 'Off';
        !            53:             };
        !            54:             kupu._initialized = false;
        !            55: 
        !            56:             var data='';
        !            57:             if(kupu.config.filtersourceedit) {
        !            58:                 window.status = _('Cleaning up HTML...');
        !            59:                 var transform = kupu._filterContent(kupu.getInnerDocument().documentElement);
        !            60:                 data = kupu.getXMLBody(transform);
        !            61:                 data = kupu._fixupSingletons(data).replace(/<\/?body[^>]*>/g, "");
        !            62:                 window.status = '';
        !            63:             } else {
        !            64:                 data = kupu.getHTMLBody();
        !            65:             }
        !            66:             sourcearea.value = data;
        !            67:             kupu.setClass(sourceClass);
        !            68:             editorframe.style.display = 'none';
        !            69:             sourcearea.style.display = 'block';
        !            70:             if (!nograb) {
        !            71:                 sourcearea.focus();
        !            72:             };
        !            73:             this._currently_editing = docobj;
        !            74:           } else {
        !            75:             kupu.setHTMLBody(sourcearea.value);
        !            76:             kupu.clearClass(sourceClass);
        !            77:             sourcearea.style.display = 'none';
        !            78:             editorframe.style.display = 'block';
        !            79:             if (/off/i.test(kupudoc.designMode)) {
        !            80:                 kupudoc.designMode = 'On';
        !            81:             };
        !            82:             if (!nograb) {
        !            83:                 docobj.getWindow().focus();
        !            84:                 var selection = this.editor.getSelection();
        !            85:                 selection.collapse();
        !            86:             };
        !            87: 
        !            88:             kupu._initialized = true;
        !            89:             this._currently_editing = null;
        !            90:         };
        !            91:         this.sourcemode = !this.sourcemode;
        !            92:     };
        !            93:     this.enable = function() {
        !            94:         KupuButtonEnable(this.sourceButton);
        !            95:     }
        !            96:     this.disable = function() {
        !            97:         KupuButtonDisable(this.sourceButton);
        !            98:     }
        !            99: };
        !           100: 
        !           101: SourceEditTool.prototype = new KupuTool;
        !           102: 
        !           103: function MultiSourceEditTool(sourcebuttonid, textareaprefix) {
        !           104:     /* Source edit tool to edit document's html source */
        !           105:     this.sourceButton = getFromSelector(sourcebuttonid);
        !           106:     this.textareaprefix = textareaprefix;
        !           107: 
        !           108:     this.getSourceArea = function() {
        !           109:         var docobj = this._currently_editing||kupu.getDocument();
        !           110:         var sourceareaid = this.textareaprefix + docobj.getEditable().id;
        !           111:         return getFromSelector(sourceareaid);
        !           112:     }
        !           113: 
        !           114:     this._currently_editing = null;
        !           115: 
        !           116: };
        !           117: 
        !           118: MultiSourceEditTool.prototype = new SourceEditTool;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>