Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ( function( $) {
- $.wpMediaUploader = function( options ) {
- var settings = $.extend({
- target : '.al-uploader', // The class wrapping the textbox
- uploaderTitle : 'SELECT OR UPLOAD AN IMAGE', // The title of the media upload popup
- uploaderButton : 'SET IMAGE', // the text of the button in the media upload popup
- multiple : false, // Allow the user to select multiple images
- buttonText : '', // The text of the upload button
- buttonClass : '.al-upload', // the class of the upload button
- previewSize : '100px', // The preview image size
- modal : true, // is the upload button within a bootstrap modal ?
- buttonStyle : { // style the button
- border : 'none',
- background : 'none',
- padding : '0',
- float : 'right',
- display : 'block'
- },
- }, options );
- // $( settings.target ).append( '<a href="#" class="' + settings.buttonClass.replace('.','') + '">' + settings.buttonText + '</a>' );
- $( settings.target ).append('<div><br><img src="#" style="display: none; width: ' + settings.previewSize + '"/></div>')
- $( settings.buttonClass ).css( settings.buttonStyle );
- $('body').on('click', settings.buttonClass, function(e) {
- e.preventDefault();
- var selector = $(this).parent( settings.target );
- var al_media_uploader = wp.media({
- title: settings.uploaderTitle,
- button: {
- text: settings.uploaderButton
- },
- multiple: settings.multiple
- })
- .on('select', function() {
- var attachment = al_media_uploader.state().get('selection').first().toJSON();
- $('.al-img-preview' ).attr('src', attachment.url);
- $('.al-img-input' ).attr('value', attachment.url);
- if( settings.modal ) {
- $('.modal').css( 'overflowY', 'auto');
- }
- })
- .open();
- });
- }
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement