-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.min.js
58 lines (49 loc) · 2.08 KB
/
plugin.min.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
52
53
54
55
56
57
58
tinymce.PluginManager.add('filestack', function(editor, url) {
this.FSkey = editor.getParam('filestack_api_key');
if(typeof this.FSkey != "string"){
console.error("You need to pass a filestack API key to the filestack tinyMCE plugin! Make sure to include the 'filestack_api_key' property in the tinyMCE init object in order to set your API key.");
return;
}
this.uploadDone = editor.getParam('filestack_onUploadDone');
this.imageSettings = {
height: editor.getParam('filestack_image_height') ? editor.getParam('filestack_image_height') : 600,
width: editor.getParam('filestack_image_width') ? editor.getParam('filestack_image_width') : 800,
fit: editor.getParam('filestack_image_fit') ? editor.getParam('filestack_image_fit') : 'max',
align: editor.getParam('filestack_image_align') ? editor.getParam('filestack_image_align') : 'center',
}
var self = this;
const tiny_fs_client = filestack.init(self.FSkey);
const options = {
maxFiles: 1,
uploadInBackground: false,
onUploadDone: function(response){
// handle the image upload function passed from the tinymce.init object
// this allows end users to handle the response from filestack how they like
if(typeof self.uploadDone == "function"){
self.uploadDone(response);
}
// then paste an img tag into the editor
tinymce.activeEditor.execCommand('mceInsertContent', false, "<img src='https://cdn.filestackcontent.com/resize=w:"+self.imageSettings.width+",h:"+self.imageSettings.height+",f:"+self.imageSettings.fit+",a:"+self.imageSettings.align+"/"+response.filesUploaded[0].handle+"' />");
}
};
const tiny_fs_picker = tiny_fs_client.picker(options);
var tinyFilestackUpload = function(){
tiny_fs_picker.open();
}
// Add a button to the toolbar
editor.ui.registry.addButton('filestack', {
icon: "browse",
text: "Filestack",
onAction: function () {
tinyFilestackUpload();
}
});
return {
getMetadata: function () {
return {
name: "filestack image uploads for tinyMCE",
url: "http://www.brookesy.net"
};
}
};
});