set-post-thumbnail.js 876 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * @output wp-admin/js/set-post-thumbnail.js
  3. */
  4. /* global ajaxurl, post_id, alert */
  5. /* exported WPSetAsThumbnail */
  6. window.WPSetAsThumbnail = function( id, nonce ) {
  7. var $link = jQuery('a#wp-post-thumbnail-' + id);
  8. $link.text( wp.i18n.__( 'Saving…' ) );
  9. jQuery.post(ajaxurl, {
  10. action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
  11. }, function(str){
  12. var win = window.dialogArguments || opener || parent || top;
  13. $link.text( wp.i18n.__( 'Use as featured image' ) );
  14. if ( str == '0' ) {
  15. alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
  16. } else {
  17. jQuery('a.wp-post-thumbnail').show();
  18. $link.text( wp.i18n.__( 'Done' ) );
  19. $link.fadeOut( 2000 );
  20. win.WPSetThumbnailID(id);
  21. win.WPSetThumbnailHTML(str);
  22. }
  23. }
  24. );
  25. };