Ticket #1176: AbbreviationPlugin.patch

File AbbreviationPlugin.patch, 10.1 kB (added by guest, 5 years ago)

Patch for the Abbreviation plugin to use the new dialog system

  • abbreviation.js

     
    66// Distributed under the same terms as HTMLArea itself. 
    77// This notice MUST stay intact for use (see license.txt). 
    88 
     9 
     10Abbreviation._pluginInfo = { 
     11  name          : "Abbreviation", 
     12  version       : "1.0", 
     13  developer     : "Udo Schmal", 
     14  developer_url : "", 
     15  sponsor       : "L.N.Schaffrath NeueMedien", 
     16  sponsor_url   : "http://www.schaffrath-neuemedien.de/", 
     17  c_owner       : "Udo Schmal & Schaffrath-NeueMedien", 
     18  license       : "htmlArea" 
     19}; 
     20 
    921function Abbreviation(editor) { 
    1022  this.editor = editor; 
    1123  var cfg = editor.config; 
     
    1426  // register the toolbar buttons provided by this plugin 
    1527  cfg.registerButton({ 
    1628    id       : "abbreviation", 
    17     tooltip  : this._lc("Abbreviation"), 
     29    tooltip  : Xinha._lc("Abbreviation", "Abbreviation"), 
    1830    image    : editor.imgURL("ed_abbreviation.gif", "Abbreviation"), 
    1931    textMode : false, 
    2032    action   : function(editor) { 
    21                  self.buttonPress(editor); 
     33                 self.show(); 
    2234               } 
    23   }) 
     35  }); 
    2436  cfg.addToolbarElement("abbreviation", "inserthorizontalrule", 1); 
    2537} 
    2638 
    27 Abbreviation._pluginInfo = { 
    28   name          : "Abbreviation", 
    29   version       : "1.0", 
    30   developer     : "Udo Schmal", 
    31   developer_url : "", 
    32   sponsor       : "L.N.Schaffrath NeueMedien", 
    33   sponsor_url   : "http://www.schaffrath-neuemedien.de/", 
    34   c_owner       : "Udo Schmal & Schaffrath-NeueMedien", 
    35   license       : "htmlArea" 
    36 }; 
     39// Fills in the text field if the acronym is either known (i.e., in the [lang].js file) 
     40// or if we're editing an existing abbreviation. 
     41Abbreviation.prototype.fillText = function(editor) { 
     42  var editor = this.editor; 
     43  var text = this.html.toUpperCase(); 
     44  var abbr = Xinha.getPluginDir(this.constructor.name) + "/abbr/" + _editor_lang + ".js"; 
     45  var abbrData = Xinha._geturlcontent(abbr); 
    3746 
    38 Abbreviation.prototype._lc = function(string) { 
    39     return Xinha._lc(string, 'Abbreviation'); 
    40 }; 
     47  if (abbrData) { 
     48    eval('abbrObj = ' + abbrData); 
     49    if (abbrObj != "") { 
     50      var dest = this.dialog.getElementById("title"); 
     51      dest.value = this.title || ""; 
     52      for (var i in abbrObj) { 
     53        same = (i.toUpperCase()==text); 
     54        if (same) 
     55          dest.value = abbrObj[i]; 
     56      } 
     57    } 
     58  } 
     59} 
    4160 
    42 Abbreviation.prototype.onGenerate = function() { 
     61Abbreviation.prototype.onGenerateOnce = function(editor) { 
    4362  this.editor.addEditorStylesheet(Xinha.getPluginDir('Abbreviation') + '/abbreviation.css'); 
     63  this.methodsReady = true; //remove this? 
     64  var self = Abbreviation; 
     65  Xinha._getback(Xinha.getPluginDir('Abbreviation') + '/dialog.html', function(getback) { self.html = getback; self.dialogReady = true; }); 
    4466}; 
    4567 
    46 Abbreviation.prototype.buttonPress = function(editor, context, updatecontextclass) { 
    47   var outparam = null; 
    48   var html = editor.getSelectedHTML(); 
     68Abbreviation.prototype.OnUpdateToolbar = function(editor) { 
     69  if (!(Abbreviation.dialogReady && Abbreviation.methodsReady)) 
     70  { 
     71    this.editor._toolbarObjects.Abbreviation.state("enabled", false); 
     72  } 
     73  else this.onUpdateToolbar = null; 
     74} 
     75 
     76Abbreviation.prototype.prepareDialog = function(html) { 
     77  var self = this 
     78  var editor = this.editor; 
     79  var dialog = this.dialog = new Xinha.Dialog(editor, Abbreviation.html, 'Xinha', {width: 260, height:140}); 
     80 
     81  dialog.getElementById('ok').onclick = function() { self.create(); }; 
     82  dialog.getElementById('delete').onclick = function() { self.ondelete(); }; 
     83  dialog.getElementById('cancel').onclick = function() { self.dialog.hide(); }; 
     84   
     85  this.dialogReady = true; 
     86} 
     87 
     88Abbreviation.prototype.show = function(editor) { 
     89  var editor = this.editor 
     90  this.html = editor.getSelectedHTML(); 
     91  if (!this.dialog) this.prepareDialog(); 
     92  var self = this; 
     93  var doc = editor._doc; 
    4994  var sel  = editor._getSelection(); 
    5095  var range  = editor._createRange(sel); 
    5196  var abbr = editor._activeElement(sel); 
     97   
    5298  if(!(abbr != null && abbr.tagName.toLowerCase() == "abbr")) { 
    5399    abbr = editor._getFirstAncestor(sel, 'abbr'); 
    54100  } 
    55   if (abbr != null && abbr.tagName.toLowerCase() == "abbr") 
    56     outparam = { title : abbr.title, 
    57                  text : abbr.innerHTML}; 
    58   else 
    59     outparam = { title : '', 
    60                  text : html}; 
     101  this.abbr = abbr; 
     102   
     103  if (abbr) this.title = abbr.title; 
     104  this.fillText(); 
    61105 
    62   editor._popupDialog( "plugin://Abbreviation/abbreviation", function( param ) { 
    63     if ( param ) { 
    64       var title = param["title"]; 
    65       if (title == "" || title == null) { 
    66         if (abbr) { 
    67           var child = abbr.innerHTML; 
    68           abbr.parentNode.removeChild(abbr); 
    69           editor.insertHTML(child); 
    70         } 
    71         return; 
     106  this.dialog.getElementById("inputs").onsubmit = function() { 
     107    self.create(); 
     108    return false; 
     109  } 
     110 
     111  this.dialog.show(); 
     112  this.dialog.getElementById("title").select(); 
     113} 
     114 
     115Abbreviation.prototype.create = function(editor) { 
     116  this.param = this.dialog.getValues(); 
     117  this.apply(); 
     118} 
     119 
     120Abbreviation.prototype.apply = function(editor) { 
     121  var editor = this.editor; 
     122  var doc = editor._doc; 
     123  var abbr = this.abbr; 
     124  var html = this.html 
     125  var param = this.param; 
     126 
     127  this.dialog.hide(); 
     128 
     129  if ( param ) { 
     130    var title = param["title"]; 
     131    if (title == "" || title == null) { 
     132      if (abbr) { 
     133        var child = abbr.innerHTML; 
     134        abbr.parentNode.removeChild(abbr); 
     135        editor.insertHTML(child); 
    72136      } 
    73       try { 
    74         var doc = editor._doc; 
    75         if (!abbr) { 
    76           abbr = doc.createElement("abbr"); 
    77           abbr.title = title; 
    78           abbr.innerHTML = html; 
    79           if (Xinha.is_ie) { 
    80             range.pasteHTML(abbr.outerHTML); 
    81           } else { 
    82             editor.insertNodeAtSelection(abbr); 
    83           } 
     137      return; 
     138    } 
     139    try { 
     140      var doc = editor._doc; 
     141      if (!abbr) { 
     142        abbr = doc.createElement("abbr"); 
     143        abbr.title = title; 
     144        abbr.innerHTML = html; 
     145        if (Xinha.is_ie) { 
     146          range.pasteHTML(abbr.outerHTML); 
    84147        } else { 
    85           abbr.title = title; 
     148          editor.insertNodeAtSelection(abbr); 
    86149        } 
     150      } else { 
     151        abbr.title = title; 
    87152      } 
    88       catch (e) { } 
    89153    } 
    90   }, outparam); 
    91 }; 
    92  No newline at end of file 
     154    catch (e) { } 
     155  } 
     156} 
     157 
     158 
     159Abbreviation.prototype.ondelete = function(editor) { 
     160  this.param = {title : ""}; 
     161  this.apply(); 
     162} 
     163 No newline at end of file 
  • dialog.html

     
    1 <html> 
    2 <head> 
    3   <title>Abbreviation</title> 
    4   <link rel="stylesheet" type="text/css" href="../../../popups/popup.css" /> 
    5   <script type="text/javascript" src="../../../popups/popup.js"></script> 
     1<h1 id="[h1]"><l10n>Abbreviation</l10n></h1> 
    62 
    7 <script type="text/javascript"> 
    8 var Abbreviation = window.opener.Abbreviation; // load the Abbreviation plugin and lang file ;-) 
     3<form name="form" action="" method="get" id="[inputs]"> 
     4  <fieldset> 
     5    <legend><l10n>Expansion:</l10n></legend> 
     6    <input type="text" id="[title]" name="[title]" size="35" /> 
     7 </fieldset> 
     8<p /> 
    99 
    10 function fillSelect(text) { 
    11   var abbr = window.location.href; 
    12   abbr = abbr.replace(/popups\/abbreviation.html/g, "abbr\/" + window.opener._editor_lang + ".js"); 
    13   var abbrData = Xinha._geturlcontent(abbr); 
    14   if (abbrData) { 
    15     eval('abbrObj = ' + abbrData); 
    16     if (abbrObj != "") { 
    17       dest = document.getElementById("select"); 
    18       for (var i in abbrObj) { 
    19         same = (i==text); 
    20         dest.options[dest.options.length] = new Option(i + "=" + abbrObj[i], abbrObj[i], false, same); 
    21         if (same) 
    22         document.getElementById("title").value = abbrObj[i]; 
    23       } 
    24     } 
    25   } 
    26 } 
    27  
    28 function Init() { 
    29   __dlg_translate("Abbreviation"); 
    30   __dlg_init(null,{width: 260, height: 160}); 
    31   var param = window.dialogArguments; 
    32   var text = null; 
    33   if (param) { 
    34     text = param["text"]; 
    35     document.getElementById("title").value = param["title"]; 
    36   } 
    37   fillSelect(text); 
    38   document.getElementById("title").focus(); 
    39 }; 
    40  
    41 function onOK() { 
    42   var param = new Object(); 
    43   param["title"] = document.getElementById("title").value; 
    44   __dlg_close(param); 
    45   return false; 
    46 } 
    47  
    48  
    49 function onDelete() { 
    50   // pass data back to the calling window 
    51   var param = new Object(); 
    52   param["title"] = ""; 
    53   __dlg_close(param); 
    54   return false; 
    55 }; 
    56  
    57 function onCancel() { 
    58   __dlg_close(null); 
    59   return false; 
    60 }; 
    61 </script> 
    62  
    63 </head> 
    64 <body class="dialog" onload="Init()"> 
    65 <div class="title">Abbreviation</div> 
    66 <form name="form" action=""> 
    67 <table border="0" style="width: 100%;"> 
    68   <tr> 
    69     <td class="lable">Expansion:</td> 
    70     <td> 
    71     <select id="select" name="select" 
    72             onChange="document.form.title.value=document.form.select.options[document.form.select.selectedIndex].value" 
    73             style="position:absolute; top:35px; left:100px; width:118px; clip:rect(0 120 22 100)"> 
    74       <option value=""></option> 
    75  
    76     </select> 
    77     <input type="text" id="title" name="title" 
    78            onChange="document.form.select.selectedIndex=-1" 
    79            style="position:absolute; top:35px; left:100px; width:100px; border-right:0"> 
    80     <!--<input type="text" id="title" name="title" value="" size="30">--> 
    81     </td> 
    82   </tr> 
    83 </table> 
    84  
    85 <div id="buttons"> 
    86    <button type="submit" name="ok" onclick="return onOK();">OK</button> 
    87    <button type="button" name="delete" onclick="return onDelete();">Delete</button> 
    88    <button type="button" name="cancel" onclick="return onCancel();">Cancel</button> 
     10<div class="buttons" id="[buttons]"> 
     11  <input type="button" id="[ok]"     value="_(OK)"     /> 
     12  <input type="button" id="[delete]" value="_(Delete)" /> 
     13  <input type="button" id="[cancel]" value="_(Cancel)" /> 
    8914</div> 
    9015</form> 
    91 </body> 
    92 </html> 
     16