web/wp-admin/js/post.dev.js
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
       
     1 var tagBox, commentsBox, editPermalink, makeSlugeditClickable, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail;
       
     2 
     1 // return an array with any duplicate, whitespace or values removed
     3 // return an array with any duplicate, whitespace or values removed
     2 function array_unique_noempty(a) {
     4 function array_unique_noempty(a) {
     3 	var out = [];
     5 	var out = [];
     4 	jQuery.each( a, function(key, val) {
     6 	jQuery.each( a, function(key, val) {
     5 		val = jQuery.trim(val);
     7 		val = jQuery.trim(val);
     7 			out.push(val);
     9 			out.push(val);
     8 		} );
    10 		} );
     9 	return out;
    11 	return out;
    10 }
    12 }
    11 
    13 
    12 function new_tag_remove_tag() {
    14 (function($){
    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 = [];
    15 
    14 	delete current_tags[num];
    16 tagBox = {
    15 
    17 	clean : function(tags) {
    16 	jQuery.each( current_tags, function(key, val) {
    18 		return tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
    17 		val = jQuery.trim(val);
    19 	},
    18 		if ( val ) {
    20 
    19 			new_tags.push(val);
    21 	parseTags : function(el) {
       
    22 		var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'), thetags = taxbox.find('.the-tags'), current_tags = thetags.val().split(','), new_tags = [];
       
    23 		delete current_tags[num];
       
    24 
       
    25 		$.each( current_tags, function(key, val) {
       
    26 			val = $.trim(val);
       
    27 			if ( val ) {
       
    28 				new_tags.push(val);
       
    29 			}
       
    30 		});
       
    31 
       
    32 		thetags.val( this.clean( new_tags.join(',') ) );
       
    33 
       
    34 		this.quickClicks(taxbox);
       
    35 		return false;
       
    36 	},
       
    37 
       
    38 	quickClicks : function(el) {
       
    39 		var thetags = $('.the-tags', el), tagchecklist = $('.tagchecklist', el), current_tags;
       
    40 
       
    41 		if ( !thetags.length )
       
    42 			return;
       
    43 
       
    44 		current_tags = thetags.val().split(',');
       
    45 		tagchecklist.empty();
       
    46 
       
    47 		$.each( current_tags, function( key, val ) {
       
    48 			var txt, button_id, id = $(el).attr('id');
       
    49 
       
    50 			val = $.trim(val);
       
    51 			if ( !val.match(/^\s+$/) && '' != val ) {
       
    52 				button_id = id + '-check-num-' + key;
       
    53 	 			txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
       
    54 	 			tagchecklist.append(txt);
       
    55 	 			$( '#' + button_id ).click( function(){ tagBox.parseTags(this); });
       
    56 			}
       
    57 		});
       
    58 	},
       
    59 
       
    60 	flushTags : function(el, a, f) {
       
    61 		a = a || false;
       
    62 		var text, tags = $('.the-tags', el), newtag = $('input.newtag', el), newtags;
       
    63 
       
    64 		text = a ? $(a).text() : newtag.val();
       
    65 		tagsval = tags.val();
       
    66 		newtags = tagsval ? tagsval + ',' + text : text;
       
    67 
       
    68 		newtags = this.clean( newtags );
       
    69 		newtags = array_unique_noempty( newtags.split(',') ).join(',');
       
    70 		tags.val(newtags);
       
    71 		this.quickClicks(el);
       
    72 
       
    73 		if ( !a )
       
    74 			newtag.val('');
       
    75 		if ( 'undefined' == typeof(f) )
       
    76 			newtag.focus();
       
    77 
       
    78 		return false;
       
    79 	},
       
    80 
       
    81 	get : function(id) {
       
    82 		var tax = id.substr(id.indexOf('-')+1);
       
    83 
       
    84 		$.post(ajaxurl, {'action':'get-tagcloud','tax':tax}, function(r, stat) {
       
    85 			if ( 0 == r || 'success' != stat )
       
    86 				r = wpAjax.broken;
       
    87 
       
    88 			r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
       
    89 			$('a', r).click(function(){
       
    90 				tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
       
    91 				return false;
       
    92 			});
       
    93 
       
    94 			$('#'+id).after(r);
       
    95 		});
       
    96 	},
       
    97 
       
    98 	init : function() {
       
    99 		var t = this, ajaxtag = $('div.ajaxtag');
       
   100 
       
   101 	    $('.tagsdiv').each( function() {
       
   102 	        tagBox.quickClicks(this);
       
   103 	    });
       
   104 
       
   105 		$('input.tagadd', ajaxtag).click(function(){
       
   106 			t.flushTags( $(this).closest('.tagsdiv') );
       
   107 		});
       
   108 
       
   109 		$('div.taghint', ajaxtag).click(function(){
       
   110 			$(this).css('visibility', 'hidden').siblings('.newtag').focus();
       
   111 		});
       
   112 
       
   113 		$('input.newtag', ajaxtag).blur(function() {
       
   114 			if ( this.value == '' )
       
   115 	            $(this).siblings('.taghint').css('visibility', '');
       
   116 	    }).focus(function(){
       
   117 			$(this).siblings('.taghint').css('visibility', 'hidden');
       
   118 		}).keyup(function(e){
       
   119 			if ( 13 == e.which ) {
       
   120 				tagBox.flushTags( $(this).closest('.tagsdiv') );
       
   121 				return false;
       
   122 			}
       
   123 		}).keypress(function(e){
       
   124 			if ( 13 == e.which ) {
       
   125 				e.preventDefault();
       
   126 				return false;
       
   127 			}
       
   128 		}).each(function(){
       
   129 			var tax = $(this).closest('div.tagsdiv').attr('id');
       
   130 			$(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
       
   131 		});
       
   132 
       
   133 	    // save tags on post save/publish
       
   134 	    $('#post').submit(function(){
       
   135 			$('div.tagsdiv').each( function() {
       
   136 	        	tagBox.flushTags(this, false, 1);
       
   137 			});
       
   138 		});
       
   139 
       
   140 		// tag cloud
       
   141 		$('a.tagcloud-link').click(function(){
       
   142 			tagBox.get( $(this).attr('id') );
       
   143 			$(this).unbind().click(function(){
       
   144 				$(this).siblings('.the-tagcloud').toggle();
       
   145 				return false;
       
   146 			});
       
   147 			return false;
       
   148 		});
       
   149 	}
       
   150 };
       
   151 
       
   152 commentsBox = {
       
   153 	st : 0,
       
   154 
       
   155 	get : function(total, num) {
       
   156 		var st = this.st, data;
       
   157 		if ( ! num )
       
   158 			num = 20;
       
   159 
       
   160 		this.st += num;
       
   161 		this.total = total;
       
   162 		$('#commentsdiv img.waiting').show();
       
   163 
       
   164 		data = {
       
   165 			'action' : 'get-comments',
       
   166 			'mode' : 'single',
       
   167 			'_ajax_nonce' : $('#add_comment_nonce').val(),
       
   168 			'post_ID' : $('#post_ID').val(),
       
   169 			'start' : st,
       
   170 			'num' : num
       
   171 		};
       
   172 
       
   173 		$.post(ajaxurl, data,
       
   174 			function(r) {
       
   175 				r = wpAjax.parseAjaxResponse(r);
       
   176 				$('#commentsdiv .widefat').show();
       
   177 				$('#commentsdiv img.waiting').hide();
       
   178 
       
   179 				if ( 'object' == typeof r && r.responses[0] ) {
       
   180 					$('#the-comment-list').append( r.responses[0].data );
       
   181 
       
   182 					theList = theExtraList = null;
       
   183 					$("a[className*=':']").unbind();
       
   184 					setCommentsList();
       
   185 
       
   186 					if ( commentsBox.st > commentsBox.total )
       
   187 						$('#show-comments').hide();
       
   188 					else
       
   189 						$('#show-comments').html(postL10n.showcomm);
       
   190 					return;
       
   191 				} else if ( 1 == r ) {
       
   192 					$('#show-comments').parent().html(postL10n.endcomm);
       
   193 					return;
       
   194 				}
       
   195 
       
   196 				$('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
       
   197 			}
       
   198 		);
       
   199 
       
   200 		return false;
       
   201 	}
       
   202 };
       
   203 
       
   204 WPSetThumbnailHTML = function(html){
       
   205 	$('.inside', '#postimagediv').html(html);
       
   206 };
       
   207 
       
   208 WPSetThumbnailID = function(id){
       
   209 	var field = $('input[value=_thumbnail_id]', '#list-table');
       
   210 	if ( field.size() > 0 ) {
       
   211 		$('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
       
   212 	}
       
   213 };
       
   214 
       
   215 WPRemoveThumbnail = function(){
       
   216 	$.post(ajaxurl, {
       
   217 		action:"set-post-thumbnail", post_id: $('#post_ID').val(), thumbnail_id: -1, cookie: encodeURIComponent(document.cookie)
       
   218 	}, function(str){
       
   219 		if ( str == '0' ) {
       
   220 			alert( setPostThumbnailL10n.error );
       
   221 		} else {
       
   222 			WPSetThumbnailHTML(str);
    20 		}
   223 		}
    21 	});
   224 	}
    22 
   225 	);
    23 	taxbox.find('.the-tags').val( new_tags.join(',').replace(/\s*,+\s*/, ',').replace(/,+/, ',').replace(/,+\s+,+/, ',').replace(/,+\s*$/, '').replace(/^\s*,+/, '') );
   226 };
    24 
   227 
    25 	tag_update_quickclicks(taxbox);
   228 })(jQuery);
    26 	return false;
   229 
    27 }
   230 jQuery(document).ready( function($) {
    28 
   231 	var catAddAfter, stamp, visibility, sticky = '', post = 'post' == pagenow || 'post-new' == pagenow, page = 'page' == pagenow || 'page-new' == pagenow;
    29 function tag_update_quickclicks(taxbox) {
   232 
    30 	if ( jQuery(taxbox).find('.the-tags').length == 0 )
   233 	// postboxes
    31 		return;
   234 	if ( post )
    32 
   235 		postboxes.add_postbox_toggles('post');
    33 	var current_tags = jQuery(taxbox).find('.the-tags').val().split(',');
   236 	else if ( page )
    34 	jQuery(taxbox).find('.tagchecklist').empty();
   237 		postboxes.add_postbox_toggles('page');
    35 	shown = false;
   238 
    36 
   239 	// multi-taxonomies
    37 	jQuery.each( current_tags, function( key, val ) {
   240 	if ( $('#tagsdiv-post_tag').length ) {
    38 		var txt, button_id;
   241 		tagBox.init();
    39 
   242 	} else {
    40 		val = jQuery.trim(val);
   243 		$('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
    41 		if ( !val.match(/^\s+$/) && '' != val ) {
   244 			if ( this.id.indexOf('tagsdiv-') === 0 ) {
    42 			button_id = jQuery(taxbox).attr('id') + '-check-num-' + key;
   245 				tagBox.init();
    43  			txt = '<span><a id="' + button_id + '" class="ntdelbutton">X</a>&nbsp;' + val + '</span> ';
   246 				return false;
    44  			jQuery(taxbox).find('.tagchecklist').append(txt);
   247 			}
    45  			jQuery( '#' + button_id ).click( new_tag_remove_tag );
   248 		});
       
   249 	}
       
   250 
       
   251 	// categories
       
   252 	if ( $('#categorydiv').length ) {
       
   253 		// TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.dev.js
       
   254 		$('a', '#category-tabs').click(function(){
       
   255 			var t = $(this).attr('href');
       
   256 			$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
       
   257 			$('#category-tabs').siblings('.tabs-panel').hide();
       
   258 			$(t).show();
       
   259 			if ( '#categories-all' == t )
       
   260 				deleteUserSetting('cats');
       
   261 			else
       
   262 				setUserSetting('cats','pop');
       
   263 			return false;
       
   264 		});
       
   265 		if ( getUserSetting('cats') )
       
   266 			$('a[href="#categories-pop"]', '#category-tabs').click();
       
   267 
       
   268 		// Ajax Cat
       
   269 		$('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
       
   270 		$('#category-add-sumbit').click( function(){ $('#newcat').focus(); } );
       
   271 
       
   272 		catAddBefore = function( s ) {
       
   273 			if ( !$('#newcat').val() )
       
   274 				return false;
       
   275 			s.data += '&' + $( ':checked', '#categorychecklist' ).serialize();
       
   276 			return s;
       
   277 		};
       
   278 
       
   279 		catAddAfter = function( r, s ) {
       
   280 			var sup, drop = $('#newcat_parent');
       
   281 
       
   282 			if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
       
   283 				drop.before(sup);
       
   284 				drop.remove();
       
   285 			}
       
   286 		};
       
   287 
       
   288 		$('#categorychecklist').wpList({
       
   289 			alt: '',
       
   290 			response: 'category-ajax-response',
       
   291 			addBefore: catAddBefore,
       
   292 			addAfter: catAddAfter
       
   293 		});
       
   294 
       
   295 		$('#category-add-toggle').click( function() {
       
   296 			$('#category-adder').toggleClass( 'wp-hidden-children' );
       
   297 			$('a[href="#categories-all"]', '#category-tabs').click();
       
   298 			return false;
       
   299 		});
       
   300 
       
   301 		$('#categorychecklist').children('li.popular-category').add( $('#categorychecklist-pop').children() ).find(':checkbox').live( 'click', function(){
       
   302 			var t = $(this), c = t.is(':checked'), id = t.val();
       
   303 			$('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
       
   304 		});
       
   305 
       
   306 	} // end cats
       
   307 
       
   308 	// Custom Fields
       
   309 	if ( $('#postcustom').length ) {
       
   310 		$('#the-list').wpList( { addAfter: function( xml, s ) {
       
   311 			$('table#list-table').show();
       
   312 			if ( typeof( autosave_update_post_ID ) != 'undefined' ) {
       
   313 				autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
       
   314 			}
       
   315 		}, addBefore: function( s ) {
       
   316 			s.data += '&post_id=' + $('#post_ID').val();
       
   317 			return s;
    46 		}
   318 		}
    47 	});
   319 		});
    48 	if ( shown )
   320 	}
    49 		jQuery(taxbox).find('.tagchecklist').prepend('<strong>'+postL10n.tagsUsed+'</strong><br />');
   321 
    50 }
   322 	// submitdiv
    51 
   323 	if ( $('#submitdiv').length ) {
    52 function tag_flush_to_text(id, a) {
   324 		stamp = $('#timestamp').html();
    53 	a = a || false;
   325 		visibility = $('#post-visibility-display').html();
    54 	var taxbox, text, tags, newtags;
   326 
    55 
   327 		function updateVisibility() {
    56 	taxbox = jQuery('#'+id);
   328 			var pvSelect = $('#post-visibility-select');
    57 	text = a ? jQuery(a).text() : taxbox.find('input.newtag').val();
   329 			if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
    58 
   330 				$('#sticky').attr('checked', false);
    59 	// is the input box empty (i.e. showing the 'Add new tag' tip)?
   331 				$('#sticky-span').hide();
    60 	if ( taxbox.find('input.newtag').hasClass('form-input-tip') && ! a )
   332 			} else {
    61 		return false;
   333 				$('#sticky-span').show();
    62 
   334 			}
    63 	tags = taxbox.find('.the-tags').val();
   335 			if ( $('input:radio:checked', pvSelect).val() != 'password' ) {
    64 	newtags = tags ? tags + ',' + text : text;
   336 				$('#password-span').hide();
    65 
   337 			} else {
    66 	// massage
   338 				$('#password-span').show();
    67 	newtags = newtags.replace(/\s+,+\s*/g, ',').replace(/,+/g, ',').replace(/,+\s+,+/g, ',').replace(/,+\s*$/g, '').replace(/^\s*,+/g, '');
   339 			}
    68 	newtags = array_unique_noempty(newtags.split(',')).join(',');
   340 		}
    69 	taxbox.find('.the-tags').val(newtags);
   341 
    70 	tag_update_quickclicks(taxbox);
   342 		function updateText() {
    71 
   343 			var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
    72 	if ( ! a )
   344 				optPublish = $('option[value=publish]', postStatus), aa = $('#aa').val(),
    73 		taxbox.find('input.newtag').val('').focus();
   345 				mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
    74 
   346 
    75 	return false;
   347 			attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
    76 }
   348 			originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
    77 
   349 			currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
    78 function tag_save_on_publish() {
   350 
    79 	jQuery('.tagsdiv').each( function(i) {
   351 			if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
    80 		if ( !jQuery(this).find('input.newtag').hasClass('form-input-tip') )
   352 				$('.timestamp-wrap', '#timestampdiv').addClass('form-invalid');
    81         	tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));
   353 				return false;
    82 		} );
   354 			} else {
    83 }
   355 				$('.timestamp-wrap', '#timestampdiv').removeClass('form-invalid');
    84 
   356 			}
    85 function tag_press_key( e ) {
   357 
    86 	if ( 13 == e.which ) {
   358 			if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
    87 		tag_flush_to_text(jQuery(e.target).parents('.tagsdiv').attr('id'));
   359 				publishOn = postL10n.publishOnFuture;
    88 		return false;
   360 				$('#publish').val( postL10n.schedule );
    89 	}
   361 			} else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
    90 };
   362 				publishOn = postL10n.publishOn;
    91 
   363 				$('#publish').val( postL10n.publish );
    92 function tag_init() {
   364 			} else {
    93 
   365 				publishOn = postL10n.publishOnPast;
    94 	jQuery('.ajaxtag').show();
   366 				if ( page )
    95     jQuery('.tagsdiv').each( function(i) {
   367 					$('#publish').val( postL10n.updatePage );
    96         tag_update_quickclicks(this);
   368 				else
    97     } );
   369 					$('#publish').val( postL10n.updatePost );
    98 
   370 			}
    99     // add the quickadd form
   371 			if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
   100     jQuery('.ajaxtag input.tagadd').click(function(){tag_flush_to_text(jQuery(this).parents('.tagsdiv').attr('id'));});
   372 				$('#timestamp').html(stamp);
   101     jQuery('.ajaxtag input.newtag').focus(function() {
   373 			} else {
   102         if ( !this.cleared ) {
   374 				$('#timestamp').html(
   103             this.cleared = true;
   375 					publishOn + ' <b>' +
   104             jQuery(this).val( '' ).removeClass( 'form-input-tip' );
   376 					$('option[value=' + $('#mm').val() + ']', '#mm').text() + ' ' +
   105         }
   377 					jj + ', ' +
   106     });
   378 					aa + ' @ ' +
   107 
   379 					hh + ':' +
   108     jQuery('.ajaxtag input.newtag').blur(function() {
   380 					mn + '</b> '
   109         if ( this.value == '' ) {
   381 				);
   110             this.cleared = false;
   382 			}
   111             jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
   383 
   112         }
   384 			if ( $('input:radio:checked', '#post-visibility-select').val() == 'private' ) {
   113     });
   385 				if ( page )
   114 
   386 					$('#publish').val( postL10n.updatePage );
   115     // auto-save tags on post save/publish
   387 				else
   116     jQuery('#publish').click( tag_save_on_publish );
   388 					$('#publish').val( postL10n.updatePost );
   117     jQuery('#save-post').click( tag_save_on_publish );
   389 				if ( optPublish.length == 0 ) {
   118 
   390 					postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
   119     // catch the enter key
   391 				} else {
   120     jQuery('.ajaxtag input.newtag').keypress( tag_press_key );
   392 					optPublish.html( postL10n.privatelyPublished );
   121 }
   393 				}
   122 
   394 				$('option[value=publish]', postStatus).attr('selected', true);
   123 var commentsBox, tagCloud;
   395 				$('.edit-post-status', '#misc-publishing-actions').hide();
   124 (function($){
   396 			} else {
   125 
   397 				if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
   126 	commentsBox = {
   398 					if ( optPublish.length ) {
   127 		st : 0,
   399 						optPublish.remove();
   128 
   400 						postStatus.val($('#hidden_post_status').val());
   129 		get : function(total, num) {
       
   130 			var st = this.st, data;
       
   131 			if ( ! num )
       
   132 				num = 20;
       
   133 
       
   134 			this.st += num;
       
   135 			this.total = total;
       
   136 			$('#commentsdiv img.waiting').show();
       
   137 
       
   138 			data = {
       
   139 				'action' : 'get-comments',
       
   140 				'mode' : 'single',
       
   141 				'_ajax_nonce' : $('#add_comment_nonce').val(),
       
   142 				'post_ID' : $('#post_ID').val(),
       
   143 				'start' : st,
       
   144 				'num' : num
       
   145 			};
       
   146 
       
   147 			$.post(ajaxurl, data,
       
   148 				function(r) {
       
   149 					r = wpAjax.parseAjaxResponse(r);
       
   150 					$('#commentsdiv .widefat').show();
       
   151 					$('#commentsdiv img.waiting').hide();
       
   152 
       
   153 					if ( 'object' == typeof r && r.responses[0] ) {
       
   154 						$('#the-comment-list').append( r.responses[0].data );
       
   155 
       
   156 						theList = theExtraList = null;
       
   157 						$("a[className*=':']").unbind();
       
   158 						setCommentsList();
       
   159 
       
   160 						if ( commentsBox.st > commentsBox.total )
       
   161 							$('#show-comments').hide();
       
   162 						else
       
   163 							$('#show-comments').html(postL10n.showcomm);
       
   164 						return;
       
   165 					} else if ( 1 == r ) {
       
   166 						$('#show-comments').parent().html(postL10n.endcomm);
       
   167 						return;
       
   168 					}
   401 					}
   169 
   402 				} else {
   170 					$('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
   403 					optPublish.html( postL10n.published );
   171 				}
   404 				}
   172 			);
   405 				if ( postStatus.is(':hidden') )
   173 
   406 					$('.edit-post-status', '#misc-publishing-actions').show();
   174 			return false;
   407 			}
       
   408 			$('#post-status-display').html($('option:selected', postStatus).text());
       
   409 			if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
       
   410 				$('#save-post').hide();
       
   411 			} else {
       
   412 				$('#save-post').show();
       
   413 				if ( $('option:selected', postStatus).val() == 'pending' ) {
       
   414 					$('#save-post').show().val( postL10n.savePending );
       
   415 				} else {
       
   416 					$('#save-post').show().val( postL10n.saveDraft );
       
   417 				}
       
   418 			}
       
   419 			return true;
   175 		}
   420 		}
   176 	};
   421 
   177 
   422 		$('.edit-visibility', '#visibility').click(function () {
   178 	tagCloud = {
   423 			if ($('#post-visibility-select').is(":hidden")) {
   179 		init : function() {
   424 				updateVisibility();
   180 			$('.tagcloud-link').click(function(){
   425 				$('#post-visibility-select').slideDown("normal");
   181 				tagCloud.get($(this).attr('id'));
   426 				$(this).hide();
   182 				$(this).unbind().click(function(){
   427 			}
   183 					$(this).siblings('.the-tagcloud').toggle();
   428 			return false;
       
   429 		});
       
   430 
       
   431 		$('.cancel-post-visibility', '#post-visibility-select').click(function () {
       
   432 			$('#post-visibility-select').slideUp("normal");
       
   433 			$('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
       
   434 			$('#post_password').val($('#hidden_post_password').val());
       
   435 			$('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked'));
       
   436 			$('#post-visibility-display').html(visibility);
       
   437 			$('.edit-visibility', '#visibility').show();
       
   438 			updateText();
       
   439 			return false;
       
   440 		});
       
   441 
       
   442 		$('.save-post-visibility', '#post-visibility-select').click(function () { // crazyhorse - multiple ok cancels
       
   443 			var pvSelect = $('#post-visibility-select');
       
   444 
       
   445 			pvSelect.slideUp("normal");
       
   446 			$('.edit-visibility', '#visibility').show();
       
   447 			updateText();
       
   448 
       
   449 			if ( $('input:radio:checked', pvSelect).val() != 'public' ) {
       
   450 				$('#sticky').attr('checked', false);
       
   451 			}
       
   452 
       
   453 			if ( true == $('#sticky').attr('checked') ) {
       
   454 				sticky = 'Sticky';
       
   455 			} else {
       
   456 				sticky = '';
       
   457 			}
       
   458 
       
   459 			$('#post-visibility-display').html(	postL10n[$('input:radio:checked', pvSelect).val() + sticky]	);
       
   460 			return false;
       
   461 		});
       
   462 
       
   463 		$('input:radio', '#post-visibility-select').change(function() {
       
   464 			updateVisibility();
       
   465 		});
       
   466 
       
   467 		$('#timestampdiv').siblings('a.edit-timestamp').click(function() {
       
   468 			if ($('#timestampdiv').is(":hidden")) {
       
   469 				$('#timestampdiv').slideDown("normal");
       
   470 				$(this).hide();
       
   471 			}
       
   472 			return false;
       
   473 		});
       
   474 
       
   475 		$('.cancel-timestamp', '#timestampdiv').click(function() {
       
   476 			$('#timestampdiv').slideUp("normal");
       
   477 			$('#mm').val($('#hidden_mm').val());
       
   478 			$('#jj').val($('#hidden_jj').val());
       
   479 			$('#aa').val($('#hidden_aa').val());
       
   480 			$('#hh').val($('#hidden_hh').val());
       
   481 			$('#mn').val($('#hidden_mn').val());
       
   482 			$('#timestampdiv').siblings('a.edit-timestamp').show();
       
   483 			updateText();
       
   484 			return false;
       
   485 		});
       
   486 
       
   487 		$('.save-timestamp', '#timestampdiv').click(function () { // crazyhorse - multiple ok cancels
       
   488 			if ( updateText() ) {
       
   489 				$('#timestampdiv').slideUp("normal");
       
   490 				$('#timestampdiv').siblings('a.edit-timestamp').show();
       
   491 			}
       
   492 			return false;
       
   493 		});
       
   494 
       
   495 		$('#post-status-select').siblings('a.edit-post-status').click(function() {
       
   496 			if ($('#post-status-select').is(":hidden")) {
       
   497 				$('#post-status-select').slideDown("normal");
       
   498 				$(this).hide();
       
   499 			}
       
   500 			return false;
       
   501 		});
       
   502 
       
   503 		$('.save-post-status', '#post-status-select').click(function() {
       
   504 			$('#post-status-select').slideUp("normal");
       
   505 			$('#post-status-select').siblings('a.edit-post-status').show();
       
   506 			updateText();
       
   507 			return false;
       
   508 		});
       
   509 
       
   510 		$('.cancel-post-status', '#post-status-select').click(function() {
       
   511 			$('#post-status-select').slideUp("normal");
       
   512 			$('#post_status').val($('#hidden_post_status').val());
       
   513 			$('#post-status-select').siblings('a.edit-post-status').show();
       
   514 			updateText();
       
   515 			return false;
       
   516 		});
       
   517 	} // end submitdiv
       
   518 
       
   519 	// permalink
       
   520 	if ( $('#edit-slug-box').length ) {
       
   521 		editPermalink = function(post_id) {
       
   522 			var i, c = 0, e = $('#editable-post-name'), revert_e = e.html(), real_slug = $('#post_name'), revert_slug = real_slug.html(), b = $('#edit-slug-buttons'), revert_b = b.html(), full = $('#editable-post-name-full').html();
       
   523 
       
   524 			$('#view-post-btn').hide();
       
   525 			b.html('<a href="#" class="save button">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
       
   526 			b.children('.save').click(function() {
       
   527 				var new_slug = e.children('input').val();
       
   528 				$.post(ajaxurl, {
       
   529 					action: 'sample-permalink',
       
   530 					post_id: post_id,
       
   531 					new_slug: new_slug,
       
   532 					new_title: $('#title').val(),
       
   533 					samplepermalinknonce: $('#samplepermalinknonce').val()
       
   534 				}, function(data) {
       
   535 					$('#edit-slug-box').html(data);
       
   536 					b.html(revert_b);
       
   537 					real_slug.attr('value', new_slug);
       
   538 					makeSlugeditClickable();
       
   539 					$('#view-post-btn').show();
       
   540 				});
       
   541 				return false;
       
   542 			});
       
   543 
       
   544 			$('.cancel', '#edit-slug-buttons').click(function() {
       
   545 				$('#view-post-btn').show();
       
   546 				e.html(revert_e);
       
   547 				b.html(revert_b);
       
   548 				real_slug.attr('value', revert_slug);
       
   549 				return false;
       
   550 			});
       
   551 
       
   552 			for ( i = 0; i < full.length; ++i ) {
       
   553 				if ( '%' == full.charAt(i) )
       
   554 					c++;
       
   555 			}
       
   556 
       
   557 			slug_value = ( c > full.length / 4 ) ? '' : full;
       
   558 			e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
       
   559 				var key = e.keyCode || 0;
       
   560 				// on enter, just save the new slug, don't save the post
       
   561 				if ( 13 == key ) {
       
   562 					b.children('.save').click();
   184 					return false;
   563 					return false;
   185 				});
   564 				}
   186 				return false;
   565 				if ( 27 == key ) {
   187 			});
   566 					b.children('.cancel').click();
   188 		},
       
   189 
       
   190 		get : function(id) {
       
   191 			var tax = id.substr(id.indexOf('-')+1);
       
   192 
       
   193 			$.post(ajaxurl, {'action':'get-tagcloud','tax':tax}, function(r, stat) {
       
   194 				if ( 0 == r || 'success' != stat )
       
   195 					r = wpAjax.broken;
       
   196 
       
   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);
       
   201 					return false;
   567 					return false;
   202 				});
   568 				}
   203 
   569 				real_slug.attr('value', this.value);
   204 				$('#'+id).after(r);
   570 			}).focus();
       
   571 		}
       
   572 
       
   573 		makeSlugeditClickable = function() {
       
   574 			$('#editable-post-name').click(function() {
       
   575 				$('#edit-slug-buttons').children('.edit-slug').click();
   205 			});
   576 			});
   206 		}
   577 		}
   207 	};
   578 		makeSlugeditClickable();
   208 
   579 	}
   209 	$(document).ready(function(){tagCloud.init();});
       
   210 })(jQuery);
       
   211 
       
   212 jQuery(document).ready( function($) {
       
   213 	var noSyncChecks = false, syncChecks, catAddAfter, stamp = $('#timestamp').html(), visibility = $('#post-visibility-display').html(), sticky = '';
       
   214 
       
   215 	// postboxes
       
   216 	postboxes.add_postbox_toggles('post');
       
   217 
       
   218 	// Editable slugs
       
   219 	make_slugedit_clickable();
       
   220 
       
   221 	// prepare the tag UI
       
   222 	tag_init();
       
   223 
       
   224 	$('#title').blur( function() {
       
   225 		if ( ($("#post_ID").val() > 0) || ($("#title").val().length == 0) )
       
   226 			return;
       
   227 
       
   228 		if ( typeof(autosave) != 'undefined' )
       
   229 			autosave();
       
   230 	});
       
   231 
       
   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: ", " } );
       
   236 	});
       
   237 
       
   238 	// category tabs
       
   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();
       
   243 		$(t).show();
       
   244 		if ( '#categories-all' == t )
       
   245 			deleteUserSetting('cats');
       
   246 		else
       
   247 			setUserSetting('cats','pop');
       
   248 		return false;
       
   249 	});
       
   250 	if ( getUserSetting('cats') )
       
   251 		$('#category-tabs a[href="#categories-pop"]').click();
       
   252 
       
   253 	// Ajax Cat
       
   254 	$('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ) } );
       
   255 	$('#category-add-sumbit').click(function(){$('#newcat').focus();});
       
   256 
       
   257 	syncChecks = function() {
       
   258 		if ( noSyncChecks )
       
   259 			return;
       
   260 		noSyncChecks = true;
       
   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;
       
   264 	};
       
   265 
       
   266 	popularCats = $('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
       
   267 	catAddBefore = function( s ) {
       
   268 		if ( !$('#newcat').val() )
       
   269 			return false;
       
   270 		s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
       
   271 		return s;
       
   272 	};
       
   273 
       
   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() )
       
   282 					return;
       
   283 				name = $.trim( th.text() );
       
   284 				o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
       
   285 				newCatParent.prepend( o );
       
   286 			} );
       
   287 			newCatParentOption.attr( 'selected', 'selected' );
       
   288 		} );
       
   289 	};
       
   290 
       
   291 	$('#categorychecklist').wpList( {
       
   292 		alt: '',
       
   293 		response: 'category-ajax-response',
       
   294 		addBefore: catAddBefore,
       
   295 		addAfter: catAddAfter
       
   296 	} );
       
   297 
       
   298 	$('#category-add-toggle').click( function() {
       
   299 		$('#category-adder').toggleClass( 'wp-hidden-children' );
       
   300 		$('#category-tabs a[href="#categories-all"]').click();
       
   301 		return false;
       
   302 	} );
       
   303 
       
   304 	$('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change(), sticky = '';
       
   305 
       
   306 	function updateVisibility() {
       
   307 		if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
       
   308 			$('#sticky').attr('checked', false);
       
   309 			$('#sticky-span').hide();
       
   310 		} else {
       
   311 			$('#sticky-span').show();
       
   312 		}
       
   313 		if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
       
   314 			$('#password-span').hide();
       
   315 		} else {
       
   316 			$('#password-span').show();
       
   317 		}
       
   318 	}
       
   319 
       
   320 	function updateText() {
       
   321 		var attemptedDate, originalDate, currentDate, publishOn;
       
   322 
       
   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 );
       
   332 		} else {
       
   333 			publishOn = postL10n.publishOnPast;
       
   334 			$('#publish').val( postL10n.update );
       
   335 		}
       
   336 		if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
       
   337 			$('#timestamp').html(stamp);
       
   338 		} else {
       
   339 			$('#timestamp').html(
       
   340 				publishOn + ' <b>' +
       
   341 				$( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
       
   342 				$('#jj').val() + ', ' +
       
   343 				$('#aa').val() + ' @ ' +
       
   344 				$('#hh').val() + ':' +
       
   345 				$('#mn').val() + '</b> '
       
   346 			);
       
   347 		}
       
   348 
       
   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>');
       
   353 			}
       
   354 			$('#post_status option[value=publish]').html( postL10n.privatelyPublished );
       
   355 			$('#post_status option[value=publish]').attr('selected', true);
       
   356 			$('.edit-post-status').hide();
       
   357 		} else {
       
   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());
       
   362 				}
       
   363 			} else {
       
   364 				$('#post_status option[value=publish]').html( postL10n.published );
       
   365 			}
       
   366 			$('.edit-post-status').show();
       
   367 		}
       
   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();
       
   371 		} else {
       
   372 			$('#save-post').show();
       
   373 			if ( $('#post_status :selected').val() == 'pending' ) {
       
   374 				$('#save-post').show().val( postL10n.savePending );
       
   375 			} else {
       
   376 				$('#save-post').show().val( postL10n.saveDraft );
       
   377 			}
       
   378 		}
       
   379 	}
       
   380 
       
   381 	$('.edit-visibility').click(function () {
       
   382 		if ($('#post-visibility-select').is(":hidden")) {
       
   383 			updateVisibility();
       
   384 			$('#post-visibility-select').slideDown("normal");
       
   385 			$('.edit-visibility').hide();
       
   386 		}
       
   387 		return false;
       
   388 	});
       
   389 
       
   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();
       
   397 		updateText();
       
   398 		return false;
       
   399 	});
       
   400 
       
   401 	$('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
       
   402 		$('#post-visibility-select').slideUp("normal");
       
   403 		$('.edit-visibility').show();
       
   404 		updateText();
       
   405 		if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
       
   406 			$('#sticky').attr('checked', false);
       
   407 		}
       
   408 
       
   409 		if ( true == $('#sticky').attr('checked') ) {
       
   410 			sticky = 'Sticky';
       
   411 		} else {
       
   412 			sticky = '';
       
   413 		}
       
   414 
       
   415 		$('#post-visibility-display').html(
       
   416 			postL10n[$('#post-visibility-select input:radio:checked').val() + sticky]
       
   417 		);
       
   418 
       
   419 		return false;
       
   420 	});
       
   421 
       
   422 	$('#post-visibility-select input:radio').change(function() {
       
   423 		updateVisibility();
       
   424 	});
       
   425 
       
   426 	$('.edit-timestamp').click(function () {
       
   427 		if ($('#timestampdiv').is(":hidden")) {
       
   428 			$('#timestampdiv').slideDown("normal");
       
   429 			$('.edit-timestamp').hide();
       
   430 		}
       
   431 
       
   432 		return false;
       
   433 	});
       
   434 
       
   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();
       
   443 		updateText();
       
   444 		return false;
       
   445 	});
       
   446 
       
   447 	$('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
       
   448 		$('#timestampdiv').slideUp("normal");
       
   449 		$('.edit-timestamp').show();
       
   450 		updateText();
       
   451 
       
   452 		return false;
       
   453 	});
       
   454 
       
   455 	$('.edit-post-status').click(function() {
       
   456 		if ($('#post-status-select').is(":hidden")) {
       
   457 			$('#post-status-select').slideDown("normal");
       
   458 			$(this).hide();
       
   459 		}
       
   460 
       
   461 		return false;
       
   462 	});
       
   463 
       
   464 	$('.save-post-status').click(function() {
       
   465 		$('#post-status-select').slideUp("normal");
       
   466 		$('.edit-post-status').show();
       
   467 		updateText();
       
   468 		return false;
       
   469 	});
       
   470 
       
   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();
       
   475 		updateText();
       
   476 		return false;
       
   477 	});
       
   478 
       
   479 	// Custom Fields
       
   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);
       
   484 		}
       
   485 	}, addBefore: function( s ) {
       
   486 		s.data += '&post_id=' + $('#post_ID').val();
       
   487 		return s;
       
   488 	}
       
   489 	});
       
   490 });
   580 });