-
Notifications
You must be signed in to change notification settings - Fork 7
/
ImageCaption.js
51 lines (43 loc) · 1.46 KB
/
ImageCaption.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
// Adds a Caption Field to the Image Block
(function ($){
SirTrevor.Blocks.Image = SirTrevor.Block.extend({
type: "image",
title: function() { return 'Image' },
droppable: true,
uploadable: true,
icon_name: 'image',
loadData: function(data){
this.$editor.html($('<img>', { src: data.file.url })).show();
this.$editor.append($('<input>', {type: 'text', class: 'st-input-string js-caption-input', name: 'text', placeholder: 'Caption', style: 'width: 100%; margin-top:10px; text-align: center;', value: data.text}));
},
onBlockRender: function(){
/* Setup the upload button */
this.$inputs.find('button').bind('click', function(ev){ ev.preventDefault(); });
this.$inputs.find('input').on('change', _.bind(function(ev){
this.onDrop(ev.currentTarget);
}, this));
},
onDrop: function(transferData){
var file = transferData.files[0],
urlAPI = (typeof URL !== "undefined") ? URL : (typeof webkitURL !== "undefined") ? webkitURL : null;
// Handle one upload at a time
if (/image/.test(file.type)) {
this.loading();
// Show this image on here
this.$inputs.hide();
this.loadData({file: {url: urlAPI.createObjectURL(file)}});
this.uploader(
file,
function(data) {
this.setData(data);
this.ready();
},
function(error){
this.addMessage(i18n.t('blocks:image:upload_error'));
this.ready();
}
);
}
}
});
}(jQuery));