llms-metabox-certificate.js 1.89 KB
Newer Older
cyrille's avatar
cyrille committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
jQuery( document ).ready(function($){

	$( '.certificate_image_button' ).click(function(e) {

		// Create Media Manager On Click to allow multiple on one Page
		var certificate_uploader;

		e.preventDefault();

		// Setup the Variables based on the Button Clicked to enable multiple
		var certificate_img_input_id = '#' + this.id + '.upload_certificate_image';
		var certificate_img_src      = 'img#' + this.id + '.llms_certificate_image';

		// If the uploader object has already been created, reopen the dialog
		if (certificate_uploader) {
			certificate_uploader.open();
			return;
		}

		// Extend the wp.media object
		certificate_uploader = wp.media.frames.file_frame = wp.media({
			title: 'Choose Certificate Image',
			button: {
				text: 'Choose Certificate'
			},
			multiple: false
		});

		// When a file is selected, grab the URL and set it as the text field's value
		certificate_uploader.on('select', function() {
			attachment = certificate_uploader.state().get( 'selection' ).first().toJSON();
			// Set the Field with the Image ID
			$( certificate_img_input_id ).val( attachment.id );
			// Set the Sample Image with the URL
			$( certificate_img_src ).attr( 'src', attachment.url );

		});

		// Open the uploader dialog
		certificate_uploader.open();

	});

});
/*
* Media Manager 3.5
* @version 1.70
*/
jQuery( document ).ready(function($){
	// Remove Image and replace with default and Erase Image ID for Certificate
	$( '.llms_certificate_clear_image_button' ).click(function(e) {
		e.preventDefault();
		var certificate_remove_input_id = 'input#' + this.id + '.upload_certificate_image';
		var certificate_img_src         = 'img#' + this.id + '.llms_certificate_image';
		var certificate_default_img_src = $( 'img#' + this.id + '.llms_certificate_default_image' ).attr( "src" );

		$( certificate_remove_input_id ).val( '' );
		$( certificate_img_src ).attr( 'src', certificate_default_img_src );
	});

});