;(function ( document, $, undefined ) { 'use strict'; var custom_uploader, targetInputClass = '.upload-image-id', previewClass = 'upload-image-preview', target_input, DFIG = {}; DFIG.upload = function () { $( '.upload-image' ).on( 'click.upload', _uploadMedia ); $( '.delete-image' ).on( 'click.delete', _deleteMedia ); $( '#addtag #submit' ).on( 'click.term', _termImages ); function _uploadMedia( e ) { e.preventDefault(); target_input = $( this ).prev( targetInputClass ); //If the uploader object has already been created, reopen the dialog if ( custom_uploader ) { custom_uploader.reset(); } //Extend the wp.media object custom_uploader = wp.media.frames.file_frame = wp.media( { title: ([DFIG.params.text]), button: { text: ([DFIG.params.text]) }, multiple: false, library: {type: 'image'} } ); //When a file is selected, grab the URL and set it as the text field's value custom_uploader.on( 'select', function () { var attachment = custom_uploader.state().get( 'selection' ).first().toJSON(), preview = $( target_input ).prevAll( '.' + previewClass ), deleteButton = $( target_input ).siblings( '.delete-image' ), previewImage = $( '
', { class: previewClass } ).append( $( '