[ Index ]
 

Code source de eGroupWare 1.2.106-2

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

title

Body

[fermer]

/phpgwapi/js/tinymce/jscripts/tiny_mce/plugins/searchreplace/ -> editor_plugin_src.js (source)

   1  /* Import theme    specific language pack */
   2  tinyMCE.importPluginLanguagePack('searchreplace', 'en,sv,zh_cn,fa,fr_ca,fr,de,pl');
   3  
   4  function TinyMCE_searchreplace_getControlHTML(control_name)    {
   5      switch (control_name) {
   6          case "search":
   7              return '<img id="{$editor_id}_search" src="{$pluginurl}/images/search.gif" title="{$lang_searchreplace_search_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearch\',true);" />';
   8  
   9          case "replace":
  10              return '<img id="{$editor_id}_replace" src="{$pluginurl}/images/replace.gif" title="{$lang_searchreplace_replace_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" onclick="tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearchReplace\',true);" />';
  11      }
  12  
  13      return "";
  14  }
  15  
  16  /**
  17   * Executes    the    search/replace commands.
  18   */
  19  function TinyMCE_searchreplace_execCommand(editor_id, element, command,    user_interface,    value) {
  20  	function defValue(key, default_value) {
  21          value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];
  22      }
  23  
  24  	function replaceSel(search_str, str) {
  25          // Get current selection
  26          if (!tinyMCE.isMSIE) {
  27              var sel = instance.contentWindow.getSelection();
  28              var rng = sel.getRangeAt(0);
  29          } else {
  30              var rng = instance.contentWindow.document.selection.createRange();
  31          }
  32  
  33          // Replace current one
  34          if (!tinyMCE.isMSIE) {
  35              var doc = instance.contentWindow.document;
  36  
  37              // This way works when the replace doesn't contain the search string
  38              if (str.indexOf(search_str) == -1) {
  39                  rng.deleteContents();
  40                  rng.insertNode(rng.createContextualFragment(str));
  41                  rng.collapse(false);
  42              } else {
  43                  // Insert content ugly way! Needed to move selection to after replace item
  44                  doc.execCommand("insertimage", false, "#mce_temp_url#");
  45                  var elm = tinyMCE.getElementByAttributeValue(doc.body, "img", "src", "#mce_temp_url#");
  46                  elm.parentNode.replaceChild(doc.createTextNode(str), elm);
  47              }
  48          } else {
  49              if (rng.item)
  50                  rng.item(0).outerHTML = str;
  51              else
  52                  rng.pasteHTML(str);
  53          }
  54      }
  55  
  56      var instance = tinyMCE.getInstanceById(editor_id);
  57  
  58      if (!value)
  59          value = new Array();
  60  
  61      // Setup defualt values
  62      defValue("editor_id", editor_id);
  63      defValue("searchstring", "");
  64      defValue("replacestring", null);
  65      defValue("replacemode", "none");
  66      defValue("casesensitive", false);
  67      defValue("backwards", false);
  68      defValue("wrap", false);
  69      defValue("wholeword", false);
  70  
  71      // Handle commands
  72      switch (command) {
  73          case "mceResetSearch":
  74              tinyMCE.lastSearchRng = null;
  75              return true;
  76  
  77          case "mceSearch":
  78              if (user_interface) {
  79                  // Open search dialog
  80                  var template = new Array();
  81  
  82                  if (value['replacestring'] != null) {
  83                      template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme
  84                      template['width'] = 310;
  85                      template['height'] = 180;
  86                  } else {
  87                      template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme
  88                      template['width'] = 280;
  89                      template['height'] = 180;
  90                  }
  91  
  92                  tinyMCE.openWindow(template, value);
  93              } else {
  94                  var win = tinyMCE.getInstanceById(editor_id).contentWindow;
  95                  var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
  96                  var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
  97  
  98                  // Whats the point
  99                  if (body.innerHTML == "") {
 100                      alert(tinyMCE.getLang('lang_searchreplace_notfound'));
 101                      return true;
 102                  }
 103  
 104                  // Handle replace current
 105                  if (value['replacemode'] == "current") {
 106                      replaceSel(value['string'], value['replacestring']);
 107  
 108                      // Search next one
 109                      value['replacemode'] = "none";
 110                      tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
 111  
 112                      return true;
 113                  }
 114  
 115                  if (tinyMCE.isMSIE) {
 116                      var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
 117                      var flags = 0;
 118  
 119                      if (value['wholeword'])
 120                          flags = flags | 2;
 121  
 122                      if (value['casesensitive'])
 123                          flags = flags | 4;
 124  
 125                      // Handle replace all mode
 126                      if (value['replacemode'] == "all") {
 127                          while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
 128                              rng.scrollIntoView();
 129                              rng.select();
 130                              rng.collapse(false);
 131                              replaceSel(value['string'], value['replacestring']);
 132                          }
 133  
 134                          alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
 135                          return true;
 136                      }
 137  
 138                      if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
 139                          rng.scrollIntoView();
 140                          rng.select();
 141                          rng.collapse(value['backwards']);
 142                          tinyMCE.lastSearchRng = rng;
 143                      } else
 144                          alert(tinyMCE.getLang('lang_searchreplace_notfound'));
 145                  } else {
 146                      if (value['replacemode'] == "all") {
 147                          while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
 148                              replaceSel(value['string'], value['replacestring']);
 149  
 150                          alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
 151                          return true;
 152                      }
 153  
 154                      if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
 155                          alert(tinyMCE.getLang('lang_searchreplace_notfound'));
 156                  }
 157              }
 158              return true;
 159  
 160          case "mceSearchReplace":
 161              value['replacestring'] = "";
 162  
 163              tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
 164              return true;
 165      }
 166  
 167      // Pass to next handler in chain
 168      return false;
 169  }
 170  
 171  function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
 172      return true;
 173  }


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7