Search code examples
jqueryjquery-uidrupal-7ckeditor

Ckeditor library strips out brackets from target attribute when using link - Drupal/Jquery UI


Hello I have a drupal 7 project that uses the ckeditor library (not module) and a plugin called ckeditor_link.

I am using this plugin so that users can link internal paths in the wysiwyg using typeahead functionality.

One of the features I was hoping for was once a user selects an internal path in the link tab of the dialog they could go to the target tab and set its value to [dialog] - this is how the shortcode for the jquery ui dialog works per the demo <a href="link-to-content" target="[dialog]">Dialog Link</a> However in the ckeditor library there is a line in the minified link.js file that strips non alphabetical characters commit:function(a){a.target||(a.target={});a.target.name=this.getValue().replace(/\W/gi,"")}

The result is that when a user links and intended for that link to be a dialog the result is actually <a href="link-to-internal-path" target="dialog">Dialog Broken</a> which will not hook into the shortcode/out of the box drupal jquery ui functionality.

How can I overwrite this ckeditor rule? Preferably directly in the ckeditor_link plugin I am using.


Solution

  • I'm not exactly sure how are you inserting target for internal link ("link to anchor in text" to my understanding) but looking at the editor code, I can tell you, the Regex pattern in question has been changed in CKEditor 4.5.5 from /\W/gi to /([^\x00-\x7F]|\s)/gi and it no longer removes []. Please see below code snippet:

    console.log("[dialog]".replace(/([^\x00-\x7F]|\s)/gi,""));
    console.log("[dialog]".replace(/\W/gi,""));

    If this pattern is indeed the source of your problem then I would strongly recommend upgrading the editor to version 4.8.