1 // return an array with any duplicate, whitespace or values removed
2 function array_unique_noempty(a) {
4 jQuery.each( a, function(key, val) {
5 val = jQuery.trim(val);
6 if ( val && jQuery.inArray(val, out) == -1 )
12 function new_tag_remove_tag() {
13 var id = jQuery( this ).attr( 'id' ), num = id.split('-check-num-')[1], taxbox = jQuery(this).parents('.tagsdiv'), current_tags = taxbox.find( '.the-tags' ).val().split(','), new_tags = [];
14 delete current_tags[num];
16 jQuery.each( current_tags, function(key, val) {
17 val = jQuery.trim(val);
23 taxbox.find('.the-tags').val( new_tags.join(',').replace(/\s*,+\s*/, ',').replace(/,+/, ',').replace(/,+\s+,+/, ',').replace(/,+\s*$/, '').replace(/^\s*,+/, '') );
25 tag_update_quickclicks(taxbox);
29 function tag_update_quickclicks(taxbox) {
30 if ( jQuery(taxbox).find('.the-tags').length == 0 )
33 var current_tags = jQuery(taxbox).find('.the-tags').val().split(',');
34 jQuery(taxbox).find('.tagchecklist').empty();
37 jQuery.each( current_tags, function( key, val ) {
40 val = jQuery.trim(val);
41 if ( !val.match(/^\s+$/) && '' != val ) {
42 button_id = jQuery(taxbox).attr('id') + '-check-num-' + key;
43 txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a> ' + val + '</span> ';
44 jQuery(taxbox).find('.tagchecklist').append(txt);
45 jQuery( '#' + button_id ).click( new_tag_remove_tag );
49 jQuery(taxbox).find('.tagchecklist').prepend('<strong>'+postL10n.tagsUsed+'</strong><br />');
52 function tag_flush_to_text(id, a) {
54 var taxbox, text, tags, newtags;
56 taxbox = jQuery('#'+id);
57 text = a ? jQuery(a).text() : taxbox.find('input.newtag').val();
59 // is the input box empty (i.e. showing the 'Add new tag' tip)?
60 if ( taxbox.find('input.newtag').hasClass('form-input-tip') && ! a )
63 tags = taxbox.find('.the-tags').val();
64 newtags = tags ? tags + ',' + text : text;
67 newtags = newtags.replace(/\s+,+\s*/g, ',').replace(/,+/g, ',').replace(/,+\s+,+/g, ',').replace(/,+\s*$/g, '').replace(/^\s*,+/g, '');
68 newtags = array_unique_noempty(newtags.split(',')).join(',');
69 taxbox.find('.the-tags').val(newtags);
70 tag_update_quickclicks(taxbox);
73 taxbox.find('input.newtag').val('').focus();
78 function tag_save_on_publish() {
79 jQuery('.tagsdiv').each( function(i) {
80 if ( !jQuery(this).find('input.newtag').hasClass('form-input-tip') )
81 tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));
85 function tag_press_key( e ) {
86 if ( 13 == e.which ) {
87 tag_flush_to_text(jQuery(e.target).parents('.tagsdiv').attr('id'));
94 jQuery('.ajaxtag').show();
95 jQuery('.tagsdiv').each( function(i) {
96 tag_update_quickclicks(this);
99 // add the quickadd form
100 jQuery('.ajaxtag input.tagadd').click(function(){tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));});
101 jQuery('.ajaxtag input.newtag').focus(function() {
102 if ( !this.cleared ) {
104 jQuery(this).val( '' ).removeClass( 'form-input-tip' );
108 jQuery('.ajaxtag input.newtag').blur(function() {
109 if ( this.value == '' ) {
110 this.cleared = false;
111 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
115 // auto-save tags on post save/publish
116 jQuery('#publish').click( tag_save_on_publish );
117 jQuery('#save-post').click( tag_save_on_publish );
119 // catch the enter key
120 jQuery('.ajaxtag input.newtag').keypress( tag_press_key );
123 var commentsBox, tagCloud;
129 get : function(total, num) {
130 var st = this.st, data;
136 $('#commentsdiv img.waiting').show();
139 'action' : 'get-comments',
141 '_ajax_nonce' : $('#add_comment_nonce').val(),
142 'post_ID' : $('#post_ID').val(),
147 $.post(ajaxurl, data,
149 r = wpAjax.parseAjaxResponse(r);
150 $('#commentsdiv .widefat').show();
151 $('#commentsdiv img.waiting').hide();
153 if ( 'object' == typeof r && r.responses[0] ) {
154 $('#the-comment-list').append( r.responses[0].data );
156 theList = theExtraList = null;
157 $("a[className*=':']").unbind();
160 if ( commentsBox.st > commentsBox.total )
161 $('#show-comments').hide();
163 $('#show-comments').html(postL10n.showcomm);
165 } else if ( 1 == r ) {
166 $('#show-comments').parent().html(postL10n.endcomm);
170 $('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
180 $('.tagcloud-link').click(function(){
181 tagCloud.get($(this).attr('id'));
182 $(this).unbind().click(function(){
183 $(this).siblings('.the-tagcloud').toggle();
191 var tax = id.substr(id.indexOf('-')+1);
193 $.post(ajaxurl, {'action':'get-tagcloud','tax':tax}, function(r, stat) {
194 if ( 0 == r || 'success' != stat )
197 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
198 $('a', r).click(function(){
199 var id = $(this).parents('p').attr('id');
200 tag_flush_to_text(id.substr(id.indexOf('-')+1), this);
209 $(document).ready(function(){tagCloud.init();});
212 jQuery(document).ready( function($) {
213 var noSyncChecks = false, syncChecks, catAddAfter, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
216 postboxes.add_postbox_toggles('post');
219 make_slugedit_clickable();
221 // prepare the tag UI
224 $('#title').blur( function() {
225 if ( ($("#post_ID").val() > 0) || ($("#title").val().length == 0) )
228 if ( typeof(autosave) != 'undefined' )
232 // auto-suggest stuff
233 $('.newtag').each(function(){
234 var tax = $(this).parents('div.tagsdiv').attr('id');
235 $(this).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
239 $('#category-tabs a').click(function(){
240 var t = $(this).attr('href');
241 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
242 $('.tabs-panel').hide();
244 if ( '#categories-all' == t )
245 deleteUserSetting('cats');
247 setUserSetting('cats','pop');
250 if ( getUserSetting('cats') )
251 $('#category-tabs a[href="#categories-pop"]').click();
254 $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
255 $('#category-add-sumbit').click(function(){$('#newcat').focus();});
257 syncChecks = function() {
261 var th = jQuery(this), c = th.is(':checked'), id = th.val().toString();
262 $('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
263 noSyncChecks = false;
266 popularCats = $('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
267 catAddBefore = function( s ) {
268 if ( !$('#newcat').val() )
270 s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
274 catAddAfter = function( r, s ) {
275 var newCatParent = jQuery('#newcat_parent'), newCatParentOption = newCatParent.find( 'option[value="-1"]' );
276 $(s.what + ' response_data', r).each( function() {
277 var t = $($(this).text());
278 t.find( 'label' ).each( function() {
279 var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name, o;
280 $('#' + id).change( syncChecks ).change();
281 if ( newCatParent.find( 'option[value="' + val + '"]' ).size() )
283 name = $.trim( th.text() );
284 o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
285 newCatParent.prepend( o );
287 newCatParentOption.attr( 'selected', 'selected' );
291 $('#categorychecklist').wpList( {
293 response: 'category-ajax-response',
294 addBefore: catAddBefore,
295 addAfter: catAddAfter
298 $('#category-add-toggle').click( function() {
299 $('#category-adder').toggleClass( 'wp-hidden-children' );
300 $('#category-tabs a[href="#categories-all"]').click();
304 $('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(), sticky = '';
306 function updateVisibility() {
307 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
308 $('#sticky').attr('checked', false);
309 $('#sticky-span').hide();
311 $('#sticky-span').show();
313 if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
314 $('#password-span').hide();
316 $('#password-span').show();
320 function updateText() {
321 var attemptedDate, originalDate, currentDate, publishOn;
323 attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val());
324 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val());
325 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val());
326 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
327 publishOn = postL10n.publishOnFuture;
328 $('#publish').val( postL10n.schedule );
329 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
330 publishOn = postL10n.publishOn;
331 $('#publish').val( postL10n.publish );
333 publishOn = postL10n.publishOnPast;
334 $('#publish').val( postL10n.update );
336 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
337 $('#timestamp').html(stamp);
339 $('#timestamp').html(
341 $( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
342 $('#jj').val() + ', ' +
343 $('#aa').val() + ' @ ' +
344 $('#hh').val() + ':' +
345 $('#mn').val() + '</b> '
349 if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) {
350 $('#publish').val( postL10n.update );
351 if ( $('#post_status option[value=publish]').length == 0 ) {
352 $('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
354 $('#post_status option[value=publish]').html( postL10n.privatelyPublished );
355 $('#post_status option[value=publish]').attr('selected', true);
356 $('.edit-post-status').hide();
358 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
359 if ( $('#post_status option[value=publish]').length != 0 ) {
360 $('#post_status option[value=publish]').remove();
361 $('#post_status').val($('#hidden_post_status').val());
364 $('#post_status option[value=publish]').html( postL10n.published );
366 $('.edit-post-status').show();
368 $('#post-status-display').html($('#post_status :selected').text());
369 if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) {
370 $('#save-post').hide();
372 $('#save-post').show();
373 if ( $('#post_status :selected').val() == 'pending' ) {
374 $('#save-post').show().val( postL10n.savePending );
376 $('#save-post').show().val( postL10n.saveDraft );
381 $('.edit-visibility').click(function () {
382 if ($('#post-visibility-select').is(":hidden")) {
384 $('#post-visibility-select').slideDown("normal");
385 $('.edit-visibility').hide();
390 $('.cancel-post-visibility').click(function () {
391 $('#post-visibility-select').slideUp("normal");
392 $('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
393 $('#post_password').val($('#hidden_post_password').val());
394 $('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked'));
395 $('#post-visibility-display').html(visibility);
396 $('.edit-visibility').show();
401 $('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
402 $('#post-visibility-select').slideUp("normal");
403 $('.edit-visibility').show();
405 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
406 $('#sticky').attr('checked', false);
409 if ( true == $('#sticky').attr('checked') ) {
415 $('#post-visibility-display').html(
416 postL10n[$('#post-visibility-select input:radio:checked').val() + sticky]
422 $('#post-visibility-select input:radio').change(function() {
426 $('.edit-timestamp').click(function () {
427 if ($('#timestampdiv').is(":hidden")) {
428 $('#timestampdiv').slideDown("normal");
429 $('.edit-timestamp').hide();
435 $('.cancel-timestamp').click(function() {
436 $('#timestampdiv').slideUp("normal");
437 $('#mm').val($('#hidden_mm').val());
438 $('#jj').val($('#hidden_jj').val());
439 $('#aa').val($('#hidden_aa').val());
440 $('#hh').val($('#hidden_hh').val());
441 $('#mn').val($('#hidden_mn').val());
442 $('.edit-timestamp').show();
447 $('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
448 $('#timestampdiv').slideUp("normal");
449 $('.edit-timestamp').show();
455 $('.edit-post-status').click(function() {
456 if ($('#post-status-select').is(":hidden")) {
457 $('#post-status-select').slideDown("normal");
464 $('.save-post-status').click(function() {
465 $('#post-status-select').slideUp("normal");
466 $('.edit-post-status').show();
471 $('.cancel-post-status').click(function() {
472 $('#post-status-select').slideUp("normal");
473 $('#post_status').val($('#hidden_post_status').val());
474 $('.edit-post-status').show();
480 $('#the-list').wpList( { addAfter: function( xml, s ) {
481 $('table#list-table').show();
482 if ( typeof( autosave_update_post_ID ) != 'undefined' ) {
483 autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
485 }, addBefore: function( s ) {
486 s.data += '&post_id=' + $('#post_ID').val();