home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress2 / wp-admin / js / set-post-thumbnail.js < prev    next >
Encoding:
JavaScript  |  2015-05-31  |  777 b   |  25 lines

  1. /* global setPostThumbnailL10n, ajaxurl, post_id, alert */
  2. /* exported WPSetAsThumbnail */
  3.  
  4. function WPSetAsThumbnail( id, nonce ) {
  5.     var $link = jQuery('a#wp-post-thumbnail-' + id);
  6.  
  7.     $link.text( setPostThumbnailL10n.saving );
  8.     jQuery.post(ajaxurl, {
  9.         action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
  10.     }, function(str){
  11.         var win = window.dialogArguments || opener || parent || top;
  12.         $link.text( setPostThumbnailL10n.setThumbnail );
  13.         if ( str == '0' ) {
  14.             alert( setPostThumbnailL10n.error );
  15.         } else {
  16.             jQuery('a.wp-post-thumbnail').show();
  17.             $link.text( setPostThumbnailL10n.done );
  18.             $link.fadeOut( 2000 );
  19.             win.WPSetThumbnailID(id);
  20.             win.WPSetThumbnailHTML(str);
  21.         }
  22.     }
  23.     );
  24. }
  25.