[wp-trac] [WordPress Trac] #16695: quicktags needs some refactoring

WordPress Trac wp-trac at lists.automattic.com
Tue Mar 1 16:35:08 UTC 2011


#16695: quicktags needs some refactoring
----------------------------------------------+----------------------------
 Reporter:  garyc40                           |       Owner:
     Type:  enhancement                       |      Status:  new
 Priority:  normal                            |   Milestone:  Awaiting
Component:  Editor                            |  Review
 Severity:  normal                            |     Version:  3.1
 Keywords:  has-patch dev-feedback 3.2-early  |  Resolution:
----------------------------------------------+----------------------------
Changes (by garyc40):

 * keywords:  has-patch => has-patch dev-feedback 3.2-early


Comment:

 Attached [attachment:16695.4.diff], which is a complete refactoring of
 `quicktags.dev.js`.

 What has been improved:

 * Code passes [http://www.jslint.com/ JSLint].

 * Code duplication is addressed. Reduce total lines from 579 to 384.

 * Unobtrusive JavaScript such as `document.write()` or
 `onclick="edInsertButton(...)"` is not used.

 * Everything is properly namespaced, i.e. no more cluttered global scope.

 * Quick Links is removed

 * An API is provided for plugins and themes to add buttons to quicktags
 toolbar. Previously they either have to hack quicktags.js directly, or use
 the global `edButtons` array. The API is based on JavaScript prototypal
 inheritance pattern.

 To add a button, a developer can extend QuickTags.Button or
 QuickTags.TagButton, override the callback to provide the desired
 functionality, then add the button by using:

 {{{
 QuickTags.registerButton(id, btnClass);
 }}}

 To extend the base classes:

 {{{
 // DivButton which inherits from TagButton
 var DivButton = function() {
         // initialize properties, like parent::__construct() in PHP
         QuickTags.TagButton.call(this, 'div', 'div', '/div', 'd');

         // override the callback when the button is clicked
         this.callback = function(element, canvas, toolbar) {
                 // do something
                 // ...
                 // then call the default TagButton callback, just like
 parent::callback() in PHP
                 QuickTags.TagButton.prototype.callback.call(this, element,
 canvas, toolbar);
         };
 };

 // inherit all methods and properties from TagButton
 DivButton.prototype = new QuickTags.TagButton();
 }}}

 This of course still needs more testing and feedback from core devs, but I
 believe it's definitely an improvement compared to the original code.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16695#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list