[wp-trac] [WordPress Trac] #32180: Make link generation in wplink.js extendable

WordPress Trac noreply at wordpress.org
Wed Apr 29 06:57:12 UTC 2015


#32180: Make link generation in wplink.js extendable
----------------------------------------+-----------------------------
 Reporter:  martinsachse                |      Owner:
     Type:  enhancement                 |     Status:  new
 Priority:  normal                      |  Milestone:  Awaiting Review
Component:  Editor                      |    Version:
 Severity:  normal                      |   Keywords:
  Focuses:  javascript, administration  |
----------------------------------------+-----------------------------
 It should be possible to extend the html that is generated by /wp-
 includes/js/wplink.js.js in the htmlUpdate-method.

 The solution that I am suggesting is the following. Seperate the
 generation of the opening a-tag (lines 293-300) into its own method e.g.

 {{{
 wpLink = {
   ...
   buildHtml: function(attrs) {
     var html = '<a href="' + attrs.href + '"';

     if ( attrs.target ) {
       html += ' target="' + attrs.target + '"';
     }

     return html + '>';
   }
   ...
 }
 }}}

 This would make it possible to extend the generated opening a-tag the
 following way:

 {{{
 (function() {
   var buildHtml = wpLink.buildHtml;

   wpLink.buildHtml = function() {
     var html = buildHtml.apply(this, arguments);

     html = html.replace('>', ' data-custom-attribute="my-data">');

     return html;
   }
 }());
 }}}

 The advantage of this method is that more than one plugin can extend the
 generation. Current solutions overwrite the complete wplink.js which will
 not work if more than one plugin try to extend the generation. It is also
 a problem if anything changes in the wplink.js with an update.

 Possible use cases for this change:
 * Plugin that extends the link-dialog with a nofollow-option
 * Plugin that extends the link-dialog with a select for classnames
 * Plugin that lets you configure custom classes for domains. e.g. every
 link to example.com gets the class example

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32180>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list