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