ldc-sbv/wp-admin/js/set-post-thumbnail.js

29 lines
876 B
JavaScript
Raw Normal View History

2021-09-21 15:01:08 +02:00
/**
* @output wp-admin/js/set-post-thumbnail.js
*/
/* global ajaxurl, post_id, alert */
2017-08-08 12:06:05 +02:00
/* exported WPSetAsThumbnail */
2021-09-21 15:01:08 +02:00
window.WPSetAsThumbnail = function( id, nonce ) {
2017-08-08 12:06:05 +02:00
var $link = jQuery('a#wp-post-thumbnail-' + id);
2021-09-21 15:01:08 +02:00
$link.text( wp.i18n.__( 'Saving…' ) );
2017-08-08 12:06:05 +02:00
jQuery.post(ajaxurl, {
action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
}, function(str){
var win = window.dialogArguments || opener || parent || top;
2021-09-21 15:01:08 +02:00
$link.text( wp.i18n.__( 'Use as featured image' ) );
2017-08-08 12:06:05 +02:00
if ( str == '0' ) {
2021-09-21 15:01:08 +02:00
alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
2017-08-08 12:06:05 +02:00
} else {
jQuery('a.wp-post-thumbnail').show();
2021-09-21 15:01:08 +02:00
$link.text( wp.i18n.__( 'Done' ) );
2017-08-08 12:06:05 +02:00
$link.fadeOut( 2000 );
win.WPSetThumbnailID(id);
win.WPSetThumbnailHTML(str);
}
}
);
2021-09-21 15:01:08 +02:00
};