-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkcpt-fading-image-widget.js
More file actions
54 lines (41 loc) · 1.57 KB
/
kcpt-fading-image-widget.js
File metadata and controls
54 lines (41 loc) · 1.57 KB
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
(function($) {
$(document).ready(function() {
window.fiwInsertImage = function(e) {
e.preventDefault();
var inputToFill = $(e.currentTarget).prev('input[type="text"]');
//If the frame already exists, reopen it
if (typeof(custom_file_frame)!=="undefined") {
custom_file_frame.close();
}
//Create WP media frame.
custom_file_frame = wp.media.frames.customHeader = wp.media({
//Title of media manager frame
title: "Select Image for Widget",
library: {
type: 'image'
},
button: {
//Button text
text: "Insert Image"
},
//Do not allow multiple files, if you want multiple, set true
multiple: false
});
//callback for selected image
custom_file_frame.on('select', function() {
var attachment = custom_file_frame.state().get('selection').first().toJSON();
$(inputToFill).val(attachment.id);
});
//Open modal
custom_file_frame.open();
};
window.bindFadingImageWidget = function() {
$('.insert-kcpt-image').off('click', fiwInsertImage);
$('.insert-kcpt-image').on('click', fiwInsertImage);
};
bindFadingImageWidget();
$(document).on('widget-added', function(e, widget) {
bindFadingImageWidget();
})
});
})(jQuery);