@lemonadejs/cropper 1.3.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.
Files changed (2) hide show
  1. package/dist/cropper.js +73 -12
  2. 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.2.1
5
+ * Description: Image cropper v1.4.0
6
6
  *
7
7
  * MIT License
8
8
  *
@@ -37,6 +37,7 @@
37
37
  var height = photoContainer.getAttribute('height') || 240;
38
38
  var modal = null;
39
39
  var crop = null;
40
+ var menu = null;
40
41
 
41
42
  var self = {};
42
43
  self.cropperArea = null;
@@ -76,6 +77,16 @@
76
77
  });
77
78
  }
78
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
+
79
90
  self.updateZoom = function(o) {
80
91
  crop.zoom(o.value);
81
92
  }
@@ -198,6 +209,20 @@
198
209
  }
199
210
  }
200
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
+
201
226
  // Template
202
227
  var template = `
203
228
  <div @ref='self.image' class="jphoto"></div>
@@ -234,7 +259,9 @@
234
259
  </div>
235
260
  </div>
236
261
  </div>
237
- </div>`;
262
+ </div>
263
+ <div @ready="self.createMenu(this)"></div>
264
+ `;
238
265
 
239
266
  // Controls
240
267
  var createControls = function(o) {
@@ -257,21 +284,55 @@
257
284
  tabs.content.style.backgroundColor = '#eee';
258
285
  }
259
286
 
260
- // Onclick event
261
287
  photoContainer.onmousedown = function(e) {
262
- if (! modal.isOpen()) {
263
- // Open modal
264
- modal.open();
265
- // Create controls for the first time only
266
- if (! photoContainer.classList.contains('controls')) {
267
- // Create controls
268
- createControls(self.controls);
269
- // Flag controls are ready
270
- photoContainer.classList.add('controls');
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();
271
309
  }
272
310
  }
273
311
  }
274
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
+
275
336
  // Remove current image
276
337
  photoContainer.onkeydown = function(e) {
277
338
  if (e.key == 'Delete' && e.target.tagName == 'IMG') {
package/package.json CHANGED
@@ -15,9 +15,9 @@
15
15
  ],
16
16
  "dependencies": {
17
17
  "lemonadejs": "^1.7.1",
18
- "jsuites": "^4.9.10",
18
+ "jsuites": "^4.9.19",
19
19
  "@jsuites/cropper": "^1.5.1"
20
20
  },
21
21
  "main": "dist/cropper.js",
22
- "version": "1.3.2"
22
+ "version": "1.4.0"
23
23
  }