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