[ Index ]
 

Code source de Kupu-1.3.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/common/ -> kupusourceedit.js (source)

   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      // method defined inline to support closure
  21      // XXX would be nice to have this defined on the prototype too, because
  22      // of subclassing issues?
  23      this.getSourceArea = function() {
  24          return getFromSelector(sourceareaid);
  25      };
  26  };
  27  
  28  SourceEditTool.prototype = new KupuTool;
  29  
  30  SourceEditTool.prototype.cancelSourceMode = function() {
  31      if (this._currently_editing) {
  32          this.switchSourceEdit(null, true);
  33      };
  34  };
  35  
  36  SourceEditTool.prototype.updateState = 
  37          SourceEditTool.prototype.cancelSourceMode;
  38  
  39  SourceEditTool.prototype.initialize = function(editor) {
  40      /* attach the event handlers */
  41      this.editor = editor;
  42      this._fixTabIndex(this.sourceButton);
  43      addEventHandler(this.sourceButton, "click", this.switchSourceEdit, this);
  44      this.editor.logMessage(_('Source edit tool initialized'));
  45  };
  46  
  47  SourceEditTool.prototype.switchSourceEdit = function(event, nograb) {
  48      var kupu = this.editor;
  49      var docobj = this._currently_editing||kupu.getDocument();
  50      var editorframe = docobj.getEditable();
  51      var sourcearea = this.getSourceArea();
  52      var kupudoc = docobj.getDocument();
  53      var sourceClass = 'kupu-sourcemode';
  54  
  55      if (!this.sourcemode) {
  56          if (window.drawertool) {
  57              window.drawertool.closeDrawer();
  58          };
  59          if (/on/i.test(kupudoc.designMode)) {
  60              kupudoc.designMode = 'Off';
  61          };
  62          kupu._initialized = false;
  63  
  64          var data='';
  65          if(kupu.config.filtersourceedit) {
  66              window.status = _('Cleaning up HTML...');
  67              var transform = kupu._filterContent(
  68                                  kupu.getInnerDocument().documentElement);
  69              data = kupu.getXMLBody(transform);
  70              data = kupu._fixupSingletons(data).replace(/<\/?body[^>]*>/g, "");
  71              window.status = '';
  72          } else {
  73              data = kupu.getHTMLBody();
  74          };
  75          sourcearea.value = data;
  76          kupu.setClass(sourceClass);
  77          editorframe.style.display = 'none';
  78          sourcearea.style.display = 'block';
  79          if (!nograb) {
  80              sourcearea.focus();
  81          };
  82          this._currently_editing = docobj;
  83        } else {
  84          kupu.setHTMLBody(sourcearea.value);
  85          kupu.clearClass(sourceClass);
  86          sourcearea.style.display = 'none';
  87          editorframe.style.display = 'block';
  88          if (/off/i.test(kupudoc.designMode)) {
  89              kupudoc.designMode = 'On';
  90          };
  91          if (!nograb) {
  92              docobj.getWindow().focus();
  93              var selection = this.editor.getSelection();
  94              selection.collapse();
  95          };
  96  
  97          kupu._initialized = true;
  98          this._currently_editing = null;
  99          this.editor.updateState();
 100      };
 101      this.sourcemode = !this.sourcemode;
 102  };
 103  
 104  SourceEditTool.prototype.enable = function() {
 105      KupuButtonEnable(this.sourceButton);
 106  };
 107  
 108  SourceEditTool.prototype.disable = function() {
 109      KupuButtonDisable(this.sourceButton);
 110  };
 111  
 112  function MultiSourceEditTool(sourcebuttonid, textareaprefix) {
 113      /* Source edit tool to edit document's html source */
 114      this.sourceButton = getFromSelector(sourcebuttonid);
 115      this.textareaprefix = textareaprefix;
 116  
 117      this._currently_editing = null;
 118  };
 119  
 120  MultiSourceEditTool.prototype = new SourceEditTool;
 121  
 122  MultiSourceEditTool.prototype.getSourceArea = function() {
 123      var docobj = this._currently_editing||kupu.getDocument();
 124      var sourceareaid = this.textareaprefix + docobj.getEditable().id;
 125      return getFromSelector(sourceareaid);
 126  };


Généré le : Sun Feb 25 15:30:41 2007 par Balluche grâce à PHPXref 0.7