source: trunk/plugins/InsertAnchor/insert-anchor.js @ 981

Last change on this file since 981 was 981, checked in by ray, 11 years ago

#1155 InsertAnchor? broken in IE 7

  • Property svn:executable set to *
  • Property svn:keywords set to LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
File size: 3.2 KB
Line 
1function InsertAnchor(editor) {
2  this.editor = editor;
3  var cfg = editor.config;
4  var self = this;
5 
6  this.placeholderImg = '<img class="IA_placeholder" src="'+_editor_url+'plugins/InsertAnchor/img/placeholder.gif" />';
7 
8  // register the toolbar buttons provided by this plugin
9  cfg.registerButton({
10  id       : "insert-anchor",
11  tooltip  : this._lc("Insert Anchor"),
12  image    : editor.imgURL("insert-anchor.gif", "InsertAnchor"),
13  textMode : false,
14  action   : function(editor) {
15               self.buttonPress(editor);
16             }
17  });
18  cfg.addToolbarElement("insert-anchor", "createlink", 1);
19}
20
21InsertAnchor._pluginInfo = {
22  name          : "InsertAnchor",
23  origin        : "version: 1.0, by Andre Rabold, MR Printware GmbH, http://www.mr-printware.de",
24  version       : "2.0",
25  developer     : "Udo Schmal",
26  developer_url : "http://www.schaffrath-neuemedien.de",
27  c_owner       : "Udo Schmal",
28  sponsor       : "L.N.Schaffrath NeueMedien",
29  sponsor_url   : "http://www.schaffrath-neuemedien.de",
30  license       : "htmlArea"
31};
32
33InsertAnchor.prototype._lc = function(string) {
34    return Xinha._lc(string, 'InsertAnchor');
35};
36
37InsertAnchor.prototype.onGenerate = function() {
38  this.editor.addEditorStylesheet(_editor_url + 'plugins/InsertAnchor/insert-anchor.css');
39 
40};
41
42InsertAnchor.prototype.inwardHtml = function(html)
43{
44        html= html.replace(/(<a[^>]*class="anchor"[^>]*>)/g,"$1"+this.placeholderImg);
45        return html;
46}
47InsertAnchor.prototype.outwardHtml = function(html)
48{
49        html= html.replace(/(<img[^>]*class="?IA_placeholder"?[^>]*>)/ig,"");
50        return html;
51}
52
53InsertAnchor.prototype.buttonPress = function(editor) {
54  var outparam = null;
55  var html = editor.getSelectedHTML();
56  var sel  = editor._getSelection();
57  var range  = editor._createRange(sel);
58  var self = this;
59  var  a = editor._activeElement(sel);
60  if(!(a != null && a.tagName.toLowerCase() == 'a')) {
61    a = editor._getFirstAncestor(sel, 'a');
62  }
63  if (a != null && a.tagName.toLowerCase() == 'a')
64    outparam = { name : a.id };
65  else
66    outparam = { name : '' };
67
68  editor._popupDialog( "plugin://InsertAnchor/insert_anchor", function( param ) {
69    if ( param ) {
70      var anchor = param["name"];
71      if (anchor == "" || anchor == null) {
72        if (a) {
73          var child = self.outwardHtml(a.innerHTML);
74          a.parentNode.removeChild(a);
75          editor.insertHTML(child);
76        }
77        return;
78      }
79      try {
80        var doc = editor._doc;
81        if (!a) {
82//          editor.surroundHTML('<a id="' + anchor + '" name="' + anchor + '" title="' + anchor + '" class="anchor">', '</a>');
83          a = doc.createElement("a");
84          a.id = anchor;
85          a.name = anchor;
86          a.title = anchor;
87          a.className = "anchor";
88          a.innerHTML = self.placeholderImg;
89                  if (html) a.innerHTML += html;
90          if (Xinha.is_ie) {
91            range.pasteHTML(a.outerHTML);
92          } else {
93            editor.insertNodeAtSelection(a);
94          }
95        } else {
96          a.id = anchor;
97          a.name = anchor;
98          a.title = anchor;
99          a.className = "anchor";
100        }
101      }
102      catch (e) { }
103    }
104  }, outparam);
105};
Note: See TracBrowser for help on using the repository browser.