-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawImage.js
More file actions
867 lines (747 loc) · 21 KB
/
drawImage.js
File metadata and controls
867 lines (747 loc) · 21 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
//Term Image
var srcImage = "http://image.prntscr.com/image/a2f0754e63de4263a607565074472079.jpg";
drawImg(srcImage);
var canvas, ghostcanvas, gctx, WIDTH, HEIGHT, blurCanvas;
var isDown = false;
var offsetX = offsetY = scrollX = scrollY = 0;
var ctx, tempCtx;
var PI2 = Math.PI * 2;
var arrDrawed, currentDrawed;
var img;
var access_blur, is_edit;
var MAX_WIDTH = MAX_HEIGHT = 500;
var ratio;
var imgBlur;
function drawImg(srcImage) {
access_blur = false;
$(window).scrollLeft(0);
$(window).scrollTop(0);
img = new Image();
arrDrawed = new Array();
currentDrawed = new Array();
is_edit = true;
if (srcImage.substring(0, 4).toLowerCase() === 'http') {
img.crossOrigin = 'anonymous';
}
img.onload = function() {
ghostcanvas = document.createElement('canvas');
blurCanvas = document.createElement('canvas');
ctxBlur = blurCanvas.getContext("2d");
tempCanvas = document.getElementById('tempCanvas');
tempCtx = tempCanvas.getContext("2d");
canvas = document.getElementById("canvas");
ctx = canvas.getContext("2d");
//ratio = Math.min(MAX_WIDTH / img.width, MAX_HEIGHT / img.height);
canvas.width = tempCanvas.width = ghostcanvas.width = WIDTH = blurCanvas.width = img.width
//* ratio;
canvas.height = tempCanvas.height = ghostcanvas.height = HEIGHT = blurCanvas.height = img.height
//* ratio;
ctx.drawImage(img,0,0);
//ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0,img.width * ratio, img.height * ratio)
ctxBlur.drawImage(canvas, 0, 0);
setTimeout(function() {
canvasOffset = $("#canvas").offset();
offsetX = parseInt(canvasOffset.left);
offsetY = parseInt(canvasOffset.top);
}, 500)
};
img.src = srcImage;
imgBlur = new Image();
imgDelete = new Image();
imgDelete.crossOrigin = 'anonymous';
imgDelete.onload = function() {
imgDelete.width = imgDelete.height = 26;
}
imgDelete.src = "http://image.prntscr.com/image/e26177aae0c04c6dbfad394df0ca2479.png";
img.src = srcImage.replace(/^https:\/\//i, 'http://');
boxes2 = [];
}
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
function setOffset(){
if(isAndroid) {
canvasOffset = canvas.getBoundingClientRect();
}else {
canvasOffset = $("#canvas").offset();
}
offsetX = parseInt(canvasOffset.left);
offsetY = parseInt(canvasOffset.top );
}
function handleMouseDown(e) {
if (!access_blur)
return;
setOffset();
e.preventDefault();
e.stopPropagation();
currentDrawed = new Array();
isDown = true;
}
function handleMouseUp(e) {
if (!access_blur)
return;
if (currentDrawed !== undefined) {
arrDrawed.push(currentDrawed);
currentDrawed = undefined;
}
e.preventDefault();
e.stopPropagation();
drawImgBlur();
// mainDraw();
isDown = false;
}
function handleMouseOut(e) {
if (!access_blur)
return;
if (currentDrawed !== undefined) {
arrDrawed.push(currentDrawed);
currentDrawed = undefined;
}
e.preventDefault();
e.stopPropagation();
if (isDown) {
drawImgBlur();
// mainDraw();
}
isDown = false;
}
function handleMouseMove(e) {
if (!isDown || !access_blur) {
return;
}
e.preventDefault();
e.stopPropagation();
if (e.type == 'touchmove') {
positionX = e.originalEvent.touches[0].pageX;
positionY = e.originalEvent.touches[0].pageY;
} else {
positionX = e.clientX;
positionY = e.clientY;
}
mouseX = parseInt(positionX - offsetX);
mouseY = parseInt(positionY - offsetY);
currentDrawed.push({
x : mouseX,
y : mouseY
});
ctx.fillStyle = "#000";
ctx.beginPath();
ctx.arc(mouseX, mouseY, 20, 0, PI2);
ctx.closePath();
ctx.fill();
tempCtx.beginPath();
tempCtx.arc(mouseX, mouseY, 20, 0, PI2);
tempCtx.closePath();
tempCtx.fill();
}
function drawImgBlur() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
tempCtx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < arrDrawed.length; i++) {
var temp = arrDrawed[i];
for (var j = 0; j < temp.length; j++) {
mouseX = temp[j].x;
mouseY = temp[j].y;
tempCtx.beginPath();
tempCtx.arc(mouseX, mouseY, 20, 0, PI2);
tempCtx.closePath();
tempCtx.fillStyle = "#fff";
tempCtx.fill();
}
}
tempCtx.save();
tempCtx.globalCompositeOperation = "source-in";
tempCtx.drawImage(img,0,0)
tempCtx.restore();
boxBlurCanvasRGBA("tempCanvas", 0, 0, tempCanvas.width, tempCanvas.height,
9, 0);
ctxBlur.save();
ctxBlur.clearRect(0, 0, canvas.width, canvas.height);
ctxBlur.drawImage(tempCanvas, 0, 0);
ctxBlur.globalCompositeOperation = "destination-over";
ctxBlur.drawImage(img,0,0)
ctxBlur.restore();
ctx.save();
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(blurCanvas, 0, 0);
drawStamp();
ctx.restore();
}
$(document).on('mousedown touchstart', '#canvas', function(e) {
setOffset();
handleMouseDown(e);
handleMouseDownTerm(e);
});
$(document).on('mouseup touchend', '#canvas', function(e) {
handleMouseUp(e);
handleMouseUpTerm(e);
});
$(document).on('mousemove touchmove', '#canvas', function(e) {
handleMouseMove(e);
handleMouseMoveTerm(e);
});
$(document).on('mouseout touchleave', '#canvas', function(e) {
handleMouseOut(e);
handleMouseOutTerm(e);
});
$(document).on('scroll', '.modal-content', function(e) {
handleMouseOut(e);
});
$(document).on('click', '#undo', function() {
arrDrawed.pop();
drawImgBlur();
});
$(window).resize(function() {
if (!is_edit)
return;
setOffset();
});
$(window).scroll(function() {
if (!is_edit)
return;
setOffset();
});
/**
*
* Term Image
*/
var stampImage = true;
var boxes2 = [];
// New, holds the 8 tiny boxes that will be our selection handles
// the selection handles will be in this order:
// 0 1 2
// 3 4
// 5 6 7
var selectionHandles = [];
// Hold canvas information
var INTERVAL = 20; // how often, in milliseconds, we check to see if a redraw
// is needed
var isDrag = false;
var isResizeDrag = false;
var expectResize = -1; // New, will save the # of the selection handle if the
// mouse is over one.
var mx, my; // mouse coordinates
// when set to true, the canvas will redraw everything
// invalidate() just sets this to false right now
// we want to call invalidate() whenever we make a change
var canvasValid = true;
// The node (if any) being selected.
// If in the future we want to select multiple objects, this will get turned
// into an array
var mySel = null;
// The selection color and width. Right now we have a red selection with a small
// width
var mySelColor = '#CC0000';
var mySelWidth = 2;
var mySelBoxColor = 'darkred'; // New for selection boxes
var mySelBoxSize = 16;
// since we can drag from anywhere in a node
// instead of just its x/y corner, we need to save
// the offset of the mouse when we start dragging.
var offsetx, offsety;
// Padding and border style widths for mouse offsets
var stylePaddingLeft, stylePaddingTop, styleBorderLeft, styleBorderTop;
var imgDelete;
// Box object to hold data
function Box2(srcImg) {
this.x = 0;
this.y = 0;
this.w = 1; // default width and height?
this.h = 1;
this.fill = 'rgba(255,255,255,0)';
this.src = srcImg;
if (srcImg) {
this.imgTerm = setImage(this.src);
}
}
function setImage(srcImg) {
var imgTerm = new Image();
imgTerm.crossOrigin = 'anonymous';
imgTerm.onload = function() {
invalidate();
}
imgTerm.src = srcImg.replace(/^https:\/\//i, 'http://');
return imgTerm;
}
// New methods on the Box class
Box2.prototype = {
// we used to have a solo draw function
// but now each box is responsible for its own drawing
// mainDraw() will call this with the normal canvas
// myDown will call this with the ghost canvas with 'black'
draw : function(context, optionalColor) {
if (context === gctx) {
context.fillStyle = 'black'; // always want black for the ghost
// canvas
} else {
context.fillStyle = this.fill;
}
// We can skip the drawing of elements that have moved off the screen:
if (this.x > WIDTH || this.y > HEIGHT)
return;
if (this.x + this.w < 0 || this.y + this.h < 0)
return;
context.fillRect(this.x, this.y, this.w, this.h);
if (this.imgTerm) {
context.drawImage(this.imgTerm, this.x, this.y, this.w, this.h);
}
// draw selection
// this is a stroke along the box and also 8 new selection handles
if (mySel === this) {
context.strokeStyle = mySelColor;
context.lineWidth = mySelWidth;
context.strokeRect(this.x, this.y, this.w, this.h);
// draw the boxes
var half = mySelBoxSize / 2;
// 0 1 2 8 9
// 3 4
// 5 6 7
// top left, middle, right
selectionHandles[0].x = this.x - half;
selectionHandles[0].y = this.y - half;
selectionHandles[1].x = this.x + this.w / 2 - half;
selectionHandles[1].y = this.y - half;
selectionHandles[2].x = this.x + this.w - half;
selectionHandles[2].y = this.y - half;
// middle left
selectionHandles[3].x = this.x - half;
selectionHandles[3].y = this.y + this.h / 2 - half;
// middle right
selectionHandles[4].x = this.x + this.w - half;
selectionHandles[4].y = this.y + this.h / 2 - half;
// bottom left, middle, right
selectionHandles[6].x = this.x + this.w / 2 - half;
selectionHandles[6].y = this.y + this.h - half;
selectionHandles[5].x = this.x - half;
selectionHandles[5].y = this.y + this.h - half;
selectionHandles[7].x = this.x + this.w - half;
selectionHandles[7].y = this.y + this.h - half;
selectionHandles[8].x = this.x + this.w - half + 10;
selectionHandles[8].y = this.y - mySelBoxSize - 10;
context.fillStyle = mySelBoxColor;
for (var i = 0; i < 9; i++) {
var cur = selectionHandles[i];
if (i == 8) {
context.drawImage(imgDelete, cur.x, cur.y);
} else if (i < 8) {
context.fillRect(cur.x, cur.y, mySelBoxSize, mySelBoxSize);
}
}
}
} // end draw
}
function addRect(x, y, w, h, fill, srcImgTerm) {
var rect = new Box2(srcImgTerm);
rect.x = x;
rect.y = y;
rect.w = w
rect.h = h;
// rect.fill = fill;
boxes2.push(rect);
invalidate();
}
// initialize our canvas, add a ghost canvas, set draw loop
// then add everything we want to intially exist on the canvas
function init2() {
// canvas = document.getElementById("canvas");
// ctx = canvas.getContext('2d');
gctx = ghostcanvas.getContext('2d');
// fixes a problem where double clicking causes text to get selected on the
// canvas
/*
* canvas.onselectstart = function() { //return false; }
*/
// fixes mouse co-ordinate problems when there's a border or padding
// see getMouse for more detail
if (document.defaultView && document.defaultView.getComputedStyle) {
stylePaddingLeft = parseInt(document.defaultView.getComputedStyle(
canvas, null)['paddingLeft'], 10) || 0;
stylePaddingTop = parseInt(document.defaultView.getComputedStyle(
canvas, null)['paddingTop'], 10) || 0;
styleBorderLeft = parseInt(document.defaultView.getComputedStyle(
canvas, null)['borderLeftWidth'], 10) || 0;
styleBorderTop = parseInt(document.defaultView.getComputedStyle(canvas,
null)['borderTopWidth'], 10) || 0;
}
// make mainDraw() fire every INTERVAL milliseconds
setInterval(mainDraw, INTERVAL);
for (var i = 0; i < 9; i++) {
var rect = new Box2;
selectionHandles.push(rect);
}
}
function clearGhost(c) {
c.clearRect(0, 0, WIDTH, HEIGHT);
}
// wipes the canvas context
function clear(c) {
c.clearRect(0, 0, WIDTH, HEIGHT);
c.drawImage(blurCanvas, 0, 0);
// c.drawImage(img, 0, 0, img.width, img.height, 0, 0, img.width *
// ratio,img.height * ratio);
}
// Main draw loop.
// While draw is called as often as the INTERVAL variable demands,
// It only ever does something if the canvas gets invalidated by our code
function mainDraw() {
if (canvasValid == false) {
clear(ctx);
drawStamp();
// Add stuff you want drawn on top all the time here
canvasValid = true;
}
}
function drawStamp() {
var l = boxes2.length;
for (var i = 0; i < l; i++) {
boxes2[i].draw(ctx); // we used to call drawshape, but now each
// box draws itself
}
}
// Happens when the mouse is moving inside the canvas
function handleMouseMoveTerm(e) {
if (!stampImage) {
return;
}
if (e.type == 'touchmove' || e.type == 'touchstart' || e.type == 'touchend') {
var l = boxes2.length;
// we are over a selection box
if (expectResize !== -1) {
e.preventDefault();
e.stopPropagation();
isResizeDrag = true;
isDrag = false;
} else {
isDrag = true;
}
}
if (isDrag) {
getMouse(e);
if (mx < 0 || my < 0 || mx > canvas.width
|| my > canvas.height) {
return;
}
mySel.x = mx - offsetx;
mySel.y = my - offsety;
// something is changing position so we better invalidate the canvas!
invalidate();
} else if (isResizeDrag) {
if (mx < 0 || my < 0 || mx > canvas.width
|| my > canvas.height) {
return;
}
// time ro resize!
var oldx = mySel.x;
var oldy = mySel.y;
// 0 1 2
// 3 4
// 5 6 7
switch (expectResize) {
case 0:
if (mx + 12 >= oldx + mySel.w || my + 12 >= oldy + mySel.h) {
isResizeDrag = true;
return;
}
mySel.x = mx;
mySel.y = my;
mySel.w += oldx - mx;
mySel.h += oldy - my;
break;
case 1:
if (my + 12 >= oldy + mySel.h) {
return;
}
mySel.y = my;
mySel.h += oldy - my;
break;
case 2:
if (mx <= oldx + 12 || my + 12 >= oldy + mySel.h) {
return;
}
mySel.y = my;
mySel.w = mx - oldx;
mySel.h += oldy - my;
break;
case 3:
if (mx + 12 >= oldx + mySel.w) {
return;
}
mySel.x = mx;
mySel.w += oldx - mx;
break;
case 4:
if (mx <= oldx + 12) {
return;
}
mySel.w = mx - oldx;
break;
case 5:
if (mx + 12 >= oldx + mySel.w || my <= oldy + 12) {
return;
}
mySel.x = mx;
mySel.w += oldx - mx;
mySel.h = my - oldy;
break;
case 6:
if (my <= oldy + 12) {
return;
}
mySel.h = my - oldy;
break;
case 7:
if (mx <= oldx + 12 || my <= oldy + 12) {
return;
}
mySel.w = mx - oldx;
mySel.h = my - oldy;
break;
}
invalidate();
}
getMouse(e);
// if there's a selection see if we grabbed one of the selection handles
if (mySel !== null && !isResizeDrag) {
for (var i = 0; i < 9; i++) {
// 0 1 2
// 3 4
// 5 6 7
var cur = selectionHandles[i];
// we dont need to use the ghost context because
// selection handles will always be rectangles
if (mx >= cur.x && mx <= cur.x + mySelBoxSize && my >= cur.y
&& my <= cur.y + mySelBoxSize) {
// we found one!
expectResize = i;
invalidate();
switch (i) {
case 0:
canvas.style.cursor = 'nw-resize';
break;
case 1:
canvas.style.cursor = 'n-resize';
break;
case 2:
canvas.style.cursor = 'ne-resize';
break;
case 3:
canvas.style.cursor = 'w-resize';
break;
case 4:
canvas.style.cursor = 'e-resize';
break;
case 5:
canvas.style.cursor = 'sw-resize';
break;
case 6:
canvas.style.cursor = 's-resize';
break;
case 7:
canvas.style.cursor = 'se-resize';
break;
case 8:
canvas.style.cursor = 'no-drop';
break;
}
return;
}
}
// not over a selection box, return to normal
isResizeDrag = false;
expectResize = -1;
canvas.style.cursor = 'auto';
}
}
// Happens when the mouse is clicked in the canvas
function handleMouseDownTerm(e) {
if (!stampImage) {
return;
}
getMouse(e);
if(imgStampSelect !== undefined){
addRect(mx, my, 50, 50, 'rgba(0,205,0,0.7)', imgStampSelect);
imgStampSelect = undefined;
}
if (mySel !== null && !isResizeDrag) {
for (var i = 0; i < 9; i++) {
// 0 1 2
// 3 4
// 5 6 7
var cur = selectionHandles[i];
// we dont need to use the ghost context because
// selection handles will always be rectangles
if (mx >= cur.x && mx <= cur.x + mySelBoxSize && my >= cur.y
&& my <= cur.y + mySelBoxSize) {
// we found one!
expectResize = i;
invalidate();
switch (i) {
case 0:
canvas.style.cursor = 'nw-resize';
break;
case 1:
canvas.style.cursor = 'n-resize';
break;
case 2:
canvas.style.cursor = 'ne-resize';
break;
case 3:
canvas.style.cursor = 'w-resize';
break;
case 4:
canvas.style.cursor = 'e-resize';
break;
case 5:
canvas.style.cursor = 'sw-resize';
break;
case 6:
canvas.style.cursor = 's-resize';
break;
case 7:
canvas.style.cursor = 'se-resize';
break;
case 8:
canvas.style.cursor = 'no-drop';
break;
}
}
}
}
var l = boxes2.length;
// we are over a selection box
if (expectResize == 8) {
for (var i = l - 1; i >= 0; i--) {
if (boxes2[i].x === mySel.x && boxes2[i].y === mySel.y) {
boxes2.splice(i, 1);
continue;
}
}
e.preventDefault();
e.stopPropagation();
// isResizeDrag = true;
clearGhost(gctx);
invalidate();
return;
}
if (expectResize !== -1) {
e.preventDefault();
e.stopPropagation();
isResizeDrag = true;
return;
}
clearGhost(gctx);
for (var i = l - 1; i >= 0; i--) {
// draw shape onto ghost context
boxes2[i].draw(gctx, 'black');
// get image data at the mouse x,y pixel
var imageData = gctx.getImageData(mx, my, 1, 1);
// var index = (mx + my * imageData.width) * 4;
// if the mouse pixel exists, select and break
if (imageData.data[3] > 0) {
mySel = boxes2[i];
offsetx = mx - mySel.x;
offsety = my - mySel.y;
mySel.x = mx - offsetx;
mySel.y = my - offsety;
isDrag = true;
e.preventDefault();
e.stopPropagation();
invalidate();
return;
}
}
// havent returned means we have selected nothing
mySel = null;
// clear the ghost canvas for next time
clearGhost(gctx);
// invalidate because we might need the selection border to disappear
invalidate();
}
function handleMouseUpTerm() {
if (!stampImage)
return;
isDrag = false;
isResizeDrag = false;
expectResize = -1;
invalidate();
}
function handleMouseOutTerm(e) {
if (!stampImage) {
return;
}
isDrag = false;
isResizeDrag = false;
invalidate();
}
function invalidate() {
canvasValid = false;
}
// Sets mx,my to the mouse position relative to the canvas
// unfortunately this can be tricky, we have to worry about padding and borders
function getMouse(e) {
if (e.type == 'touchmove' || e.type == 'touchstart' || e.type == 'touchend') {
positionX = e.originalEvent.touches[0].pageX;
positionY = e.originalEvent.touches[0].pageY;
} else {
positionX = e.clientX;
positionY = e.clientY;
}
mx = positionX - offsetX + scrollX;
my = positionY - offsetY + scrollY;
}
$(document).on('click', '.blurImage', function(e) {
clearSelection();
active($(this));
access_blur = true;
imgStampSelect = undefined;
termImage = false;
stampImage = false;
disable(".stampImage");
term_active = false;
$(".listTerms").hide();
if (mySel != null) {
mySel = null;
// clear the ghost canvas for next time
clearGhost(gctx);
// invalidate because we might need the selection border to disappear
invalidate();
}
});
var term_active = false;
$(document).on('click', '.stampImage', function(e) {
clearSelection();
stampImage = true;
disable(".blurImage");
access_blur = false;
init2();
active($(this));
if(!term_active){
$(".listTerms").show();
}else{
$(".listTerms").hide();
}
term_active = !term_active;
e.preventDefault();
});
var imgStampSelect = undefined ;
var dragImage = false;
$(document).on('mousedown', '.listTerms img', function() {
dragImage = true;
imgStampSelect = $(this).attr("src");
stampImage = true;
term_active = false;
$(".listTerms").hide();
});
function clearSelection() {
if(document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}
function active(selector) {
$(selector).removeClass("red").addClass("blue");
}
function disable(selector) {
$(selector).removeClass("blue").addClass("red");
}