-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathscript.js
51 lines (35 loc) · 1.26 KB
/
script.js
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
(function($){
'use strict';
$(document).ready(function(){
var image_frame;
$('.mcc-box__field-container').on('click', '.js-mcc-box-image-upload-button', function(e){
e.preventDefault();
image_frame = wp.media.frames.image_frame = wp.media({library: {type: 'image'}});
image_frame.open();
var id = $(this).data('hidden-input').replace(/(\[|\])/g, '\\$1');
console.log(id);
image_frame.on('select', function() {
var attachment = image_frame.state().get('selection').first().toJSON();
console.log(id);
$('#image-'+id).val(attachment.url);
$('#js-'+id+'-image-preview').removeClass('is-hidden').attr('src', attachment.url);
$('.js-mcc-box-image-upload-button').text('Change Image');
$('#'+id).css({background: 'red'});
});
image_frame.open();
});
$('.mcc-box__field-container').on('click', '.mcc-box-repeated-header', function(){
$(this).siblings('.mcc-box__repeated-content').toggleClass('is-hidden');
});
$('.mcc-box__repeated-blocks').on('click', '.mcc-box__remove', function() {
$(this).closest('.mcc-box__repeated').remove();
return false;
});
$('.mcc-box__repeated-blocks').sortable({
opacity: 0.6,
revert: true,
cursor: 'move',
handle: '.js-mcc-box-sort'
});
});
})(jQuery);