diff --git a/wp-includes/js/quicktags.dev.js b/wp-includes/js/quicktags.dev.js index 169aeb06dd..27ec6f203e 100644 --- a/wp-includes/js/quicktags.dev.js +++ b/wp-includes/js/quicktags.dev.js @@ -52,7 +52,7 @@ function edInsertContent(bah, txt) { * @see QTags.addButton() */ function edButton(id, display, tagStart, tagEnd, access, open) { - return QTags.addButton( id, display, tagStart, tagEnd, open, access ); + return QTags.addButton( id, display, tagStart, tagEnd, open, access, '', -1 ); } (function(){ @@ -140,12 +140,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) { var t = this, id = settings.id, - buttons = {}, - theButtons = {}, canvas = document.getElementById(id), name = 'qt_' + id, - html = '', - i, tb, qb, btn, onclick, toolbar_id; + tb, onclick, toolbar_id; if ( !id || !canvas ) return false; @@ -153,17 +150,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) { t.name = name; t.id = id; t.canvas = canvas; - - // default buttons - for ( i in edButtons ) { - if ( !edButtons[i] ) - continue; - - buttons[edButtons[i].id] = edButtons[i]; - } + t.settings = settings; if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) ) { - buttons['fullscreen'] = new qt.FullscreenButton(); // back compat hack :-( edCanvas = canvas; toolbar_id = 'ed_toolbar'; @@ -171,43 +160,11 @@ function edButton(id, display, tagStart, tagEnd, access, open) { toolbar_id = name + '_toolbar'; } - // add custom buttons - for ( i in t._customButtons ) { - buttons[i] = new t._customButtons[i](); - } - - if ( settings.buttons ) { - qb = settings.buttons.split(','); - - for ( i in qb ) { - btn = qb[i]; - if ( buttons[btn] ) - theButtons[btn] = buttons[btn]; - } - } else { - theButtons = buttons; - } - - if ( settings.disabled_buttons ) { - qb = settings.disabled_buttons.split(','); - - for ( i in qb ) { - btn = qb[i]; - if ( theButtons[btn] ) - delete(theButtons[btn]); - } - } - - for ( i in theButtons ) - html += theButtons[i].html(name + '_'); - tb = document.createElement('div'); tb.id = toolbar_id; tb.className = 'quicktags-toolbar'; canvas.parentNode.insertBefore(tb, canvas); - - tb.innerHTML = html; t.toolbar = tb; // listen for click events @@ -221,8 +178,8 @@ function edButton(id, display, tagStart, tagEnd, access, open) { t.canvas = canvas = document.getElementById(id); i = target.id.replace(name + '_', ''); - if ( theButtons[i] ) - theButtons[i].callback.call(theButtons[i], target, canvas, t); + if ( t.theButtons[i] ) + t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t); } }; @@ -233,13 +190,19 @@ function edButton(id, display, tagStart, tagEnd, access, open) { } t.getButton = function(id) { - return buttons[id]; + return t.theButtons[id]; + }; + + t.getButtonElement = function(id) { + return document.getElementById(name + '_' + id); }; qt.instances[id] = t; - if ( !qt.instances[0] ) + if ( !qt.instances[0] ) { qt.instances[0] = qt.instances[id]; + _domReady( function(){ qt._buttonsInit(); } ); + } }; qt.instances = {}; @@ -251,7 +214,67 @@ function edButton(id, display, tagStart, tagEnd, access, open) { qt.getInstance = function(id) { return qt.instances[id]; }; - + + qt._buttonsInit = function() { + var t = this, instance, canvas, name, settings, buttons = {}, theButtons = {}, html = '', id, i, qb, btn;; + + for ( id in t.instances ) { + if ( id == 0 ) + continue; + + instance = t.instances[id]; + canvas = instance.canvas; + name = instance.name; + settings = instance.settings; + + // set buttons + for ( i in edButtons ) { + if ( !edButtons[i] ) + continue; + + buttons[edButtons[i].id] = edButtons[i]; + } + + if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) ) + buttons['fullscreen'] = new qt.FullscreenButton(); + + // add custom buttons + for ( i in t._customButtons ) { + if ( !buttons[i] ) + buttons[i] = new t._customButtons[i](); + } + + if ( settings.buttons ) { + qb = settings.buttons.split(','); + + for ( i in qb ) { + btn = qb[i]; + if ( buttons[btn] ) + theButtons[btn] = buttons[btn]; + } + } else { + theButtons = buttons; + } + + if ( settings.disabled_buttons ) { + qb = settings.disabled_buttons.split(','); + + for ( i in qb ) { + btn = qb[i]; + if ( theButtons[btn] ) + delete(theButtons[btn]); + } + } + + for ( i in theButtons ) + html += theButtons[i].html(name + '_'); + + instance.toolbar.innerHTML = html; + instance.theButtons = theButtons; + } + t.buttonsInitDone = true; + }; + /** * Main API function for adding a button to Quicktags * @@ -283,16 +306,21 @@ function edButton(id, display, tagStart, tagEnd, access, open) { if ( !id || !display ) return; + priority = priority || 0; + if ( typeof(arg1) == 'function' ) { btn = new qt.Button(id, display, access, title); btn.callback = arg1; - } else if ( typeof(arg1) == 'string' && arg1 && arg2 ) { + } else if ( arg1 && arg2 && typeof(arg1) == 'string' ) { btn = new qt.TagButton(id, display, arg1, arg2, access, arg3, title); } else { return; } - if ( priority ) { + if ( priority == -1 ) // back-compat + return btn; + + if ( priority > 0 ) { while ( typeof(edButtons[priority]) != 'undefined' ) { priority++ } @@ -301,6 +329,9 @@ function edButton(id, display, tagStart, tagEnd, access, open) { } 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) { diff --git a/wp-includes/js/quicktags.js b/wp-includes/js/quicktags.js index 6744cbd80c..c537edcf2e 100644 --- a/wp-includes/js/quicktags.js +++ b/wp-includes/js/quicktags.js @@ -1 +1 @@ -var QTags,edButtons=[],edCanvas;function quicktags(a){return new QTags(a)}function edInsertContent(b,a){return QTags.insertContent(a)}function edButton(f,e,c,b,a,d){return QTags.addButton(f,e,c,b,d,a)}(function(){var c=function(h){var g,f,e;if(typeof jQuery!="undefined"){jQuery(document).ready(h)}else{g=c;g.funcs=[];g.ready=function(){if(!g.isReady){g.isReady=true;for(f=0;f'};d.Button.prototype.callback=function(){};d.TagButton=function(l,j,g,f,e,h,k){var i=this;d.Button.call(i,l,j,e,k);i.tagStart=g;i.tagEnd=f;i.open=h};d.TagButton.prototype=new d.Button();d.TagButton.prototype.openTag=function(h,f){var g=this;if(!f.openTags){f.openTags=[]}if(g.tagEnd){f.openTags.push(g.id);h.value="/"+h.value}};d.TagButton.prototype.closeTag=function(j,f){var h=this,g=h.isOpen(f);if(g!==false){f.openTags.splice(g,1)}j.value=h.display};d.TagButton.prototype.isOpen=function(e){var h=this,g=0,f=false;if(e.openTags){while(f===false&&g0){g.text=w.tagStart+g.text+m}else{if(w.isOpen(q)===false||w.tagEnd===""){g.text=w.tagStart;w.openTag(p,q)}else{g.text=m;w.closeTag(p,q)}}j.focus()}else{if(j.selectionStart||j.selectionStart=="0"){s=j.selectionStart;f=j.selectionEnd;n=f;h=j.scrollTop;k=u.substring(0,s);e=u.substring(f,u.length);o=u.substring(s,f);if(s!=f){j.value=k+w.tagStart+o+m+e;if(m===""){n=s}n+=w.tagStart.length+m.length}else{if(w.isOpen(q)===false||w.tagEnd===""){j.value=k+w.tagStart+e;w.openTag(p,q);n=s+w.tagStart.length}else{j.value=k+m+e;n=s+m.length;w.closeTag(p,q)}}j.focus();j.selectionStart=n;j.selectionEnd=n;j.scrollTop=h}else{if(w.isOpen(q)!==false||w.tagEnd===""){j.value+=w.tagStart;w.openTag(p,q)}else{j.value+=m;w.closeTag(p,q)}j.focus()}}};d.SpellButton=function(){d.Button.call(this,"spell",quicktagsL10n.lookup,"",quicktagsL10n.dictionaryLookup)};d.SpellButton.prototype=new d.Button();d.SpellButton.prototype.callback=function(i,h,e){var k="",j,g,f;if(document.selection){h.focus();j=document.selection.createRange();if(j.text.length>0){k=j.text}}else{if(h.selectionStart||h.selectionStart=="0"){g=h.selectionStart;f=h.selectionEnd;if(g!=f){k=h.value.substring(g,f)}}}if(k===""){k=prompt(quicktagsL10n.wordLookup,"")}if(k!==null&&/^\w[\w ]*$/.test(k)){window.open("http://www.answers.com/"+encodeURIComponent(k))}};d.CloseButton=function(){d.Button.call(this,"close",quicktagsL10n.closeTags,"",quicktagsL10n.closeAllOpenTags)};d.CloseButton.prototype=new d.Button();d.CloseButton.prototype.callback=function(j,k,f){var h,g,i=f.openTags;if(i){while(i.length>0){h=f.getButton(i[i.length-1]);g=document.getElementById(f.name+"_"+h.id);h.callback.call(h,g,k,f)}}};d.closeAllTags=function(g){var e=this.getInstance(g),f=e.getButton("close");f.callback.call(f,"",e.canvas,e)};d.LinkButton=function(){d.TagButton.call(this,"link","link","","","a")};d.LinkButton.prototype=new d.TagButton();d.LinkButton.prototype.callback=function(j,k,h,g){var f,i=this;if(typeof(wpLink)!="undefined"){wpLink.open();return}if(!g){g="http://"}if(i.isOpen(h)===false){f=prompt(quicktagsL10n.enterURL,g);if(f){i.tagStart='';d.TagButton.prototype.callback.call(i,j,k,h)}}else{d.TagButton.prototype.callback.call(i,j,k,h)}};d.ImgButton=function(){d.TagButton.call(this,"img","img","","","m",-1)};d.ImgButton.prototype=new d.TagButton();d.ImgButton.prototype.callback=function(i,k,g,f){if(!f){f="http://"}var j=prompt(quicktagsL10n.enterImageURL,f),h;if(j){h=prompt(quicktagsL10n.enterImageDescription,"");this.tagStart=''+h+'';d.TagButton.prototype.callback.call(this,i,k,g)}};d.FullscreenButton=function(){d.Button.call(this,"fullscreen",quicktagsL10n.fullscreen,"f",quicktagsL10n.toggleFullscreen)};d.FullscreenButton.prototype=new d.Button();d.FullscreenButton.prototype.callback=function(f,g){if(g.id!="content"||typeof(fullscreen)=="undefined"){return}fullscreen.on()};edButtons[10]=new d.TagButton("strong","b","","","b");edButtons[20]=new d.TagButton("em","i","","","i"),edButtons[30]=new d.LinkButton(),edButtons[40]=new d.TagButton("block","b-quote","\n\n
","
\n\n","q"),edButtons[50]=new d.TagButton("del","del",'',"","d"),edButtons[60]=new d.TagButton("ins","ins",'',"","s"),edButtons[70]=new d.ImgButton(),edButtons[80]=new d.TagButton("ul","ul","
    \n","
\n\n","u"),edButtons[90]=new d.TagButton("ol","ol","
    \n","
\n\n","o"),edButtons[100]=new d.TagButton("li","li","\t
  • ","
  • \n","l"),edButtons[110]=new d.TagButton("code","code","","","c"),edButtons[120]=new d.TagButton("more","more","","","t",-1),edButtons[130]=new d.SpellButton(),edButtons[140]=new d.CloseButton()})(); \ No newline at end of file +var QTags,edButtons=[],edCanvas;function quicktags(a){return new QTags(a)}function edInsertContent(b,a){return QTags.insertContent(a)}function edButton(f,e,c,b,a,d){return QTags.addButton(f,e,c,b,d,a,"",-1)}(function(){var c=function(h){var g,f,e;if(typeof jQuery!="undefined"){jQuery(document).ready(h)}else{g=c;g.funcs=[];g.ready=function(){if(!g.isReady){g.isReady=true;for(f=0;f0){while(typeof(edButtons[m])!="undefined"){m++}edButtons[m]=f}else{edButtons[edButtons.length]=f}if(this.buttonsInitDone){this._buttonsInit()}};d.insertContent=function(h){var i,g,f,j,k,e=document.getElementById(wpActiveEditor);if(!e){return false}if(document.selection){e.focus();i=document.selection.createRange();i.text=h;e.focus()}else{if(e.selectionStart||e.selectionStart=="0"){k=e.value;g=e.selectionStart;f=e.selectionEnd;j=e.scrollTop;e.value=k.substring(0,g)+h+k.substring(f,k.length);e.focus();e.selectionStart=g+h.length;e.selectionEnd=g+h.length;e.scrollTop=j}else{e.value+=h;e.focus()}}return true};d.Button=function(i,g,e,h){var f=this;f.id=i;f.display=g;f.access=e;f.title=h||""};d.Button.prototype.html=function(f){var e=this.access?' accesskey="'+this.access+'"':"";return''};d.Button.prototype.callback=function(){};d.TagButton=function(l,j,g,f,e,h,k){var i=this;d.Button.call(i,l,j,e,k);i.tagStart=g;i.tagEnd=f;i.open=h};d.TagButton.prototype=new d.Button();d.TagButton.prototype.openTag=function(h,f){var g=this;if(!f.openTags){f.openTags=[]}if(g.tagEnd){f.openTags.push(g.id);h.value="/"+h.value}};d.TagButton.prototype.closeTag=function(j,f){var h=this,g=h.isOpen(f);if(g!==false){f.openTags.splice(g,1)}j.value=h.display};d.TagButton.prototype.isOpen=function(e){var h=this,g=0,f=false;if(e.openTags){while(f===false&&g0){g.text=w.tagStart+g.text+m}else{if(w.isOpen(q)===false||w.tagEnd===""){g.text=w.tagStart;w.openTag(p,q)}else{g.text=m;w.closeTag(p,q)}}j.focus()}else{if(j.selectionStart||j.selectionStart=="0"){s=j.selectionStart;f=j.selectionEnd;n=f;h=j.scrollTop;k=u.substring(0,s);e=u.substring(f,u.length);o=u.substring(s,f);if(s!=f){j.value=k+w.tagStart+o+m+e;if(m===""){n=s}n+=w.tagStart.length+m.length}else{if(w.isOpen(q)===false||w.tagEnd===""){j.value=k+w.tagStart+e;w.openTag(p,q);n=s+w.tagStart.length}else{j.value=k+m+e;n=s+m.length;w.closeTag(p,q)}}j.focus();j.selectionStart=n;j.selectionEnd=n;j.scrollTop=h}else{if(w.isOpen(q)!==false||w.tagEnd===""){j.value+=w.tagStart;w.openTag(p,q)}else{j.value+=m;w.closeTag(p,q)}j.focus()}}};d.SpellButton=function(){d.Button.call(this,"spell",quicktagsL10n.lookup,"",quicktagsL10n.dictionaryLookup)};d.SpellButton.prototype=new d.Button();d.SpellButton.prototype.callback=function(i,h,e){var k="",j,g,f;if(document.selection){h.focus();j=document.selection.createRange();if(j.text.length>0){k=j.text}}else{if(h.selectionStart||h.selectionStart=="0"){g=h.selectionStart;f=h.selectionEnd;if(g!=f){k=h.value.substring(g,f)}}}if(k===""){k=prompt(quicktagsL10n.wordLookup,"")}if(k!==null&&/^\w[\w ]*$/.test(k)){window.open("http://www.answers.com/"+encodeURIComponent(k))}};d.CloseButton=function(){d.Button.call(this,"close",quicktagsL10n.closeTags,"",quicktagsL10n.closeAllOpenTags)};d.CloseButton.prototype=new d.Button();d.CloseButton.prototype.callback=function(j,k,f){var h,g,i=f.openTags;if(i){while(i.length>0){h=f.getButton(i[i.length-1]);g=document.getElementById(f.name+"_"+h.id);h.callback.call(h,g,k,f)}}};d.closeAllTags=function(g){var e=this.getInstance(g),f=e.getButton("close");f.callback.call(f,"",e.canvas,e)};d.LinkButton=function(){d.TagButton.call(this,"link","link","","
    ","a")};d.LinkButton.prototype=new d.TagButton();d.LinkButton.prototype.callback=function(j,k,h,g){var f,i=this;if(typeof(wpLink)!="undefined"){wpLink.open();return}if(!g){g="http://"}if(i.isOpen(h)===false){f=prompt(quicktagsL10n.enterURL,g);if(f){i.tagStart='';d.TagButton.prototype.callback.call(i,j,k,h)}}else{d.TagButton.prototype.callback.call(i,j,k,h)}};d.ImgButton=function(){d.TagButton.call(this,"img","img","","","m",-1)};d.ImgButton.prototype=new d.TagButton();d.ImgButton.prototype.callback=function(i,k,g,f){if(!f){f="http://"}var j=prompt(quicktagsL10n.enterImageURL,f),h;if(j){h=prompt(quicktagsL10n.enterImageDescription,"");this.tagStart=''+h+'';d.TagButton.prototype.callback.call(this,i,k,g)}};d.FullscreenButton=function(){d.Button.call(this,"fullscreen",quicktagsL10n.fullscreen,"f",quicktagsL10n.toggleFullscreen)};d.FullscreenButton.prototype=new d.Button();d.FullscreenButton.prototype.callback=function(f,g){if(g.id!="content"||typeof(fullscreen)=="undefined"){return}fullscreen.on()};edButtons[10]=new d.TagButton("strong","b","","","b");edButtons[20]=new d.TagButton("em","i","","","i"),edButtons[30]=new d.LinkButton(),edButtons[40]=new d.TagButton("block","b-quote","\n\n
    ","
    \n\n","q"),edButtons[50]=new d.TagButton("del","del",'',"","d"),edButtons[60]=new d.TagButton("ins","ins",'',"","s"),edButtons[70]=new d.ImgButton(),edButtons[80]=new d.TagButton("ul","ul","
      \n","
    \n\n","u"),edButtons[90]=new d.TagButton("ol","ol","
      \n","
    \n\n","o"),edButtons[100]=new d.TagButton("li","li","\t
  • ","
  • \n","l"),edButtons[110]=new d.TagButton("code","code","","","c"),edButtons[120]=new d.TagButton("more","more","","","t",-1),edButtons[130]=new d.SpellButton(),edButtons[140]=new d.CloseButton()})(); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index fb2ac42e4f..5fd4958df8 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -68,7 +68,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1', 1 ); - $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110820', 1 ); + $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110826', 1 ); $scripts->add_script_data( 'quicktags', 'quicktagsL10n', array( 'wordLookup' => __('Enter a word to look up:'), 'dictionaryLookup' => esc_attr(__('Dictionary lookup')),