Guest User

Untitled

a guest
Jul 10th, 2013
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if ($('#menu-to-edit')) {
  2.             var file2_frame = wp.media.featuredImage.frame();
  3.         }
  4.         $('#menu-to-edit').delegate('.set-post-thumbnail', 'click', function( event ) {
  5.             var obj = '';
  6.             event.preventDefault();
  7.             event.stopPropagation();
  8.             var obj = $(this);
  9.             console.log(obj);
  10.  
  11.             file2_frame.on('select',function() {
  12.  
  13.                 attachment = file2_frame.state().get('selection').first().toJSON();
  14.  
  15.                 var img_obj = obj.data('targetimg');
  16.                 var img_id = obj.data('targetid');
  17.                 var item_id = obj.data('itemid');
  18.  
  19.                 $.post(ajaxurl,{action:'set_thumbnail',id:attachment.id,item:item_id}, function(data){
  20.                     if (data == 1) {
  21.                         console.log('wena');
  22.                     }
  23.                 });
  24.                 //console.log( img_obj );
  25.                 $('.'+img_obj).attr('src', attachment.sizes.thumbnail.url);
  26.                 $('.'+img_id).val(attachment.id);
  27.                 console.log(attachment);
  28.                 file2_frame.state('destroy');
  29.             });
  30.  
  31.             file2_frame.open();
  32.             return false;
  33.         });
  34. }
Advertisement
Add Comment
Please, Sign In to add comment