Changeset 1037 for branches/new-dialogs


Ignore:
Timestamp:
09/25/08 22:57:10 (11 years ago)
Author:
nicholasbs
Message:

Applied AbbreviationPlugin?.patch from #1176 with some general code cleanup

Location:
branches/new-dialogs/plugins/Abbreviation
Files:
1 deleted
1 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/new-dialogs/plugins/Abbreviation/abbreviation.js

    r999 r1037  
    1515  cfg.registerButton({ 
    1616    id       : "abbreviation", 
    17     tooltip  : this._lc("Abbreviation"), 
     17    tooltip  : Xinha._lc("Abbreviation", "Abbreviation"), 
    1818    image    : editor.imgURL("ed_abbreviation.gif", "Abbreviation"), 
    1919    textMode : false, 
    2020    action   : function(editor) { 
    21                  self.buttonPress(editor); 
     21                 self.show(); 
    2222               } 
    23   }) 
     23  }); 
    2424  cfg.addToolbarElement("abbreviation", "inserthorizontalrule", 1); 
    2525} 
     
    3636}; 
    3737 
    38 Abbreviation.prototype._lc = function(string) { 
    39     return Xinha._lc(string, 'Abbreviation'); 
     38// Fills in the text field if the acronym is either known (i.e., in the [lang].js file) 
     39// or if we're editing an existing abbreviation. 
     40Abbreviation.prototype.fillText = function() { 
     41  var editor = this.editor; 
     42  var text = this.html.toUpperCase(); 
     43  var abbr = Xinha.getPluginDir(this.constructor.name) + "/abbr/" + _editor_lang + ".js"; 
     44  var abbrData = Xinha._geturlcontent(abbr); 
     45 
     46  if (abbrData) { 
     47    eval('abbrObj = ' + abbrData); 
     48    if (abbrObj != "") { 
     49      var dest = this.dialog.getElementById("title"); 
     50      dest.value = this.title || ""; 
     51      for (var i in abbrObj) { 
     52        same = (i.toUpperCase()==text); 
     53        if (same) 
     54          dest.value = abbrObj[i]; 
     55      } 
     56    } 
     57  } 
     58} 
     59 
     60Abbreviation.prototype.onGenerateOnce = function(editor) { 
     61  this.editor.addEditorStylesheet(Xinha.getPluginDir('Abbreviation') + '/abbreviation.css'); 
     62  this.methodsReady = true; //remove this? 
     63  var self = Abbreviation; 
     64  Xinha._getback(Xinha.getPluginDir('Abbreviation') + '/dialog.html', function(getback) { self.html = getback; self.dialogReady = true; }); 
    4065}; 
    4166 
    42 Abbreviation.prototype.onGenerate = function() { 
    43   this.editor.addEditorStylesheet(Xinha.getPluginDir('Abbreviation') + '/abbreviation.css'); 
    44 }; 
     67Abbreviation.prototype.OnUpdateToolbar = function(editor) { 
     68  if (!(Abbreviation.dialogReady && Abbreviation.methodsReady)) 
     69  { 
     70    this.editor._toolbarObjects.Abbreviation.state("enabled", false); 
     71  } 
     72  else this.onUpdateToolbar = null; 
     73} 
    4574 
    46 Abbreviation.prototype.buttonPress = function(editor, context, updatecontextclass) { 
    47   var outparam = null; 
    48   var html = editor.getSelectedHTML(); 
     75Abbreviation.prototype.prepareDialog = function(html) { 
     76  var self = this; 
     77  var editor = this.editor; 
     78  var dialog = this.dialog = new Xinha.Dialog(editor, Abbreviation.html, 'Xinha', {width: 260, height:140}); 
     79 
     80  dialog.getElementById('ok').onclick = function() { self.apply(); }; 
     81  dialog.getElementById('delete').onclick = function() { self.ondelete(); }; 
     82  dialog.getElementById('cancel').onclick = function() { self.dialog.hide(); }; 
     83   
     84  this.dialogReady = true; 
     85} 
     86 
     87Abbreviation.prototype.show = function(editor) { 
     88  var editor = this.editor; 
     89  this.html = editor.getSelectedHTML(); 
     90  if (!this.dialog) this.prepareDialog(); 
     91  var self = this; 
     92  var doc = editor._doc; 
    4993  var sel  = editor._getSelection(); 
    5094  var range  = editor._createRange(sel); 
    5195  var abbr = editor._activeElement(sel); 
     96   
    5297  if(!(abbr != null && abbr.tagName.toLowerCase() == "abbr")) { 
    5398    abbr = editor._getFirstAncestor(sel, 'abbr'); 
    5499  } 
    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}; 
     100  this.abbr = abbr; 
     101   
     102  if (abbr) this.title = abbr.title; 
     103  this.fillText(); 
    61104 
    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); 
     105  this.dialog.getElementById("inputs").onsubmit = function() { 
     106    self.apply(); 
     107    return false; 
     108  } 
     109 
     110  this.dialog.show(); 
     111  this.dialog.getElementById("title").select(); 
     112} 
     113 
     114Abbreviation.prototype.apply = function() { 
     115  var editor = this.editor; 
     116  var doc = editor._doc; 
     117  var abbr = this.abbr; 
     118  var html = this.html; 
     119  var param = this.dialog.hide(); 
     120 
     121  if ( param ) { 
     122    var title = param["title"]; 
     123    if (title == "" || title == null) { 
     124      if (abbr) { 
     125        var child = abbr.innerHTML; 
     126        abbr.parentNode.removeChild(abbr); 
     127        editor.insertHTML(child); // FIX: This doesn't work in Safari 3  
     128      } 
     129      return; 
     130    } 
     131    try { 
     132      if (!abbr) { 
     133        abbr = doc.createElement("abbr"); 
     134        abbr.title = title; 
     135        abbr.innerHTML = html; 
     136        if (Xinha.is_ie) { 
     137          range.pasteHTML(abbr.outerHTML); 
     138        } else { 
     139          editor.insertNodeAtSelection(abbr); 
    70140        } 
    71         return; 
     141      } else { 
     142        abbr.title = title; 
    72143      } 
    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           } 
    84         } else { 
    85           abbr.title = title; 
    86         } 
    87       } 
    88       catch (e) { } 
    89144    } 
    90   }, outparam); 
    91 }; 
     145    catch (e) { } 
     146  } 
     147} 
     148 
     149 
     150Abbreviation.prototype.ondelete = function() { 
     151  this.dialog.getElementById('title').value = ""; 
     152  this.apply(); 
     153} 
  • branches/new-dialogs/plugins/Abbreviation/dialog.html

    r1036 r1037  
    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 
Note: See TracChangeset for help on using the changeset viewer.