1 var tagBox,commentsBox,editPermalink,makeSlugeditClickable,WPSetThumbnailHTML,WPSetThumbnailID,WPRemoveThumbnail,wptitlehint;function array_unique_noempty(b){var c=[];jQuery.each(b,function(a,d){d=jQuery.trim(d);if(d&&jQuery.inArray(d,c)==-1){c.push(d)}});return c}(function(a){tagBox={clean:function(c){var b=postL10n.comma;if(","!==b){c=c.replace(new RegExp(b,"g"),",")}c=c.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,"");if(","!==b){c=c.replace(/,/g,b)}return c},parseTags:function(f){var i=f.id,c=i.split("-check-num-")[1],e=a(f).closest(".tagsdiv"),h=e.find(".the-tags"),b=postL10n.comma,d=h.val().split(b),g=[];delete d[c];a.each(d,function(j,k){k=a.trim(k);if(k){g.push(k)}});h.val(this.clean(g.join(b)));this.quickClicks(e);return false},quickClicks:function(d){var g=a(".the-tags",d),e=a(".tagchecklist",d),f=a(d).attr("id"),b,c;if(!g.length){return}c=g.prop("disabled");b=g.val().split(postL10n.comma);e.empty();a.each(b,function(i,k){var j,h;k=a.trim(k);if(!k){return}j=a("<span />").text(k);if(!c){h=a('<a id="'+f+"-check-num-"+i+'" class="ntdelbutton">X</a>');h.click(function(){tagBox.parseTags(this)});j.prepend(" ").prepend(h)}e.append(j)})},flushTags:function(g,c,h){c=c||false;var d=a(".the-tags",g),j=a("input.newtag",g),b=postL10n.comma,e,i;i=c?a(c).text():j.val();tagsval=d.val();e=tagsval?tagsval+b+i:i;e=this.clean(e);e=array_unique_noempty(e.split(b)).join(b);d.val(e);this.quickClicks(g);if(!c){j.val("")}if("undefined"==typeof(h)){j.focus()}return false},get:function(c){var b=c.substr(c.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:b},function(e,d){if(0==e||"success"!=d){e=wpAjax.broken}e=a('<p id="tagcloud-'+b+'" class="the-tagcloud">'+e+"</p>");a("a",e).click(function(){tagBox.flushTags(a(this).closest(".inside").children(".tagsdiv"),this);return false});a("#"+c).after(e)})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)});a("input.tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))});a("div.taghint",c).click(function(){a(this).css("visibility","hidden").parent().siblings(".newtag").focus()});a("input.newtag",c).blur(function(){if(this.value==""){a(this).parent().siblings(".taghint").css("visibility","")}}).focus(function(){a(this).parent().siblings(".taghint").css("visibility","hidden")}).keyup(function(d){if(13==d.which){tagBox.flushTags(a(this).closest(".tagsdiv"));return false}}).keypress(function(d){if(13==d.which){d.preventDefault();return false}}).each(function(){var d=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+d,{delay:500,minchars:2,multiple:true,multipleSep:postL10n.comma+" "})});a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,false,1)})});a("a.tagcloud-link").click(function(){tagBox.get(a(this).attr("id"));a(this).unbind().click(function(){a(this).siblings(".the-tagcloud").toggle();return false});return false})}};commentsBox={st:0,get:function(d,c){var b=this.st,e;if(!c){c=20}this.st+=c;this.total=d;a("#commentsdiv img.waiting").show();e={action:"get-comments",mode:"single",_ajax_nonce:a("#add_comment_nonce").val(),p:a("#post_ID").val(),start:b,number:c};a.post(ajaxurl,e,function(f){f=wpAjax.parseAjaxResponse(f);a("#commentsdiv .widefat").show();a("#commentsdiv img.waiting").hide();if("object"==typeof f&&f.responses[0]){a("#the-comment-list").append(f.responses[0].data);theList=theExtraList=null;a("a[className*=':']").unbind();if(commentsBox.st>commentsBox.total){a("#show-comments").hide()}else{a("#show-comments").show().children("a").html(postL10n.showcomm)}return}else{if(1==f){a("#show-comments").html(postL10n.endcomm);return}}a("#the-comment-list").append('<tr><td colspan="2">'+wpAjax.broken+"</td></tr>")});return false}};WPSetThumbnailHTML=function(b){a(".inside","#postimagediv").html(b)};WPSetThumbnailID=function(c){var b=a('input[value="_thumbnail_id"]',"#list-table");if(b.size()>0){a("#meta\\["+b.attr("id").match(/[0-9]+/)+"\\]\\[value\\]").text(c)}};WPRemoveThumbnail=function(b){a.post(ajaxurl,{action:"set-post-thumbnail",post_id:a("#post_ID").val(),thumbnail_id:-1,_ajax_nonce:b,cookie:encodeURIComponent(document.cookie)},function(c){if(c=="0"){alert(setPostThumbnailL10n.error)}else{WPSetThumbnailHTML(c)}})}})(jQuery);jQuery(document).ready(function(f){var b,a,g="",e=0,h=f("#content");postboxes.add_postbox_toggles(pagenow);if(f("#tagsdiv-post_tag").length){tagBox.init()}else{f("#side-sortables, #normal-sortables, #advanced-sortables").children("div.postbox").each(function(){if(this.id.indexOf("tagsdiv-")===0){tagBox.init();return false}})}f(".categorydiv").each(function(){var n=f(this).attr("id"),j=false,m,o,l,i,k;l=n.split("-");l.shift();i=l.join("-");k=i+"_tab";if(i=="category"){k="cats"}f("a","#"+i+"-tabs").click(function(){var p=f(this).attr("href");f(this).parent().addClass("tabs").siblings("li").removeClass("tabs");f("#"+i+"-tabs").siblings(".tabs-panel").hide();f(p).show();if("#"+i+"-all"==p){deleteUserSetting(k)}else{setUserSetting(k,"pop")}return false});if(getUserSetting(k)){f('a[href="#'+i+'-pop"]',"#"+i+"-tabs").click()}f("#new"+i).one("focus",function(){f(this).val("").removeClass("form-input-tip")});f("#"+i+"-add-submit").click(function(){f("#new"+i).focus()});m=function(){if(j){return}j=true;var p=jQuery(this),r=p.is(":checked"),q=p.val().toString();f("#in-"+i+"-"+q+", #in-"+i+"-category-"+q).prop("checked",r);j=false};catAddBefore=function(p){if(!f("#new"+i).val()){return false}p.data+="&"+f(":checked","#"+i+"checklist").serialize();f("#"+i+"-add-submit").prop("disabled",true);return p};o=function(u,t){var q,p=f("#new"+i+"_parent");f("#"+i+"-add-submit").prop("disabled",false);if("undefined"!=t.parsed.responses[0]&&(q=t.parsed.responses[0].supplemental.newcat_parent)){p.before(q);p.remove()}};f("#"+i+"checklist").wpList({alt:"",response:i+"-ajax-response",addBefore:catAddBefore,addAfter:o});f("#"+i+"-add-toggle").click(function(){f("#"+i+"-adder").toggleClass("wp-hidden-children");f('a[href="#'+i+'-all"]',"#"+i+"-tabs").click();f("#new"+i).focus();return false});f("#"+i+'checklist li.popular-category input[type="checkbox"], #'+i+'checklist-pop input[type="checkbox"]').live("click",function(){var p=f(this),r=p.is(":checked"),q=p.val();if(q&&p.parents("#taxonomy-"+i).length){f("#in-"+i+"-"+q+", #in-popular-"+i+"-"+q).prop("checked",r)}})});if(f("#postcustom").length){f("#the-list").wpList({addAfter:function(i,j){f("table#list-table").show()},addBefore:function(i){i.data+="&post_id="+f("#post_ID").val();return i}})}if(f("#submitdiv").length){b=f("#timestamp").html();a=f("#post-visibility-display").html();function d(){var i=f("#post-visibility-select");if(f("input:radio:checked",i).val()!="public"){f("#sticky").prop("checked",false);f("#sticky-span").hide()}else{f("#sticky-span").show()}if(f("input:radio:checked",i).val()!="password"){f("#password-span").hide()}else{f("#password-span").show()}}function c(){var p,q,j,s,r=f("#post_status"),k=f('option[value="publish"]',r),i=f("#aa").val(),n=f("#mm").val(),o=f("#jj").val(),m=f("#hh").val(),l=f("#mn").val();p=new Date(i,n-1,o,m,l);q=new Date(f("#hidden_aa").val(),f("#hidden_mm").val()-1,f("#hidden_jj").val(),f("#hidden_hh").val(),f("#hidden_mn").val());j=new Date(f("#cur_aa").val(),f("#cur_mm").val()-1,f("#cur_jj").val(),f("#cur_hh").val(),f("#cur_mn").val());if(p.getFullYear()!=i||(1+p.getMonth())!=n||p.getDate()!=o||p.getMinutes()!=l){f(".timestamp-wrap","#timestampdiv").addClass("form-invalid");return false}else{f(".timestamp-wrap","#timestampdiv").removeClass("form-invalid")}if(p>j&&f("#original_post_status").val()!="future"){s=postL10n.publishOnFuture;f("#publish").val(postL10n.schedule)}else{if(p<=j&&f("#original_post_status").val()!="publish"){s=postL10n.publishOn;f("#publish").val(postL10n.publish)}else{s=postL10n.publishOnPast;f("#publish").val(postL10n.update)}}if(q.toUTCString()==p.toUTCString()){f("#timestamp").html(b)}else{f("#timestamp").html(s+" <b>"+f('option[value="'+f("#mm").val()+'"]',"#mm").text()+" "+o+", "+i+" @ "+m+":"+l+"</b> ")}if(f("input:radio:checked","#post-visibility-select").val()=="private"){f("#publish").val(postL10n.update);if(k.length==0){r.append('<option value="publish">'+postL10n.privatelyPublished+"</option>")}else{k.html(postL10n.privatelyPublished)}f('option[value="publish"]',r).prop("selected",true);f(".edit-post-status","#misc-publishing-actions").hide()}else{if(f("#original_post_status").val()=="future"||f("#original_post_status").val()=="draft"){if(k.length){k.remove();r.val(f("#hidden_post_status").val())}}else{k.html(postL10n.published)}if(r.is(":hidden")){f(".edit-post-status","#misc-publishing-actions").show()}}f("#post-status-display").html(f("option:selected",r).text());if(f("option:selected",r).val()=="private"||f("option:selected",r).val()=="publish"){f("#save-post").hide()}else{f("#save-post").show();if(f("option:selected",r).val()=="pending"){f("#save-post").show().val(postL10n.savePending)}else{f("#save-post").show().val(postL10n.saveDraft)}}return true}f(".edit-visibility","#visibility").click(function(){if(f("#post-visibility-select").is(":hidden")){d();f("#post-visibility-select").slideDown("fast");f(this).hide()}return false});f(".cancel-post-visibility","#post-visibility-select").click(function(){f("#post-visibility-select").slideUp("fast");f("#visibility-radio-"+f("#hidden-post-visibility").val()).prop("checked",true);f("#post_password").val(f("#hidden_post_password").val());f("#sticky").prop("checked",f("#hidden-post-sticky").prop("checked"));f("#post-visibility-display").html(a);f(".edit-visibility","#visibility").show();c();return false});f(".save-post-visibility","#post-visibility-select").click(function(){var i=f("#post-visibility-select");i.slideUp("fast");f(".edit-visibility","#visibility").show();c();if(f("input:radio:checked",i).val()!="public"){f("#sticky").prop("checked",false)}if(true==f("#sticky").prop("checked")){g="Sticky"}else{g=""}f("#post-visibility-display").html(postL10n[f("input:radio:checked",i).val()+g]);return false});f("input:radio","#post-visibility-select").change(function(){d()});f("#timestampdiv").siblings("a.edit-timestamp").click(function(){if(f("#timestampdiv").is(":hidden")){f("#timestampdiv").slideDown("fast");f(this).hide()}return false});f(".cancel-timestamp","#timestampdiv").click(function(){f("#timestampdiv").slideUp("fast");f("#mm").val(f("#hidden_mm").val());f("#jj").val(f("#hidden_jj").val());f("#aa").val(f("#hidden_aa").val());f("#hh").val(f("#hidden_hh").val());f("#mn").val(f("#hidden_mn").val());f("#timestampdiv").siblings("a.edit-timestamp").show();c();return false});f(".save-timestamp","#timestampdiv").click(function(){if(c()){f("#timestampdiv").slideUp("fast");f("#timestampdiv").siblings("a.edit-timestamp").show()}return false});f("#post-status-select").siblings("a.edit-post-status").click(function(){if(f("#post-status-select").is(":hidden")){f("#post-status-select").slideDown("fast");f(this).hide()}return false});f(".save-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("fast");f("#post-status-select").siblings("a.edit-post-status").show();c();return false});f(".cancel-post-status","#post-status-select").click(function(){f("#post-status-select").slideUp("fast");f("#post_status").val(f("#hidden_post_status").val());f("#post-status-select").siblings("a.edit-post-status").show();c();return false})}if(f("#edit-slug-box").length){editPermalink=function(j){var k,n=0,m=f("#editable-post-name"),o=m.html(),r=f("#post_name"),s=r.val(),p=f("#edit-slug-buttons"),q=p.html(),l=f("#editable-post-name-full").html();f("#view-post-btn").hide();p.html('<a href="#" class="save button">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+"</a>");p.children(".save").click(function(){var i=m.children("input").val();if(i==f("#editable-post-name-full").text()){return f(".cancel","#edit-slug-buttons").click()}f.post(ajaxurl,{action:"sample-permalink",post_id:j,new_slug:i,new_title:f("#title").val(),samplepermalinknonce:f("#samplepermalinknonce").val()},function(t){f("#edit-slug-box").html(t);p.html(q);r.val(i);makeSlugeditClickable();f("#view-post-btn").show()});return false});f(".cancel","#edit-slug-buttons").click(function(){f("#view-post-btn").show();m.html(o);p.html(q);r.val(s);return false});for(k=0;k<l.length;++k){if("%"==l.charAt(k)){n++}}slug_value=(n>l.length/4)?"":l;m.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(t){var i=t.keyCode||0;if(13==i){p.children(".save").click();return false}if(27==i){p.children(".cancel").click();return false}r.val(this.value)}).focus()};makeSlugeditClickable=function(){f("#editable-post-name").click(function(){f("#edit-slug-buttons").children(".edit-slug").click()})};makeSlugeditClickable()}if(typeof(wpWordCount)!="undefined"){f(document).triggerHandler("wpcountwords",[h.val()]);h.keyup(function(j){var i=j.keyCode||j.charCode;if(i==e){return true}if(13==i||8==e||46==e){f(document).triggerHandler("wpcountwords",[h.val()])}e=i;return true})}wptitlehint=function(k){k=k||"title";var i=f("#"+k),j=f("#"+k+"-prompt-text");if(i.val()==""){j.css("visibility","")}j.click(function(){f(this).css("visibility","hidden");i.focus()});i.blur(function(){if(this.value==""){j.css("visibility","")}}).focus(function(){j.css("visibility","hidden")}).keydown(function(l){j.css("visibility","hidden");f(this).unbind(l)})};wptitlehint()}); |
1 var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint; |
|
2 |
|
3 // return an array with any duplicate, whitespace or values removed |
|
4 function array_unique_noempty(a) { |
|
5 var out = []; |
|
6 jQuery.each( a, function(key, val) { |
|
7 val = jQuery.trim(val); |
|
8 if ( val && jQuery.inArray(val, out) == -1 ) |
|
9 out.push(val); |
|
10 } ); |
|
11 return out; |
|
12 } |
|
13 |
|
14 (function($){ |
|
15 |
|
16 tagBox = { |
|
17 clean : function(tags) { |
|
18 var comma = postL10n.comma; |
|
19 if ( ',' !== comma ) |
|
20 tags = tags.replace(new RegExp(comma, 'g'), ','); |
|
21 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, ''); |
|
22 if ( ',' !== comma ) |
|
23 tags = tags.replace(/,/g, comma); |
|
24 return tags; |
|
25 }, |
|
26 |
|
27 parseTags : function(el) { |
|
28 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), |
|
29 thetags = taxbox.find('.the-tags'), comma = postL10n.comma, |
|
30 current_tags = thetags.val().split(comma), new_tags = []; |
|
31 delete current_tags[num]; |
|
32 |
|
33 $.each( current_tags, function(key, val) { |
|
34 val = $.trim(val); |
|
35 if ( val ) { |
|
36 new_tags.push(val); |
|
37 } |
|
38 }); |
|
39 |
|
40 thetags.val( this.clean( new_tags.join(comma) ) ); |
|
41 |
|
42 this.quickClicks(taxbox); |
|
43 return false; |
|
44 }, |
|
45 |
|
46 quickClicks : function(el) { |
|
47 var thetags = $('.the-tags', el), |
|
48 tagchecklist = $('.tagchecklist', el), |
|
49 id = $(el).attr('id'), |
|
50 current_tags, disabled; |
|
51 |
|
52 if ( !thetags.length ) |
|
53 return; |
|
54 |
|
55 disabled = thetags.prop('disabled'); |
|
56 |
|
57 current_tags = thetags.val().split(postL10n.comma); |
|
58 tagchecklist.empty(); |
|
59 |
|
60 $.each( current_tags, function( key, val ) { |
|
61 var span, xbutton; |
|
62 |
|
63 val = $.trim( val ); |
|
64 |
|
65 if ( ! val ) |
|
66 return; |
|
67 |
|
68 // Create a new span, and ensure the text is properly escaped. |
|
69 span = $('<span />').text( val ); |
|
70 |
|
71 // If tags editing isn't disabled, create the X button. |
|
72 if ( ! disabled ) { |
|
73 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' ); |
|
74 xbutton.click( function(){ tagBox.parseTags(this); }); |
|
75 span.prepend(' ').prepend( xbutton ); |
|
76 } |
|
77 |
|
78 // Append the span to the tag list. |
|
79 tagchecklist.append( span ); |
|
80 }); |
|
81 }, |
|
82 |
|
83 flushTags : function(el, a, f) { |
|
84 a = a || false; |
|
85 var tags = $('.the-tags', el), |
|
86 newtag = $('input.newtag', el), |
|
87 comma = postL10n.comma, |
|
88 newtags, text; |
|
89 |
|
90 text = a ? $(a).text() : newtag.val(); |
|
91 tagsval = tags.val(); |
|
92 newtags = tagsval ? tagsval + comma + text : text; |
|
93 |
|
94 newtags = this.clean( newtags ); |
|
95 newtags = array_unique_noempty( newtags.split(comma) ).join(comma); |
|
96 tags.val(newtags); |
|
97 this.quickClicks(el); |
|
98 |
|
99 if ( !a ) |
|
100 newtag.val(''); |
|
101 if ( 'undefined' == typeof(f) ) |
|
102 newtag.focus(); |
|
103 |
|
104 return false; |
|
105 }, |
|
106 |
|
107 get : function(id) { |
|
108 var tax = id.substr(id.indexOf('-')+1); |
|
109 |
|
110 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) { |
|
111 if ( 0 == r || 'success' != stat ) |
|
112 r = wpAjax.broken; |
|
113 |
|
114 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>'); |
|
115 $('a', r).click(function(){ |
|
116 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this); |
|
117 return false; |
|
118 }); |
|
119 |
|
120 $('#'+id).after(r); |
|
121 }); |
|
122 }, |
|
123 |
|
124 init : function() { |
|
125 var t = this, ajaxtag = $('div.ajaxtag'); |
|
126 |
|
127 $('.tagsdiv').each( function() { |
|
128 tagBox.quickClicks(this); |
|
129 }); |
|
130 |
|
131 $('input.tagadd', ajaxtag).click(function(){ |
|
132 t.flushTags( $(this).closest('.tagsdiv') ); |
|
133 }); |
|
134 |
|
135 $('div.taghint', ajaxtag).click(function(){ |
|
136 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus(); |
|
137 }); |
|
138 |
|
139 $('input.newtag', ajaxtag).blur(function() { |
|
140 if ( this.value == '' ) |
|
141 $(this).parent().siblings('.taghint').css('visibility', ''); |
|
142 }).focus(function(){ |
|
143 $(this).parent().siblings('.taghint').css('visibility', 'hidden'); |
|
144 }).keyup(function(e){ |
|
145 if ( 13 == e.which ) { |
|
146 tagBox.flushTags( $(this).closest('.tagsdiv') ); |
|
147 return false; |
|
148 } |
|
149 }).keypress(function(e){ |
|
150 if ( 13 == e.which ) { |
|
151 e.preventDefault(); |
|
152 return false; |
|
153 } |
|
154 }).each(function(){ |
|
155 var tax = $(this).closest('div.tagsdiv').attr('id'); |
|
156 $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } ); |
|
157 }); |
|
158 |
|
159 // save tags on post save/publish |
|
160 $('#post').submit(function(){ |
|
161 $('div.tagsdiv').each( function() { |
|
162 tagBox.flushTags(this, false, 1); |
|
163 }); |
|
164 }); |
|
165 |
|
166 // tag cloud |
|
167 $('a.tagcloud-link').click(function(){ |
|
168 if ( ! $('.the-tagcloud').length ) |
|
169 tagBox.get( $(this).attr('id') ); |
|
170 $(this).siblings('.the-tagcloud').toggle(); |
|
171 return false; |
|
172 }); |
|
173 } |
|
174 }; |
|
175 |
|
176 commentsBox = { |
|
177 st : 0, |
|
178 |
|
179 get : function(total, num) { |
|
180 var st = this.st, data; |
|
181 if ( ! num ) |
|
182 num = 20; |
|
183 |
|
184 this.st += num; |
|
185 this.total = total; |
|
186 $('#commentsdiv .spinner').show(); |
|
187 |
|
188 data = { |
|
189 'action' : 'get-comments', |
|
190 'mode' : 'single', |
|
191 '_ajax_nonce' : $('#add_comment_nonce').val(), |
|
192 'p' : $('#post_ID').val(), |
|
193 'start' : st, |
|
194 'number' : num |
|
195 }; |
|
196 |
|
197 $.post(ajaxurl, data, |
|
198 function(r) { |
|
199 r = wpAjax.parseAjaxResponse(r); |
|
200 $('#commentsdiv .widefat').show(); |
|
201 $('#commentsdiv .spinner').hide(); |
|
202 |
|
203 if ( 'object' == typeof r && r.responses[0] ) { |
|
204 $('#the-comment-list').append( r.responses[0].data ); |
|
205 |
|
206 theList = theExtraList = null; |
|
207 $("a[className*=':']").unbind(); |
|
208 |
|
209 if ( commentsBox.st > commentsBox.total ) |
|
210 $('#show-comments').hide(); |
|
211 else |
|
212 $('#show-comments').show().children('a').html(postL10n.showcomm); |
|
213 |
|
214 return; |
|
215 } else if ( 1 == r ) { |
|
216 $('#show-comments').html(postL10n.endcomm); |
|
217 return; |
|
218 } |
|
219 |
|
220 $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>'); |
|
221 } |
|
222 ); |
|
223 |
|
224 return false; |
|
225 } |
|
226 }; |
|
227 |
|
228 WPSetThumbnailHTML = function(html){ |
|
229 $('.inside', '#postimagediv').html(html); |
|
230 }; |
|
231 |
|
232 WPSetThumbnailID = function(id){ |
|
233 var field = $('input[value="_thumbnail_id"]', '#list-table'); |
|
234 if ( field.size() > 0 ) { |
|
235 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); |
|
236 } |
|
237 }; |
|
238 |
|
239 WPRemoveThumbnail = function(nonce){ |
|
240 $.post(ajaxurl, { |
|
241 action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie) |
|
242 }, function(str){ |
|
243 if ( str == '0' ) { |
|
244 alert( setPostThumbnailL10n.error ); |
|
245 } else { |
|
246 WPSetThumbnailHTML(str); |
|
247 } |
|
248 } |
|
249 ); |
|
250 }; |
|
251 |
|
252 })(jQuery); |
|
253 |
|
254 jQuery(document).ready( function($) { |
|
255 var stamp, visibility, sticky = '', last = 0, co = $('#content'); |
|
256 |
|
257 postboxes.add_postbox_toggles(pagenow); |
|
258 |
|
259 // multi-taxonomies |
|
260 if ( $('#tagsdiv-post_tag').length ) { |
|
261 tagBox.init(); |
|
262 } else { |
|
263 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){ |
|
264 if ( this.id.indexOf('tagsdiv-') === 0 ) { |
|
265 tagBox.init(); |
|
266 return false; |
|
267 } |
|
268 }); |
|
269 } |
|
270 |
|
271 // categories |
|
272 $('.categorydiv').each( function(){ |
|
273 var this_id = $(this).attr('id'), noSyncChecks = false, syncChecks, catAddAfter, taxonomyParts, taxonomy, settingName; |
|
274 |
|
275 taxonomyParts = this_id.split('-'); |
|
276 taxonomyParts.shift(); |
|
277 taxonomy = taxonomyParts.join('-'); |
|
278 settingName = taxonomy + '_tab'; |
|
279 if ( taxonomy == 'category' ) |
|
280 settingName = 'cats'; |
|
281 |
|
282 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js |
|
283 $('a', '#' + taxonomy + '-tabs').click( function(){ |
|
284 var t = $(this).attr('href'); |
|
285 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); |
|
286 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide(); |
|
287 $(t).show(); |
|
288 if ( '#' + taxonomy + '-all' == t ) |
|
289 deleteUserSetting(settingName); |
|
290 else |
|
291 setUserSetting(settingName, 'pop'); |
|
292 return false; |
|
293 }); |
|
294 |
|
295 if ( getUserSetting(settingName) ) |
|
296 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click(); |
|
297 |
|
298 // Ajax Cat |
|
299 $('#new' + taxonomy).one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } ); |
|
300 |
|
301 $('#new' + taxonomy).keypress( function(event){ |
|
302 if( 13 === event.keyCode ) { |
|
303 event.preventDefault(); |
|
304 $('#' + taxonomy + '-add-submit').click(); |
|
305 } |
|
306 }); |
|
307 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); }); |
|
308 |
|
309 syncChecks = function() { |
|
310 if ( noSyncChecks ) |
|
311 return; |
|
312 noSyncChecks = true; |
|
313 var th = jQuery(this), c = th.is(':checked'), id = th.val().toString(); |
|
314 $('#in-' + taxonomy + '-' + id + ', #in-' + taxonomy + '-category-' + id).prop( 'checked', c ); |
|
315 noSyncChecks = false; |
|
316 }; |
|
317 |
|
318 catAddBefore = function( s ) { |
|
319 if ( !$('#new'+taxonomy).val() ) |
|
320 return false; |
|
321 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize(); |
|
322 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true ); |
|
323 return s; |
|
324 }; |
|
325 |
|
326 catAddAfter = function( r, s ) { |
|
327 var sup, drop = $('#new'+taxonomy+'_parent'); |
|
328 |
|
329 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false ); |
|
330 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) { |
|
331 drop.before(sup); |
|
332 drop.remove(); |
|
333 } |
|
334 }; |
|
335 |
|
336 $('#' + taxonomy + 'checklist').wpList({ |
|
337 alt: '', |
|
338 response: taxonomy + '-ajax-response', |
|
339 addBefore: catAddBefore, |
|
340 addAfter: catAddAfter |
|
341 }); |
|
342 |
|
343 $('#' + taxonomy + '-add-toggle').click( function() { |
|
344 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' ); |
|
345 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click(); |
|
346 $('#new'+taxonomy).focus(); |
|
347 return false; |
|
348 }); |
|
349 |
|
350 $('#' + taxonomy + 'checklist li.popular-category input[type="checkbox"], #' + taxonomy + 'checklist-pop input[type="checkbox"]').live( 'click', function(){ |
|
351 var t = $(this), c = t.is(':checked'), id = t.val(); |
|
352 if ( id && t.parents('#taxonomy-'+taxonomy).length ) |
|
353 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c ); |
|
354 }); |
|
355 |
|
356 }); // end cats |
|
357 |
|
358 // Custom Fields |
|
359 if ( $('#postcustom').length ) { |
|
360 $('#the-list').wpList( { addAfter: function( xml, s ) { |
|
361 $('table#list-table').show(); |
|
362 }, addBefore: function( s ) { |
|
363 s.data += '&post_id=' + $('#post_ID').val(); |
|
364 return s; |
|
365 } |
|
366 }); |
|
367 } |
|
368 |
|
369 // submitdiv |
|
370 if ( $('#submitdiv').length ) { |
|
371 stamp = $('#timestamp').html(); |
|
372 visibility = $('#post-visibility-display').html(); |
|
373 |
|
374 function updateVisibility() { |
|
375 var pvSelect = $('#post-visibility-select'); |
|
376 if ( $('input:radio:checked', pvSelect).val() != 'public' ) { |
|
377 $('#sticky').prop('checked', false); |
|
378 $('#sticky-span').hide(); |
|
379 } else { |
|
380 $('#sticky-span').show(); |
|
381 } |
|
382 if ( $('input:radio:checked', pvSelect).val() != 'password' ) { |
|
383 $('#password-span').hide(); |
|
384 } else { |
|
385 $('#password-span').show(); |
|
386 } |
|
387 } |
|
388 |
|
389 function updateText() { |
|
390 |
|
391 if ( ! $('#timestampdiv').length ) |
|
392 return true; |
|
393 |
|
394 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'), |
|
395 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(), |
|
396 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(); |
|
397 |
|
398 attemptedDate = new Date( aa, mm - 1, jj, hh, mn ); |
|
399 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() ); |
|
400 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() ); |
|
401 |
|
402 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) { |
|
403 $('.timestamp-wrap', '#timestampdiv').addClass('form-invalid'); |
|
404 return false; |
|
405 } else { |
|
406 $('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid'); |
|
407 } |
|
408 |
|
409 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) { |
|
410 publishOn = postL10n.publishOnFuture; |
|
411 $('#publish').val( postL10n.schedule ); |
|
412 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) { |
|
413 publishOn = postL10n.publishOn; |
|
414 $('#publish').val( postL10n.publish ); |
|
415 } else { |
|
416 publishOn = postL10n.publishOnPast; |
|
417 $('#publish').val( postL10n.update ); |
|
418 } |
|
419 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack |
|
420 $('#timestamp').html(stamp); |
|
421 } else { |
|
422 $('#timestamp').html( |
|
423 publishOn + ' <b>' + |
|
424 $('option[value="' + $('#mm').val() + '"]', '#mm').text() + ' ' + |
|
425 jj + ', ' + |
|
426 aa + ' @ ' + |
|
427 hh + ':' + |
|
428 mn + '</b> ' |
|
429 ); |
|
430 } |
|
431 |
|
432 if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) { |
|
433 $('#publish').val( postL10n.update ); |
|
434 if ( optPublish.length == 0 ) { |
|
435 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>'); |
|
436 } else { |
|
437 optPublish.html( postL10n.privatelyPublished ); |
|
438 } |
|
439 $('option[value="publish"]', postStatus).prop('selected', true); |
|
440 $('.edit-post-status', '#misc-publishing-actions').hide(); |
|
441 } else { |
|
442 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) { |
|
443 if ( optPublish.length ) { |
|
444 optPublish.remove(); |
|
445 postStatus.val($('#hidden_post_status').val()); |
|
446 } |
|
447 } else { |
|
448 optPublish.html( postL10n.published ); |
|
449 } |
|
450 if ( postStatus.is(':hidden') ) |
|
451 $('.edit-post-status', '#misc-publishing-actions').show(); |
|
452 } |
|
453 $('#post-status-display').html($('option:selected', postStatus).text()); |
|
454 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { |
|
455 $('#save-post').hide(); |
|
456 } else { |
|
457 $('#save-post').show(); |
|
458 if ( $('option:selected', postStatus).val() == 'pending' ) { |
|
459 $('#save-post').show().val( postL10n.savePending ); |
|
460 } else { |
|
461 $('#save-post').show().val( postL10n.saveDraft ); |
|
462 } |
|
463 } |
|
464 return true; |
|
465 } |
|
466 |
|
467 $('.edit-visibility', '#visibility').click(function () { |
|
468 if ($('#post-visibility-select').is(":hidden")) { |
|
469 updateVisibility(); |
|
470 $('#post-visibility-select').slideDown('fast'); |
|
471 $(this).hide(); |
|
472 } |
|
473 return false; |
|
474 }); |
|
475 |
|
476 $('.cancel-post-visibility', '#post-visibility-select').click(function () { |
|
477 $('#post-visibility-select').slideUp('fast'); |
|
478 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true); |
|
479 $('#post_password').val($('#hidden_post_password').val()); |
|
480 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked')); |
|
481 $('#post-visibility-display').html(visibility); |
|
482 $('.edit-visibility', '#visibility').show(); |
|
483 updateText(); |
|
484 return false; |
|
485 }); |
|
486 |
|
487 $('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels |
|
488 var pvSelect = $('#post-visibility-select'); |
|
489 |
|
490 pvSelect.slideUp('fast'); |
|
491 $('.edit-visibility', '#visibility').show(); |
|
492 updateText(); |
|
493 |
|
494 if ( $('input:radio:checked', pvSelect).val() != 'public' ) { |
|
495 $('#sticky').prop('checked', false); |
|
496 } // WEAPON LOCKED |
|
497 |
|
498 if ( true == $('#sticky').prop('checked') ) { |
|
499 sticky = 'Sticky'; |
|
500 } else { |
|
501 sticky = ''; |
|
502 } |
|
503 |
|
504 $('#post-visibility-display').html( postL10n[$('input:radio:checked', pvSelect).val() + sticky] ); |
|
505 return false; |
|
506 }); |
|
507 |
|
508 $('input:radio', '#post-visibility-select').change(function() { |
|
509 updateVisibility(); |
|
510 }); |
|
511 |
|
512 $('#timestampdiv').siblings('a.edit-timestamp').click(function() { |
|
513 if ($('#timestampdiv').is(":hidden")) { |
|
514 $('#timestampdiv').slideDown('fast'); |
|
515 $('#mm').focus(); |
|
516 $(this).hide(); |
|
517 } |
|
518 return false; |
|
519 }); |
|
520 |
|
521 $('.cancel-timestamp', '#timestampdiv').click(function() { |
|
522 $('#timestampdiv').slideUp('fast'); |
|
523 $('#mm').val($('#hidden_mm').val()); |
|
524 $('#jj').val($('#hidden_jj').val()); |
|
525 $('#aa').val($('#hidden_aa').val()); |
|
526 $('#hh').val($('#hidden_hh').val()); |
|
527 $('#mn').val($('#hidden_mn').val()); |
|
528 $('#timestampdiv').siblings('a.edit-timestamp').show(); |
|
529 updateText(); |
|
530 return false; |
|
531 }); |
|
532 |
|
533 $('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels |
|
534 if ( updateText() ) { |
|
535 $('#timestampdiv').slideUp('fast'); |
|
536 $('#timestampdiv').siblings('a.edit-timestamp').show(); |
|
537 } |
|
538 return false; |
|
539 }); |
|
540 |
|
541 $('#post').on( 'submit', function(e){ |
|
542 if ( ! updateText() ) { |
|
543 e.preventDefault(); |
|
544 $('#timestampdiv').show(); |
|
545 $('#publishing-action .spinner').hide(); |
|
546 $('#publish').prop('disabled', false).removeClass('button-primary-disabled'); |
|
547 return false; |
|
548 } |
|
549 }); |
|
550 |
|
551 $('#post-status-select').siblings('a.edit-post-status').click(function() { |
|
552 if ($('#post-status-select').is(":hidden")) { |
|
553 $('#post-status-select').slideDown('fast'); |
|
554 $(this).hide(); |
|
555 } |
|
556 return false; |
|
557 }); |
|
558 |
|
559 $('.save-post-status', '#post-status-select').click(function() { |
|
560 $('#post-status-select').slideUp('fast'); |
|
561 $('#post-status-select').siblings('a.edit-post-status').show(); |
|
562 updateText(); |
|
563 return false; |
|
564 }); |
|
565 |
|
566 $('.cancel-post-status', '#post-status-select').click(function() { |
|
567 $('#post-status-select').slideUp('fast'); |
|
568 $('#post_status').val($('#hidden_post_status').val()); |
|
569 $('#post-status-select').siblings('a.edit-post-status').show(); |
|
570 updateText(); |
|
571 return false; |
|
572 }); |
|
573 } // end submitdiv |
|
574 |
|
575 // permalink |
|
576 if ( $('#edit-slug-box').length ) { |
|
577 editPermalink = function(post_id) { |
|
578 var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.val(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html(); |
|
579 |
|
580 $('#view-post-btn').hide(); |
|
581 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>'); |
|
582 b.children('.save').click(function() { |
|
583 var new_slug = e.children('input').val(); |
|
584 if ( new_slug == $('#editable-post-name-full').text() ) { |
|
585 return $('.cancel', '#edit-slug-buttons').click(); |
|
586 } |
|
587 $.post(ajaxurl, { |
|
588 action: 'sample-permalink', |
|
589 post_id: post_id, |
|
590 new_slug: new_slug, |
|
591 new_title: $('#title').val(), |
|
592 samplepermalinknonce: $('#samplepermalinknonce').val() |
|
593 }, function(data) { |
|
594 $('#edit-slug-box').html(data); |
|
595 b.html(revert_b); |
|
596 real_slug.val(new_slug); |
|
597 makeSlugeditClickable(); |
|
598 $('#view-post-btn').show(); |
|
599 }); |
|
600 return false; |
|
601 }); |
|
602 |
|
603 $('.cancel', '#edit-slug-buttons').click(function() { |
|
604 $('#view-post-btn').show(); |
|
605 e.html(revert_e); |
|
606 b.html(revert_b); |
|
607 real_slug.val(revert_slug); |
|
608 return false; |
|
609 }); |
|
610 |
|
611 for ( i = 0; i < full.length; ++i ) { |
|
612 if ( '%' == full.charAt(i) ) |
|
613 c++; |
|
614 } |
|
615 |
|
616 slug_value = ( c > full.length / 4 ) ? '' : full; |
|
617 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){ |
|
618 var key = e.keyCode || 0; |
|
619 // on enter, just save the new slug, don't save the post |
|
620 if ( 13 == key ) { |
|
621 b.children('.save').click(); |
|
622 return false; |
|
623 } |
|
624 if ( 27 == key ) { |
|
625 b.children('.cancel').click(); |
|
626 return false; |
|
627 } |
|
628 real_slug.val(this.value); |
|
629 }).focus(); |
|
630 } |
|
631 |
|
632 makeSlugeditClickable = function() { |
|
633 $('#editable-post-name').click(function() { |
|
634 $('#edit-slug-buttons').children('.edit-slug').click(); |
|
635 }); |
|
636 } |
|
637 makeSlugeditClickable(); |
|
638 } |
|
639 |
|
640 // word count |
|
641 if ( typeof(wpWordCount) != 'undefined' ) { |
|
642 $(document).triggerHandler('wpcountwords', [ co.val() ]); |
|
643 |
|
644 co.keyup( function(e) { |
|
645 var k = e.keyCode || e.charCode; |
|
646 |
|
647 if ( k == last ) |
|
648 return true; |
|
649 |
|
650 if ( 13 == k || 8 == last || 46 == last ) |
|
651 $(document).triggerHandler('wpcountwords', [ co.val() ]); |
|
652 |
|
653 last = k; |
|
654 return true; |
|
655 }); |
|
656 } |
|
657 |
|
658 wptitlehint = function(id) { |
|
659 id = id || 'title'; |
|
660 |
|
661 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text'); |
|
662 |
|
663 if ( title.val() == '' ) |
|
664 titleprompt.removeClass('screen-reader-text'); |
|
665 |
|
666 titleprompt.click(function(){ |
|
667 $(this).addClass('screen-reader-text'); |
|
668 title.focus(); |
|
669 }); |
|
670 |
|
671 title.blur(function(){ |
|
672 if ( this.value == '' ) |
|
673 titleprompt.removeClass('screen-reader-text'); |
|
674 }).focus(function(){ |
|
675 titleprompt.addClass('screen-reader-text'); |
|
676 }).keydown(function(e){ |
|
677 titleprompt.addClass('screen-reader-text'); |
|
678 $(this).unbind(e); |
|
679 }); |
|
680 } |
|
681 |
|
682 wptitlehint(); |
|
683 |
|
684 // resizable textarea#content |
|
685 (function() { |
|
686 var textarea = $('textarea#content'), offset = null, el; |
|
687 // No point for touch devices |
|
688 if ( 'ontouchstart' in window ) |
|
689 return; |
|
690 |
|
691 function dragging(e) { |
|
692 textarea.height( Math.max(50, offset + e.pageY) + 'px' ); |
|
693 return false; |
|
694 } |
|
695 |
|
696 function endDrag(e) { |
|
697 var height = $('#wp-content-editor-container').height(); |
|
698 |
|
699 textarea.focus(); |
|
700 $(document).unbind('mousemove', dragging).unbind('mouseup', endDrag); |
|
701 |
|
702 height -= 33; // compensate for toolbars, padding... |
|
703 // sanity check |
|
704 if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) ) |
|
705 setUserSetting( 'ed_size', height ); |
|
706 } |
|
707 |
|
708 textarea.css('resize', 'none'); |
|
709 el = $('<div id="content-resize-handle"><br></div>'); |
|
710 $('#wp-content-wrap').append(el); |
|
711 el.on('mousedown', function(e) { |
|
712 offset = textarea.height() - e.pageY; |
|
713 textarea.blur(); |
|
714 $(document).mousemove(dragging).mouseup(endDrag); |
|
715 return false; |
|
716 }); |
|
717 })(); |
|
718 |
|
719 if ( typeof(tinymce) != 'undefined' ) { |
|
720 tinymce.onAddEditor.add(function(mce, ed){ |
|
721 // iOS expands the iframe to full height and the user cannot adjust it. |
|
722 if ( ed.id != 'content' || tinymce.isIOS5 ) |
|
723 return; |
|
724 |
|
725 // resize TinyMCE to match the textarea height when switching Text -> Visual |
|
726 ed.onLoadContent.add( function(ed, o) { |
|
727 var ifr_height, height = parseInt( $('#content').css('height'), 10 ), |
|
728 tb_height = $('#content_tbl tr.mceFirst').height(); |
|
729 |
|
730 if ( height && !isNaN(height) && tb_height ) { |
|
731 ifr_height = (height - tb_height) + 12; // compensate for padding in the textarea |
|
732 // sanity check |
|
733 if ( ifr_height > 50 && ifr_height < 5000 ) { |
|
734 $('#content_tbl').css('height', '' ); |
|
735 $('#content_ifr').css('height', ifr_height + 'px' ); |
|
736 } |
|
737 } |
|
738 }); |
|
739 |
|
740 // resize the textarea to match TinyMCE's height when switching Visual -> Text |
|
741 ed.onSaveContent.add( function(ed, o) { |
|
742 var height = $('#content_tbl').height(); |
|
743 |
|
744 if ( height && height > 83 && height < 5000 ) { |
|
745 height -= 33; |
|
746 |
|
747 $('#content').css( 'height', height + 'px' ); |
|
748 } |
|
749 }); |
|
750 |
|
751 // save on resizing TinyMCE |
|
752 ed.onPostRender.add(function() { |
|
753 $('#content_resize').on('mousedown.wp-mce-resize', function(e){ |
|
754 $(document).on('mouseup.wp-mce-resize', function(e){ |
|
755 var height = $('#wp-content-editor-container').height(); |
|
756 |
|
757 height -= 33; |
|
758 // sanity check |
|
759 if ( height > 50 && height < 5000 && height != getUserSetting( 'ed_size' ) ) |
|
760 setUserSetting( 'ed_size', height ); |
|
761 |
|
762 $(document).off('mouseup.wp-mce-resize'); |
|
763 }); |
|
764 }); |
|
765 }); |
|
766 }); |
|
767 } |
|
768 }); |