Index: abbreviation.js
===================================================================
--- abbreviation.js	(revision 1015)
+++ abbreviation.js	(working copy)
@@ -6,6 +6,18 @@
 // Distributed under the same terms as HTMLArea itself.
 // This notice MUST stay intact for use (see license.txt).
 
+
+Abbreviation._pluginInfo = {
+  name          : "Abbreviation",
+  version       : "1.0",
+  developer     : "Udo Schmal",
+  developer_url : "",
+  sponsor       : "L.N.Schaffrath NeueMedien",
+  sponsor_url   : "http://www.schaffrath-neuemedien.de/",
+  c_owner       : "Udo Schmal & Schaffrath-NeueMedien",
+  license       : "htmlArea"
+};
+
 function Abbreviation(editor) {
   this.editor = editor;
   var cfg = editor.config;
@@ -14,78 +26,137 @@
   // register the toolbar buttons provided by this plugin
   cfg.registerButton({
     id       : "abbreviation",
-    tooltip  : this._lc("Abbreviation"),
+    tooltip  : Xinha._lc("Abbreviation", "Abbreviation"),
     image    : editor.imgURL("ed_abbreviation.gif", "Abbreviation"),
     textMode : false,
     action   : function(editor) {
-                 self.buttonPress(editor);
+                 self.show();
                }
-  })
+  });
   cfg.addToolbarElement("abbreviation", "inserthorizontalrule", 1);
 }
 
-Abbreviation._pluginInfo = {
-  name          : "Abbreviation",
-  version       : "1.0",
-  developer     : "Udo Schmal",
-  developer_url : "",
-  sponsor       : "L.N.Schaffrath NeueMedien",
-  sponsor_url   : "http://www.schaffrath-neuemedien.de/",
-  c_owner       : "Udo Schmal & Schaffrath-NeueMedien",
-  license       : "htmlArea"
-};
+// Fills in the text field if the acronym is either known (i.e., in the [lang].js file)
+// or if we're editing an existing abbreviation.
+Abbreviation.prototype.fillText = function(editor) {
+  var editor = this.editor;
+  var text = this.html.toUpperCase();
+  var abbr = Xinha.getPluginDir(this.constructor.name) + "/abbr/" + _editor_lang + ".js";
+  var abbrData = Xinha._geturlcontent(abbr);
 
-Abbreviation.prototype._lc = function(string) {
-    return Xinha._lc(string, 'Abbreviation');
-};
+  if (abbrData) {
+    eval('abbrObj = ' + abbrData);
+    if (abbrObj != "") {
+      var dest = this.dialog.getElementById("title");
+      dest.value = this.title || "";
+      for (var i in abbrObj) {
+        same = (i.toUpperCase()==text);
+        if (same)
+          dest.value = abbrObj[i];
+      }
+    }
+  }
+}
 
-Abbreviation.prototype.onGenerate = function() {
+Abbreviation.prototype.onGenerateOnce = function(editor) {
   this.editor.addEditorStylesheet(Xinha.getPluginDir('Abbreviation') + '/abbreviation.css');
+  this.methodsReady = true; //remove this?
+  var self = Abbreviation;
+  Xinha._getback(Xinha.getPluginDir('Abbreviation') + '/dialog.html', function(getback) { self.html = getback; self.dialogReady = true; });
 };
 
-Abbreviation.prototype.buttonPress = function(editor, context, updatecontextclass) {
-  var outparam = null;
-  var html = editor.getSelectedHTML();
+Abbreviation.prototype.OnUpdateToolbar = function(editor) {
+  if (!(Abbreviation.dialogReady && Abbreviation.methodsReady))
+  {
+    this.editor._toolbarObjects.Abbreviation.state("enabled", false);
+  }
+  else this.onUpdateToolbar = null;
+}
+
+Abbreviation.prototype.prepareDialog = function(html) {
+  var self = this
+  var editor = this.editor;
+  var dialog = this.dialog = new Xinha.Dialog(editor, Abbreviation.html, 'Xinha', {width: 260, height:140});
+
+  dialog.getElementById('ok').onclick = function() { self.create(); };
+  dialog.getElementById('delete').onclick = function() { self.ondelete(); };
+  dialog.getElementById('cancel').onclick = function() { self.dialog.hide(); };
+  
+  this.dialogReady = true;
+}
+
+Abbreviation.prototype.show = function(editor) {
+  var editor = this.editor
+  this.html = editor.getSelectedHTML();
+  if (!this.dialog) this.prepareDialog();
+  var self = this;
+  var doc = editor._doc;
   var sel  = editor._getSelection();
   var range  = editor._createRange(sel);
   var abbr = editor._activeElement(sel);
+  
   if(!(abbr != null && abbr.tagName.toLowerCase() == "abbr")) {
     abbr = editor._getFirstAncestor(sel, 'abbr');
   }
-  if (abbr != null && abbr.tagName.toLowerCase() == "abbr")
-    outparam = { title : abbr.title,
-                 text : abbr.innerHTML};
-  else
-    outparam = { title : '',
-                 text : html};
+  this.abbr = abbr;
+  
+  if (abbr) this.title = abbr.title;
+  this.fillText();
 
-  editor._popupDialog( "plugin://Abbreviation/abbreviation", function( param ) {
-    if ( param ) {
-      var title = param["title"];
-      if (title == "" || title == null) {
-        if (abbr) {
-          var child = abbr.innerHTML;
-          abbr.parentNode.removeChild(abbr);
-          editor.insertHTML(child);
-        }
-        return;
+  this.dialog.getElementById("inputs").onsubmit = function() {
+    self.create();
+    return false;
+  }
+
+  this.dialog.show();
+  this.dialog.getElementById("title").select();
+}
+
+Abbreviation.prototype.create = function(editor) {
+  this.param = this.dialog.getValues();
+  this.apply();
+}
+
+Abbreviation.prototype.apply = function(editor) {
+  var editor = this.editor;
+  var doc = editor._doc;
+  var abbr = this.abbr;
+  var html = this.html
+  var param = this.param;
+
+  this.dialog.hide();
+
+  if ( param ) {
+    var title = param["title"];
+    if (title == "" || title == null) {
+      if (abbr) {
+        var child = abbr.innerHTML;
+        abbr.parentNode.removeChild(abbr);
+        editor.insertHTML(child);
       }
-      try {
-        var doc = editor._doc;
-        if (!abbr) {
-          abbr = doc.createElement("abbr");
-          abbr.title = title;
-          abbr.innerHTML = html;
-          if (Xinha.is_ie) {
-            range.pasteHTML(abbr.outerHTML);
-          } else {
-            editor.insertNodeAtSelection(abbr);
-          }
+      return;
+    }
+    try {
+      var doc = editor._doc;
+      if (!abbr) {
+        abbr = doc.createElement("abbr");
+        abbr.title = title;
+        abbr.innerHTML = html;
+        if (Xinha.is_ie) {
+          range.pasteHTML(abbr.outerHTML);
         } else {
-          abbr.title = title;
+          editor.insertNodeAtSelection(abbr);
         }
+      } else {
+        abbr.title = title;
       }
-      catch (e) { }
     }
-  }, outparam);
-};
\ No newline at end of file
+    catch (e) { }
+  }
+}
+
+
+Abbreviation.prototype.ondelete = function(editor) {
+  this.param = {title : ""};
+  this.apply();
+}
\ No newline at end of file
Index: dialog.html
===================================================================
--- dialog.html	(revision 1015)
+++ dialog.html	(working copy)
@@ -1,92 +1,16 @@
-<html>
-<head>
-  <title>Abbreviation</title>
-  <link rel="stylesheet" type="text/css" href="../../../popups/popup.css" />
-  <script type="text/javascript" src="../../../popups/popup.js"></script>
+<h1 id="[h1]"><l10n>Abbreviation</l10n></h1>
 
-<script type="text/javascript">
-var Abbreviation = window.opener.Abbreviation; // load the Abbreviation plugin and lang file ;-)
+<form name="form" action="" method="get" id="[inputs]">
+  <fieldset>
+    <legend><l10n>Expansion:</l10n></legend>
+    <input type="text" id="[title]" name="[title]" size="35" />
+ </fieldset>
+<p />
 
-function fillSelect(text) {
-  var abbr = window.location.href;
-  abbr = abbr.replace(/popups\/abbreviation.html/g, "abbr\/" + window.opener._editor_lang + ".js");
-  var abbrData = Xinha._geturlcontent(abbr);
-  if (abbrData) {
-    eval('abbrObj = ' + abbrData);
-    if (abbrObj != "") {
-      dest = document.getElementById("select");
-      for (var i in abbrObj) {
-        same = (i==text);
-        dest.options[dest.options.length] = new Option(i + "=" + abbrObj[i], abbrObj[i], false, same);
-        if (same)
-        document.getElementById("title").value = abbrObj[i];
-      }
-    }
-  }
-}
-
-function Init() {
-  __dlg_translate("Abbreviation");
-  __dlg_init(null,{width: 260, height: 160});
-  var param = window.dialogArguments;
-  var text = null;
-  if (param) {
-    text = param["text"];
-    document.getElementById("title").value = param["title"];
-  }
-  fillSelect(text);
-  document.getElementById("title").focus();
-};
-
-function onOK() {
-  var param = new Object();
-  param["title"] = document.getElementById("title").value;
-  __dlg_close(param);
-  return false;
-}
-
-
-function onDelete() {
-  // pass data back to the calling window
-  var param = new Object();
-  param["title"] = "";
-  __dlg_close(param);
-  return false;
-};
-
-function onCancel() {
-  __dlg_close(null);
-  return false;
-};
-</script>
-
-</head>
-<body class="dialog" onload="Init()">
-<div class="title">Abbreviation</div>
-<form name="form" action="">
-<table border="0" style="width: 100%;">
-  <tr>
-    <td class="lable">Expansion:</td>
-    <td>
-    <select id="select" name="select"
-            onChange="document.form.title.value=document.form.select.options[document.form.select.selectedIndex].value"
-            style="position:absolute; top:35px; left:100px; width:118px; clip:rect(0 120 22 100)">
-      <option value=""></option>
-
-    </select>
-    <input type="text" id="title" name="title"
-           onChange="document.form.select.selectedIndex=-1"
-           style="position:absolute; top:35px; left:100px; width:100px; border-right:0">
-    <!--<input type="text" id="title" name="title" value="" size="30">-->
-    </td>
-  </tr>
-</table>
-
-<div id="buttons">
-   <button type="submit" name="ok" onclick="return onOK();">OK</button>
-   <button type="button" name="delete" onclick="return onDelete();">Delete</button>
-   <button type="button" name="cancel" onclick="return onCancel();">Cancel</button>
+<div class="buttons" id="[buttons]">
+  <input type="button" id="[ok]"     value="_(OK)"     />
+  <input type="button" id="[delete]" value="_(Delete)" />
+  <input type="button" id="[cancel]" value="_(Cancel)" />
 </div>
 </form>
-</body>
-</html>
+

