@lemonadejs/cropper 1.2.2 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cropper.js +85 -22
- package/package.json +2 -2
package/dist/cropper.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* (c) LemonadeJS components
|
|
3
3
|
*
|
|
4
4
|
* Website: https://lemonadejs.net
|
|
5
|
-
* Description: Image cropper v1.
|
|
5
|
+
* Description: Image cropper v1.4.0
|
|
6
6
|
*
|
|
7
7
|
* MIT License
|
|
8
8
|
*
|
|
@@ -16,16 +16,19 @@
|
|
|
16
16
|
|
|
17
17
|
'use strict';
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (
|
|
19
|
+
// Load jSuites
|
|
20
|
+
if (typeof(jSuites) == 'undefined') {
|
|
21
|
+
if (window.jSuites) {
|
|
22
|
+
var jSuites = window.jSuites;
|
|
23
|
+
} else if (typeof(require) === 'function') {
|
|
22
24
|
var jSuites = require('jsuites');
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Set the app extensions
|
|
29
|
+
if (typeof(jSuites.crop) == 'undefined' && typeof(require) === 'function') {
|
|
30
|
+
// Loading App Extensions
|
|
31
|
+
jSuites.crop = require('@jsuites/cropper');
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
return (function(photoContainer) {
|
|
@@ -34,6 +37,7 @@
|
|
|
34
37
|
var height = photoContainer.getAttribute('height') || 240;
|
|
35
38
|
var modal = null;
|
|
36
39
|
var crop = null;
|
|
40
|
+
var menu = null;
|
|
37
41
|
|
|
38
42
|
var self = {};
|
|
39
43
|
self.cropperArea = null;
|
|
@@ -73,6 +77,16 @@
|
|
|
73
77
|
});
|
|
74
78
|
}
|
|
75
79
|
|
|
80
|
+
self.createMenu = function(o) {
|
|
81
|
+
// Start contextmenu component
|
|
82
|
+
menu = jSuites.contextmenu(o, {
|
|
83
|
+
onclick: function(a,b) {
|
|
84
|
+
a.close();
|
|
85
|
+
b.stopPropagation();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
76
90
|
self.updateZoom = function(o) {
|
|
77
91
|
crop.zoom(o.value);
|
|
78
92
|
}
|
|
@@ -195,9 +209,23 @@
|
|
|
195
209
|
}
|
|
196
210
|
}
|
|
197
211
|
|
|
212
|
+
self.open = function() {
|
|
213
|
+
if (! modal.isOpen()) {
|
|
214
|
+
// Open modal
|
|
215
|
+
modal.open();
|
|
216
|
+
// Create controls for the first time only
|
|
217
|
+
if (!photoContainer.classList.contains('controls')) {
|
|
218
|
+
// Create controls
|
|
219
|
+
createControls(self.controls);
|
|
220
|
+
// Flag controls are ready
|
|
221
|
+
photoContainer.classList.add('controls');
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
198
226
|
// Template
|
|
199
227
|
var template = `
|
|
200
|
-
<div @ref='self.image'></div>
|
|
228
|
+
<div @ref='self.image' class="jphoto"></div>
|
|
201
229
|
<div @ready='self.createModal(this)'>
|
|
202
230
|
<div @ready='self.createCropper(this)' @ref='self.cropperArea'></div>
|
|
203
231
|
<div @ref='self.controls'>
|
|
@@ -231,7 +259,9 @@
|
|
|
231
259
|
</div>
|
|
232
260
|
</div>
|
|
233
261
|
</div>
|
|
234
|
-
</div
|
|
262
|
+
</div>
|
|
263
|
+
<div @ready="self.createMenu(this)"></div>
|
|
264
|
+
`;
|
|
235
265
|
|
|
236
266
|
// Controls
|
|
237
267
|
var createControls = function(o) {
|
|
@@ -254,22 +284,55 @@
|
|
|
254
284
|
tabs.content.style.backgroundColor = '#eee';
|
|
255
285
|
}
|
|
256
286
|
|
|
257
|
-
// Onclick event
|
|
258
|
-
photoContainer.classList.add('jupload');
|
|
259
287
|
photoContainer.onmousedown = function(e) {
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
288
|
+
if (e.target.tagName == 'IMG') {
|
|
289
|
+
e.target.focus();
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Onclick event
|
|
294
|
+
photoContainer.onclick = function(e) {
|
|
295
|
+
e = e || window.event;
|
|
296
|
+
if (e.buttons) {
|
|
297
|
+
var mouseButton = e.buttons;
|
|
298
|
+
} else if (e.button) {
|
|
299
|
+
var mouseButton = e.button;
|
|
300
|
+
} else {
|
|
301
|
+
var mouseButton = e.which;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
if (mouseButton == 1) {
|
|
305
|
+
self.open();
|
|
306
|
+
} else {
|
|
307
|
+
if (e.target.tagName == 'IMG') {
|
|
308
|
+
e.target.focus();
|
|
269
309
|
}
|
|
270
310
|
}
|
|
271
311
|
}
|
|
272
312
|
|
|
313
|
+
photoContainer.oncontextmenu = function(e) {
|
|
314
|
+
if (e.target.tagName == 'IMG') {
|
|
315
|
+
menu.open(e, [
|
|
316
|
+
{
|
|
317
|
+
title: jSuites.translate('Change image'),
|
|
318
|
+
icon: 'edit',
|
|
319
|
+
onclick: function() {
|
|
320
|
+
self.open();
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
title: jSuites.translate('Delete image'),
|
|
325
|
+
icon: 'delete',
|
|
326
|
+
shortcut: 'DELETE',
|
|
327
|
+
onclick: function() {
|
|
328
|
+
e.target.remove();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
]);
|
|
332
|
+
e.preventDefault();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
273
336
|
// Remove current image
|
|
274
337
|
photoContainer.onkeydown = function(e) {
|
|
275
338
|
if (e.key == 'Delete' && e.target.tagName == 'IMG') {
|