[ Index ]
 

Code source de TinyMCE 2.1.0

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

title

Body

[fermer]

/jscripts/tiny_mce/plugins/fullpage/ -> editor_plugin_src.js (source)

   1  /**
   2   * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
   3   *
   4   * @author Moxiecode
   5   * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
   6   */
   7  
   8  /* Import plugin specific language pack */
   9  tinyMCE.importPluginLanguagePack('fullpage');
  10  
  11  var TinyMCE_FullPagePlugin = {
  12      getInfo : function() {
  13          return {
  14              longname : 'Fullpage',
  15              author : 'Moxiecode Systems AB',
  16              authorurl : 'http://tinymce.moxiecode.com',
  17              infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
  18              version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  19          };
  20      },
  21  
  22      getControlHTML : function(cn) {
  23          switch (cn) {
  24              case "fullpage":
  25                  return tinyMCE.getButtonHTML(cn, 'lang_fullpage_desc', '{$pluginurl}/images/fullpage.gif', 'mceFullPageProperties');
  26          }
  27  
  28          return "";
  29      },
  30  
  31      execCommand : function(editor_id, element, command, user_interface, value) {
  32          // Handle commands
  33          switch (command) {
  34              case "mceFullPageProperties":
  35                  var template = new Array();
  36  
  37                  template['file']   = '../../plugins/fullpage/fullpage.htm';
  38                  template['width']  = 430;
  39                  template['height'] = 485 + (tinyMCE.isOpera ? 5 : 0);
  40  
  41                  template['width'] += tinyMCE.getLang('lang_fullpage_delta_width', 0);
  42                  template['height'] += tinyMCE.getLang('lang_fullpage_delta_height', 0);
  43  
  44                  tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
  45              return true;
  46  
  47              case "mceFullPageUpdate":
  48                  TinyMCE_FullPagePlugin._addToHead(tinyMCE.getInstanceById(editor_id));
  49                  return true;
  50         }
  51  
  52         // Pass to next handler in chain
  53         return false;
  54      },
  55  
  56      cleanup : function(type, content, inst) {
  57          switch (type) {
  58              case "insert_to_editor":
  59                  var tmp = content.toLowerCase();
  60                  var pos = tmp.indexOf('<body'), pos2;
  61  
  62                  // Split page in header and body chunks
  63                  if (pos != -1) {
  64                      pos = tmp.indexOf('>', pos);
  65                      pos2 = tmp.lastIndexOf('</body>');
  66                      inst.fullpageTopContent = content.substring(0, pos + 1);
  67                      content = content.substring(pos + 1, pos2);
  68                      // tinyMCE.debug(inst.fullpageTopContent, content);
  69                  } else {
  70                      if (!inst.fullpageTopContent) {
  71                          var docType = tinyMCE.getParam("fullpage_default_doctype", '<!DOCTYPE html PUBLIC "-/'+'/W3C//DTD XHTML 1.0 Transitional/'+'/EN" "http:/'+'/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
  72                          var enc = tinyMCE.getParam("fullpage_default_encoding", 'utf-8');
  73                          var title = tinyMCE.getParam("fullpage_default_title", 'Untitled document');
  74                          var lang = tinyMCE.getParam("fullpage_default_langcode", 'en');
  75                          var pi = tinyMCE.getParam("fullpage_default_xml_pi", true);
  76                          var ff = tinyMCE.getParam("fullpage_default_font_family", "");
  77                          var fz = tinyMCE.getParam("fullpage_default_font_size", "");
  78                          var ds = tinyMCE.getParam("fullpage_default_style", "");
  79                          var dtc = tinyMCE.getParam("fullpage_default_text_color", "");
  80  
  81                          // Xml encode it
  82                          title = title.replace(/&/g, '&amp;');
  83                          title = title.replace(/\"/g, '&quot;');
  84                          title = title.replace(/</g, '&lt;');
  85                          title = title.replace(/>/g, '&gt;');
  86  
  87                          tmp = '';
  88  
  89                          // Make default chunk
  90                          if (pi)
  91                              tmp += '<?xml version="1.0" encoding="' + enc + '"?>\n';
  92  
  93                          tmp += docType + '\n';
  94                          tmp += '<html xmlns="http:/'+'/www.w3.org/1999/xhtml" lang="' + lang + '" xml:lang="' + lang + '">\n';
  95                          tmp += '<head>\n';
  96                          tmp += '\t<title>' + title + '</title>\n';
  97                          tmp += '\t<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />\n';
  98                          tmp += '</head>\n';
  99                          tmp += '<body';
 100  
 101                          if (ff != '' || fz != '') {
 102                              tmp += ' style="';
 103  
 104                              if (ds != '')
 105                                  tmp += ds + ";";
 106  
 107                              if (ff != '')
 108                                  tmp += 'font-family: ' + ff + ";";
 109  
 110                              if (fz != '')
 111                                  tmp += 'font-size: ' + fz + ";";
 112  
 113                              tmp += '"';
 114                          }
 115  
 116                          if (dtc != '')
 117                              tmp += ' text="' + dtc + '"';
 118  
 119                          tmp += '>\n';
 120  
 121                          inst.fullpageTopContent = tmp;
 122                      }
 123                  }
 124  
 125                  this._addToHead(inst);
 126  
 127                  break;
 128  
 129              case "get_from_editor":
 130                  if (inst.fullpageTopContent)
 131                      content = inst.fullpageTopContent + content + "\n</body>\n</html>";
 132  
 133                  break;
 134          }
 135  
 136          // Pass through to next handler in chain
 137          return content;
 138      },
 139  
 140      // Private plugin internal methods
 141  
 142      _addToHead : function(inst) {
 143          var doc = inst.getDoc();
 144          var head = doc.getElementsByTagName("head")[0];
 145          var body = doc.body;
 146          var h = inst.fullpageTopContent;
 147          var e = doc.createElement("body");
 148          var nl, i, le, tmp;
 149  
 150          // Remove stuff we don't want
 151          h = h.replace(/(\r|\n)/gi, '');
 152          h = h.replace(/<\?[^\>]*\>/gi, '');
 153          h = h.replace(/<\/?(!DOCTYPE|head|html)[^\>]*\>/gi, '');
 154          h = h.replace(/<script(.*?)<\/script>/gi, '');
 155          h = h.replace(/<title(.*?)<\/title>/gi, '');
 156          h = h.replace(/<(meta|base)[^>]*>/gi, '');
 157  
 158          // Make link and style elements into pre
 159          h = h.replace(/<link([^>]*)\/>/gi, '<pre mce_type="link" $1></pre>');
 160          //h = h.replace(/<style([^>]*)>(.*?)<\/style>/gi, '<pre mce_type="style" $1>$2</pre>');
 161  
 162          // Make body a div
 163          h = h.replace(/<body/gi, '<div mce_type="body"');
 164          h += '</div>';
 165  
 166          // Now crapy MSIE can parse it
 167          e.innerHTML = h;
 168  
 169          // Reset all body attributes
 170          body.vLink = body.aLink = body.link = body.text = '';
 171          body.style.cssText = '';
 172  
 173          // Delete all old links
 174          nl = head.getElementsByTagName('link');
 175          for (i=0; i<nl.length; i++) {
 176              if (tinyMCE.getAttrib(nl[i], 'mce_head') == "true")
 177                  nl[i].parentNode.removeChild(nl[i]);
 178          }
 179  
 180          // Add link elements
 181          nl = e.getElementsByTagName('pre');
 182          for (i=0; i<nl.length; i++) {
 183              tmp = tinyMCE.getAttrib(nl[i], 'media');
 184              if (tinyMCE.getAttrib(nl[i], 'mce_type') == "link" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(nl[i], 'rel') == "stylesheet") {
 185                  le = doc.createElement("link");
 186  
 187                  le.rel = "stylesheet";
 188                  le.href = tinyMCE.getAttrib(nl[i], 'href');
 189                  le.setAttribute("mce_head", "true");
 190  
 191                  head.appendChild(le);
 192              }
 193          }
 194  
 195          // Add body attributes
 196          nl = e.getElementsByTagName('div');
 197          if (nl.length > 0) {
 198              body.style.cssText = tinyMCE.getAttrib(nl[0], 'style');
 199  
 200              if ((tmp = tinyMCE.getAttrib(nl[0], 'leftmargin')) != '' && body.style.marginLeft == '')
 201                  body.style.marginLeft = tmp + "px";
 202  
 203              if ((tmp = tinyMCE.getAttrib(nl[0], 'rightmargin')) != '' && body.style.marginRight == '')
 204                  body.style.marginRight = tmp + "px";
 205  
 206              if ((tmp = tinyMCE.getAttrib(nl[0], 'topmargin')) != '' && body.style.marginTop == '')
 207                  body.style.marginTop = tmp + "px";
 208  
 209              if ((tmp = tinyMCE.getAttrib(nl[0], 'bottommargin')) != '' && body.style.marginBottom == '')
 210                  body.style.marginBottom = tmp + "px";
 211  
 212              body.dir = tinyMCE.getAttrib(nl[0], 'dir');
 213              body.vLink = tinyMCE.getAttrib(nl[0], 'vlink');
 214              body.aLink = tinyMCE.getAttrib(nl[0], 'alink');
 215              body.link = tinyMCE.getAttrib(nl[0], 'link');
 216              body.text = tinyMCE.getAttrib(nl[0], 'text');
 217  
 218              if ((tmp = tinyMCE.getAttrib(nl[0], 'background')) != '')
 219                  body.style.backgroundImage = "url('" + tmp + "')";
 220  
 221              if ((tmp = tinyMCE.getAttrib(nl[0], 'bgcolor')) != '')
 222                  body.style.backgroundColor = tmp;
 223          }
 224      }
 225  };
 226  
 227  tinyMCE.addPlugin("fullpage", TinyMCE_FullPagePlugin);


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