[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  /**

   2   * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $

   3   *

   4   * @author Moxiecode

   5   * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.

   6   */
   7  
   8  tinyMCE.importPluginLanguagePack('searchreplace');
   9  
  10  var TinyMCE_SearchReplacePlugin = {
  11      getInfo : function() {
  12          return {
  13              longname : 'Search/Replace',
  14              author : 'Moxiecode Systems AB',
  15              authorurl : 'http://tinymce.moxiecode.com',
  16              infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html',
  17              version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
  18          };
  19      },
  20  
  21      initInstance : function (inst) {
  22          inst.addShortcut('ctrl', 'f', 'lang_searchreplace_search_desc', 'mceSearch', true);
  23          // No CTRL+R for "replace" because browsers will reload page instead of executing plugin

  24      },
  25  
  26      getControlHTML : function (cn) {
  27          switch (cn) {
  28              case "search" :
  29                  return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif','mceSearch', true);
  30  
  31              case "replace" :
  32                  return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true);
  33          }
  34  
  35          return "";
  36      },
  37  
  38      execCommand : function (editor_id, element, command, user_interface, value) {
  39          var inst = tinyMCE.getInstanceById(editor_id), selectedText = inst.selection.getSelectedText(), rng;
  40  
  41  		function defValue(key, default_value) {
  42              value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];
  43          }
  44  
  45  		function replaceSel(search_str, str, back) {
  46              inst.execCommand('mceInsertContent', false, str);
  47          }
  48  
  49          if (!value)
  50              value = [];
  51  
  52          defValue("editor_id", editor_id);
  53          defValue("searchstring", selectedText);
  54          defValue("replacestring", null);
  55          defValue("replacemode", "none");
  56          defValue("casesensitive", false);
  57          defValue("backwards", false);
  58          defValue("wrap", false);
  59          defValue("wholeword", false);
  60          defValue("inline", "yes");
  61          defValue("resizable", "no");
  62  
  63          switch (command) {
  64              case "mceResetSearch" :
  65                  tinyMCE.lastSearchRng = null;
  66                  return true;
  67  
  68              case "mceSearch" :
  69                  if (user_interface) {
  70                      var template = new Array();
  71  
  72                      template['file'] = '../../plugins/searchreplace/searchreplace.htm';
  73                      template['width'] = 380;
  74                      template['height'] = 155 + (tinyMCE.isNS7 ? 20 : 0) + (tinyMCE.isMSIE ? 15 : 0);
  75                      template['width'] += tinyMCE.getLang('lang_searchreplace_delta_width', 0);
  76                      template['height'] += tinyMCE.getLang('lang_searchreplace_delta_height', 0);
  77  
  78                      inst.execCommand('SelectAll');
  79  
  80                      if (tinyMCE.isMSIE) {
  81                          var r = inst.selection.getRng();
  82                          r.collapse(true);
  83                          r.select();
  84                      } else
  85                          inst.selection.getSel().collapseToStart();
  86  
  87                      tinyMCE.openWindow(template, value);
  88                  } else {
  89                      var win = tinyMCE.getInstanceById(editor_id).contentWindow;
  90                      var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
  91                      var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
  92                      if (body.innerHTML == "") {
  93                          alert(tinyMCE.getLang('lang_searchreplace_notfound'));
  94                          return true;
  95                      }
  96  
  97                      if (value['replacemode'] == "current") {
  98                          replaceSel(value['string'], value['replacestring'], value['backwards']);
  99                          value['replacemode'] = "none";
 100                          tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
 101                          return true;
 102                      }
 103  
 104                      if (tinyMCE.isMSIE) {
 105                          var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
 106                          var flags = 0;
 107                          if (value['wholeword'])
 108                              flags = flags | 2;
 109  
 110                          if (value['casesensitive'])
 111                              flags = flags | 4;
 112  
 113                          if (!rng.findText) {
 114                              alert('This operation is currently not supported by this browser.');
 115                              return true;
 116                          }
 117  
 118                          if (value['replacemode'] == "all") {
 119                              while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
 120                                  rng.scrollIntoView();
 121                                  rng.select();
 122                                  rng.collapse(false);
 123                                  replaceSel(value['string'], value['replacestring'], value['backwards']);
 124                              }
 125  
 126                              alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
 127                              return true;
 128                          }
 129  
 130                          if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
 131                              rng.scrollIntoView();
 132                              rng.select();
 133                              rng.collapse(value['backwards']);
 134                              tinyMCE.lastSearchRng = rng;
 135                          } else
 136                              alert(tinyMCE.getLang('lang_searchreplace_notfound'));
 137  
 138                      } else {
 139                          if (value['replacemode'] == "all") {
 140                              while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
 141                                  replaceSel(value['string'], value['replacestring'], value['backwards']);
 142  
 143                              alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
 144                              return true;
 145                          }
 146  
 147                          if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
 148                              alert(tinyMCE.getLang('lang_searchreplace_notfound'));
 149                      }
 150                  }
 151  
 152                  return true;
 153  
 154              case "mceSearchReplace" :
 155                  value['replacestring'] = "";
 156                  tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
 157                  return true;
 158          }
 159  
 160          return false;
 161      }
 162  };
 163  
 164  tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics