websupporter

WP Term Meta Javascript

Dec 14th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. jQuery( document ).ready( function(){
  2.     jQuery( '#thumbnail_mediathek' ).click( function( event ){
  3.         event.preventDefault();
  4.  
  5.         if ( frame ) {
  6.             frame.open();
  7.             return;
  8.         }
  9.    
  10.         // Create a new media frame
  11.         var frame = wp.media({
  12.             title: 'Wähle ein Kategorienbild',
  13.             button: {
  14.                 text: 'Verwende dieses Bild'
  15.             },
  16.             multiple: false  // Set to true to allow multiple files to be selected
  17.         });
  18.  
  19.    
  20.         // When an image is selected in the media frame...
  21.         frame.on( 'select', function() {
  22.             // Get media attachment details from the frame state
  23.             var attachment = frame.state().get('selection').first().toJSON();  
  24.             console.log( attachment );
  25.             var txt = '<img src="' + attachment.url + '" style="max-width:100%" /><input type="hidden" name="_thumbnail_id" value="' + attachment.id + '" />';
  26.             jQuery( '#thumbnail' ).find( 'img' ).remove();
  27.             jQuery( txt ).insertBefore( jQuery( '#thumbnail button' ) );
  28.         });
  29.  
  30.         // Finally, open the modal on click
  31.         frame.open();
  32.     });
  33. });
Advertisement
Add Comment
Please, Sign In to add comment