Ticket #1553 (closed defect: fixed)
editor._createLink is not a function
| Reported by: | guest | Owned by: | gogo |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.97 |
| Component: | Xinha Core | Version: | trunk |
| Severity: | normal | Keywords: | |
| Cc: | ethan.jucovy@… |
Description
There's some confusing code in XinhaCore.js related to execCommand("_createLink"):
case "createlink": this._createLink();
The _createLink function is never defined on the Xinha editor object.
From code comments elsewhere, it looks like the intention is to define the function in a plugin, which will be modules/CreateLink if no other plugin (like Linker) overrides it. ("This is the standard implementation of the Xinha.prototype._createLink method")
But, Xinha.prototype._createLink is NOT defined by Linker, nor by CreateLink. Instead, both plugins work by overriding the default behavior of the createlink button on the toolbar.
Default behavior:
createlink: [ "Insert Web Link", ["ed_buttons_main.png",6,1], false, function(e) { e._createLink(); } ],
CreateLink override:
editor.config.btnList.createlink[3] = function() { self.show(self._getSelectedAnchor()); }
Linker override:
editor.config.btnList.createlink[3]
= function(e, objname, obj) { linker._createLink(linker._getSelectedAnchor()); };
(Here linker refers to the Linker plugin object, not the xinha editor object. The Linker object defines a _createLink method on itself, but not on the xinha editor object.)
CreateLink is a module, so it will always be loaded and override the default behavior. But there are three problems with this:
- It's confusing to somebody reading the code.
- It means there is no standard way to trigger a "createlink" command or to listen for a "createlink" event (which would be useful; see #1552)
- XinhaCore.js itself assumes the editor object has a _createLink method
XinhaCore.js tries to call editor._createLink() if you double-click on an anchor element:
this.dblclickList =
{
"a": [function(e, target) {e._createLink(target);}],
"img": [function(e, target) {e._insertImage(target);}]
};
This causes a Javascript error in browsers, because e._createLink is not defined.
In fact the DoubleClick plugin has to override this definition:
this.editor.dblClickList = {
a: [ function(e) {e.config.btnList['createlink'][3](e); } ],
The same approach is used with InsertImage and editor._insertImage, but there it seems to be done (more) correctly: InsertImage defines editor.prototype._insertImage, and execCommand("insertimage") calls that function.
Proposed solutions:
- (Better solution) The code should define editor.prototype._createLink, and execCommand("createlink") should be the standard way to trigger a link-creation action.
- (Worse solution) References to editor._createLink should be removed.
