Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. ( function( $) {
  2. $.wpMediaUploader = function( options ) {
  3.  
  4. var settings = $.extend({
  5.  
  6. target : '.al-uploader', // The class wrapping the textbox
  7. uploaderTitle : 'SELECT OR UPLOAD AN IMAGE', // The title of the media upload popup
  8. uploaderButton : 'SET IMAGE', // the text of the button in the media upload popup
  9. multiple : false, // Allow the user to select multiple images
  10. buttonText : '', // The text of the upload button
  11. buttonClass : '.al-upload', // the class of the upload button
  12. previewSize : '100px', // The preview image size
  13. modal : true, // is the upload button within a bootstrap modal ?
  14. buttonStyle : { // style the button
  15. border : 'none',
  16. background : 'none',
  17. padding : '0',
  18. float : 'right',
  19. display : 'block'
  20. },
  21.  
  22. }, options );
  23.  
  24.  
  25. // $( settings.target ).append( '<a href="#" class="' + settings.buttonClass.replace('.','') + '">' + settings.buttonText + '</a>' );
  26. $( settings.target ).append('<div><br><img src="#" style="display: none; width: ' + settings.previewSize + '"/></div>')
  27.  
  28. $( settings.buttonClass ).css( settings.buttonStyle );
  29.  
  30. $('body').on('click', settings.buttonClass, function(e) {
  31.  
  32. e.preventDefault();
  33. var selector = $(this).parent( settings.target );
  34. var al_media_uploader = wp.media({
  35. title: settings.uploaderTitle,
  36. button: {
  37. text: settings.uploaderButton
  38. },
  39. multiple: settings.multiple
  40. })
  41. .on('select', function() {
  42. var attachment = al_media_uploader.state().get('selection').first().toJSON();
  43. $('.al-img-preview' ).attr('src', attachment.url);
  44. $('.al-img-input' ).attr('value', attachment.url);
  45. if( settings.modal ) {
  46. $('.modal').css( 'overflowY', 'auto');
  47. }
  48. })
  49. .open();
  50. });
  51.  
  52.  
  53. }
  54. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement