Ignore:
Timestamp:
10/02/08 17:07:26 (11 years ago)
Author:
douglas
Message:

FIXED Ticket #1176 Merging new dialogs branch back to trunk.

Location:
trunk/plugins/Abbreviation
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/Abbreviation/abbreviation.js

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