[ Index ]
 

Code source de Kupu-1.3.5

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

title

Body

[fermer]

/plone/kupu_plone_layer/ -> kupuploneeditor.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  KupuEditor.prototype._getBase = function(dom) {
  12      var base = dom.getElementsByTagName('base');
  13      if (base.length) {
  14          return base[0].getAttribute('href');
  15      } else {
  16          return '';
  17      }
  18  }
  19  
  20  // $Id: kupuploneeditor.js 9879 2005-03-18 12:04:00Z yuppie $
  21  KupuEditor.prototype.makeLinksRelative = function(contents,base,debug) {
  22      // After extracting text from Internet Explorer, all the links in
  23      // the document are absolute.
  24      // we can't use the DOM to convert them to relative links, since
  25      // its the DOM that corrupts them to absolute to begin with.
  26      // Instead we can find the base from the DOM and do replace on the
  27      // text until all our links are relative.
  28  
  29      var href = base.replace(/\/[^\/]*$/, '/');
  30      var hrefparts = href.split('/');
  31      return contents.replace(/(<[^>]* (?:src|href)=")([^"]*)"/g,
  32          function(str, tag, url, offset, contents) {
  33              var resolveuid = url.indexOf('/resolveuid/');
  34              if (resolveuid != -1) {
  35                  str = tag + url.substr(resolveuid+1)+'"';
  36                  return str;
  37              }
  38              var urlparts = url.split('#');
  39              var anchor = urlparts[1] || '';
  40              url = urlparts[0];
  41              var urlparts = url.split('/');
  42              var common = 0;
  43              while (common < urlparts.length &&
  44                     common < hrefparts.length &&
  45                     urlparts[common]==hrefparts[common])
  46                  common++;
  47              var last = urlparts[common];
  48              if (common+1 == urlparts.length && last=='emptypage') {
  49                  urlparts[common] = '';
  50              }
  51              // The base and the url have 'common' parts in common.
  52              // First two are the protocol, so only do stuff if more
  53              // than two match.
  54              if (common > 2) {
  55                  var path = new Array();
  56                  var i = 0;
  57                  for (; i+common < hrefparts.length-1; i++) {
  58                      path[i] = '..';
  59                  };
  60                  while (common < urlparts.length) {
  61                      path[i++] = urlparts[common++];
  62                  };
  63                  if (i==0) {
  64                      path[i++] = '.';
  65                  }
  66                  str = path.join('/');
  67                  if (anchor) {
  68                      str = [str,anchor].join('#');
  69                  }
  70                  str = tag + str+'"';
  71              };
  72              return str;
  73          });
  74  };
  75  
  76  KupuEditor.prototype.saveDataToField = function(form, field) {
  77      var sourcetool = this.getTool('sourceedittool');
  78      if (sourcetool) {sourcetool.cancelSourceMode();};
  79  
  80      if (!this._initialized) {
  81          return;
  82      };
  83      this._initialized = false;
  84  
  85      // set the window status so people can see we're actually saving
  86      window.status= "Please wait while saving document...";
  87  
  88      // pass the content through the filters
  89      this.logMessage("Starting HTML cleanup");
  90  
  91      var transform = this._filterContent(this.getInnerDocument().documentElement);
  92  
  93      // We need to get the contents of the body node as xml, but we don't
  94      // want the body node itself, so we use a regex to remove it
  95      var contents = kupu.getXMLBody(transform);
  96      if (/^<body[^>]*>(<\/?(p|br)[^>]*>|\&nbsp;)*<\/body>$/.test(contents)) {
  97          contents = ''; /* Ignore nearly empty contents */
  98      }
  99      var base = this._getBase(transform);
 100      contents = this._fixupSingletons(contents);
 101      contents = this.makeLinksRelative(contents, base).replace(/<\/?body[^>]*>/g, "");
 102      this.logMessage("Cleanup done, sending document to server");
 103  
 104      // now create the form input
 105      var document = form.ownerDocument;
 106  
 107      field.value = contents;
 108      
 109      kupu.content_changed = false;
 110  };


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