multi-thumbs.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function MultiPostThumbnailsSetThumbnailHTML(html, id, post_type){
  2. jQuery('.inside', '#' + post_type + '-' + id).html(html);
  3. };
  4. function MultiPostThumbnailsSetThumbnailID(thumb_id, id, post_type){
  5. var field = jQuery('input[value=_' + post_type + '_' + id + '_thumbnail_id]', '#list-table');
  6. if ( field.size() > 0 ) {
  7. jQuery('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(thumb_id);
  8. }
  9. };
  10. function MultiPostThumbnailsRemoveThumbnail(id, post_type, nonce){
  11. jQuery.post(ajaxurl, {
  12. action:'set-' + post_type + '-' + id + '-thumbnail', post_id: jQuery('#post_ID').val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
  13. }, function(str){
  14. if ( str == '0' ) {
  15. alert( setPostThumbnailL10n.error );
  16. } else {
  17. MultiPostThumbnailsSetThumbnailHTML(str, id, post_type);
  18. }
  19. }
  20. );
  21. };
  22. function MultiPostThumbnailsSetAsThumbnail(thumb_id, id, post_type, nonce){
  23. var $link = jQuery('a#' + post_type + '-' + id + '-thumbnail-' + thumb_id);
  24. $link.text( setPostThumbnailL10n.saving );
  25. jQuery.post(ajaxurl, {
  26. action:'set-' + post_type + '-' + id + '-thumbnail', post_id: post_id, thumbnail_id: thumb_id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
  27. }, function(str){
  28. var win = window.dialogArguments || opener || parent || top;
  29. $link.text( setPostThumbnailL10n.setThumbnail );
  30. if ( str == '0' ) {
  31. alert( setPostThumbnailL10n.error );
  32. } else {
  33. $link.show();
  34. $link.text( setPostThumbnailL10n.done );
  35. $link.fadeOut( 2000, function() {
  36. jQuery('tr.' + post_type + '-' + id + '-thumbnail').hide();
  37. });
  38. win.MultiPostThumbnailsSetThumbnailID(thumb_id, id, post_type);
  39. win.MultiPostThumbnailsSetThumbnailHTML(str, id, post_type);
  40. }
  41. }
  42. );
  43. }