| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?> |
| 2 |
<script> |
| 3 |
|
| 4 |
jQuery("document").ready(function($) { |
| 5 |
|
| 6 |
// ================================================== |
| 7 |
// Dealing with uploading images |
| 8 |
// ================================================== |
| 9 |
|
| 10 |
$('.yydev_upload_image, .yydev_light_img_bg').click(function(e) { |
| 11 |
|
| 12 |
var uploadButtonParent = $(this).parent(); |
| 13 |
|
| 14 |
e.preventDefault(); |
| 15 |
var image = wp.media({ |
| 16 |
title: 'Upload Image'}).open() |
| 17 |
.on('select', function(e){ |
| 18 |
|
| 19 |
// This will return the selected image from the Media Uploader, the result is an object |
| 20 |
var images_length = image.state().get("selection").length; |
| 21 |
var images = image.state().get("selection").models; |
| 22 |
|
| 23 |
console.log(images); |
| 24 |
|
| 25 |
var image_url = images[0].toJSON().url; |
| 26 |
var image_alt = images[0].toJSON().alt; |
| 27 |
var image_caption = images[0].toJSON().caption; |
| 28 |
var image_title = images[0].toJSON().title; |
| 29 |
var image_id = images[0].toJSON().id; |
| 30 |
|
| 31 |
// Let's assign the url value to the input field |
| 32 |
uploadButtonParent.find('.yydev_light_img_bg').attr('src', image_url); // changing image icon |
| 33 |
uploadButtonParent.find('.yydev_image_input').val(image_url); // changing input url |
| 34 |
|
| 35 |
}); // .on('select', function(e){ |
| 36 |
|
| 37 |
}); // $('.edit-button-image-upload').click(function(e) { |
| 38 |
|
| 39 |
// ================================================== |
| 40 |
// Changing the background of icon image on background change |
| 41 |
// ================================================== |
| 42 |
|
| 43 |
$('input#background_color').change(function() { |
| 44 |
|
| 45 |
var backgroundValue = $(this).val(); |
| 46 |
$("img.yydev_light_img_bg").css("background", backgroundValue); |
| 47 |
|
| 48 |
}); // $('input#background_color').change(function() { |
| 49 |
|
| 50 |
}); // jQuery("document").ready(function($) { |
| 51 |
|
| 52 |
</script> |