Opened 9 years ago
Closed 9 years ago
#13885 closed Task (fixed)
Make Image2 widget linking possible without a direct dependency of Link Plugin.
Reported by: | Olek Nowodziński | Owned by: | Olek Nowodziński |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 4.5.5 |
Component: | UI : Widgets | Version: | |
Keywords: | Drupal | Cc: | wim.leers@…, nate@… |
Description
A followup of https://www.drupal.org/node/2510380.
Problem
At the moment, linking of Image2 widgets depends strictly on Link Plugin's CKEDITOR.plugins.link.(parse|get)LinkAttributes
- https://github.com/ckeditor/ckeditor-dev/blob/7856fe93f844be5053fa62cad1ece1ba6fc8635b/plugins/image2/plugin.js#L412-L421
- https://github.com/ckeditor/ckeditor-dev/blob/7856fe93f844be5053fa62cad1ece1ba6fc8635b/plugins/image2/plugin.js#L615
- https://github.com/ckeditor/ckeditor-dev/blob/7856fe93f844be5053fa62cad1ece1ba6fc8635b/plugins/image2/plugin.js#L1355-L1356
Because of this hard dependency, when the Link plugin is not loaded, there's no way to enable Image2 widget linking with an external link parser/serialiser (like (parse|get)LinkAttributes
).
Cake recipe
The idea is quite straightforward: let's provide the link parsing/serialisation API via static CKEDITOR.plugins.image2
namespace, which already exists.
A method like CKEDITOR.plugins.image2.getLinkAPI()
could return CKEDITOR.plugins.link
namespace. Or a custom object, if one decided to overwrite it:
CKEDITOR.plugins.image2.getLinkAPI = function() { return { getLinkAttributes: function () { custom implementation }, parseLinkAttributes: function () { custom implementation } } }
Profits:
- Re–enable linking when Link plugin is not loaded.
- Allow a custom parsers/serialisers, which could be much simpler than default
CKEDITOR.plugins.link.(parse|get)LinkAttributes
implementations.
Change History (14)
comment:1 Changed 9 years ago by
Owner: | set to Olek Nowodziński |
---|---|
Status: | new → assigned |
comment:2 Changed 9 years ago by
comment:3 Changed 9 years ago by
Cc: | wim.leers@… added |
---|---|
Keywords: | Drupal added |
comment:4 Changed 9 years ago by
Cc: | nate@… added |
---|
comment:6 Changed 9 years ago by
@a.nowodzinski pinged me. I tested this, and it works splendidly.
Full review plus how Drupal would use this API at https://www.drupal.org/node/2510380#comment-10522410.
Text from there quoted here:
Good news! @oleq notified me that he has a proposed solution ready for testing at http://dev.ckeditor.com/ticket/13885#comment:5. I worked on updating the above patch to use the new API that his patch adds. And it indeed allows us to simplify the code here, *and* not pretend the CKEditor <code>link</code> plugin is present.
Note this is a future interdiff, that we cannot use until we update to CKEditor 4.5.5 (see #2321583) and until that fix is actually <em>committed</em> to CKEditor 4.5.5.
So, hurray, this will become more maintainable with CKEditor 4.5.5!
comment:7 Changed 9 years ago by
Remember my rant in chat about how the link
plugin's data model is full with legacy stuff that makes it very hard to understand and use?
Well, I'm afraid this API will actually have to explicitly document that. Because if it doesn't use the exact same data structure, then it won't work.
Except… I could actually "ignore" link
's data model and just use my own, as long as getLinkAttributes()
returns the expected data structure ({set: {…}, remove: {}…}
). Because the only thing that "actually" needs to be able to deal with parseLinkAttributes()
's return value, is getLinkAttributes()
, right?
comment:8 Changed 9 years ago by
@Wim: If you decide to use a custom Link dialog then yes, you can use whatever parseLinkAttributes()
(getLinkAttributesParser()
) implementation you want and you should be safe.
However you just need to keep the getLinkAttributes()
API ({set: {…}, remove: {}…})
) because it is used in CKEDITOR.plugins.image2.stateShifter
to change the state of the widget.
I'll extend the documentation strings for both methods implemented in this ticket. I think that Link Plugin's legacy data format also deserves a few words of comment.
comment:10 Changed 9 years ago by
This will allow me to fix something in drupallink
(Drupal's custom link
plugin): the link
plugin does "not" support just about any attribute you throw at it. The drupallink
plugin does (needs to be able to).
Therefore, with the empowerment to have our own data structure in parseLinkAttributes()
, we *can* support that without abusing link
's data model.
comment:11 Changed 9 years ago by
Pushed an extensive documentation of getLinkAttributes(Parser|Getter)()
and updated documentation of (parse|get)LinkAttributes()
to branch:t/13885.
comment:12 Changed 9 years ago by
Status: | assigned → review |
---|
comment:14 Changed 9 years ago by
Resolution: | → fixed |
---|---|
Status: | review → closed |
Great! Merged to master with git:68b6b3bc.
cc