[wp-trac] [WordPress Trac] #16695: quicktags needs some refactoring
WordPress Trac
wp-trac at lists.automattic.com
Mon Feb 28 17:58:30 UTC 2011
#16695: quicktags needs some refactoring
-------------------------+------------------------------
Reporter: garyc40 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version: 3.1
Severity: normal | Resolution:
Keywords: has-patch |
-------------------------+------------------------------
Comment (by filosofo):
Also, if we're going to rewrite quicktags, let's get rid of some of that
HTML-building duplication and generalize the edButton object to generate
the markup (and attach its click callback) based on the parameters it
already has.
I did this a couple years ago like so: (I'd change some things now, such
as setting the DOM element properties instead of attributes, and it could
just as well be an `input` element instead of a `button`.)
{{{
// button object
var Button = function(args) {
args = args || {};
var that = this;
this.build = function() {
var attrs = {
accesskey:this.access,
'class':'qtags-button',
id:this.id,
type:'button'
},
i, button = document.createElement('button');
button.innerHTML = this.display;
for ( i in attrs )
if ( attrs[i] )
button.setAttribute(i, attrs[i]);
button.onclick = function() { that.callback.apply(that,
that.callbackArgs) };
return button;
};
this.opentags = function() {
return !! ( this.opens > 0 );
};
this.opens = 0; // counts of open versions of this tag
this.display = args.display;
this.tagStart = args.tagStart || '<' + this.display + '>';
this.tagEnd = args.tagEnd || '</' + this.display + '>';
this.id = args.id || 'qtags-' + this.display;
this.callback = args.callback || function() {};
this.callbackArgs = args.callbackArgs || [];
this.access = args.access;
this.open = args.open || 0;
this.el = this.build();
return this;
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/16695#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list