1/**
2 * Title: media-uploader-new.js
3 *
4 * Description: Defines JS for media uploader for WP3.5 and later.
5 *
6 * Please do not edit this file. This file is part of the Cyber Chimps Framework and all modifications
7 * should be made in a child theme.
8 *
9 * @category Cyber Chimps Framework
10 * @package  Framework
11 * @since    1.0
12 * @author   CyberChimps
13 * @license  http://www.opensource.org/licenses/gpl-license.php GPL v3.0 (or later)
14 * @link     http://www.cyberchimps.com/
15 */
16
17jQuery(document).ready(function ($) {
18	var _custom_media = true;
19	var _orig_send_attachment = wp.media.editor.send.attachment;
20
21	$('.upload-image-button').click(function (e) {
22
23		// Get reference to the parent.
24		var parent = jQuery(this).parent();
25
26		var send_attachment_bkp = wp.media.editor.send.attachment;
27		var button = $(this);
28
29		_custom_media = true;
30		wp.media.editor.send.attachment = function (props, attachment) {
31			if (_custom_media) {
32				parent.find('.upload-image-field').val(attachment.url);
33				parent.find('.image-preview').attr('src', attachment.url);
34			}
35			else {
36				return _orig_send_attachment.apply(this, [props, attachment]);
37			}
38			;
39		}
40
41		wp.media.editor.open(button);
42		return false;
43	});
44
45	jQuery('.add_media').on('click', function () {
46		_custom_media = false;
47	});
48});