source: trunk/plugins/Abbreviation/abbreviation.js @ 893

Last change on this file since 893 was 893, checked in by ray, 12 years ago
  • #1079 Plugin DynamicCSS lists Xinha internal CSS
  • #1080 Some plugins leave behind stylesheet links in fullpage mode
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 2.8 KB
Line 
1// Abbreviation plugin for Xinha
2// Implementation by Udo Schmal & Schaffrath NeueMedien
3// Original Author - Udo Schmal
4//
5// (c) Udo Schmal & Schaffrath NeueMedien 2004
6// Distributed under the same terms as HTMLArea itself.
7// This notice MUST stay intact for use (see license.txt).
8
9function Abbreviation(editor) {
10  this.editor = editor;
11  var cfg = editor.config;
12  var self = this;
13
14  // register the toolbar buttons provided by this plugin
15  cfg.registerButton({
16    id       : "abbreviation",
17    tooltip  : this._lc("Abbreviation"),
18    image    : editor.imgURL("ed_abbreviation.gif", "Abbreviation"),
19    textMode : false,
20    action   : function(editor) {
21                 self.buttonPress(editor);
22               }
23  })
24  cfg.addToolbarElement("abbreviation", "inserthorizontalrule", 1);
25}
26
27Abbreviation._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};
37
38Abbreviation.prototype._lc = function(string) {
39    return Xinha._lc(string, 'Abbreviation');
40};
41
42Abbreviation.prototype.onGenerate = function() {
43  this.editor.addEditorStylesheet(_editor_url + 'plugins/Abbreviation/abbreviation.css');
44};
45
46Abbreviation.prototype.buttonPress = function(editor, context, updatecontextclass) {
47  var outparam = null;
48  var html = editor.getSelectedHTML();
49  var sel  = editor._getSelection();
50  var range  = editor._createRange(sel);
51  var abbr = editor._activeElement(sel);
52  if(!(abbr != null && abbr.tagName.toLowerCase() == "abbr")) {
53    abbr = editor._getFirstAncestor(sel, 'abbr');
54  }
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};
61
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;
72      }
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) { }
89    }
90  }, outparam);
91};
Note: See TracBrowser for help on using the repository browser.