wp/wp-admin/js/post.js
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
   133 	 * @param {string} nonce Nonce to use in the request.
   133 	 * @param {string} nonce Nonce to use in the request.
   134 	 *
   134 	 *
   135 	 * @global
   135 	 * @global
   136 	 */
   136 	 */
   137 	window.WPRemoveThumbnail = function(nonce){
   137 	window.WPRemoveThumbnail = function(nonce){
   138 		$.post(ajaxurl, {
   138 		$.post(
   139 			action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
   139 			ajaxurl, {
   140 		},
   140 				action: 'set-post-thumbnail',
       
   141 				post_id: $( '#post_ID' ).val(),
       
   142 				thumbnail_id: -1,
       
   143 				_ajax_nonce: nonce,
       
   144 				cookie: encodeURIComponent( document.cookie )
       
   145 			},
   141 			/**
   146 			/**
   142 			 * Handle server response
   147 			 * Handle server response
   143 			 *
   148 			 *
   144 			 * @param {string} str Response, will be '0' when an error occurred otherwise contains link to add Featured Image.
   149 			 * @param {string} str Response, will be '0' when an error occurred otherwise contains link to add Featured Image.
   145 			 */
   150 			 */
   146 			function(str){
   151 			function(str){
   147 			if ( str == '0' ) {
   152 				if ( str == '0' ) {
   148 				alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
   153 					alert( __( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
   149 			} else {
   154 				} else {
   150 				WPSetThumbnailHTML(str);
   155 					WPSetThumbnailHTML(str);
   151 			}
   156 				}
   152 		}
   157 			}
   153 		);
   158 		);
   154 	};
   159 	};
   155 
   160 
   156 	/**
   161 	/**
   157 	 * Heartbeat locks.
   162 	 * Heartbeat locks.
   205 							'class': 'avatar avatar-64 photo',
   210 							'class': 'avatar avatar-64 photo',
   206 							width: 64,
   211 							width: 64,
   207 							height: 64,
   212 							height: 64,
   208 							alt: '',
   213 							alt: '',
   209 							src: received.lock_error.avatar_src,
   214 							src: received.lock_error.avatar_src,
   210 							srcset: received.lock_error.avatar_src_2x ? received.lock_error.avatar_src_2x + ' 2x' : undefined
   215 							srcset: received.lock_error.avatar_src_2x ?
       
   216 								received.lock_error.avatar_src_2x + ' 2x' :
       
   217 								undefined
   211 						} );
   218 						} );
   212 						wrap.find('div.post-locked-avatar').empty().append( avatar );
   219 						wrap.find('div.post-locked-avatar').empty().append( avatar );
   213 					}
   220 					}
   214 
   221 
   215 					wrap.show().find('.currently-editing').text( received.lock_error.text );
   222 					wrap.show().find('.currently-editing').text( received.lock_error.text );
   664 			$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' );
   671 			$('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').trigger( 'click' );
   665 			$('#new'+taxonomy).trigger( 'focus' );
   672 			$('#new'+taxonomy).trigger( 'focus' );
   666 		});
   673 		});
   667 
   674 
   668 		// Sync checked items between "All {taxonomy}" and "Most used" lists.
   675 		// Sync checked items between "All {taxonomy}" and "Most used" lists.
   669 		$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
   676 		$('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on(
   670 			var t = $(this), c = t.is(':checked'), id = t.val();
   677 			'click',
   671 			if ( id && t.parents('#taxonomy-'+taxonomy).length )
   678 			'li.popular-category > label input[type="checkbox"]',
   672 				$('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
   679 			function() {
   673 		});
   680 				var t = $(this), c = t.is(':checked'), id = t.val();
       
   681 				if ( id && t.parents('#taxonomy-'+taxonomy).length )
       
   682 					$('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
       
   683 			}
       
   684 		);
   674 
   685 
   675 	}); // End cats.
   686 	}); // End cats.
   676 
   687 
   677 	// Custom Fields postbox.
   688 	// Custom Fields postbox.
   678 	if ( $('#postcustom').length ) {
   689 	if ( $('#postcustom').length ) {
   747 			var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
   758 			var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
   748 				optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
   759 				optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
   749 				mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
   760 				mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
   750 
   761 
   751 			attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
   762 			attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
   752 			originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
   763 			originalDate = new Date(
   753 			currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
   764 				$('#hidden_aa').val(),
       
   765 				$('#hidden_mm').val() -1,
       
   766 				$('#hidden_jj').val(),
       
   767 				$('#hidden_hh').val(),
       
   768 				$('#hidden_mn').val()
       
   769 			);
       
   770 			currentDate = new Date(
       
   771 				$('#cur_aa').val(),
       
   772 				$('#cur_mm').val() -1,
       
   773 				$('#cur_jj').val(),
       
   774 				$('#cur_hh').val(),
       
   775 				$('#cur_mn').val()
       
   776 			);
   754 
   777 
   755 			// Catch unexpected date problems.
   778 			// Catch unexpected date problems.
   756 			if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
   779 			if (
       
   780 				attemptedDate.getFullYear() != aa ||
       
   781 				(1 + attemptedDate.getMonth()) != mm ||
       
   782 				attemptedDate.getDate() != jj ||
       
   783 				attemptedDate.getMinutes() != mn
       
   784 			) {
   757 				$timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
   785 				$timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
   758 				return false;
   786 				return false;
   759 			} else {
   787 			} else {
   760 				$timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
   788 				$timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
   761 			}
   789 			}
   818 				// Remove any potential tags from post status text.
   846 				// Remove any potential tags from post status text.
   819 				wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() )
   847 				wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() )
   820 			);
   848 			);
   821 
   849 
   822 			// Show or hide the "Save Draft" button.
   850 			// Show or hide the "Save Draft" button.
   823 			if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
   851 			if (
       
   852 				$('option:selected', postStatus).val() == 'private' ||
       
   853 				$('option:selected', postStatus).val() == 'publish'
       
   854 			) {
   824 				$('#save-post').hide();
   855 				$('#save-post').hide();
   825 			} else {
   856 			} else {
   826 				$('#save-post').show();
   857 				$('#save-post').show();
   827 				if ( $('option:selected', postStatus).val() == 'pending' ) {
   858 				if ( $('option:selected', postStatus).val() == 'pending' ) {
   828 					$('#save-post').show().val( __( 'Save as Pending' ) );
   859 					$('#save-post').show().val( __( 'Save as Pending' ) );
   970 	 * @global
  1001 	 * @global
   971 	 *
  1002 	 *
   972 	 * @return {void}
  1003 	 * @return {void}
   973 	 */
  1004 	 */
   974 	function editPermalink() {
  1005 	function editPermalink() {
   975 		var i, slug_value,
  1006 		var i, slug_value, slug_label,
   976 			$el, revert_e,
  1007 			$el, revert_e,
   977 			c = 0,
  1008 			c = 0,
   978 			real_slug = $('#post_name'),
  1009 			real_slug = $('#post_name'),
   979 			revert_slug = real_slug.val(),
  1010 			revert_slug = real_slug.val(),
   980 			permalink = $( '#sample-permalink' ),
  1011 			permalink = $( '#sample-permalink' ),
   992 
  1023 
   993 		// Save current content to revert to when cancelling.
  1024 		// Save current content to revert to when cancelling.
   994 		$el = $( '#editable-post-name' );
  1025 		$el = $( '#editable-post-name' );
   995 		revert_e = $el.html();
  1026 		revert_e = $el.html();
   996 
  1027 
   997 		buttons.html( '<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> <button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>' );
  1028 		buttons.html(
       
  1029 			'<button type="button" class="save button button-small">' + __( 'OK' ) + '</button> ' +
       
  1030 			'<button type="button" class="cancel button-link">' + __( 'Cancel' ) + '</button>'
       
  1031 		);
   998 
  1032 
   999 		// Save permalink changes.
  1033 		// Save permalink changes.
  1000 		buttons.children( '.save' ).on( 'click', function() {
  1034 		buttons.children( '.save' ).on( 'click', function() {
  1001 			var new_slug = $el.children( 'input' ).val();
  1035 			var new_slug = $el.children( 'input' ).val();
  1002 
  1036 
  1046 		for ( i = 0; i < full.length; ++i ) {
  1080 		for ( i = 0; i < full.length; ++i ) {
  1047 			if ( '%' == full.charAt(i) )
  1081 			if ( '%' == full.charAt(i) )
  1048 				c++;
  1082 				c++;
  1049 		}
  1083 		}
  1050 		slug_value = ( c > full.length / 4 ) ? '' : full;
  1084 		slug_value = ( c > full.length / 4 ) ? '' : full;
  1051 
  1085 		slug_label = __( 'URL Slug' );
  1052 		$el.html( '<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" />' ).children( 'input' ).on( 'keydown', function( e ) {
  1086 
       
  1087 		$el.html(
       
  1088 			'<label for="new-post-slug" class="screen-reader-text">' + slug_label + '</label>' +
       
  1089 			'<input type="text" id="new-post-slug" value="' + slug_value + '" autocomplete="off" spellcheck="false" />'
       
  1090 		).children( 'input' ).on( 'keydown', function( e ) {
  1053 			var key = e.which;
  1091 			var key = e.which;
  1054 			// On [Enter], just save the new slug, don't save the post.
  1092 			// On [Enter], just save the new slug, don't save the post.
  1055 			if ( 13 === key ) {
  1093 			if ( 13 === key ) {
  1056 				e.preventDefault();
  1094 				e.preventDefault();
  1057 				buttons.children( '.save' ).trigger( 'click' );
  1095 				buttons.children( '.save' ).trigger( 'click' );
  1221 
  1259 
  1222 	// Save on pressing [Ctrl]/[Command] + [S] in the Text editor.
  1260 	// Save on pressing [Ctrl]/[Command] + [S] in the Text editor.
  1223 	$textarea.on( 'keydown.wp-autosave', function( event ) {
  1261 	$textarea.on( 'keydown.wp-autosave', function( event ) {
  1224 		// Key [S] has code 83.
  1262 		// Key [S] has code 83.
  1225 		if ( event.which === 83 ) {
  1263 		if ( event.which === 83 ) {
  1226 			if ( event.shiftKey || event.altKey || ( isMac && ( ! event.metaKey || event.ctrlKey ) ) || ( ! isMac && ! event.ctrlKey ) ) {
  1264 			if (
       
  1265 				event.shiftKey ||
       
  1266 				event.altKey ||
       
  1267 				( isMac && ( ! event.metaKey || event.ctrlKey ) ) ||
       
  1268 				( ! isMac && ! event.ctrlKey )
       
  1269 			) {
  1227 				return;
  1270 				return;
  1228 			}
  1271 			}
  1229 
  1272 
  1230 			wp.autosave && wp.autosave.server.triggerSave();
  1273 			wp.autosave && wp.autosave.server.triggerSave();
  1231 			event.preventDefault();
  1274 			event.preventDefault();