Make WordPress Core

Changeset 18497


Ignore:
Timestamp:
08/03/2011 10:11:12 AM (15 years ago)
Author:
azaozz
Message:

Refactor Quicktags, props garyc40, see #16695

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/js/edit-comments.dev.js

    r18254 r18497  
    549549        $(document).delegate('span.delete a.delete', 'click', function(){return false;});
    550550
    551         if ( typeof QTags != 'undefined' )
    552                 ed_reply = new QTags('ed_reply', 'replycontent', 'replycontainer', 'more,fullscreen');
     551        if ( typeof QTags != 'undefined' ) {
     552                quicktags({quicktags_id: 'replycontent', quicktags_buttons: 'strong,em,link,block,del,ins,img,ul,ol,li,code,spell,close'});
     553       
     554       
     555        console.debug('typeof QTags')
     556        }
    553557
    554558        if ( typeof $.table_hotkeys != 'undefined' ) {
  • trunk/wp-admin/js/edit-comments.js

    r18114 r18497  
    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('<tr id="undo-'+k+'" class="undo un'+p+'" style="display:none;"><td colspan="'+m+'">'+note+"</td></tr>")}else{q=a(".comment-author",l).text();r=a('<div id="undo-'+k+'" style="display:none;" class="undo un'+p+'">'+note+"</div>")}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(l<j){return}if(m){j=l}c.val(k.toString());a("span.total-type-count").each(function(){updateCount(a(this),k)})};dashboardTotals=function(q){var p=a("#dashboard_right_now"),l,o,m,k;q=q||0;if(isNaN(q)||!p.length){return}l=a("span.total-count",p);o=a("span.approved-count",p);m=getCount(l);m=m+q;k=m-getCount(a("span.pending-count",p))-getCount(a("span.spam-count",p));updateCount(l,m);updateCount(o,k)};getCount=function(k){var l=parseInt(k.html().replace(/[^0-9]+/g,""),10);if(isNaN(l)){return 0}return l};updateCount=function(l,m){var k="";if(isNaN(m)){return}m=m<1?"0":m.toString();if(m.length>3){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)&&j<n.parsed.responses[0].supplemental.time){total_items_i18n=n.parsed.responses[0].supplemental.total_items_i18n||"";if(total_items_i18n){a(".displaying-num").text(total_items_i18n);a(".total-pages").text(n.parsed.responses[0].supplemental.total_pages_i18n);a(".tablenav-pages").find(".next-page, .last-page").toggleClass("disabled",n.parsed.responses[0].supplemental.total_pages==a(".current-page").val())}d(q,n.parsed.responses[0].supplemental.time,true)}else{d(q,k,false)}}if(!theExtraList||theExtraList.size()==0||theExtraList.children().size()==0||u||m){return}theList.get(0).wpList.add(theExtraList.children(":eq(0)").remove().clone());b()};b=function(n){var l=a.query.get(),k=a(".total-pages").text(),m=a('input[name="_per_page"]',"#comments-form").val();if(!l.paged){l.paged=1}if(l.paged>k){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<h){window.scroll(0,h-c+35)}else{if(o-20<p){window.scroll(0,o-35)}}a("#replycontent").focus().keyup(function(q){if(q.which==27){commentReply.revert()}})},600);return false},send:function(){var b={};a("#replysubmit .error").hide();a("#replysubmit .waiting").show();a("#replyrow input").not(":button").each(function(){b[a(this).attr("name")]=a(this).val()});b.content=a("#replycontent").val();b.id=b.comment_post_ID;b.comments_listing=this.comments_listing;b.p=a('[name="p"]').val();if(a("#comment-"+a("#comment_ID").val()).hasClass("unapproved")){b.approve_parent=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){commentReply.show(c)},error:function(c){commentReply.error(c)}});return false},show:function(d){var f=this,g,i,h,e,b;f.revert();if(typeof(d)=="string"){f.error({responseText:d});return false}g=wpAjax.parseAjaxResponse(d);if(g.errors){f.error({responseText:wpAjax.broken});return false}g=g.responses[0];i=g.data;h="#comment-"+g.id;if("edit-comment"==f.act){a(h).remove()}if(g.supplemental.parent_approved){b=a("#comment-"+g.supplemental.parent_approved);updatePending(getCount(a("span.pending-count").eq(0))-1);if(this.comments_listing=="moderated"){b.animate({backgroundColor:"#CCEEBB"},400,function(){b.fadeOut()});return}}a(i).hide();a("#replyrow").after(i);h=a(h);f.addEvents(h);e=h.hasClass("unapproved")?"#FFFFE0":h.closest(".widefat").css("backgroundColor");h.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:e},300,function(){if(b&&b.length){b.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:e},300).removeClass("unapproved").addClass("approved").find("div.comment_status").html("1")}})},error:function(b){var c=b.statusText;a("#replysubmit .waiting").hide();if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/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);
     1var 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('<tr id="undo-'+k+'" class="undo un'+p+'" style="display:none;"><td colspan="'+m+'">'+note+"</td></tr>")}else{q=a(".comment-author",l).text();r=a('<div id="undo-'+k+'" style="display:none;" class="undo un'+p+'">'+note+"</div>")}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(l<j){return}if(m){j=l}c.val(k.toString());a("span.total-type-count").each(function(){updateCount(a(this),k)})};dashboardTotals=function(q){var p=a("#dashboard_right_now"),l,o,m,k;q=q||0;if(isNaN(q)||!p.length){return}l=a("span.total-count",p);o=a("span.approved-count",p);m=getCount(l);m=m+q;k=m-getCount(a("span.pending-count",p))-getCount(a("span.spam-count",p));updateCount(l,m);updateCount(o,k)};getCount=function(k){var l=parseInt(k.html().replace(/[^0-9]+/g,""),10);if(isNaN(l)){return 0}return l};updateCount=function(l,m){var k="";if(isNaN(m)){return}m=m<1?"0":m.toString();if(m.length>3){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)&&j<n.parsed.responses[0].supplemental.time){total_items_i18n=n.parsed.responses[0].supplemental.total_items_i18n||"";if(total_items_i18n){a(".displaying-num").text(total_items_i18n);a(".total-pages").text(n.parsed.responses[0].supplemental.total_pages_i18n);a(".tablenav-pages").find(".next-page, .last-page").toggleClass("disabled",n.parsed.responses[0].supplemental.total_pages==a(".current-page").val())}d(q,n.parsed.responses[0].supplemental.time,true)}else{d(q,k,false)}}if(!theExtraList||theExtraList.size()==0||theExtraList.children().size()==0||u||m){return}theList.get(0).wpList.add(theExtraList.children(":eq(0)").remove().clone());b()};b=function(n){var l=a.query.get(),k=a(".total-pages").text(),m=a('input[name="_per_page"]',"#comments-form").val();if(!l.paged){l.paged=1}if(l.paged>k){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<h){window.scroll(0,h-c+35)}else{if(o-20<p){window.scroll(0,o-35)}}a("#replycontent").focus().keyup(function(q){if(q.which==27){commentReply.revert()}})},600);return false},send:function(){var b={};a("#replysubmit .error").hide();a("#replysubmit .waiting").show();a("#replyrow input").not(":button").each(function(){b[a(this).attr("name")]=a(this).val()});b.content=a("#replycontent").val();b.id=b.comment_post_ID;b.comments_listing=this.comments_listing;b.p=a('[name="p"]').val();if(a("#comment-"+a("#comment_ID").val()).hasClass("unapproved")){b.approve_parent=1}a.ajax({type:"POST",url:ajaxurl,data:b,success:function(c){commentReply.show(c)},error:function(c){commentReply.error(c)}});return false},show:function(d){var f=this,g,i,h,e,b;f.revert();if(typeof(d)=="string"){f.error({responseText:d});return false}g=wpAjax.parseAjaxResponse(d);if(g.errors){f.error({responseText:wpAjax.broken});return false}g=g.responses[0];i=g.data;h="#comment-"+g.id;if("edit-comment"==f.act){a(h).remove()}if(g.supplemental.parent_approved){b=a("#comment-"+g.supplemental.parent_approved);updatePending(getCount(a("span.pending-count").eq(0))-1);if(this.comments_listing=="moderated"){b.animate({backgroundColor:"#CCEEBB"},400,function(){b.fadeOut()});return}}a(i).hide();a("#replyrow").after(i);h=a(h);f.addEvents(h);e=h.hasClass("unapproved")?"#FFFFE0":h.closest(".widefat").css("backgroundColor");h.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:e},300,function(){if(b&&b.length){b.animate({backgroundColor:"#CCEEBB"},300).animate({backgroundColor:e},300).removeClass("unapproved").addClass("approved").find("div.comment_status").html("1")}})},error:function(b){var c=b.statusText;a("#replysubmit .waiting").hide();if(b.responseText){c=b.responseText.replace(/<.[^<>]*?>/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);
  • trunk/wp-includes/js/quicktags.dev.js

    r17785 r18497  
     1/*
     2 * Quicktags
     3 *
     4 * This is the HTML editor in WordPress. It can be attached to any textarea and will
     5 * append a toolbar above it. This script is self-contained (does not require external libraries).
     6 *
     7 * Run quicktags(settings) to initialize it, where settings is an object containing up to 3 properties:
     8 * settings = {
     9 *   quicktags_id: 'myid', // required
     10 *   buttons: '', // optional
     11 *   disabled_buttons: '' // optional
     12 * }
     13 *
     14 * The settings can also be a string quicktags_id.
     15 *
     16 * quicktags_id The ID of the textarea that will be the editor canvas
     17 * buttons Comma separated list of the buttons IDs that will be shown. Buttons added by plugins
     18 * will not show. Default: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,spell,close'
     19 * disabled_buttons Comma separated list of the buttons IDs that should be excluded. Buttons
     20 * added by plugins will show unless specifically disabled.
     21 */
     22
    123// new edit toolbar used with permission
    224// by Alex King
    325// http://www.alexking.org/
    426
    5 var edButtons = new Array(), edLinks = new Array(), edOpenTags = new Array(), now = new Date(), datetime;
    6 
    7 function edButton(id, display, tagStart, tagEnd, access, open) {
    8         this.id = id;                           // used to name the toolbar button
    9         this.display = display;         // label on button
    10         this.tagStart = tagStart;       // open tag
    11         this.tagEnd = tagEnd;           // close tag
    12         this.access = access;           // access key
    13         this.open = open;                       // set to -1 if tag does not need to be closed
     27var QTags, edButtons, edButton;
     28
     29function quicktags(settings) {
     30        return new QTags(settings);
    1431}
    1532
    16 function zeroise(number, threshold) {
    17         // FIXME: or we could use an implementation of printf in js here
    18         var str = number.toString();
    19         if (number < 0) { str = str.substr(1, str.length) }
    20         while (str.length < threshold) { str = "0" + str }
    21         if (number < 0) { str = '-' + str }
    22         return str;
    23 }
    24 
    25 datetime = now.getUTCFullYear() + '-' +
    26 zeroise(now.getUTCMonth() + 1, 2) + '-' +
    27 zeroise(now.getUTCDate(), 2) + 'T' +
    28 zeroise(now.getUTCHours(), 2) + ':' +
    29 zeroise(now.getUTCMinutes(), 2) + ':' +
    30 zeroise(now.getUTCSeconds() ,2) +
    31 '+00:00';
    32 
    33 edButtons[edButtons.length] =
    34 new edButton('ed_strong'
    35 ,'b'
    36 ,'<strong>'
    37 ,'</strong>'
    38 ,'b'
    39 );
    40 
    41 edButtons[edButtons.length] =
    42 new edButton('ed_em'
    43 ,'i'
    44 ,'<em>'
    45 ,'</em>'
    46 ,'i'
    47 );
    48 
    49 edButtons[edButtons.length] =
    50 new edButton('ed_link'
    51 ,'link'
    52 ,''
    53 ,'</a>'
    54 ,'a'
    55 ); // special case
    56 
    57 edButtons[edButtons.length] =
    58 new edButton('ed_block'
    59 ,'b-quote'
    60 ,'\n\n<blockquote>'
    61 ,'</blockquote>\n\n'
    62 ,'q'
    63 );
    64 
    65 
    66 edButtons[edButtons.length] =
    67 new edButton('ed_del'
    68 ,'del'
    69 ,'<del datetime="' + datetime + '">'
    70 ,'</del>'
    71 ,'d'
    72 );
    73 
    74 edButtons[edButtons.length] =
    75 new edButton('ed_ins'
    76 ,'ins'
    77 ,'<ins datetime="' + datetime + '">'
    78 ,'</ins>'
    79 ,'s'
    80 );
    81 
    82 edButtons[edButtons.length] =
    83 new edButton('ed_img'
    84 ,'img'
    85 ,''
    86 ,''
    87 ,'m'
    88 ,-1
    89 ); // special case
    90 
    91 edButtons[edButtons.length] =
    92 new edButton('ed_ul'
    93 ,'ul'
    94 ,'<ul>\n'
    95 ,'</ul>\n\n'
    96 ,'u'
    97 );
    98 
    99 edButtons[edButtons.length] =
    100 new edButton('ed_ol'
    101 ,'ol'
    102 ,'<ol>\n'
    103 ,'</ol>\n\n'
    104 ,'o'
    105 );
    106 
    107 edButtons[edButtons.length] =
    108 new edButton('ed_li'
    109 ,'li'
    110 ,'\t<li>'
    111 ,'</li>\n'
    112 ,'l'
    113 );
    114 
    115 edButtons[edButtons.length] =
    116 new edButton('ed_code'
    117 ,'code'
    118 ,'<code>'
    119 ,'</code>'
    120 ,'c'
    121 );
    122 
    123 edButtons[edButtons.length] =
    124 new edButton('ed_more'
    125 ,'more'
    126 ,'<!--more-->'
    127 ,''
    128 ,'t'
    129 ,-1
    130 );
    131 /*
    132 edButtons[edButtons.length] =
    133 new edButton('ed_next'
    134 ,'page'
    135 ,'<!--nextpage-->'
    136 ,''
    137 ,'p'
    138 ,-1
    139 );
    140 */
    141 function edLink() {
    142         this.display = '';
    143         this.URL = '';
    144         this.newWin = 0;
    145 }
    146 
    147 edLinks[edLinks.length] = new edLink('WordPress'
    148                                     ,'http://wordpress.org/'
    149                                     );
    150 
    151 edLinks[edLinks.length] = new edLink('alexking.org'
    152                                     ,'http://www.alexking.org/'
    153                                     );
    154 
    155 function edShowButton(button, i) {
    156         if (button.id == 'ed_img') {
    157                 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertImage(edCanvas);" value="' + button.display + '" />');
    158         }
    159         else if (button.id == 'ed_link') {
    160                 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertLink(edCanvas, ' + i + ');" value="' + button.display + '" />');
    161         }
    162         else {
    163                 document.write('<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertTag(edCanvas, ' + i + ');" value="' + button.display + '"  />');
    164         }
    165 }
    166 
    167 function edShowLinks() {
    168         var tempStr = '<select onchange="edQuickLink(this.options[this.selectedIndex].value, this);"><option value="-1" selected>' + quicktagsL10n.quickLinks + '</option>', i;
    169         for (i = 0; i < edLinks.length; i++) {
    170                 tempStr += '<option value="' + i + '">' + edLinks[i].display + '</option>';
    171         }
    172         tempStr += '</select>';
    173         document.write(tempStr);
    174 }
    175 
    176 function edAddTag(button) {
    177         if (edButtons[button].tagEnd != '') {
    178                 edOpenTags[edOpenTags.length] = button;
    179                 document.getElementById(edButtons[button].id).value = '/' + document.getElementById(edButtons[button].id).value;
    180         }
    181 }
    182 
    183 function edRemoveTag(button) {
    184         for (var i = 0; i < edOpenTags.length; i++) {
    185                 if (edOpenTags[i] == button) {
    186                         edOpenTags.splice(i, 1);
    187                         document.getElementById(edButtons[button].id).value =           document.getElementById(edButtons[button].id).value.replace('/', '');
    188                 }
    189         }
    190 }
    191 
    192 function edCheckOpenTags(button) {
    193         var tag = 0, i;
    194         for (i = 0; i < edOpenTags.length; i++) {
    195                 if (edOpenTags[i] == button) {
    196                         tag++;
    197                 }
    198         }
    199         if (tag > 0) {
    200                 return true; // tag found
    201         }
    202         else {
    203                 return false; // tag not found
    204         }
    205 }
    206 
    207 function edCloseAllTags() {
    208         var count = edOpenTags.length, o;
    209         for (o = 0; o < count; o++) {
    210                 edInsertTag(edCanvas, edOpenTags[edOpenTags.length - 1]);
    211         }
    212 }
    213 
    214 function edQuickLink(i, thisSelect) {
    215         if (i > -1) {
    216                 var newWin = '', tempStr;
    217                 if (edLinks[i].newWin == 1) {
    218                         newWin = ' target="_blank"';
    219                 }
    220                 tempStr = '<a href="' + edLinks[i].URL + '"' + newWin + '>'
    221                             + edLinks[i].display
    222                             + '</a>';
    223                 thisSelect.selectedIndex = 0;
    224                 edInsertContent(edCanvas, tempStr);
    225         }
    226         else {
    227                 thisSelect.selectedIndex = 0;
    228         }
    229 }
    230 
    231 function edSpell(myField) {
    232         var word = '', sel, startPos, endPos;
    233         if (document.selection) {
    234                 myField.focus();
    235             sel = document.selection.createRange();
    236                 if (sel.text.length > 0) {
    237                         word = sel.text;
    238                 }
    239         }
    240         else if (myField.selectionStart || myField.selectionStart == '0') {
    241                 startPos = myField.selectionStart;
    242                 endPos = myField.selectionEnd;
    243                 if (startPos != endPos) {
    244                         word = myField.value.substring(startPos, endPos);
    245                 }
    246         }
    247         if (word == '') {
    248                 word = prompt(quicktagsL10n.wordLookup, '');
    249         }
    250         if (word !== null && /^\w[\w ]*$/.test(word)) {
    251                 window.open('http://www.answers.com/' + escape(word));
    252         }
    253 }
    254 
    255 function edToolbar() {
    256         document.write('<div id="ed_toolbar">');
    257         for (var i = 0; i < edButtons.length; i++) {
    258                 edShowButton(edButtons[i], i);
    259         }
    260         document.write('<input type="button" id="ed_spell" class="ed_button" onclick="edSpell(edCanvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />');
    261         document.write('<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags();" title="' + quicktagsL10n.closeAllOpenTags + '" value="' + quicktagsL10n.closeTags + '" />');
    262         document.write('<input type="button" id="ed_fullscreen" class="ed_button" onclick="fullscreen.on();" title="' + quicktagsL10n.toggleFullscreen + '" value="' + quicktagsL10n.fullscreen + '" />');
    263 //      edShowLinks(); // disabled by default
    264         document.write('</div>');
    265 }
    266 
    267 // insertion code
    268 
    269 function edInsertTag(myField, i) {
    270         //IE support
    271         if (document.selection) {
    272                 myField.focus();
    273             var sel = document.selection.createRange();
    274                 if (sel.text.length > 0) {
    275                         sel.text = edButtons[i].tagStart + sel.text + edButtons[i].tagEnd;
    276                 }
     33(function(){
     34        // private stuff is prefixed with an underscore
     35        var _domReady = function(func) {
     36                var t, i,  DOMContentLoaded;
     37
     38                if ( typeof jQuery != 'undefined' ) {
     39                        jQuery(document).ready(func);
     40                } else {
     41                        t = _domReady;
     42                        t.funcs = [];
     43
     44                        t.ready = function() {
     45                                if ( ! t.isReady ) {
     46                                        t.isReady = true;
     47                                        for ( i = 0; i < t.funcs.length; i++ ) {
     48                                                t.funcs[i]();
     49                                        }
     50                                }
     51                        };
     52
     53                        if ( t.isReady ) {
     54                                func();
     55                        } else {
     56                                t.funcs.push(func);
     57                        }
     58
     59                        if ( ! t.eventAttached ) {
     60                                if ( document.addEventListener ) {
     61                                        DOMContentLoaded = function(){document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);t.ready();};
     62                                        document.addEventListener('DOMContentLoaded', DOMContentLoaded, false);
     63                                        window.addEventListener('load', t.ready, false);
     64                                } else if ( document.attachEvent ) {
     65                                        DOMContentLoaded = function(){if (document.readyState === 'complete'){ document.detachEvent('onreadystatechange', DOMContentLoaded);t.ready();}};
     66                                        document.attachEvent('onreadystatechange', DOMContentLoaded);
     67                                        window.attachEvent('onload', t.ready);
     68
     69                                        (function(){
     70                                                try {
     71                                                        document.documentElement.doScroll("left");
     72                                                } catch(e) {
     73                                                        setTimeout(arguments.callee, 50);
     74                                                        return;
     75                                                }
     76
     77                                                t.ready();
     78                                        })();
     79                                }
     80
     81                                t.eventAttached = true;
     82                        }
     83                }
     84        },
     85
     86        _datetime = (function() {
     87                var now = new Date(), zeroise;
     88
     89                zeroise = function(number) {
     90                        var str = number.toString();
     91
     92                        if ( str.length < 2 )
     93                                str = "0" + str;
     94
     95                        return str;
     96                }
     97
     98                return now.getUTCFullYear() + '-' +
     99                        zeroise( now.getUTCMonth() + 1 ) + '-' +
     100                        zeroise( now.getUTCDate() ) + 'T' +
     101                        zeroise( now.getUTCHours() ) + ':' +
     102                        zeroise( now.getUTCMinutes() ) + ':' +
     103                        zeroise( now.getUTCSeconds() ) +
     104                        '+00:00';
     105        })(),
     106
     107        _customButtons = {},
     108        qt;
     109
     110        qt = QTags = function(settings) {
     111                if ( typeof(settings) == 'string' )
     112                        settings = {quicktags_id: settings};
     113                else if ( typeof(settings) != 'object' )
     114                        return false;
     115
     116                var t = this,
     117                        id = settings.quicktags_id,
     118                        buttons = {},
     119                        theButtons = {},
     120                        canvas = document.getElementById(id),
     121                        name = 'qt_' + id,
     122                        html = '',
     123                        i, tb, qb, btn, onclick;
     124
     125                if ( !id || !canvas )
     126                        return false;
     127
     128                t.name = name;
     129                t.id = id;
     130
     131                // default buttons
     132                for ( i in edButtons ) {
     133                        buttons[edButtons[i].id] = edButtons[i];
     134                }
     135
     136                if ( id == 'content' && adminpage && ( adminpage == 'post-new-php' || adminpage == 'post-php' ) )
     137                        buttons['fullscreen'] = new qt.FullscreenButton();
     138
     139                // add custom buttons
     140                for ( i in t._customButtons ) {
     141                        buttons[i] = new t._customButtons[i]();
     142                }
     143
     144                if ( settings.quicktags_buttons ) {
     145                        qb = settings.quicktags_buttons.split(',');
     146
     147                        for ( i in qb ) {
     148                                btn = qb[i];
     149                                if ( buttons[btn] )
     150                                        theButtons[btn] = buttons[btn];
     151                        }
     152                } else {
     153                        theButtons = buttons;
     154                }
     155
     156                if ( settings.quicktags_disabled_buttons ) {
     157                        qb = settings.quicktags_disabled_buttons.split(',');
     158
     159                        for ( i in qb ) {
     160                                btn = qb[i];
     161                                if ( theButtons[btn] )
     162                                        delete(theButtons[btn]);
     163                        }
     164                }
     165
     166                for ( i in theButtons )
     167                        html += theButtons[i].html(name + '_');
     168
     169                tb = document.createElement('div');
     170                tb.id = name + '_toolbar';
     171                tb.className = 'quicktags-toolbar';
     172
     173                canvas.parentNode.insertBefore(tb, canvas);
     174
     175                tb.innerHTML = html;
     176                t.toolbar = tb;
     177
     178                // listen for click events
     179                onclick = function(e) {
     180                        e = e || window.event;
     181                        var target = e.target || e.srcElement, i;
     182
     183                        // as long as it has the class ed_button, execute the callback
     184                        if ( /\s+ed_button\s+/.test(' ' + target.className + ' ' ) ) {
     185                                // we have to reassign canvas here
     186                                t.canvas = canvas = document.getElementById(id);
     187                                i = target.id.replace(name + '_', '');
     188
     189                                if ( theButtons[i] )
     190                                        theButtons[i].callback.call(theButtons[i], target, canvas, t);
     191                        }
     192                };
     193
     194                if ( tb.addEventListener ) {
     195                        tb.addEventListener('click', onclick, false);
     196                } else if ( tb.attachEvent ) {
     197                        tb.attachEvent('onclick', onclick);
     198                }
     199
     200                qt.instances[id] = t;
     201        };
     202
     203        qt.instances = {};
     204
     205        qt.registerButton = function(id, btnClass) {
     206                _customButtons[id] = btnClass;
     207        };
     208
     209        qt.getInstance = function(id) {
     210                return qt.instances[id];
     211        };
     212
     213        qt.insertContent = function(editor_id, content) {
     214                var sel, startPos, endPos, scrollTop, text, ed = document.getElementById(editor_id);
     215
     216                if ( document.selection ) { //IE
     217                        ed.focus();
     218                        sel = document.selection.createRange();
     219                        sel.text = content;
     220                        ed.focus();
     221                } else if ( ed.selectionStart || ed.selectionStart == '0' ) { // all other
     222                        text = ed.value;
     223                        startPos = ed.selectionStart;
     224                        endPos = ed.selectionEnd;
     225                        scrollTop = ed.scrollTop;
     226
     227                        ed.value = text.substring(0, startPos) + content + text.substring(endPos, text.length);
     228
     229                        ed.focus();
     230                        ed.selectionStart = startPos + content.length;
     231                        ed.selectionEnd = startPos + content.length;
     232                        ed.scrollTop = scrollTop;
     233                } else {
     234                        ed.value += content;
     235                        ed.focus();
     236                }
     237        };
     238
     239        // a plain, dumb button
     240        qt.Button = function(id, display, access, title) {
     241                var t = this;
     242                t.id = id;
     243                t.display = display;
     244                t.access = access;
     245                t.title = title || '';
     246        };
     247        qt.Button.prototype.html = function(idPrefix) {
     248                var access = this.access ? ' accesskey="' + this.access + '"' : '';
     249                return '<input type="button" id="' + idPrefix + this.id + '"' + access + ' class="ed_button" title="' + this.title + '" value="' + this.display + '" />';
     250        };
     251        qt.Button.prototype.callback = function(canvas) {};
     252
     253        // a button that inserts HTML tag
     254        qt.TagButton = function(id, display, tagStart, tagEnd, access, open, title) {
     255                var t = this;
     256                qt.Button.call(t, id, display, access, title);
     257                t.tagStart = tagStart;
     258                t.tagEnd = tagEnd;
     259                t.open = open;
     260        };
     261        qt.TagButton.prototype = new qt.Button();
     262        qt.TagButton.prototype.openTag = function(e, tb) {
     263                var t = this;
     264                if ( ! tb.openTags ) {
     265                        tb.openTags = [];
     266                }
     267                if ( t.tagEnd ) {
     268                        tb.openTags.push(t.id);
     269                        e.value = '/' + e.value;
     270                }
     271        };
     272        qt.TagButton.prototype.closeTag = function(e, tb) {
     273                var t = this,
     274                        i = t.isOpen(tb);
     275
     276                if ( i !== false ) {
     277                        tb.openTags.splice(i, 1);
     278                }
     279
     280                e.value = t.display;
     281        };
     282        // whether a tag is open or not. Returns false if not open, or current open depth of the tag
     283        qt.TagButton.prototype.isOpen = function (tb) {
     284                var t = this, i = 0, ret = false;
     285                if ( tb.openTags ) {
     286                        while ( ret === false && i < tb.openTags.length ) {
     287                                ret = tb.openTags[i] == t.id ? i : false;
     288                                i ++;
     289                        }
     290                } else {
     291                        ret = false;
     292                }
     293                return ret;
     294        };
     295        qt.TagButton.prototype.callback = function(element, canvas, toolbar) {
     296                var t = this, startPos, endPos, cursorPos, scrollTop, v, l, r, i, sel;
     297
     298                v = canvas.value;
     299
     300                // IE support
     301                if ( document.selection ) {
     302                        canvas.focus();
     303                        sel = document.selection.createRange();
     304                        if ( sel.text.length > 0 ) {
     305                                sel.text = t.tagStart + sel.text + t.tagEnd;
     306                        } else {
     307                                if ( t.isOpen(toolbar) === false || t.tagEnd === '' ) {
     308                                        sel.text = t.tagStart;
     309                                        t.openTag(element, toolbar);
     310                                } else {
     311                                        sel.text = t.tagEnd;
     312                                        t.closeTag(element, toolbar);
     313                                }
     314                        }
     315                        canvas.focus();
     316                }
     317                // moz, webkit, opera
     318                else if ( canvas.selectionStart || canvas.selectionStart == '0' ) {
     319                        startPos = canvas.selectionStart;
     320                        endPos = canvas.selectionEnd;
     321                        cursorPos = endPos;
     322                        scrollTop = canvas.scrollTop;
     323                        l = v.substring(0, startPos); // left of the selection
     324                        r = v.substring(endPos, v.length); // right of the selection
     325                        i = v.substring(startPos, endPos); // inside the selection
     326                        if ( startPos != endPos ) {
     327                                canvas.value = l + t.tagStart + i + t.tagEnd + r;
     328                                if ( t.tagEnd === '' ) {
     329                                        cursorPos = startPos;
     330                                }
     331                                cursorPos += t.tagStart.length + t.tagEnd.length;
     332                        } else {
     333                                if ( t.isOpen(toolbar) === false || t.tagEnd === '' ) {
     334                                        canvas.value = l + t.tagStart + r;
     335                                        t.openTag(element, toolbar);
     336                                        cursorPos = startPos + t.tagStart.length;
     337                                } else {
     338                                        canvas.value = l + t.tagEnd + r;
     339                                        cursorPos = startPos + t.tagEnd.length;
     340                                        t.closeTag(element, toolbar);
     341                                }
     342                        }
     343
     344                        canvas.focus();
     345                        canvas.selectionStart = cursorPos;
     346                        canvas.selectionEnd = cursorPos;
     347                        canvas.scrollTop = scrollTop;
     348                }
     349                // other browsers
    277350                else {
    278                         if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
    279                                 sel.text = edButtons[i].tagStart;
    280                                 edAddTag(i);
    281                         }
    282                         else {
    283                                 sel.text = edButtons[i].tagEnd;
    284                                 edRemoveTag(i);
    285                         }
    286                 }
    287                 myField.focus();
    288         }
    289         //MOZILLA/NETSCAPE support
    290         else if (myField.selectionStart || myField.selectionStart == '0') {
    291                 var startPos = myField.selectionStart, endPos = myField.selectionEnd, cursorPos = endPos, scrollTop = myField.scrollTop;
    292 
    293                 if (startPos != endPos) {
    294                         myField.value = myField.value.substring(0, startPos)
    295                                       + edButtons[i].tagStart
    296                                       + myField.value.substring(startPos, endPos)
    297                                       + edButtons[i].tagEnd
    298                                       + myField.value.substring(endPos, myField.value.length);
    299                         cursorPos += edButtons[i].tagStart.length + edButtons[i].tagEnd.length;
    300                 }
    301                 else {
    302                         if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
    303                                 myField.value = myField.value.substring(0, startPos)
    304                                               + edButtons[i].tagStart
    305                                               + myField.value.substring(endPos, myField.value.length);
    306                                 edAddTag(i);
    307                                 cursorPos = startPos + edButtons[i].tagStart.length;
    308                         }
    309                         else {
    310                                 myField.value = myField.value.substring(0, startPos)
    311                                               + edButtons[i].tagEnd
    312                                               + myField.value.substring(endPos, myField.value.length);
    313                                 edRemoveTag(i);
    314                                 cursorPos = startPos + edButtons[i].tagEnd.length;
    315                         }
    316                 }
    317                 myField.focus();
    318                 myField.selectionStart = cursorPos;
    319                 myField.selectionEnd = cursorPos;
    320                 myField.scrollTop = scrollTop;
    321         }
    322         else {
    323                 if (!edCheckOpenTags(i) || edButtons[i].tagEnd == '') {
    324                         myField.value += edButtons[i].tagStart;
    325                         edAddTag(i);
    326                 }
    327                 else {
    328                         myField.value += edButtons[i].tagEnd;
    329                         edRemoveTag(i);
    330                 }
    331                 myField.focus();
    332         }
    333 }
    334 
    335 function edInsertContent(myField, myValue) {
    336         var sel, startPos, endPos, scrollTop;
    337 
    338         //IE support
    339         if (document.selection) {
    340                 myField.focus();
    341                 sel = document.selection.createRange();
    342                 sel.text = myValue;
    343                 myField.focus();
    344         }
    345         //MOZILLA/NETSCAPE support
    346         else if (myField.selectionStart || myField.selectionStart == '0') {
    347                 startPos = myField.selectionStart;
    348                 endPos = myField.selectionEnd;
    349                 scrollTop = myField.scrollTop;
    350                 myField.value = myField.value.substring(0, startPos)
    351                               + myValue
    352                       + myField.value.substring(endPos, myField.value.length);
    353                 myField.focus();
    354                 myField.selectionStart = startPos + myValue.length;
    355                 myField.selectionEnd = startPos + myValue.length;
    356                 myField.scrollTop = scrollTop;
    357         } else {
    358                 myField.value += myValue;
    359                 myField.focus();
    360         }
    361 }
    362 
    363 function edInsertLink(myField, i, defaultValue) {
    364         if ( 'object' == typeof(wpLink) ) {
    365                 wpLink.open();
    366         } else {
    367                 if (!defaultValue) {
    368                         defaultValue = 'http://';
    369                 }
    370                 if (!edCheckOpenTags(i)) {
    371                         var URL = prompt(quicktagsL10n.enterURL, defaultValue);
    372                         if (URL) {
    373                                 edButtons[i].tagStart = '<a href="' + URL + '">';
    374                                 edInsertTag(myField, i);
    375                         }
    376                 }
    377                 else {
    378                         edInsertTag(myField, i);
    379                 }
    380         }
    381 }
    382 
    383 function edInsertImage(myField) {
    384         var myValue = prompt(quicktagsL10n.enterImageURL, 'http://');
    385         if (myValue) {
    386                 myValue = '<img src="'
    387                                 + myValue
    388                                 + '" alt="' + prompt(quicktagsL10n.enterImageDescription, '')
    389                                 + '" />';
    390                 edInsertContent(myField, myValue);
    391         }
    392 }
    393 
    394 
    395 // Allow multiple instances.
    396 // Name = unique value, id = textarea id, container = container div.
    397 // Can disable some buttons by passing comma delimited string as 4th param.
    398 var QTags = function(name, id, container, disabled) {
    399         var t = this, cont = document.getElementById(container), i, tag, tb, html, sel;
    400 
    401         t.Buttons = [];
    402         t.Links = [];
    403         t.OpenTags = [];
    404         t.Canvas = document.getElementById(id);
    405 
    406         if ( ! t.Canvas || ! cont )
    407                 return;
    408 
    409         disabled = ( typeof disabled != 'undefined' ) ? ','+disabled+',' : '';
    410 
    411         t.edShowButton = function(button, i) {
    412                 if ( disabled && (disabled.indexOf(','+button.display+',') != -1) )
    413                         return '';
    414                 else if ( button.id == name+'_img' )
    415                         return '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="edInsertImage('+name+'.Canvas);" value="' + button.display + '" />';
    416                 else if (button.id == name+'_link')
    417                         return '<input type="button" id="' + button.id + '" accesskey="' + button.access + '" class="ed_button" onclick="'+name+'.edInsertLink('+i+');" value="'+button.display+'" />';
    418                 else
    419                         return '<input type="button" id="' + button.id + '" accesskey="'+button.access+'" class="ed_button" onclick="'+name+'.edInsertTag('+i+');" value="'+button.display+'" />';
    420         };
    421 
    422         t.edAddTag = function(button) {
    423                 if ( t.Buttons[button].tagEnd != '' ) {
    424                         t.OpenTags[t.OpenTags.length] = button;
    425                         document.getElementById(t.Buttons[button].id).value = '/' + document.getElementById(t.Buttons[button].id).value;
    426                 }
    427         };
    428 
    429         t.edRemoveTag = function(button) {
    430                 for ( i = 0; i < t.OpenTags.length; i++ ) {
    431                         if ( t.OpenTags[i] == button ) {
    432                                 t.OpenTags.splice(i, 1);
    433                                 document.getElementById(t.Buttons[button].id).value = document.getElementById(t.Buttons[button].id).value.replace('/', '');
    434                         }
    435                 }
    436         };
    437 
    438         t.edCheckOpenTags = function(button) {
    439                 tag = 0;
    440                 for ( var i = 0; i < t.OpenTags.length; i++ ) {
    441                         if ( t.OpenTags[i] == button )
    442                                 tag++;
    443                 }
    444                 if ( tag > 0 ) return true; // tag found
    445                 else return false; // tag not found
    446         };
    447 
    448         this.edCloseAllTags = function() {
    449                 var count = t.OpenTags.length;
    450                 for ( var o = 0; o < count; o++ )
    451                         t.edInsertTag(t.OpenTags[t.OpenTags.length - 1]);
    452         };
    453 
    454         this.edQuickLink = function(i, thisSelect) {
    455                 if ( i > -1 ) {
    456                         var newWin = '', tempStr;
    457                         if ( Links[i].newWin == 1 ) {
    458                                 newWin = ' target="_blank"';
    459                         }
    460                         tempStr = '<a href="' + Links[i].URL + '"' + newWin + '>'
    461                                     + Links[i].display
    462                                     + '</a>';
    463                         thisSelect.selectedIndex = 0;
    464                         edInsertContent(t.Canvas, tempStr);
    465                 } else {
    466                         thisSelect.selectedIndex = 0;
    467                 }
    468         };
    469 
    470         // insertion code
    471         t.edInsertTag = function(i) {
    472                 //IE support
     351                        if ( t.isOpen(toolbar) !== false || t.tagEnd === '' ) {
     352                                canvas.value += t.tagStart;
     353                                t.openTag(element, toolbar);
     354                        } else {
     355                                canvas.value += t.tagEnd;
     356                                t.closeTag(element, toolbar);
     357                        }
     358                        canvas.focus();
     359                }
     360        };
     361
     362        // the spell button
     363        qt.SpellButton = function() {
     364                qt.Button.call(this, 'spell', quicktagsL10n.lookup, '', quicktagsL10n.dictionaryLookup);
     365        };
     366        qt.SpellButton.prototype = new qt.Button();
     367        qt.SpellButton.prototype.callback = function(element, canvas, toolbar) {
     368                var word = '', sel, startPos, endPos;
     369
    473370                if ( document.selection ) {
    474                         t.Canvas.focus();
    475                     sel = document.selection.createRange();
     371                        canvas.focus();
     372                        sel = document.selection.createRange();
    476373                        if ( sel.text.length > 0 ) {
    477                                 sel.text = t.Buttons[i].tagStart + sel.text + t.Buttons[i].tagEnd;
    478                         } else {
    479                                 if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
    480                                         sel.text = t.Buttons[i].tagStart;
    481                                         t.edAddTag(i);
    482                                 } else {
    483                                         sel.text = t.Buttons[i].tagEnd;
    484                                         t.edRemoveTag(i);
    485                                 }
    486                         }
    487                         t.Canvas.focus();
    488                 } else if ( t.Canvas.selectionStart || t.Canvas.selectionStart == '0' ) { //MOZILLA/NETSCAPE support
    489                         var startPos = t.Canvas.selectionStart, endPos = t.Canvas.selectionEnd, cursorPos = endPos, scrollTop = t.Canvas.scrollTop;
    490 
     374                                word = sel.text;
     375                        }
     376                }
     377                else if ( canvas.selectionStart || canvas.selectionStart == '0' ) {
     378                        startPos = canvas.selectionStart;
     379                        endPos = canvas.selectionEnd;
    491380                        if ( startPos != endPos ) {
    492                                 t.Canvas.value = t.Canvas.value.substring(0, startPos)
    493                                               + t.Buttons[i].tagStart
    494                                               + t.Canvas.value.substring(startPos, endPos)
    495                                               + t.Buttons[i].tagEnd
    496                                               + t.Canvas.value.substring(endPos, t.Canvas.value.length);
    497                                 cursorPos += t.Buttons[i].tagStart.length + t.Buttons[i].tagEnd.length;
    498                         } else {
    499                                 if ( !t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
    500                                         t.Canvas.value = t.Canvas.value.substring(0, startPos)
    501                                                       + t.Buttons[i].tagStart
    502                                                       + t.Canvas.value.substring(endPos, t.Canvas.value.length);
    503                                         t.edAddTag(i);
    504                                         cursorPos = startPos + t.Buttons[i].tagStart.length;
    505                                 } else {
    506                                         t.Canvas.value = t.Canvas.value.substring(0, startPos)
    507                                                       + t.Buttons[i].tagEnd
    508                                                       + t.Canvas.value.substring(endPos, t.Canvas.value.length);
    509                                         t.edRemoveTag(i);
    510                                         cursorPos = startPos + t.Buttons[i].tagEnd.length;
    511                                 }
    512                         }
    513                         t.Canvas.focus();
    514                         t.Canvas.selectionStart = cursorPos;
    515                         t.Canvas.selectionEnd = cursorPos;
    516                         t.Canvas.scrollTop = scrollTop;
    517                 } else {
    518                         if ( ! t.edCheckOpenTags(i) || t.Buttons[i].tagEnd == '' ) {
    519                                 t.Canvas.value += Buttons[i].tagStart;
    520                                 t.edAddTag(i);
    521                         } else {
    522                                 t.Canvas.value += Buttons[i].tagEnd;
    523                                 t.edRemoveTag(i);
    524                         }
    525                         t.Canvas.focus();
    526                 }
    527         };
    528 
    529         this.edInsertLink = function(i, defaultValue) {
     381                                word = canvas.value.substring(startPos, endPos);
     382                        }
     383                }
     384
     385                if ( word === '' ) {
     386                        word = prompt(quicktagsL10n.wordLookup, '');
     387                }
     388
     389                if ( word !== null && /^\w[\w ]*$/.test(word)) {
     390                        window.open('http://www.answers.com/' + encodeURIComponent(word));
     391                }
     392        };
     393
     394        // the close button
     395        qt.CloseButton = function() {
     396                qt.Button.call(this, 'close', quicktagsL10n.closeTags, '', quicktagsL10n.closeAllOpenTags);
     397        };
     398        qt.CloseButton.prototype = new qt.Button();
     399        qt.CloseButton.prototype.callback = function(e, c, tb) {
     400                var button, element, tbo = tb.openTags;
     401                if ( tbo ) {
     402                        while ( tbo.length > 0 ) {
     403                                button = tb.getButton(tbo[tbo.length - 1]);
     404                                element = document.getElementById(tb.name + '_' + button.id);
     405                                button.callback.call(button, element, c, tb);
     406                        }
     407                }
     408        };
     409
     410        qt.prototype.closeAllTags = function() {
     411                var btn = this.getButton('close');
     412                btn.callback.call(btn, '', this.canvas, this.toolbar);
     413        };
     414
     415        // the link button
     416        qt.LinkButton = function() {
     417                qt.TagButton.call(this, 'link', 'link', '', '</a>', 'a');
     418        };
     419        qt.LinkButton.prototype = new qt.TagButton();
     420        qt.LinkButton.prototype.callback = function(e, c, tb, defaultValue) {
     421                var URL, t = this;
     422
     423                if ( typeof(wpLink) != 'undefined' ) {
     424                        wpLink.open();
     425                        return;
     426                }
     427
    530428                if ( ! defaultValue )
    531429                        defaultValue = 'http://';
    532430
    533                 if ( ! t.edCheckOpenTags(i) ) {
    534                         var URL = prompt(quicktagsL10n.enterURL, defaultValue);
     431                if ( t.isOpen(tb) === false ) {
     432                        URL = prompt(quicktagsL10n.enterURL, defaultValue);
    535433                        if ( URL ) {
    536                                 t.Buttons[i].tagStart = '<a href="' + URL + '">';
    537                                 t.edInsertTag(i);
     434                                t.tagStart = '<a href="' + URL + '">';
     435                                qt.TagButton.prototype.callback.call(t, e, c, tb);
    538436                        }
    539437                } else {
    540                         t.edInsertTag(i);
    541                 }
    542         };
    543 
    544         this.edInsertImage = function() {
    545                 var myValue = prompt(quicktagsL10n.enterImageURL, 'http://');
    546                 if ( myValue ) {
    547                         myValue = '<img src="'
    548                                         + myValue
    549                                         + '" alt="' + prompt(quicktagsL10n.enterImageDescription, '')
    550                                         + '" />';
    551                         edInsertContent(t.Canvas, myValue);
    552                 }
    553         };
    554 
    555         t.Buttons[t.Buttons.length] = new edButton(name+'_strong','b','<strong>','</strong>','b');
    556         t.Buttons[t.Buttons.length] = new edButton(name+'_em','i','<em>','</em>','i');
    557         t.Buttons[t.Buttons.length] = new edButton(name+'_link','link','','</a>','a'); // special case
    558         t.Buttons[t.Buttons.length] = new edButton(name+'_block','b-quote','\n\n<blockquote>','</blockquote>\n\n','q');
    559         t.Buttons[t.Buttons.length] = new edButton(name+'_del','del','<del datetime="' + datetime + '">','</del>','d');
    560         t.Buttons[t.Buttons.length] = new edButton(name+'_ins','ins','<ins datetime="' + datetime + '">','</ins>','s');
    561         t.Buttons[t.Buttons.length] = new edButton(name+'_img','img','','','m',-1); // special case
    562         t.Buttons[t.Buttons.length] = new edButton(name+'_ul','ul','<ul>\n','</ul>\n\n','u');
    563         t.Buttons[t.Buttons.length] = new edButton(name+'_ol','ol','<ol>\n','</ol>\n\n','o');
    564         t.Buttons[t.Buttons.length] = new edButton(name+'_li','li','\t<li>','</li>\n','l');
    565         t.Buttons[t.Buttons.length] = new edButton(name+'_code','code','<code>','</code>','c');
    566         t.Buttons[t.Buttons.length] = new edButton(name+'_more','more','<!--more-->','','t',-1);
    567 //      t.Buttons[t.Buttons.length] = new edButton(name+'_next','page','<!--nextpage-->','','p',-1);
    568 
    569         tb = document.createElement('div');
    570         tb.id = name+'_qtags';
    571 
    572         html = '<div id="'+name+'_toolbar">';
    573         for (i = 0; i < t.Buttons.length; i++)
    574                 html += t.edShowButton(t.Buttons[i], i);
    575 
    576         html += '<input type="button" id="'+name+'_ed_spell" class="ed_button" onclick="edSpell('+name+'.Canvas);" title="' + quicktagsL10n.dictionaryLookup + '" value="' + quicktagsL10n.lookup + '" />';
    577         html += '<input type="button" id="'+name+'_ed_close" class="ed_button" onclick="'+name+'.edCloseAllTags();" title="' + quicktagsL10n.closeAllOpenTags + '" value="' + quicktagsL10n.closeTags + '" /></div>';
    578 
    579         tb.innerHTML = html;
    580         cont.parentNode.insertBefore(tb, cont);
    581 
    582 };
     438                        qt.TagButton.prototype.callback.call(t, e, c, tb);
     439                }
     440        };
     441
     442        // the img button
     443        qt.ImgButton = function() {
     444                qt.TagButton.call(this, 'img', 'img', '', '', 'm', -1);
     445        };
     446        qt.ImgButton.prototype = new qt.TagButton();
     447        qt.ImgButton.prototype.callback = function(e, c, tb, defaultValue) {
     448                if ( ! defaultValue ) {
     449                        defaultValue = 'http://';
     450                }
     451                var src = prompt(quicktagsL10n.enterImageURL, defaultValue), alt;
     452                if ( src ) {
     453                        alt = prompt(quicktagsL10n.enterImageDescription, '');
     454                        this.tagStart = '<img src="' + src + '" alt="' + alt + '" />';
     455                        qt.TagButton.prototype.callback.call(this, e, c, tb);
     456                }
     457        };
     458
     459        qt.FullscreenButton = function() {
     460                qt.Button.call(this, 'fullscreen', quicktagsL10n.fullscreen, 'f', quicktagsL10n.toggleFullscreen);
     461        };
     462        qt.FullscreenButton.prototype = new qt.Button();
     463        qt.FullscreenButton.prototype.callback = function(e, c) {
     464                if ( c.id != 'content' || typeof(fullscreen) == 'undefined' )
     465                        return;
     466
     467                fullscreen.on();
     468        };
     469
     470        // ensure backward compatibility
     471        edButtons = [
     472                new qt.TagButton('strong','b','<strong>','</strong>','b'),
     473                new qt.TagButton('em','i','<em>','</em>','i'),
     474                new qt.LinkButton(), // special case
     475                new qt.TagButton('block','b-quote','\n\n<blockquote>','</blockquote>\n\n','q'),
     476                new qt.TagButton('del','del','<del datetime="' + _datetime + '">','</del>','d'),
     477                new qt.TagButton('ins','ins','<ins datetime="' + _datetime + '">','</ins>','s'),
     478                new qt.ImgButton(), // special case
     479                new qt.TagButton('ul','ul','<ul>\n','</ul>\n\n','u'),
     480                new qt.TagButton('ol','ol','<ol>\n','</ol>\n\n','o'),
     481                new qt.TagButton('li','li','\t<li>','</li>\n','l'),
     482                new qt.TagButton('code','code','<code>','</code>','c'),
     483                new qt.TagButton('more','more','<!--more-->','','t',-1),
     484                new qt.SpellButton(),
     485                new qt.CloseButton()
     486        ];
     487
     488        edButton = qt.TagButton;
     489})();
  • trunk/wp-includes/js/quicktags.js

    r17785 r18497  
    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<a){c="0"+c}if(b<0){c="-"+c}return c}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","<strong>","</strong>","b");edButtons[edButtons.length]=new edButton("ed_em","i","<em>","</em>","i");edButtons[edButtons.length]=new edButton("ed_link","link","","</a>","a");edButtons[edButtons.length]=new edButton("ed_block","b-quote","\n\n<blockquote>","</blockquote>\n\n","q");edButtons[edButtons.length]=new edButton("ed_del","del",'<del datetime="'+datetime+'">',"</del>","d");edButtons[edButtons.length]=new edButton("ed_ins","ins",'<ins datetime="'+datetime+'">',"</ins>","s");edButtons[edButtons.length]=new edButton("ed_img","img","","","m",-1);edButtons[edButtons.length]=new edButton("ed_ul","ul","<ul>\n","</ul>\n\n","u");edButtons[edButtons.length]=new edButton("ed_ol","ol","<ol>\n","</ol>\n\n","o");edButtons[edButtons.length]=new edButton("ed_li","li","\t<li>","</li>\n","l");edButtons[edButtons.length]=new edButton("ed_code","code","<code>","</code>","c");edButtons[edButtons.length]=new edButton("ed_more","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('<input type="button" id="'+b.id+'" accesskey="'+b.access+'" class="ed_button" onclick="edInsertImage(edCanvas);" value="'+b.display+'" />')}else{if(b.id=="ed_link"){document.write('<input type="button" id="'+b.id+'" accesskey="'+b.access+'" class="ed_button" onclick="edInsertLink(edCanvas, '+a+');" value="'+b.display+'" />')}else{document.write('<input type="button" id="'+b.id+'" accesskey="'+b.access+'" class="ed_button" onclick="edInsertTag(edCanvas, '+a+');" value="'+b.display+'"  />')}}}function edShowLinks(){var a='<select onchange="edQuickLink(this.options[this.selectedIndex].value, this);"><option value="-1" selected>'+quicktagsL10n.quickLinks+"</option>",b;for(b=0;b<edLinks.length;b++){a+='<option value="'+b+'">'+edLinks[b].display+"</option>"}a+="</select>";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;a<edOpenTags.length;a++){if(edOpenTags[a]==b){edOpenTags.splice(a,1);document.getElementById(edButtons[b].id).value=document.getElementById(edButtons[b].id).value.replace("/","")}}}function edCheckOpenTags(c){var a=0,b;for(b=0;b<edOpenTags.length;b++){if(edOpenTags[b]==c){a++}}if(a>0){return true}else{return false}}function edCloseAllTags(){var a=edOpenTags.length,b;for(b=0;b<a;b++){edInsertTag(edCanvas,edOpenTags[edOpenTags.length-1])}}function edQuickLink(c,d){if(c>-1){var b="",a;if(edLinks[c].newWin==1){b=' target="_blank"'}a='<a href="'+edLinks[c].URL+'"'+b+">"+edLinks[c].display+"</a>";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('<div id="ed_toolbar">');for(var a=0;a<edButtons.length;a++){edShowButton(edButtons[a],a)}document.write('<input type="button" id="ed_spell" class="ed_button" onclick="edSpell(edCanvas);" title="'+quicktagsL10n.dictionaryLookup+'" value="'+quicktagsL10n.lookup+'" />');document.write('<input type="button" id="ed_close" class="ed_button" onclick="edCloseAllTags();" title="'+quicktagsL10n.closeAllOpenTags+'" value="'+quicktagsL10n.closeTags+'" />');document.write('<input type="button" id="ed_fullscreen" class="ed_button" onclick="fullscreen.on();" title="'+quicktagsL10n.toggleFullscreen+'" value="'+quicktagsL10n.fullscreen+'" />');document.write("</div>")}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='<a href="'+a+'">';edInsertTag(d,c)}}else{edInsertTag(d,c)}}}function edInsertImage(b){var a=prompt(quicktagsL10n.enterImageURL,"http://");if(a){a='<img src="'+a+'" alt="'+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'<input type="button" id="'+n.id+'" accesskey="'+n.access+'" class="ed_button" onclick="edInsertImage('+a+'.Canvas);" value="'+n.display+'" />'}else{if(n.id==a+"_link"){return'<input type="button" id="'+n.id+'" accesskey="'+n.access+'" class="ed_button" onclick="'+a+".edInsertLink("+m+');" value="'+n.display+'" />'}else{return'<input type="button" id="'+n.id+'" accesskey="'+n.access+'" class="ed_button" onclick="'+a+".edInsertTag("+m+');" value="'+n.display+'" />'}}}};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;g<j.OpenTags.length;g++){if(j.OpenTags[g]==i){j.OpenTags.splice(g,1);document.getElementById(j.Buttons[i].id).value=document.getElementById(j.Buttons[i].id).value.replace("/","")}}};j.edCheckOpenTags=function(n){l=0;for(var m=0;m<j.OpenTags.length;m++){if(j.OpenTags[m]==n){l++}}if(l>0){return true}else{return false}};this.edCloseAllTags=function(){var i=j.OpenTags.length;for(var m=0;m<i;m++){j.edInsertTag(j.OpenTags[j.OpenTags.length-1])}};this.edQuickLink=function(o,p){if(o>-1){var n="",m;if(Links[o].newWin==1){n=' target="_blank"'}m='<a href="'+Links[o].URL+'"'+n+">"+Links[o].display+"</a>";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='<a href="'+m+'">';j.edInsertTag(o)}}else{j.edInsertTag(o)}};this.edInsertImage=function(){var i=prompt(quicktagsL10n.enterImageURL,"http://");if(i){i='<img src="'+i+'" alt="'+prompt(quicktagsL10n.enterImageDescription,"")+'" />';edInsertContent(j.Canvas,i)}};j.Buttons[j.Buttons.length]=new edButton(a+"_strong","b","<strong>","</strong>","b");j.Buttons[j.Buttons.length]=new edButton(a+"_em","i","<em>","</em>","i");j.Buttons[j.Buttons.length]=new edButton(a+"_link","link","","</a>","a");j.Buttons[j.Buttons.length]=new edButton(a+"_block","b-quote","\n\n<blockquote>","</blockquote>\n\n","q");j.Buttons[j.Buttons.length]=new edButton(a+"_del","del",'<del datetime="'+datetime+'">',"</del>","d");j.Buttons[j.Buttons.length]=new edButton(a+"_ins","ins",'<ins datetime="'+datetime+'">',"</ins>","s");j.Buttons[j.Buttons.length]=new edButton(a+"_img","img","","","m",-1);j.Buttons[j.Buttons.length]=new edButton(a+"_ul","ul","<ul>\n","</ul>\n\n","u");j.Buttons[j.Buttons.length]=new edButton(a+"_ol","ol","<ol>\n","</ol>\n\n","o");j.Buttons[j.Buttons.length]=new edButton(a+"_li","li","\t<li>","</li>\n","l");j.Buttons[j.Buttons.length]=new edButton(a+"_code","code","<code>","</code>","c");j.Buttons[j.Buttons.length]=new edButton(a+"_more","more","<!--more-->","","t",-1);e=document.createElement("div");e.id=a+"_qtags";h='<div id="'+a+'_toolbar">';for(g=0;g<j.Buttons.length;g++){h+=j.edShowButton(j.Buttons[g],g)}h+='<input type="button" id="'+a+'_ed_spell" class="ed_button" onclick="edSpell('+a+'.Canvas);" title="'+quicktagsL10n.dictionaryLookup+'" value="'+quicktagsL10n.lookup+'" />';h+='<input type="button" id="'+a+'_ed_close" class="ed_button" onclick="'+a+'.edCloseAllTags();" title="'+quicktagsL10n.closeAllOpenTags+'" value="'+quicktagsL10n.closeTags+'" /></div>';e.innerHTML=h;k.parentNode.insertBefore(e,k)};
     1var 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<g.funcs.length;f++){g.funcs[f]()}}};if(g.isReady){h()}else{g.funcs.push(h)}if(!g.eventAttached){if(document.addEventListener){e=function(){document.removeEventListener("DOMContentLoaded",e,false);g.ready()};document.addEventListener("DOMContentLoaded",e,false);window.addEventListener("load",g.ready,false)}else{if(document.attachEvent){e=function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",e);g.ready()}};document.attachEvent("onreadystatechange",e);window.attachEvent("onload",g.ready);(function(){try{document.documentElement.doScroll("left")}catch(i){setTimeout(arguments.callee,50);return}g.ready()})()}}g.eventAttached=true}}},a=(function(){var e=new Date(),f;f=function(g){var h=g.toString();if(h.length<2){h="0"+h}return h};return e.getUTCFullYear()+"-"+f(e.getUTCMonth()+1)+"-"+f(e.getUTCDate())+"T"+f(e.getUTCHours())+":"+f(e.getUTCMinutes())+":"+f(e.getUTCSeconds())+"+00:00"})(),b={},d;d=QTags=function(j){if(typeof(j)=="string"){j={quicktags_id:j}}else{if(typeof(j)!="object"){return false}}var r=this,f=j.quicktags_id,p={},o={},h=document.getElementById(f),e="qt_"+f,n="",m,k,l,g,q;if(!f||!h){return false}r.name=e;r.id=f;for(m in edButtons){p[edButtons[m].id]=edButtons[m]}if(f=="content"&&adminpage&&(adminpage=="post-new-php"||adminpage=="post-php")){p.fullscreen=new d.FullscreenButton()}for(m in r._customButtons){p[m]=new r._customButtons[m]()}if(j.quicktags_buttons){l=j.quicktags_buttons.split(",");for(m in l){g=l[m];if(p[g]){o[g]=p[g]}}}else{o=p}if(j.quicktags_disabled_buttons){l=j.quicktags_disabled_buttons.split(",");for(m in l){g=l[m];if(o[g]){delete (o[g])}}}for(m in o){n+=o[m].html(e+"_")}k=document.createElement("div");k.id=e+"_toolbar";k.className="quicktags-toolbar";h.parentNode.insertBefore(k,h);k.innerHTML=n;r.toolbar=k;q=function(u){u=u||window.event;var t=u.target||u.srcElement,s;if(/\s+ed_button\s+/.test(" "+t.className+" ")){r.canvas=h=document.getElementById(f);s=t.id.replace(e+"_","");if(o[s]){o[s].callback.call(o[s],t,h,r)}}};if(k.addEventListener){k.addEventListener("click",q,false)}else{if(k.attachEvent){k.attachEvent("onclick",q)}}d.instances[f]=r};d.instances={};d.registerButton=function(f,e){b[f]=e};d.getInstance=function(e){return d.instances[e]};d.insertContent=function(l,h){var i,g,f,j,k,e=document.getElementById(l);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()}}};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'<input type="button" id="'+f+this.id+'"'+e+' class="ed_button" title="'+this.title+'" value="'+this.display+'" />'};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&&g<e.openTags.length){f=e.openTags[g]==h.id?g:false;g++}}else{f=false}return f};d.TagButton.prototype.callback=function(o,j,q){var u=this,p,f,m,h,s,k,e,n,g;s=j.value;if(document.selection){j.focus();g=document.selection.createRange();if(g.text.length>0){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>","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='<a href="'+f+'">';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='<img src="'+j+'" alt="'+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","<strong>","</strong>","b"),new d.TagButton("em","i","<em>","</em>","i"),new d.LinkButton(),new d.TagButton("block","b-quote","\n\n<blockquote>","</blockquote>\n\n","q"),new d.TagButton("del","del",'<del datetime="'+a+'">',"</del>","d"),new d.TagButton("ins","ins",'<ins datetime="'+a+'">',"</ins>","s"),new d.ImgButton(),new d.TagButton("ul","ul","<ul>\n","</ul>\n\n","u"),new d.TagButton("ol","ol","<ol>\n","</ol>\n\n","o"),new d.TagButton("li","li","\t<li>","</li>\n","l"),new d.TagButton("code","code","<code>","</code>","c"),new d.TagButton("more","more","<!--more-->","","t",-1),new d.SpellButton(),new d.CloseButton()];edButton=d.TagButton})();
  • trunk/wp-includes/script-loader.php

    r18496 r18497  
    6868        $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", false, '1.6.1', 1 );
    6969
    70         $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110502', 1 );
     70        $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", false, '20110802', 1 );
    7171        $scripts->add_script_data( 'quicktags', 'quicktagsL10n', array(
    72                 'quickLinks' => __('(Quick Links)'),
    7372                'wordLookup' => __('Enter a word to look up:'),
    7473                'dictionaryLookup' => esc_attr(__('Dictionary lookup')),
     
    266265                $scripts->add( 'admin-custom-fields', "/wp-admin/js/custom-fields$suffix.js", array('wp-lists'), '20110429', 1 );
    267266
    268                 $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110602', 1 );
     267                $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array('wp-lists', 'jquery-ui-resizable', 'quicktags', 'jquery-query'), '20110802', 1 );
    269268                $scripts->add_script_data( 'admin-comments', 'adminCommentsL10n', array(
    270269                        'hotkeys_highlight_first' => isset($_GET['hotkeys_highlight_first']),
Note: See TracChangeset for help on using the changeset viewer.