(function($){

	function widgetUploader() {

		$( document ).on( 'click', '.widget-image-uploader', function(e) {

			e.preventDefault();

			var send_attachment_bkp = wp.media.editor.send.attachment;
			var button              = $( this );
			var id                  = $( this ).prev().attr('id');

			wp.media.editor.send.attachment = function( props, attachment ) {
				$( "#"+id ).val( attachment.url );
			}

			wp.media.editor.open( button );
		});

	}

	widgetUploader();

})(jQuery);

