From 230fb8f3e33500f3d53b6f6c1a471ac6d52a5265 Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 3 Aug 2011 10:11:12 +0000 Subject: [PATCH] Refactor Quicktags, props garyc40, see #16695 git-svn-id: http://svn.automattic.com/wordpress/trunk@18497 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/edit-comments.dev.js | 8 +- wp-admin/js/edit-comments.js | 2 +- wp-includes/js/quicktags.dev.js | 985 ++++++++++++++----------------- wp-includes/js/quicktags.js | 2 +- wp-includes/script-loader.php | 5 +- 5 files changed, 456 insertions(+), 546 deletions(-) diff --git a/wp-admin/js/edit-comments.dev.js b/wp-admin/js/edit-comments.dev.js index 7cffd564ec..dfacc693bb 100644 --- a/wp-admin/js/edit-comments.dev.js +++ b/wp-admin/js/edit-comments.dev.js @@ -548,8 +548,12 @@ $(document).ready(function(){ commentReply.init(); $(document).delegate('span.delete a.delete', 'click', function(){return false;}); - if ( typeof QTags != 'undefined' ) - ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more,fullscreen'); + if ( typeof QTags != 'undefined' ) { + quicktags({quicktags_id: 'replycontent', quicktags_buttons: 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close'}); + + + console.debug('typeof QTags') + } if ( typeof $.table_hotkeys != 'undefined' ) { make_hotkeys_redirect = function(which) { diff --git a/wp-admin/js/edit-comments.js b/wp-admin/js/edit-comments.js index c7c417cedd..655889f502 100644 --- a/wp-admin/js/edit-comments.js +++ b/wp-admin/js/edit-comments.js @@ -1 +1 @@ -var theList,theExtraList,toggleWithKeyboard=false,getCount,updateCount,updatePending,dashboardTotals;(function(a){setCommentsList=function(){var c,e,g,j=0,f,h,d,i,b;c=a('input[name="_total"]',"#comments-form");e=a('input[name="_per_page"]',"#comments-form");g=a('input[name="_page"]',"#comments-form");f=function(n,l){var p=a("#"+l.element),k,o,m;k=a("#replyrow");o=a("#comment_ID",k).val();m=a("#replybtn",k);if(p.is(".unapproved")){if(l.data.id==o){m.text(adminCommentsL10n.replyApprove)}p.find("div.comment_status").html("0")}else{if(l.data.id==o){m.text(adminCommentsL10n.reply)}p.find("div.comment_status").html("1")}a("span.pending-count").each(function(){var q=a(this),s,r;s=q.html().replace(/[^0-9]+/g,"");s=parseInt(s,10);if(isNaN(s)){return}r=a("#"+l.element).is("."+l.dimClass)?1:-1;s=s+r;if(s<0){s=0}q.closest(".awaiting-mod")[0==s?"addClass":"removeClass"]("count-0");updateCount(q,s);dashboardTotals()})};h=function(o,s){var u=a(o.target).attr("class"),k,l,m,r,t,q,p=false;o.data._total=c.val()||0;o.data._per_page=e.val()||0;o.data._page=g.val()||0;o.data._url=document.location.href;o.data.comment_status=a('input[name="comment_status"]',"#comments-form").val();if(u.indexOf(":trash=1")!=-1){p="trash"}else{if(u.indexOf(":spam=1")!=-1){p="spam"}}if(p){k=u.replace(/.*?comment-([0-9]+).*/,"$1");l=a("#comment-"+k);note=a("#"+p+"-undo-holder").html();l.find(".check-column :checkbox").prop("checked",false);if(l.siblings("#replyrow").length&&commentReply.cid==k){commentReply.close()}if(l.is("tr")){m=l.children(":visible").length;q=a(".author strong",l).text();r=a(''+note+"")}else{q=a(".comment-author",l).text();r=a('")}l.before(r);a("strong","#undo-"+k).text(q+" ");t=a(".undo a","#undo-"+k);t.attr("href","comment.php?action=un"+p+"comment&c="+k+"&_wpnonce="+o.data._ajax_nonce);t.attr("class","delete:the-comment-list:comment-"+k+"::un"+p+"=1 vim-z vim-destructive");a(".avatar",l).clone().prependTo("#undo-"+k+" ."+p+"-undo-inside");t.click(function(){s.wpList.del(this);a("#undo-"+k).css({backgroundColor:"#ceb"}).fadeOut(350,function(){a(this).remove();a("#comment-"+k).css("backgroundColor","").fadeIn(300,function(){a(this).show()})});return false})}return o};d=function(k,l,m){if(l3){while(m.length>3){k=thousandsSeparator+m.substr(m.length-3)+k;m=m.substr(0,m.length-3)}m=m+k}l.html(m)};updatePending=function(k){a("span.pending-count").each(function(){var l=a(this);if(k<0){k=0}l.closest(".awaiting-mod")[0==k?"addClass":"removeClass"]("count-0");updateCount(l,k);dashboardTotals()})};i=function(k,n){var q,o,u=a(n.target).parent().is("span.untrash"),m=a(n.target).parent().is("span.unspam"),t,s,l,p=a("#"+n.element).is(".unapproved");function v(r){if(a(n.target).parent().is("span."+r)){return 1}else{if(a("#"+n.element).is("."+r)){return -1}}return 0}t=v("spam");s=v("trash");if(u){s=-1}if(m){t=-1}l=getCount(a("span.pending-count").eq(0));if(a(n.target).parent().is("span.unapprove")||((u||m)&&p)){l=l+1}else{if(p){l=l-1}}updatePending(l);a("span.spam-count").each(function(){var r=a(this),w=getCount(r)+t;updateCount(r,w)});a("span.trash-count").each(function(){var r=a(this),w=getCount(r)+s;updateCount(r,w)});if(a("#dashboard_right_now").length){o=s?-1*s:0;dashboardTotals(o)}else{q=c.val()?parseInt(c.val(),10):0;q=q-t-s;if(q<0){q=0}if(("object"==typeof k)&&jk){return}if(n){theExtraList.empty();l.number=Math.min(8,m)}else{l.number=1;l.offset=Math.min(8,m)-1}l.no_placeholder=true;l.paged++;if(true===l.comment_type){l.comment_type=""}l=a.extend(l,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:a("#_ajax_fetch_list_nonce").val()});a.ajax({url:ajaxurl,global:false,dataType:"json",data:l,success:function(o){theExtraList.get(0).wpList.add(o.rows)}})};theExtraList=a("#the-extra-comment-list").wpList({alt:"",delColor:"none",addColor:"none"});theList=a("#the-comment-list").wpList({alt:"",delBefore:h,dimAfter:f,delAfter:i,addColor:"none"}).bind("wpListDelEnd",function(l,k){var m=k.element.replace(/[^0-9]+/g,"");if(k.target.className.indexOf(":trash=1")!=-1||k.target.className.indexOf(":spam=1")!=-1){a("#undo-"+m).fadeIn(300,function(){a(this).show()})}})};commentReply={cid:"",act:"",init:function(){var b=a("#replyrow");a("a.cancel",b).click(function(){return commentReply.revert()});a("a.save",b).click(function(){return commentReply.send()});a("input#author, input#author-email, input#author-url",b).keypress(function(c){if(c.which==13){commentReply.send();c.preventDefault();return false}});a("#the-comment-list .column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())});a("#doaction, #doaction2, #post-query-submit").click(function(c){if(a("#the-comment-list #replyrow").length>0){commentReply.close()}});this.comments_listing=a('#comments-form > input[name="comment_status"]').val()||""},addEvents:function(b){b.each(function(){a(this).find(".column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())})})},toggle:function(b){if(a(b).css("display")!="none"){a(b).find("a.vim-q").click()}},revert:function(){if(a("#the-comment-list #replyrow").length<1){return false}a("#replyrow").fadeOut("fast",function(){commentReply.close()});return false},close:function(){var b;if(this.cid){b=a("#comment-"+this.cid);if(this.act=="edit-comment"){b.fadeIn(300,function(){b.show()}).css("backgroundColor","")}a("#replyrow").hide();a("#com-reply").append(a("#replyrow"));a("#replycontent").val("");a("input","#edithead").val("");a(".error","#replysubmit").html("").hide();a(".waiting","#replysubmit").hide();if(a.browser.msie){a("#replycontainer, #replycontent").css("height","120px")}else{a("#replycontainer").resizable("destroy").css("height","120px")}this.cid=""}},open:function(b,d,k){var m=this,e,f,i,g,j=a("#comment-"+b),l;m.close();m.cid=b;e=a("#replyrow");f=a("#inline-"+b);i=m.act=(k=="edit")?"edit-comment":"replyto-comment";a("#action",e).val(i);a("#comment_post_ID",e).val(d);a("#comment_ID",e).val(b);if(k=="edit"){a("#author",e).val(a("div.author",f).text());a("#author-email",e).val(a("div.author-email",f).text());a("#author-url",e).val(a("div.author-url",f).text());a("#status",e).val(a("div.comment_status",f).text());a("#replycontent",e).val(a("textarea.comment",f).val());a("#edithead, #savebtn",e).show();a("#replyhead, #replybtn",e).hide();g=j.height();if(g>220){if(a.browser.msie){a("#replycontainer, #replycontent",e).height(g-105)}else{a("#replycontainer",e).height(g-105)}}j.after(e).fadeOut("fast",function(){a("#replyrow").fadeIn(300,function(){a(this).show()})})}else{l=a("#replybtn",e);a("#edithead, #savebtn",e).hide();a("#replyhead, #replybtn",e).show();j.after(e);if(j.hasClass("unapproved")){l.text(adminCommentsL10n.replyApprove)}else{l.text(adminCommentsL10n.reply)}a("#replyrow").fadeIn(300,function(){a(this).show()})}setTimeout(function(){var o,h,p,c,n;o=a("#replyrow").offset().top;h=o+a("#replyrow").height();p=window.pageYOffset||document.documentElement.scrollTop;c=document.documentElement.clientHeight||self.innerHeight||0;n=p+c;if(n-20]*?>/g,"")}if(c){a("#replysubmit .error").html(c).show()}}};a(document).ready(function(){var e,b,c,d;setCommentsList();commentReply.init();a(document).delegate("span.delete a.delete","click",function(){return false});if(typeof QTags!="undefined"){ed_reply=new QTags("ed_reply","replycontent","replycontainer","more,fullscreen")}if(typeof a.table_hotkeys!="undefined"){e=function(f){return function(){var h,g;h="next"==f?"first":"last";g=a(".tablenav-pages ."+f+"-page:not(.disabled)");if(g.length){window.location=g[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g,"")+"&hotkeys_highlight_"+h+"=1"}}};b=function(g,f){window.location=a("span.edit a",f).attr("href")};c=function(){toggleWithKeyboard=true;a("input:checkbox","#cb").click().prop("checked",false);toggleWithKeyboard=false};d=function(f){return function(){var g=a('select[name="action"]');a('option[value="'+f+'"]',g).prop("selected",true);a("#doaction").click()}};a.table_hotkeys(a("table.widefat"),["a","u","s","d","r","q","z",["e",b],["shift+x",c],["shift+a",d("approve")],["shift+s",d("spam")],["shift+d",d("delete")],["shift+t",d("trash")],["shift+z",d("untrash")],["shift+u",d("unapprove")]],{highlight_first:adminCommentsL10n.hotkeys_highlight_first,highlight_last:adminCommentsL10n.hotkeys_highlight_last,prev_page_link_cb:e("prev"),next_page_link_cb:e("next")})}})})(jQuery); \ No newline at end of file +var theList,theExtraList,toggleWithKeyboard=false,getCount,updateCount,updatePending,dashboardTotals;(function(a){setCommentsList=function(){var c,e,g,j=0,f,h,d,i,b;c=a('input[name="_total"]',"#comments-form");e=a('input[name="_per_page"]',"#comments-form");g=a('input[name="_page"]',"#comments-form");f=function(n,l){var p=a("#"+l.element),k,o,m;k=a("#replyrow");o=a("#comment_ID",k).val();m=a("#replybtn",k);if(p.is(".unapproved")){if(l.data.id==o){m.text(adminCommentsL10n.replyApprove)}p.find("div.comment_status").html("0")}else{if(l.data.id==o){m.text(adminCommentsL10n.reply)}p.find("div.comment_status").html("1")}a("span.pending-count").each(function(){var q=a(this),s,r;s=q.html().replace(/[^0-9]+/g,"");s=parseInt(s,10);if(isNaN(s)){return}r=a("#"+l.element).is("."+l.dimClass)?1:-1;s=s+r;if(s<0){s=0}q.closest(".awaiting-mod")[0==s?"addClass":"removeClass"]("count-0");updateCount(q,s);dashboardTotals()})};h=function(o,s){var u=a(o.target).attr("class"),k,l,m,r,t,q,p=false;o.data._total=c.val()||0;o.data._per_page=e.val()||0;o.data._page=g.val()||0;o.data._url=document.location.href;o.data.comment_status=a('input[name="comment_status"]',"#comments-form").val();if(u.indexOf(":trash=1")!=-1){p="trash"}else{if(u.indexOf(":spam=1")!=-1){p="spam"}}if(p){k=u.replace(/.*?comment-([0-9]+).*/,"$1");l=a("#comment-"+k);note=a("#"+p+"-undo-holder").html();l.find(".check-column :checkbox").prop("checked",false);if(l.siblings("#replyrow").length&&commentReply.cid==k){commentReply.close()}if(l.is("tr")){m=l.children(":visible").length;q=a(".author strong",l).text();r=a(''+note+"")}else{q=a(".comment-author",l).text();r=a('")}l.before(r);a("strong","#undo-"+k).text(q+" ");t=a(".undo a","#undo-"+k);t.attr("href","comment.php?action=un"+p+"comment&c="+k+"&_wpnonce="+o.data._ajax_nonce);t.attr("class","delete:the-comment-list:comment-"+k+"::un"+p+"=1 vim-z vim-destructive");a(".avatar",l).clone().prependTo("#undo-"+k+" ."+p+"-undo-inside");t.click(function(){s.wpList.del(this);a("#undo-"+k).css({backgroundColor:"#ceb"}).fadeOut(350,function(){a(this).remove();a("#comment-"+k).css("backgroundColor","").fadeIn(300,function(){a(this).show()})});return false})}return o};d=function(k,l,m){if(l3){while(m.length>3){k=thousandsSeparator+m.substr(m.length-3)+k;m=m.substr(0,m.length-3)}m=m+k}l.html(m)};updatePending=function(k){a("span.pending-count").each(function(){var l=a(this);if(k<0){k=0}l.closest(".awaiting-mod")[0==k?"addClass":"removeClass"]("count-0");updateCount(l,k);dashboardTotals()})};i=function(k,n){var q,o,u=a(n.target).parent().is("span.untrash"),m=a(n.target).parent().is("span.unspam"),t,s,l,p=a("#"+n.element).is(".unapproved");function v(r){if(a(n.target).parent().is("span."+r)){return 1}else{if(a("#"+n.element).is("."+r)){return -1}}return 0}t=v("spam");s=v("trash");if(u){s=-1}if(m){t=-1}l=getCount(a("span.pending-count").eq(0));if(a(n.target).parent().is("span.unapprove")||((u||m)&&p)){l=l+1}else{if(p){l=l-1}}updatePending(l);a("span.spam-count").each(function(){var r=a(this),w=getCount(r)+t;updateCount(r,w)});a("span.trash-count").each(function(){var r=a(this),w=getCount(r)+s;updateCount(r,w)});if(a("#dashboard_right_now").length){o=s?-1*s:0;dashboardTotals(o)}else{q=c.val()?parseInt(c.val(),10):0;q=q-t-s;if(q<0){q=0}if(("object"==typeof k)&&jk){return}if(n){theExtraList.empty();l.number=Math.min(8,m)}else{l.number=1;l.offset=Math.min(8,m)-1}l.no_placeholder=true;l.paged++;if(true===l.comment_type){l.comment_type=""}l=a.extend(l,{action:"fetch-list",list_args:list_args,_ajax_fetch_list_nonce:a("#_ajax_fetch_list_nonce").val()});a.ajax({url:ajaxurl,global:false,dataType:"json",data:l,success:function(o){theExtraList.get(0).wpList.add(o.rows)}})};theExtraList=a("#the-extra-comment-list").wpList({alt:"",delColor:"none",addColor:"none"});theList=a("#the-comment-list").wpList({alt:"",delBefore:h,dimAfter:f,delAfter:i,addColor:"none"}).bind("wpListDelEnd",function(l,k){var m=k.element.replace(/[^0-9]+/g,"");if(k.target.className.indexOf(":trash=1")!=-1||k.target.className.indexOf(":spam=1")!=-1){a("#undo-"+m).fadeIn(300,function(){a(this).show()})}})};commentReply={cid:"",act:"",init:function(){var b=a("#replyrow");a("a.cancel",b).click(function(){return commentReply.revert()});a("a.save",b).click(function(){return commentReply.send()});a("input#author, input#author-email, input#author-url",b).keypress(function(c){if(c.which==13){commentReply.send();c.preventDefault();return false}});a("#the-comment-list .column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())});a("#doaction, #doaction2, #post-query-submit").click(function(c){if(a("#the-comment-list #replyrow").length>0){commentReply.close()}});this.comments_listing=a('#comments-form > input[name="comment_status"]').val()||""},addEvents:function(b){b.each(function(){a(this).find(".column-comment > p").dblclick(function(){commentReply.toggle(a(this).parent())})})},toggle:function(b){if(a(b).css("display")!="none"){a(b).find("a.vim-q").click()}},revert:function(){if(a("#the-comment-list #replyrow").length<1){return false}a("#replyrow").fadeOut("fast",function(){commentReply.close()});return false},close:function(){var b;if(this.cid){b=a("#comment-"+this.cid);if(this.act=="edit-comment"){b.fadeIn(300,function(){b.show()}).css("backgroundColor","")}a("#replyrow").hide();a("#com-reply").append(a("#replyrow"));a("#replycontent").val("");a("input","#edithead").val("");a(".error","#replysubmit").html("").hide();a(".waiting","#replysubmit").hide();if(a.browser.msie){a("#replycontainer, #replycontent").css("height","120px")}else{a("#replycontainer").resizable("destroy").css("height","120px")}this.cid=""}},open:function(b,d,k){var m=this,e,f,i,g,j=a("#comment-"+b),l;m.close();m.cid=b;e=a("#replyrow");f=a("#inline-"+b);i=m.act=(k=="edit")?"edit-comment":"replyto-comment";a("#action",e).val(i);a("#comment_post_ID",e).val(d);a("#comment_ID",e).val(b);if(k=="edit"){a("#author",e).val(a("div.author",f).text());a("#author-email",e).val(a("div.author-email",f).text());a("#author-url",e).val(a("div.author-url",f).text());a("#status",e).val(a("div.comment_status",f).text());a("#replycontent",e).val(a("textarea.comment",f).val());a("#edithead, #savebtn",e).show();a("#replyhead, #replybtn",e).hide();g=j.height();if(g>220){if(a.browser.msie){a("#replycontainer, #replycontent",e).height(g-105)}else{a("#replycontainer",e).height(g-105)}}j.after(e).fadeOut("fast",function(){a("#replyrow").fadeIn(300,function(){a(this).show()})})}else{l=a("#replybtn",e);a("#edithead, #savebtn",e).hide();a("#replyhead, #replybtn",e).show();j.after(e);if(j.hasClass("unapproved")){l.text(adminCommentsL10n.replyApprove)}else{l.text(adminCommentsL10n.reply)}a("#replyrow").fadeIn(300,function(){a(this).show()})}setTimeout(function(){var o,h,p,c,n;o=a("#replyrow").offset().top;h=o+a("#replyrow").height();p=window.pageYOffset||document.documentElement.scrollTop;c=document.documentElement.clientHeight||self.innerHeight||0;n=p+c;if(n-20]*?>/g,"")}if(c){a("#replysubmit .error").html(c).show()}}};a(document).ready(function(){var e,b,c,d;setCommentsList();commentReply.init();a(document).delegate("span.delete a.delete","click",function(){return false});if(typeof QTags!="undefined"){quicktags({quicktags_id:"replycontent",quicktags_buttons:"strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close"});console.debug("typeof QTags")}if(typeof a.table_hotkeys!="undefined"){e=function(f){return function(){var h,g;h="next"==f?"first":"last";g=a(".tablenav-pages ."+f+"-page:not(.disabled)");if(g.length){window.location=g[0].href.replace(/\&hotkeys_highlight_(first|last)=1/g,"")+"&hotkeys_highlight_"+h+"=1"}}};b=function(g,f){window.location=a("span.edit a",f).attr("href")};c=function(){toggleWithKeyboard=true;a("input:checkbox","#cb").click().prop("checked",false);toggleWithKeyboard=false};d=function(f){return function(){var g=a('select[name="action"]');a('option[value="'+f+'"]',g).prop("selected",true);a("#doaction").click()}};a.table_hotkeys(a("table.widefat"),["a","u","s","d","r","q","z",["e",b],["shift+x",c],["shift+a",d("approve")],["shift+s",d("spam")],["shift+d",d("delete")],["shift+t",d("trash")],["shift+z",d("untrash")],["shift+u",d("unapprove")]],{highlight_first:adminCommentsL10n.hotkeys_highlight_first,highlight_last:adminCommentsL10n.hotkeys_highlight_last,prev_page_link_cb:e("prev"),next_page_link_cb:e("next")})}})})(jQuery); \ No newline at end of file diff --git a/wp-includes/js/quicktags.dev.js b/wp-includes/js/quicktags.dev.js index f6ab23a4ba..d4de51912c 100644 --- a/wp-includes/js/quicktags.dev.js +++ b/wp-includes/js/quicktags.dev.js @@ -1,582 +1,489 @@ +/* + * Quicktags + * + * This is the HTML editor in WordPress. It can be attached to any textarea and will + * append a toolbar above it. This script is self-contained (does not require external libraries). + * + * Run quicktags(settings) to initialize it, where settings is an object containing up to 3 properties: + * settings = { + * quicktags_id: 'myid', // required + * buttons: '', // optional + * disabled_buttons: '' // optional + * } + * + * The settings can also be a string quicktags_id. + * + * quicktags_id The ID of the textarea that will be the editor canvas + * buttons Comma separated list of the buttons IDs that will be shown. Buttons added by plugins + * will not show. Default: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close' + * disabled_buttons Comma separated list of the buttons IDs that should be excluded. Buttons + * added by plugins will show unless specifically disabled. + */ + // new edit toolbar used with permission // by Alex King // http://www.alexking.org/ -var edButtons = new Array(), edLinks = new Array(), edOpenTags = new Array(), now = new Date(), datetime; +var QTags, edButtons, edButton; -function edButton(id, display, tagStart, tagEnd, access, open) { - this.id = id; // used to name the toolbar button - this.display = display; // label on button - this.tagStart = tagStart; // open tag - this.tagEnd = tagEnd; // close tag - this.access = access; // access key - this.open = open; // set to -1 if tag does not need to be closed +function quicktags(settings) { + return new QTags(settings); } -function zeroise(number, threshold) { - // FIXME: or we could use an implementation of printf in js here - var str = number.toString(); - if (number < 0) { str = str.substr(1, str.length) } - while (str.length < threshold) { str = "0" + str } - if (number < 0) { str = '-' + str } - return str; -} +(function(){ + // private stuff is prefixed with an underscore + var _domReady = function(func) { + var t, i, DOMContentLoaded; -datetime = now.getUTCFullYear() + '-' + -zeroise(now.getUTCMonth() + 1, 2) + '-' + -zeroise(now.getUTCDate(), 2) + 'T' + -zeroise(now.getUTCHours(), 2) + ':' + -zeroise(now.getUTCMinutes(), 2) + ':' + -zeroise(now.getUTCSeconds() ,2) + -'+00:00'; - -edButtons[edButtons.length] = -new edButton('ed_strong' -,'b' -,'' -,'' -,'b' -); - -edButtons[edButtons.length] = -new edButton('ed_em' -,'i' -,'' -,'' -,'i' -); - -edButtons[edButtons.length] = -new edButton('ed_link' -,'link' -,'' -,'' -,'a' -); // special case - -edButtons[edButtons.length] = -new edButton('ed_block' -,'b-quote' -,'\n\n
' -,'
\n\n' -,'q' -); - - -edButtons[edButtons.length] = -new edButton('ed_del' -,'del' -,'' -,'' -,'d' -); - -edButtons[edButtons.length] = -new edButton('ed_ins' -,'ins' -,'' -,'' -,'s' -); - -edButtons[edButtons.length] = -new edButton('ed_img' -,'img' -,'' -,'' -,'m' -,-1 -); // special case - -edButtons[edButtons.length] = -new edButton('ed_ul' -,'ul' -,'
    \n' -,'
\n\n' -,'u' -); - -edButtons[edButtons.length] = -new edButton('ed_ol' -,'ol' -,'
    \n' -,'
\n\n' -,'o' -); - -edButtons[edButtons.length] = -new edButton('ed_li' -,'li' -,'\t
  • ' -,'
  • \n' -,'l' -); - -edButtons[edButtons.length] = -new edButton('ed_code' -,'code' -,'' -,'' -,'c' -); - -edButtons[edButtons.length] = -new edButton('ed_more' -,'more' -,'' -,'' -,'t' -,-1 -); -/* -edButtons[edButtons.length] = -new edButton('ed_next' -,'page' -,'' -,'' -,'p' -,-1 -); -*/ -function edLink() { - this.display = ''; - this.URL = ''; - this.newWin = 0; -} - -edLinks[edLinks.length] = new edLink('WordPress' - ,'http://wordpress.org/' - ); - -edLinks[edLinks.length] = new edLink('alexking.org' - ,'http://www.alexking.org/' - ); - -function edShowButton(button, i) { - if (button.id == 'ed_img') { - document.write(''); - } - else if (button.id == 'ed_link') { - document.write(''); - } - else { - document.write(''); - } -} - -function edShowLinks() { - var tempStr = ''; - document.write(tempStr); -} - -function edAddTag(button) { - if (edButtons[button].tagEnd != '') { - edOpenTags[edOpenTags.length] = button; - document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value; - } -} - -function edRemoveTag(button) { - for (var i = 0; i < edOpenTags.length; i++) { - if (edOpenTags[i] == button) { - edOpenTags.splice(i, 1); - document.getElementById(edButtons[button].id).value = document.getElementById(edButtons[button].id).value.replace('/', ''); - } - } -} - -function edCheckOpenTags(button) { - var tag = 0, i; - for (i = 0; i < edOpenTags.length; i++) { - if (edOpenTags[i] == button) { - tag++; - } - } - if (tag > 0) { - return true; // tag found - } - else { - return false; // tag not found - } -} - -function edCloseAllTags() { - var count = edOpenTags.length, o; - for (o = 0; o < count; o++) { - edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]); - } -} - -function edQuickLink(i, thisSelect) { - if (i > -1) { - var newWin = '', tempStr; - if (edLinks[i].newWin == 1) { - newWin = ' target="_blank"'; - } - tempStr = '' - + edLinks[i].display - + ''; - thisSelect.selectedIndex = 0; - edInsertContent(edCanvas, tempStr); - } - else { - thisSelect.selectedIndex = 0; - } -} - -function edSpell(myField) { - var word = '', sel, startPos, endPos; - if (document.selection) { - myField.focus(); - sel = document.selection.createRange(); - if (sel.text.length > 0) { - word = sel.text; - } - } - else if (myField.selectionStart || myField.selectionStart == '0') { - startPos = myField.selectionStart; - endPos = myField.selectionEnd; - if (startPos != endPos) { - word = myField.value.substring(startPos, endPos); - } - } - if (word == '') { - word = prompt(quicktagsL10n.wordLookup, ''); - } - if (word !== null && /^\w[\w ]*$/.test(word)) { - window.open('http://www.answers.com/' + escape(word)); - } -} - -function edToolbar() { - document.write('
    '); - for (var i = 0; i < edButtons.length; i++) { - edShowButton(edButtons[i], i); - } - document.write(''); - document.write(''); - document.write(''); -// edShowLinks(); // disabled by default - document.write('
    '); -} - -// insertion code - -function edInsertTag(myField, i) { - //IE support - if (document.selection) { - myField.focus(); - var sel = document.selection.createRange(); - if (sel.text.length > 0) { - sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd; - } - else { - if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') { - sel.text = edButtons[i].tagStart; - edAddTag(i); - } - else { - sel.text = edButtons[i].tagEnd; - edRemoveTag(i); - } - } - myField.focus(); - } - //MOZILLA/NETSCAPE support - else if (myField.selectionStart || myField.selectionStart == '0') { - var startPos = myField.selectionStart, endPos = myField.selectionEnd, cursorPos = endPos, scrollTop = myField.scrollTop; - - if (startPos != endPos) { - myField.value = myField.value.substring(0, startPos) - + edButtons[i].tagStart - + myField.value.substring(startPos, endPos) - + edButtons[i].tagEnd - + myField.value.substring(endPos, myField.value.length); - cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length; - } - else { - if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') { - myField.value = myField.value.substring(0, startPos) - + edButtons[i].tagStart - + myField.value.substring(endPos, myField.value.length); - edAddTag(i); - cursorPos = startPos + edButtons[i].tagStart.length; - } - else { - myField.value = myField.value.substring(0, startPos) - + edButtons[i].tagEnd - + myField.value.substring(endPos, myField.value.length); - edRemoveTag(i); - cursorPos = startPos + edButtons[i].tagEnd.length; - } - } - myField.focus(); - myField.selectionStart = cursorPos; - myField.selectionEnd = cursorPos; - myField.scrollTop = scrollTop; - } - else { - if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') { - myField.value += edButtons[i].tagStart; - edAddTag(i); - } - else { - myField.value += edButtons[i].tagEnd; - edRemoveTag(i); - } - myField.focus(); - } -} - -function edInsertContent(myField, myValue) { - var sel, startPos, endPos, scrollTop; - - //IE support - if (document.selection) { - myField.focus(); - sel = document.selection.createRange(); - sel.text = myValue; - myField.focus(); - } - //MOZILLA/NETSCAPE support - else if (myField.selectionStart || myField.selectionStart == '0') { - startPos = myField.selectionStart; - endPos = myField.selectionEnd; - scrollTop = myField.scrollTop; - myField.value = myField.value.substring(0, startPos) - + myValue - + myField.value.substring(endPos, myField.value.length); - myField.focus(); - myField.selectionStart = startPos + myValue.length; - myField.selectionEnd = startPos + myValue.length; - myField.scrollTop = scrollTop; - } else { - myField.value += myValue; - myField.focus(); - } -} - -function edInsertLink(myField, i, defaultValue) { - if ( 'object' == typeof(wpLink) ) { - wpLink.open(); - } else { - if (!defaultValue) { - defaultValue = 'http://'; - } - if (!edCheckOpenTags(i)) { - var URL = prompt(quicktagsL10n.enterURL, defaultValue); - if (URL) { - edButtons[i].tagStart = ''; - edInsertTag(myField, i); - } - } - else { - edInsertTag(myField, i); - } - } -} - -function edInsertImage(myField) { - var myValue = prompt(quicktagsL10n.enterImageURL, 'http://'); - if (myValue) { - myValue = '' + prompt(quicktagsL10n.enterImageDescription, '')
-				+ ''; - edInsertContent(myField, myValue); - } -} - - -// Allow multiple instances. -// Name = unique value, id = textarea id, container = container div. -// Can disable some buttons by passing comma delimited string as 4th param. -var QTags = function(name, id, container, disabled) { - var t = this, cont = document.getElementById(container), i, tag, tb, html, sel; - - t.Buttons = []; - t.Links = []; - t.OpenTags = []; - t.Canvas = document.getElementById(id); - - if ( ! t.Canvas || ! cont ) - return; - - disabled = ( typeof disabled != 'undefined' ) ? ','+disabled+',' : ''; - - t.edShowButton = function(button, i) { - if ( disabled && (disabled.indexOf(','+button.display+',') != -1) ) - return ''; - else if ( button.id == name+'_img' ) - return ''; - else if (button.id == name+'_link') - return ''; - else - return ''; - }; - - t.edAddTag = function(button) { - if ( t.Buttons[button].tagEnd != '' ) { - t.OpenTags[t.OpenTags.length] = button; - document.getElementById(t.Buttons[button].id).value = '/' + document.getElementById(t.Buttons[button].id).value; - } - }; - - t.edRemoveTag = function(button) { - for ( i = 0; i < t.OpenTags.length; i++ ) { - if ( t.OpenTags[i] == button ) { - t.OpenTags.splice(i, 1); - document.getElementById(t.Buttons[button].id).value = document.getElementById(t.Buttons[button].id).value.replace('/', ''); - } - } - }; - - t.edCheckOpenTags = function(button) { - tag = 0; - for ( var i = 0; i < t.OpenTags.length; i++ ) { - if ( t.OpenTags[i] == button ) - tag++; - } - if ( tag > 0 ) return true; // tag found - else return false; // tag not found - }; - - this.edCloseAllTags = function() { - var count = t.OpenTags.length; - for ( var o = 0; o < count; o++ ) - t.edInsertTag(t.OpenTags[t.OpenTags.length - 1]); - }; - - this.edQuickLink = function(i, thisSelect) { - if ( i > -1 ) { - var newWin = '', tempStr; - if ( Links[i].newWin == 1 ) { - newWin = ' target="_blank"'; - } - tempStr = '' - + Links[i].display - + ''; - thisSelect.selectedIndex = 0; - edInsertContent(t.Canvas, tempStr); + if ( typeof jQuery != 'undefined' ) { + jQuery(document).ready(func); } else { - thisSelect.selectedIndex = 0; + t = _domReady; + t.funcs = []; + + t.ready = function() { + if ( ! t.isReady ) { + t.isReady = true; + for ( i = 0; i < t.funcs.length; i++ ) { + t.funcs[i](); + } + } + }; + + if ( t.isReady ) { + func(); + } else { + t.funcs.push(func); + } + + if ( ! t.eventAttached ) { + if ( document.addEventListener ) { + DOMContentLoaded = function(){document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);t.ready();}; + document.addEventListener('DOMContentLoaded', DOMContentLoaded, false); + window.addEventListener('load', t.ready, false); + } else if ( document.attachEvent ) { + DOMContentLoaded = function(){if (document.readyState === 'complete'){ document.detachEvent('onreadystatechange', DOMContentLoaded);t.ready();}}; + document.attachEvent('onreadystatechange', DOMContentLoaded); + window.attachEvent('onload', t.ready); + + (function(){ + try { + document.documentElement.doScroll("left"); + } catch(e) { + setTimeout(arguments.callee, 50); + return; + } + + t.ready(); + })(); + } + + t.eventAttached = true; + } + } + }, + + _datetime = (function() { + var now = new Date(), zeroise; + + zeroise = function(number) { + var str = number.toString(); + + if ( str.length < 2 ) + str = "0" + str; + + return str; + } + + return now.getUTCFullYear() + '-' + + zeroise( now.getUTCMonth() + 1 ) + '-' + + zeroise( now.getUTCDate() ) + 'T' + + zeroise( now.getUTCHours() ) + ':' + + zeroise( now.getUTCMinutes() ) + ':' + + zeroise( now.getUTCSeconds() ) + + '+00:00'; + })(), + + _customButtons = {}, + qt; + + qt = QTags = function(settings) { + if ( typeof(settings) == 'string' ) + settings = {quicktags_id: settings}; + else if ( typeof(settings) != 'object' ) + return false; + + var t = this, + id = settings.quicktags_id, + buttons = {}, + theButtons = {}, + canvas = document.getElementById(id), + name = 'qt_' + id, + html = '', + i, tb, qb, btn, onclick; + + if ( !id || !canvas ) + return false; + + t.name = name; + t.id = id; + + // default buttons + for ( i in edButtons ) { + 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 ) { + buttons[i] = new t._customButtons[i](); + } + + if ( settings.quicktags_buttons ) { + qb = settings.quicktags_buttons.split(','); + + for ( i in qb ) { + btn = qb[i]; + if ( buttons[btn] ) + theButtons[btn] = buttons[btn]; + } + } else { + theButtons = buttons; + } + + if ( settings.quicktags_disabled_buttons ) { + qb = settings.quicktags_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 = name + '_toolbar'; + tb.className = 'quicktags-toolbar'; + + canvas.parentNode.insertBefore(tb, canvas); + + tb.innerHTML = html; + t.toolbar = tb; + + // listen for click events + onclick = function(e) { + e = e || window.event; + var target = e.target || e.srcElement, i; + + // as long as it has the class ed_button, execute the callback + if ( /\s+ed_button\s+/.test(' ' + target.className + ' ' ) ) { + // we have to reassign canvas here + t.canvas = canvas = document.getElementById(id); + i = target.id.replace(name + '_', ''); + + if ( theButtons[i] ) + theButtons[i].callback.call(theButtons[i], target, canvas, t); + } + }; + + if ( tb.addEventListener ) { + tb.addEventListener('click', onclick, false); + } else if ( tb.attachEvent ) { + tb.attachEvent('onclick', onclick); + } + + qt.instances[id] = t; + }; + + qt.instances = {}; + + qt.registerButton = function(id, btnClass) { + _customButtons[id] = btnClass; + }; + + qt.getInstance = function(id) { + return qt.instances[id]; + }; + + qt.insertContent = function(editor_id, content) { + var sel, startPos, endPos, scrollTop, text, ed = document.getElementById(editor_id); + + if ( document.selection ) { //IE + ed.focus(); + sel = document.selection.createRange(); + sel.text = content; + ed.focus(); + } else if ( ed.selectionStart || ed.selectionStart == '0' ) { // all other + text = ed.value; + startPos = ed.selectionStart; + endPos = ed.selectionEnd; + scrollTop = ed.scrollTop; + + ed.value = text.substring(0, startPos) + content + text.substring(endPos, text.length); + + ed.focus(); + ed.selectionStart = startPos + content.length; + ed.selectionEnd = startPos + content.length; + ed.scrollTop = scrollTop; + } else { + ed.value += content; + ed.focus(); } }; - // insertion code - t.edInsertTag = function(i) { - //IE support + // a plain, dumb button + qt.Button = function(id, display, access, title) { + var t = this; + t.id = id; + t.display = display; + t.access = access; + t.title = title || ''; + }; + qt.Button.prototype.html = function(idPrefix) { + var access = this.access ? ' accesskey="' + this.access + '"' : ''; + return ''; + }; + qt.Button.prototype.callback = function(canvas) {}; + + // a button that inserts HTML tag + qt.TagButton = function(id, display, tagStart, tagEnd, access, open, title) { + var t = this; + qt.Button.call(t, id, display, access, title); + t.tagStart = tagStart; + t.tagEnd = tagEnd; + t.open = open; + }; + qt.TagButton.prototype = new qt.Button(); + qt.TagButton.prototype.openTag = function(e, tb) { + var t = this; + if ( ! tb.openTags ) { + tb.openTags = []; + } + if ( t.tagEnd ) { + tb.openTags.push(t.id); + e.value = '/' + e.value; + } + }; + qt.TagButton.prototype.closeTag = function(e, tb) { + var t = this, + i = t.isOpen(tb); + + if ( i !== false ) { + tb.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 (tb) { + var t = this, i = 0, ret = false; + if ( tb.openTags ) { + while ( ret === false && i < tb.openTags.length ) { + ret = tb.openTags[i] == t.id ? i : false; + i ++; + } + } else { + ret = false; + } + return ret; + }; + qt.TagButton.prototype.callback = function(element, canvas, toolbar) { + var t = this, startPos, endPos, cursorPos, scrollTop, v, l, r, i, sel; + + v = canvas.value; + + // IE support if ( document.selection ) { - t.Canvas.focus(); - sel = document.selection.createRange(); + canvas.focus(); + sel = document.selection.createRange(); if ( sel.text.length > 0 ) { - sel.text = t.Buttons[i].tagStart + sel.text + t.Buttons[i].tagEnd; + sel.text = t.tagStart + sel.text + t.tagEnd; } else { - if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) { - sel.text = t.Buttons[i].tagStart; - t.edAddTag(i); + if ( t.isOpen(toolbar) === false || t.tagEnd === '' ) { + sel.text = t.tagStart; + t.openTag(element, toolbar); } else { - sel.text = t.Buttons[i].tagEnd; - t.edRemoveTag(i); + sel.text = t.tagEnd; + t.closeTag(element, toolbar); } } - t.Canvas.focus(); - } else if ( t.Canvas.selectionStart || t.Canvas.selectionStart == '0' ) { //MOZILLA/NETSCAPE support - var startPos = t.Canvas.selectionStart, endPos = t.Canvas.selectionEnd, cursorPos = endPos, scrollTop = t.Canvas.scrollTop; - + canvas.focus(); + } + // moz, webkit, opera + else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { + startPos = canvas.selectionStart; + endPos = canvas.selectionEnd; + cursorPos = endPos; + scrollTop = canvas.scrollTop; + l = v.substring(0, startPos); // left of the selection + r = v.substring(endPos, v.length); // right of the selection + i = v.substring(startPos, endPos); // inside the selection if ( startPos != endPos ) { - t.Canvas.value = t.Canvas.value.substring(0, startPos) - + t.Buttons[i].tagStart - + t.Canvas.value.substring(startPos, endPos) - + t.Buttons[i].tagEnd - + t.Canvas.value.substring(endPos, t.Canvas.value.length); - cursorPos += t.Buttons[i].tagStart.length + t.Buttons[i].tagEnd.length; + canvas.value = l + t.tagStart + i + t.tagEnd + r; + if ( t.tagEnd === '' ) { + cursorPos = startPos; + } + cursorPos += t.tagStart.length + t.tagEnd.length; } else { - if ( !t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) { - t.Canvas.value = t.Canvas.value.substring(0, startPos) - + t.Buttons[i].tagStart - + t.Canvas.value.substring(endPos, t.Canvas.value.length); - t.edAddTag(i); - cursorPos = startPos + t.Buttons[i].tagStart.length; + if ( t.isOpen(toolbar) === false || t.tagEnd === '' ) { + canvas.value = l + t.tagStart + r; + t.openTag(element, toolbar); + cursorPos = startPos + t.tagStart.length; } else { - t.Canvas.value = t.Canvas.value.substring(0, startPos) - + t.Buttons[i].tagEnd - + t.Canvas.value.substring(endPos, t.Canvas.value.length); - t.edRemoveTag(i); - cursorPos = startPos + t.Buttons[i].tagEnd.length; + canvas.value = l + t.tagEnd + r; + cursorPos = startPos + t.tagEnd.length; + t.closeTag(element, toolbar); } } - t.Canvas.focus(); - t.Canvas.selectionStart = cursorPos; - t.Canvas.selectionEnd = cursorPos; - t.Canvas.scrollTop = scrollTop; - } else { - if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) { - t.Canvas.value += Buttons[i].tagStart; - t.edAddTag(i); + + canvas.focus(); + canvas.selectionStart = cursorPos; + canvas.selectionEnd = cursorPos; + canvas.scrollTop = scrollTop; + } + // other browsers + else { + if ( t.isOpen(toolbar) !== false || t.tagEnd === '' ) { + canvas.value += t.tagStart; + t.openTag(element, toolbar); } else { - t.Canvas.value += Buttons[i].tagEnd; - t.edRemoveTag(i); + canvas.value += t.tagEnd; + t.closeTag(element, toolbar); } - t.Canvas.focus(); + canvas.focus(); } }; - this.edInsertLink = function(i, defaultValue) { + // the spell button + qt.SpellButton = function() { + qt.Button.call(this, 'spell', quicktagsL10n.lookup, '', quicktagsL10n.dictionaryLookup); + }; + qt.SpellButton.prototype = new qt.Button(); + qt.SpellButton.prototype.callback = function(element, canvas, toolbar) { + var word = '', sel, startPos, endPos; + + if ( document.selection ) { + canvas.focus(); + sel = document.selection.createRange(); + if ( sel.text.length > 0 ) { + word = sel.text; + } + } + else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { + startPos = canvas.selectionStart; + endPos = canvas.selectionEnd; + if ( startPos != endPos ) { + word = canvas.value.substring(startPos, endPos); + } + } + + if ( word === '' ) { + word = prompt(quicktagsL10n.wordLookup, ''); + } + + if ( word !== null && /^\w[\w ]*$/.test(word)) { + window.open('http://www.answers.com/' + encodeURIComponent(word)); + } + }; + + // the close button + qt.CloseButton = function() { + qt.Button.call(this, 'close', quicktagsL10n.closeTags, '', quicktagsL10n.closeAllOpenTags); + }; + qt.CloseButton.prototype = new qt.Button(); + qt.CloseButton.prototype.callback = function(e, c, tb) { + var button, element, tbo = tb.openTags; + if ( tbo ) { + while ( tbo.length > 0 ) { + button = tb.getButton(tbo[tbo.length - 1]); + element = document.getElementById(tb.name + '_' + button.id); + button.callback.call(button, element, c, tb); + } + } + }; + + qt.prototype.closeAllTags = function() { + var btn = this.getButton('close'); + btn.callback.call(btn, '', this.canvas, this.toolbar); + }; + + // the link button + qt.LinkButton = function() { + qt.TagButton.call(this, 'link', 'link', '', '', 'a'); + }; + qt.LinkButton.prototype = new qt.TagButton(); + qt.LinkButton.prototype.callback = function(e, c, tb, defaultValue) { + var URL, t = this; + + if ( typeof(wpLink) != 'undefined' ) { + wpLink.open(); + return; + } + if ( ! defaultValue ) defaultValue = 'http://'; - if ( ! t.edCheckOpenTags(i) ) { - var URL = prompt(quicktagsL10n.enterURL, defaultValue); + if ( t.isOpen(tb) === false ) { + URL = prompt(quicktagsL10n.enterURL, defaultValue); if ( URL ) { - t.Buttons[i].tagStart = ''; - t.edInsertTag(i); + t.tagStart = ''; + qt.TagButton.prototype.callback.call(t, e, c, tb); } } else { - t.edInsertTag(i); + qt.TagButton.prototype.callback.call(t, e, c, tb); } }; - this.edInsertImage = function() { - var myValue = prompt(quicktagsL10n.enterImageURL, 'http://'); - if ( myValue ) { - myValue = '' + prompt(quicktagsL10n.enterImageDescription, '')
-					+ ''; - edInsertContent(t.Canvas, myValue); + // the img button + qt.ImgButton = function() { + qt.TagButton.call(this, 'img', 'img', '', '', 'm', -1); + }; + qt.ImgButton.prototype = new qt.TagButton(); + qt.ImgButton.prototype.callback = function(e, c, tb, defaultValue) { + if ( ! defaultValue ) { + defaultValue = 'http://'; + } + var src = prompt(quicktagsL10n.enterImageURL, defaultValue), alt; + if ( src ) { + alt = prompt(quicktagsL10n.enterImageDescription, ''); + this.tagStart = '' + alt + ''; + qt.TagButton.prototype.callback.call(this, e, c, tb); } }; - t.Buttons[t.Buttons.length] = new edButton(name+'_strong','b','','','b'); - t.Buttons[t.Buttons.length] = new edButton(name+'_em','i','','','i'); - t.Buttons[t.Buttons.length] = new edButton(name+'_link','link','','','a'); // special case - t.Buttons[t.Buttons.length] = new edButton(name+'_block','b-quote','\n\n
    ','
    \n\n','q'); - t.Buttons[t.Buttons.length] = new edButton(name+'_del','del','','','d'); - t.Buttons[t.Buttons.length] = new edButton(name+'_ins','ins','','','s'); - t.Buttons[t.Buttons.length] = new edButton(name+'_img','img','','','m',-1); // special case - t.Buttons[t.Buttons.length] = new edButton(name+'_ul','ul','
      \n','
    \n\n','u'); - t.Buttons[t.Buttons.length] = new edButton(name+'_ol','ol','
      \n','
    \n\n','o'); - t.Buttons[t.Buttons.length] = new edButton(name+'_li','li','\t
  • ','
  • \n','l'); - t.Buttons[t.Buttons.length] = new edButton(name+'_code','code','','','c'); - t.Buttons[t.Buttons.length] = new edButton(name+'_more','more','','','t',-1); -// t.Buttons[t.Buttons.length] = new edButton(name+'_next','page','','','p',-1); + qt.FullscreenButton = function() { + qt.Button.call(this, 'fullscreen', quicktagsL10n.fullscreen, 'f', quicktagsL10n.toggleFullscreen); + }; + qt.FullscreenButton.prototype = new qt.Button(); + qt.FullscreenButton.prototype.callback = function(e, c) { + if ( c.id != 'content' || typeof(fullscreen) == 'undefined' ) + return; - tb = document.createElement('div'); - tb.id = name+'_qtags'; + fullscreen.on(); + }; - html = '
    '; - for (i = 0; i < t.Buttons.length; i++) - html += t.edShowButton(t.Buttons[i], i); + // ensure backward compatibility + edButtons = [ + new qt.TagButton('strong','b','','','b'), + new qt.TagButton('em','i','','','i'), + new qt.LinkButton(), // special case + new qt.TagButton('block','b-quote','\n\n
    ','
    \n\n','q'), + new qt.TagButton('del','del','','','d'), + new qt.TagButton('ins','ins','','','s'), + new qt.ImgButton(), // special case + new qt.TagButton('ul','ul','
      \n','
    \n\n','u'), + new qt.TagButton('ol','ol','
      \n','
    \n\n','o'), + new qt.TagButton('li','li','\t
  • ','
  • \n','l'), + new qt.TagButton('code','code','','','c'), + new qt.TagButton('more','more','','','t',-1), + new qt.SpellButton(), + new qt.CloseButton() + ]; - html += ''; - html += '
    '; - - tb.innerHTML = html; - cont.parentNode.insertBefore(tb, cont); - -}; + edButton = qt.TagButton; +})(); diff --git a/wp-includes/js/quicktags.js b/wp-includes/js/quicktags.js index e179e1b482..ca361968cf 100644 --- a/wp-includes/js/quicktags.js +++ b/wp-includes/js/quicktags.js @@ -1 +1 @@ -var edButtons=new Array(),edLinks=new Array(),edOpenTags=new Array(),now=new Date(),datetime;function edButton(f,e,c,b,a,d){this.id=f;this.display=e;this.tagStart=c;this.tagEnd=b;this.access=a;this.open=d}function zeroise(b,a){var c=b.toString();if(b<0){c=c.substr(1,c.length)}while(c.length","","b");edButtons[edButtons.length]=new edButton("ed_em","i","","","i");edButtons[edButtons.length]=new edButton("ed_link","link","","","a");edButtons[edButtons.length]=new edButton("ed_block","b-quote","\n\n
    ","
    \n\n","q");edButtons[edButtons.length]=new edButton("ed_del","del",'',"","d");edButtons[edButtons.length]=new edButton("ed_ins","ins",'',"","s");edButtons[edButtons.length]=new edButton("ed_img","img","","","m",-1);edButtons[edButtons.length]=new edButton("ed_ul","ul","
      \n","
    \n\n","u");edButtons[edButtons.length]=new edButton("ed_ol","ol","
      \n","
    \n\n","o");edButtons[edButtons.length]=new edButton("ed_li","li","\t
  • ","
  • \n","l");edButtons[edButtons.length]=new edButton("ed_code","code","","","c");edButtons[edButtons.length]=new edButton("ed_more","more","","","t",-1);function edLink(){this.display="";this.URL="";this.newWin=0}edLinks[edLinks.length]=new edLink("WordPress","http://wordpress.org/");edLinks[edLinks.length]=new edLink("alexking.org","http://www.alexking.org/");function edShowButton(b,a){if(b.id=="ed_img"){document.write('')}else{if(b.id=="ed_link"){document.write('')}else{document.write('')}}}function edShowLinks(){var a='";document.write(a)}function edAddTag(a){if(edButtons[a].tagEnd!=""){edOpenTags[edOpenTags.length]=a;document.getElementById(edButtons[a].id).value="/"+document.getElementById(edButtons[a].id).value}}function edRemoveTag(b){for(var a=0;a0){return true}else{return false}}function edCloseAllTags(){var a=edOpenTags.length,b;for(b=0;b-1){var b="",a;if(edLinks[c].newWin==1){b=' target="_blank"'}a='"+edLinks[c].display+"";d.selectedIndex=0;edInsertContent(edCanvas,a)}else{d.selectedIndex=0}}function edSpell(c){var e="",d,b,a;if(document.selection){c.focus();d=document.selection.createRange();if(d.text.length>0){e=d.text}}else{if(c.selectionStart||c.selectionStart=="0"){b=c.selectionStart;a=c.selectionEnd;if(b!=a){e=c.value.substring(b,a)}}}if(e==""){e=prompt(quicktagsL10n.wordLookup,"")}if(e!==null&&/^\w[\w ]*$/.test(e)){window.open("http://www.answers.com/"+escape(e))}}function edToolbar(){document.write('
    ');for(var a=0;a');document.write('');document.write('');document.write("
    ")}function edInsertTag(d,c){if(document.selection){d.focus();var e=document.selection.createRange();if(e.text.length>0){e.text=edButtons[c].tagStart+e.text+edButtons[c].tagEnd}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){e.text=edButtons[c].tagStart;edAddTag(c)}else{e.text=edButtons[c].tagEnd;edRemoveTag(c)}}d.focus()}else{if(d.selectionStart||d.selectionStart=="0"){var b=d.selectionStart,a=d.selectionEnd,g=a,f=d.scrollTop;if(b!=a){d.value=d.value.substring(0,b)+edButtons[c].tagStart+d.value.substring(b,a)+edButtons[c].tagEnd+d.value.substring(a,d.value.length);g+=edButtons[c].tagStart.length+edButtons[c].tagEnd.length}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){d.value=d.value.substring(0,b)+edButtons[c].tagStart+d.value.substring(a,d.value.length);edAddTag(c);g=b+edButtons[c].tagStart.length}else{d.value=d.value.substring(0,b)+edButtons[c].tagEnd+d.value.substring(a,d.value.length);edRemoveTag(c);g=b+edButtons[c].tagEnd.length}}d.focus();d.selectionStart=g;d.selectionEnd=g;d.scrollTop=f}else{if(!edCheckOpenTags(c)||edButtons[c].tagEnd==""){d.value+=edButtons[c].tagStart;edAddTag(c)}else{d.value+=edButtons[c].tagEnd;edRemoveTag(c)}d.focus()}}}function edInsertContent(d,c){var e,b,a,f;if(document.selection){d.focus();e=document.selection.createRange();e.text=c;d.focus()}else{if(d.selectionStart||d.selectionStart=="0"){b=d.selectionStart;a=d.selectionEnd;f=d.scrollTop;d.value=d.value.substring(0,b)+c+d.value.substring(a,d.value.length);d.focus();d.selectionStart=b+c.length;d.selectionEnd=b+c.length;d.scrollTop=f}else{d.value+=c;d.focus()}}}function edInsertLink(d,c,b){if("object"==typeof(wpLink)){wpLink.open()}else{if(!b){b="http://"}if(!edCheckOpenTags(c)){var a=prompt(quicktagsL10n.enterURL,b);if(a){edButtons[c].tagStart='';edInsertTag(d,c)}}else{edInsertTag(d,c)}}}function edInsertImage(b){var a=prompt(quicktagsL10n.enterImageURL,"http://");if(a){a=''+prompt(quicktagsL10n.enterImageDescription,';edInsertContent(b,a)}}var QTags=function(a,c,b,f){var j=this,k=document.getElementById(b),g,l,e,h,d;j.Buttons=[];j.Links=[];j.OpenTags=[];j.Canvas=document.getElementById(c);if(!j.Canvas||!k){return}f=(typeof f!="undefined")?","+f+",":"";j.edShowButton=function(n,m){if(f&&(f.indexOf(","+n.display+",")!=-1)){return""}else{if(n.id==a+"_img"){return''}else{if(n.id==a+"_link"){return''}else{return''}}}};j.edAddTag=function(i){if(j.Buttons[i].tagEnd!=""){j.OpenTags[j.OpenTags.length]=i;document.getElementById(j.Buttons[i].id).value="/"+document.getElementById(j.Buttons[i].id).value}};j.edRemoveTag=function(i){for(g=0;g0){return true}else{return false}};this.edCloseAllTags=function(){var i=j.OpenTags.length;for(var m=0;m-1){var n="",m;if(Links[o].newWin==1){n=' target="_blank"'}m='"+Links[o].display+"";p.selectedIndex=0;edInsertContent(j.Canvas,m)}else{p.selectedIndex=0}};j.edInsertTag=function(o){if(document.selection){j.Canvas.focus();d=document.selection.createRange();if(d.text.length>0){d.text=j.Buttons[o].tagStart+d.text+j.Buttons[o].tagEnd}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){d.text=j.Buttons[o].tagStart;j.edAddTag(o)}else{d.text=j.Buttons[o].tagEnd;j.edRemoveTag(o)}}j.Canvas.focus()}else{if(j.Canvas.selectionStart||j.Canvas.selectionStart=="0"){var n=j.Canvas.selectionStart,m=j.Canvas.selectionEnd,q=m,p=j.Canvas.scrollTop;if(n!=m){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(n,m)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);q+=j.Buttons[o].tagStart.length+j.Buttons[o].tagEnd.length}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagStart+j.Canvas.value.substring(m,j.Canvas.value.length);j.edAddTag(o);q=n+j.Buttons[o].tagStart.length}else{j.Canvas.value=j.Canvas.value.substring(0,n)+j.Buttons[o].tagEnd+j.Canvas.value.substring(m,j.Canvas.value.length);j.edRemoveTag(o);q=n+j.Buttons[o].tagEnd.length}}j.Canvas.focus();j.Canvas.selectionStart=q;j.Canvas.selectionEnd=q;j.Canvas.scrollTop=p}else{if(!j.edCheckOpenTags(o)||j.Buttons[o].tagEnd==""){j.Canvas.value+=Buttons[o].tagStart;j.edAddTag(o)}else{j.Canvas.value+=Buttons[o].tagEnd;j.edRemoveTag(o)}j.Canvas.focus()}}};this.edInsertLink=function(o,n){if(!n){n="http://"}if(!j.edCheckOpenTags(o)){var m=prompt(quicktagsL10n.enterURL,n);if(m){j.Buttons[o].tagStart='';j.edInsertTag(o)}}else{j.edInsertTag(o)}};this.edInsertImage=function(){var i=prompt(quicktagsL10n.enterImageURL,"http://");if(i){i=''+prompt(quicktagsL10n.enterImageDescription,';edInsertContent(j.Canvas,i)}};j.Buttons[j.Buttons.length]=new edButton(a+"_strong","b","","","b");j.Buttons[j.Buttons.length]=new edButton(a+"_em","i","","","i");j.Buttons[j.Buttons.length]=new edButton(a+"_link","link","","","a");j.Buttons[j.Buttons.length]=new edButton(a+"_block","b-quote","\n\n
    ","
    \n\n","q");j.Buttons[j.Buttons.length]=new edButton(a+"_del","del",'',"","d");j.Buttons[j.Buttons.length]=new edButton(a+"_ins","ins",'',"","s");j.Buttons[j.Buttons.length]=new edButton(a+"_img","img","","","m",-1);j.Buttons[j.Buttons.length]=new edButton(a+"_ul","ul","
      \n","
    \n\n","u");j.Buttons[j.Buttons.length]=new edButton(a+"_ol","ol","
      \n","
    \n\n","o");j.Buttons[j.Buttons.length]=new edButton(a+"_li","li","\t
  • ","
  • \n","l");j.Buttons[j.Buttons.length]=new edButton(a+"_code","code","","","c");j.Buttons[j.Buttons.length]=new edButton(a+"_more","more","","","t",-1);e=document.createElement("div");e.id=a+"_qtags";h='
    ';for(g=0;g';h+='
    ';e.innerHTML=h;k.parentNode.insertBefore(e,k)}; \ No newline at end of file +var QTags,edButtons,edButton;function quicktags(a){return new QTags(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(e){};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=u.tagStart+g.text+u.tagEnd}else{if(u.isOpen(q)===false||u.tagEnd===""){g.text=u.tagStart;u.openTag(o,q)}else{g.text=u.tagEnd;u.closeTag(o,q)}}j.focus()}else{if(j.selectionStart||j.selectionStart=="0"){p=j.selectionStart;f=j.selectionEnd;m=f;h=j.scrollTop;k=s.substring(0,p);e=s.substring(f,s.length);n=s.substring(p,f);if(p!=f){j.value=k+u.tagStart+n+u.tagEnd+e;if(u.tagEnd===""){m=p}m+=u.tagStart.length+u.tagEnd.length}else{if(u.isOpen(q)===false||u.tagEnd===""){j.value=k+u.tagStart+e;u.openTag(o,q);m=p+u.tagStart.length}else{j.value=k+u.tagEnd+e;m=p+u.tagEnd.length;u.closeTag(o,q)}}j.focus();j.selectionStart=m;j.selectionEnd=m;j.scrollTop=h}else{if(u.isOpen(q)!==false||u.tagEnd===""){j.value+=u.tagStart;u.openTag(o,q)}else{j.value+=u.tagEnd;u.closeTag(o,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(h,g,i){var k="",j,f,e;if(document.selection){g.focus();j=document.selection.createRange();if(j.text.length>0){k=j.text}}else{if(g.selectionStart||g.selectionStart=="0"){f=g.selectionStart;e=g.selectionEnd;if(f!=e){k=g.value.substring(f,e)}}}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.prototype.closeAllTags=function(){var e=this.getButton("close");e.callback.call(e,"",this.canvas,this.toolbar)};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=[new d.TagButton("strong","b","","","b"),new d.TagButton("em","i","","","i"),new d.LinkButton(),new d.TagButton("block","b-quote","\n\n
    ","
    \n\n","q"),new d.TagButton("del","del",'',"","d"),new d.TagButton("ins","ins",'',"","s"),new d.ImgButton(),new d.TagButton("ul","ul","
      \n","
    \n\n","u"),new d.TagButton("ol","ol","
      \n","
    \n\n","o"),new d.TagButton("li","li","\t
  • ","
  • \n","l"),new d.TagButton("code","code","","","c"),new d.TagButton("more","more","","","t",-1),new d.SpellButton(),new d.CloseButton()];edButton=d.TagButton})(); \ No newline at end of file diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index dc05527ed6..a024f873a2 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -67,9 +67,8 @@ 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, '20110502', 1 ); + $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110802', 1 ); $scripts->add_script_data( 'quicktags', 'quicktagsL10n', array( - 'quickLinks' => __('(Quick Links)'), 'wordLookup' => __('Enter a word to look up:'), 'dictionaryLookup' => esc_attr(__('Dictionary lookup')), 'lookup' => esc_attr(__('lookup')), @@ -265,7 +264,7 @@ function wp_default_scripts( &$scripts ) { $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20110429', 1 ); - $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110602', 1 ); + $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110802', 1 ); $scripts->add_script_data( 'admin-comments', 'adminCommentsL10n', array( 'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']), 'hotkeys_highlight_last' => isset($_GET['hotkeys_highlight_last']),