home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / tinymce-advanced / mce / visualchars / editor_plugin.js
Encoding:
Text File  |  2008-02-20  |  2.7 KB  |  96 lines

  1. /**
  2.  * $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $
  3.  *
  4.  * @author Moxiecode
  5.  * @copyright Copyright ⌐ 2004-2007, Moxiecode Systems AB, All rights reserved.
  6.  */
  7.  
  8. // EN lang variables
  9. tadvmce = realTinyMCE;
  10. tadvmce.addToLang('visualchars',{
  11. desc : 'Visual control characters on/off.'
  12. });
  13.  
  14. /* Import plugin specific language pack */
  15. //tinyMCE.importPluginLanguagePack('visualchars');
  16.  
  17. var TinyMCE_VisualCharsPlugin = {
  18.     getInfo : function() {
  19.         return {
  20.             longname : 'Visual characters',
  21.             author : 'Moxiecode Systems AB',
  22.             authorurl : 'http://tinymce.moxiecode.com',
  23.             infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/visualchars',
  24.             version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  25.         };
  26.     },
  27.  
  28.     initInstance : function(inst) {
  29.         inst.visualChars = {
  30.             state : false
  31.         };
  32.     },
  33.  
  34.     getControlHTML : function(cn) {
  35.         switch (cn) {
  36.             case "visualchars":
  37.                 return tinyMCE.getButtonHTML(cn, 'lang_visualchars_desc', '{$pluginurl}/images/visualchars.gif', 'mceVisualChars', false);
  38.         }
  39.  
  40.         return "";
  41.     },
  42.  
  43.     execCommand : function(editor_id, element, command, user_interface, value) {
  44.         var inst = tinyMCE.getInstanceById(editor_id);
  45.  
  46.         switch (command) {
  47.             case "mceVisualChars":
  48.                 this._toggleVisualChars(editor_id, inst);
  49.                 return true;
  50.         }
  51.  
  52.         return false;
  53.     },
  54.  
  55.     cleanup : function(type, content, inst) {
  56.         if (type == "insert_to_editor_dom" || type == "get_from_editor_dom") {
  57.             inst.visualChars.state = true;
  58.             this._toggleVisualChars(inst.editorId, inst);
  59.         }
  60.  
  61.         return content;
  62.     },
  63.  
  64.     // Private plugin internal methods
  65.  
  66.     _toggleVisualChars : function(editor_id, inst) {
  67.         var nl, i, h, d = inst.getDoc(), b = inst.getBody(), nv, s = inst.selection, bo;
  68.  
  69.         inst.visualChars.state = !inst.visualChars.state;
  70.  
  71.         bo = s.getBookmark(true);
  72.  
  73.         tinyMCE.switchClass(editor_id + '_visualchars', inst.visualChars.state ? 'mceButtonSelected' : 'mceButtonNormal');
  74.  
  75.         if (inst.visualChars.state) {
  76.             nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 3 && n.nodeValue && n.nodeValue.indexOf('\u00a0') != -1;});
  77.  
  78.             for (i=0; i<nl.length; i++) {
  79.                 nv = nl[i].nodeValue;
  80.                 nv = nv.replace(/(\u00a0+)/g, '<span class="mceItemHiddenVisualChar">$1</span>');
  81.                 nv = nv.replace(/\u00a0/g, '\u00b7');
  82.                 tinyMCE.setOuterHTML(nl[i], nv, d);
  83.             }
  84.         } else {
  85.             nl = tinyMCE.selectNodes(b, function(n) {return n.nodeType == 1 && n.nodeName == 'SPAN' && n.className == 'mceItemHiddenVisualChar';});
  86.  
  87.             for (i=0; i<nl.length; i++)
  88.                 tinyMCE.setOuterHTML(nl[i], nl[i].innerHTML.replace(/(·|\u00b7)/g, ' '), d);
  89.         }
  90.  
  91.         //s.moveToBookmark(bo);
  92.     }
  93. };
  94.  
  95. tinyMCE.addPlugin("visualchars", TinyMCE_VisualCharsPlugin);
  96.