source: trunk/plugins/DefinitionList/definition-list.js @ 893

Last change on this file since 893 was 893, checked in by ray, 11 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// DefinitionList plugin for Xinha
2// Distributed under the same terms as Xinha itself.
3// This notice MUST stay intact for use (see license.txt).
4
5
6function DefinitionList(editor) {
7  this.editor = editor;
8  var cfg = editor.config;
9  var bl = DefinitionList.btnList;
10  var self = this;
11  // register the toolbar buttons provided by this plugin
12  var toolbar = ["linebreak"];
13  for (var i = 0; i < bl.length; ++i) {
14    var btn = bl[i];
15    if (!btn) {
16      toolbar.push("separator");
17    } else {
18      var id = btn[0];
19      cfg.registerButton(id, this._lc(btn[1]), editor.imgURL("ed_" + btn[0] + ".gif", "DefinitionList"), false,
20             function(editor, id) {
21               // dispatch button press event
22               self.buttonPress(editor, id);
23             });
24      toolbar.push(id);
25    }
26  }
27  // add a new line in the toolbar
28  cfg.toolbar.push(toolbar);
29}
30
31DefinitionList._pluginInfo = {
32  name          : "DefinitionList",
33  version       : "1.0",
34  developer     : "Udo Schmal",
35  developer_url : "",
36  c_owner       : "Udo Schmal",
37  license       : "htmlArea"
38};
39
40// the list of buttons added by this plugin
41DefinitionList.btnList = [
42  ["dl", "definition list"],
43  ["dt", "definition term"],
44  ["dd", "definition description"]
45  ];
46
47DefinitionList.prototype._lc = function(string) {
48  return Xinha._lc(string, 'DefinitionList');
49};
50
51DefinitionList.prototype.onGenerate = function() {
52  this.editor.addEditorStylesheet(_editor_url + 'plugins/DefinitionList/definition-list.css');
53};
54
55DefinitionList.prototype.buttonPress = function(editor,button_id) {
56  if (button_id=='dl') { //definition list
57    var pe = editor.getParentElement();
58    while (pe.parentNode.tagName.toLowerCase() != 'body') {
59      pe = pe.parentNode;
60    }
61    var dx = editor._doc.createElement(button_id);
62    dx.innerHTML = '&nbsp;';
63    if(pe.parentNode.lastChild==pe) {
64      pe.parentNode.appendChild(dx);
65    }else{
66      pe.parentNode.insertBefore(dx,pe.nextSibling);
67    }
68  } else if ((button_id=='dt')||(button_id=='dd')) { //definition term or description
69    var pe = editor.getParentElement();
70    while (pe && (pe.nodeType == 1) && (pe.tagName.toLowerCase() != 'body')) {
71      if(pe.tagName.toLowerCase() == 'dl') {
72        var dx = editor._doc.createElement(button_id);
73        dx.innerHTML = '&nbsp;';
74        pe.appendChild(dx);
75        break;
76      }else if((pe.tagName.toLowerCase() == 'dt')||(pe.tagName.toLowerCase() == 'dd')){
77        var dx = editor._doc.createElement(button_id)
78        dx.innerHTML = '&nbsp;';
79        if(pe.parentNode.lastChild==pe) {
80        pe.parentNode.appendChild(dx);
81        }else{
82          pe.parentNode.insertBefore(dx,pe.nextSibling);
83        }
84        break;
85      }
86      pe = pe.parentNode;
87    }
88    if(pe.tagName.toLowerCase() == 'body')
89  alert('You can insert a definition term or description only in a definition list!');
90  }
91};
Note: See TracBrowser for help on using the repository browser.