+
+ edButtons[priority] = btn;
+ } else {
+ edButtons[edButtons.length] = btn;
+ }
+
+ if ( this.buttonsInitDone )
+ this._buttonsInit(); // add the button HTML to all instances toolbars if addButton() was called too late
+ };
+
+ qt.insertContent = function(content) {
+ var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor);
+
+ if ( !canvas )
+ return false;
+
+ if ( document.selection ) { //IE
+ canvas.focus();
+ sel = document.selection.createRange();
+ sel.text = content;
+ canvas.focus();
+ } else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { // FF, WebKit, Opera
+ text = canvas.value;
+ startPos = canvas.selectionStart;
+ endPos = canvas.selectionEnd;
+ scrollTop = canvas.scrollTop;
+
+ canvas.value = text.substring(0, startPos) + content + text.substring(endPos, text.length);
+
+ canvas.focus();
+ canvas.selectionStart = startPos + content.length;
+ canvas.selectionEnd = startPos + content.length;
+ canvas.scrollTop = scrollTop;
+ } else {
+ canvas.value += content;
+ canvas.focus();
+ }
+ return true;
+ };
+
+ // a plain, dumb button
+ qt.Button = function(id, display, access, title, instance) {
+ var t = this;
+ t.id = id;
+ t.display = display;
+ t.access = access;
+ t.title = title || '';
+ t.instance = instance || '';
+ };
+ qt.Button.prototype.html = function(idPrefix) {
+ var access = this.access ? ' accesskey="' + this.access + '"' : '';
+ return '<input type="button" id="' + idPrefix + this.id + '"' + access + ' class="ed_button" title="' + this.title + '" value="' + this.display + '" />';
+ };
+ qt.Button.prototype.callback = function(){};
+
+ // a button that inserts HTML tag
+ qt.TagButton = function(id, display, tagStart, tagEnd, access, title, instance) {
+ var t = this;
+ qt.Button.call(t, id, display, access, title, instance);
+ t.tagStart = tagStart;
+ t.tagEnd = tagEnd;
+ };
+ qt.TagButton.prototype = new qt.Button();
+ qt.TagButton.prototype.openTag = function(e, ed) {
+ var t = this;
+
+ if ( ! ed.openTags ) {
+ ed.openTags = [];
+ }
+ if ( t.tagEnd ) {
+ ed.openTags.push(t.id);
+ e.value = '/' + e.value;
+ }
+ };
+ qt.TagButton.prototype.closeTag = function(e, ed) {
+ var t = this, i = t.isOpen(ed);
+
+ if ( i !== false ) {
+ ed.openTags.splice(i, 1);
+ }
+
+ e.value = t.display;
+ };
+ // whether a tag is open or not. Returns false if not open, or current open depth of the tag
+ qt.TagButton.prototype.isOpen = function (ed) {
+ var t = this, i = 0, ret = false;
+ if ( ed.openTags ) {
+ while ( ret === false && i < ed.openTags.length ) {
+ ret = ed.openTags[i] == t.id ? i : false;
+ i ++;