-
Notifications
You must be signed in to change notification settings - Fork 0
/
filerobot.js
127 lines (119 loc) · 3.11 KB
/
filerobot.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Implements filerobot edit interface.
*
* @see https://github.com/scaleflex/filerobot-image-editor
* @since 1.0.0
* @package uhleloX\var\extensions\x-file-robot
*/
(function( $ ) {
'use strict';
$( window ).on(
'load',
function() {
/**
* Upload the Image to server/Save existing image.
*/
function x_send_img( imageData, imageDesignState ) {
$.ajax(
{
method: 'POST',
url: window.location.origin + '/ajax.php',
data: { 'imgURL' : imageData.imageBase64, 'imgFullName' : imageData.fullName, 'mimeType' : imageData.mimeType },
headers: {
'X-CSRF-TOKEN': 'x_add',
'X-CSRF-SEED': $( 'input[name=x_token]' ).val(),
'X-REQUEST-SOURCE': 'filerobot-img-upl-editor',
},
}
).done(
function( msg ) {
if ( 'true' === msg ) {
var d = new Date();
$( '#x_media_item_still' ).attr( 'src', window.location.origin + '/var/uploads/' + $( 'input[name=uuid]' ).val() + '?' + d )
$( '#x_filerobot_loading' ).hide();
}
}
);
}
/**
* Instantiate filerobot.
*/
const { TABS, TOOLS } = window.FilerobotImageEditor;
const config = {
source: window.location.origin + '/var/uploads/' + $( 'input[name=uuid]' ).val(),
onBeforeSave: function(info){
// Return false to interrupt default onSave operations.
return false
},
onSave: function( imageData, imageDesignState ) {
x_send_img( imageData, imageDesignState );
},
annotationsCommon: {
fill: '#ff0000'
},
Text: { text: 'uhleloX is just cool...' },
// Translations pull data from external source, abort.
useBackendTranslations: false,
translations: {
profile: 'Profile',
coverPhoto: 'Cover photo',
facebook: 'Facebook',
socialMedia: 'Social Media',
fbProfileSize: '180x180px',
fbCoverPhotoSize: '820x312px',
},
Crop: {
presetsItems: [
{
titleKey: 'classicTv',
descriptionKey: '4:3',
ratio: 4 / 3,
},
{
titleKey: 'cinemascope',
descriptionKey: '21:9',
ratio: 21 / 9,
},
],
presetsFolders: [
{
titleKey: 'socialMedia', // will be translated into Social Media as backend contains this translation key.
groups: [
{
titleKey: 'facebook',
items: [
{
titleKey: 'profile',
width: 180,
height: 180,
descriptionKey: 'fbProfileSize',
},
{
titleKey: 'coverPhoto',
width: 820,
height: 312,
descriptionKey: 'fbCoverPhotoSize',
},
],
},
],
},
],
},
tabsIds: [ TABS.ADJUST, TABS.FINETUNE, TABS.FILTERS, TABS.WATERMARK, TABS.ANNOTATE, TABS.RESIZE ],
defaultTabId: TABS.ADJUST,
defaultToolId: TOOLS.CROP,
};
// Assuming we have a div with id="media_item_container".
const filerobotImageEditor = new FilerobotImageEditor(
document.querySelector( '#media_item_containerEditor' ),
config,
);
filerobotImageEditor.render(
{
// Options, if any.
}
);
}
);
})( jQuery );