Blame view

app/scripts/controllers/tshirtdesign.js 16 KB
6f105dbd5   Truong LD   add source code i...
1
  define(['app'], function (app) {
2f4c31749   DANG   Fix text design a...
2
  	app.controller('TshirtdesignCtrl', function ($scope, $rootScope, $window, $timeout, $illustration) {
6f105dbd5   Truong LD   add source code i...
3
  		var canvas = new fabric.Canvas('main-design-container');
2f4c31749   DANG   Fix text design a...
4
  		//Set width and height canvas
360081503   DANG   Fix reponsive
5
  		function setSizeCanvas() {
4ae9cc634   DANG   fix reponsive
6
7
  			if(typeof $rootScope.placeTshirt.place == 'undefined')
  				return;
360081503   DANG   Fix reponsive
8
9
  			var _modalWidth = $('.modal-dialog').width();
  			var _windowWidth = window.innerWidth;
4ae9cc634   DANG   fix reponsive
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
  			var place = $rootScope.placeTshirt.place;
  
  			switch (place) {
  				case 't_shirt_p_1' :
  					$scope.designCanvasClass = 'design-content-t_shirt_p_1';
  					if(_windowWidth > 762) {
  						var _contentCanvasWidth = (_modalWidth*8/12)/1.2;
  						var _contentCanvasHeight = _contentCanvasWidth;
  					} else {
  						var _contentCanvasWidth = _windowWidth-70;
  						var _contentCanvasHeight = _contentCanvasWidth;
  					}
  					break;
  				case 't_shirt_p_2' :
  					$scope.designCanvasClass = 'design-content-t_shirt_p_2';
  					if(_windowWidth > 762) {
  						var _contentCanvasWidth = (_modalWidth*8/12)/1.2;
  						var _contentCanvasHeight = (_modalWidth*8/12)/2.2;
  
  					} else {
  						var _contentCanvasWidth = _windowWidth-70;
  						var _contentCanvasHeight = (_windowWidth)/2.5;
  					}
  					break;
  				default:
  					break;
360081503   DANG   Fix reponsive
36
37
38
  			}
  
  			canvas.setWidth(_contentCanvasWidth);
4ae9cc634   DANG   fix reponsive
39
  			canvas.setHeight(_contentCanvasHeight);
2f4c31749   DANG   Fix text design a...
40
  		}
360081503   DANG   Fix reponsive
41
42
43
44
45
  		setSizeCanvas();
  		//Window resize event
  		$(window).resize(function () {
  			setSizeCanvas();
  		});
2f4c31749   DANG   Fix text design a...
46
  		//Custom control
21a01f6ac   Dang YoungWorld   fix bug action "O...
47
  		fabric.Object.prototype.transparentCorners = true;
cc65fa102   DANG   Custom control
48
  		fabric.Object.prototype.hasRotatingPoint = false;
e6cd2bf54   DANG   update version
49

cc65fa102   DANG   Custom control
50
51
52
53
  		var ctrVisible = {tl: false, ml:false, bl:false, mb: false, br: true, mr: false, tr: true, mt: true, mtr: false};
  		for(key in ctrVisible) {
  			fabric.Object.prototype.setControlVisible(key,ctrVisible[key]);
  		}
e6cd2bf54   DANG   update version
54

cc65fa102   DANG   Custom control
55
56
57
58
59
60
61
62
63
  		fabric.Object.prototype.customiseCornerIcons({
  			settings: {
  				borderColor: '#0000ff',
  				cornerSize: 25,
  				cornerShape: 'circle',
  				cornerBackgroundColor: '#0171b4',
  				cornerPadding: 6
  			},
  			mt: {
39a1e279b   DANG   update
64
  				icon: 'images/control-icon/ok.png'
cc65fa102   DANG   Custom control
65
66
67
68
69
70
71
72
73
74
75
76
  			},
  			br: {
  				icon: 'images/control-icon/resize.png'
  			},
  			tr: {
  				icon: 'images/control-icon/rotate.png'
  			}
  		});
  
  		fabric.Canvas.prototype.customiseControls({
  			mt: {
  				cursor: 'pointer',
2f4c31749   DANG   Fix text design a...
77
  				action: function(e, target) {
21a01f6ac   Dang YoungWorld   fix bug action "O...
78
79
  					fabric.Object.prototype.selectable = false;
  					canvas.deactivateAll();
360081503   DANG   Fix reponsive
80
81
  					delete currentObj;
  					$scope.designTextValue = '';
21a01f6ac   Dang YoungWorld   fix bug action "O...
82
83
84
  					$timeout(function(){
  						fabric.Object.prototype.selectable = true;
  					},20);
cc65fa102   DANG   Custom control
85
86
87
88
89
90
91
92
93
94
  				}
  			},
  			br: {
  
  			},
  			tr: {
  				action: 'rotate',
  				cursor: 'crosshair'
  			}
  		});
6f105dbd5   Truong LD   add source code i...
95

6f105dbd5   Truong LD   add source code i...
96
  		canvas.on({
92271fd7c   DANG   add event
97
  			'object:added'      : onIllustrationAdded,
c3bee6bb3   TRUONG   fix trash icon ef...
98
  			'object:moving'     : onIllustrationMoving,
92271fd7c   DANG   add event
99
100
101
102
103
  			'object:scaling'    : onIllustrationChange,
  			'object:rotating'   : onIllustrationChange,
  			'object:selected'   : onObjectSelected,
  			'object:modified'   : onIllustrationModifield,
  			'selection:cleared' : onObjectOut,
6f105dbd5   Truong LD   add source code i...
104
  		});
aff3eb043   TRUONG   update illustrati...
105
106
107
108
109
110
111
112
  		
  		var currentObj;
  		var listObj = [];
  		var stateObj = [];
  		var indexCurr = 0;
  		var indexCurr2 = 0;
  		var actionObj = false;
  		var refreshObj = true;
92271fd7c   DANG   add event
113
  		var spacingNum = 0;
2f4c31749   DANG   Fix text design a...
114
  		$scope.itemFont = 0;
cc65fa102   DANG   Custom control
115

2f4c31749   DANG   Fix text design a...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
  		$scope.showDesignTab = function(tab){
  			canvas.deactivateAll().renderAll();
  			$rootScope.isShowLeftPanel = tab;
  			switch (tab) {
  				case 'illustration': {
  					$scope.IllustrationList = $illustration.getAll();
  					$rootScope.outputImage = false;
  					$scope.illustrationSelectConfig = {
  						allowClear:true
  					};
  					$timeout(function(){
  						$('.illstration-item').tooltip({
  							animated: 'fade',
  							placement: 'bottom',
  							html: true
  						});
2f4c31749   DANG   Fix text design a...
132
133
134
135
136
137
138
139
140
  					},1000);
  					break;
  				}
  				case 'text': {
  					break;
  				}
  			}
  		};
  		$scope.showDesignTab('default');
cc65fa102   DANG   Custom control
141

aff3eb043   TRUONG   update illustrati...
142
143
144
  		
  		function onIllustrationAdded(options){
  			var object = options.target;
aff3eb043   TRUONG   update illustrati...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
  		
  		    if (actionObj === true) {
  		        stateObj = [stateObj[indexCurr2]];
  		        listObj = [listObj[indexCurr2]];
  		
  		        actionObj = false;
  		        console.log(stateObj);
  		        indexCurr = 1;
  		    }
  		    object.saveState();
  		
  		    console.log(object.originalState);
  		    stateObj[indexCurr] = JSON.stringify(object.originalState);
  		    listObj[indexCurr] = object;
  		    indexCurr++;
  		    indexCurr2 = indexCurr - 1;
  		    refreshObj = true;
  		}
  		
1d6ddfa62   TRUONG   merge
164
  		function onIllustrationModifield(options){
d7aae10e2   TRUONG   update fix delete...
165
  			$('.object-border').hide();
c3bee6bb3   TRUONG   fix trash icon ef...
166
167
168
169
  			//
  		    var pointer = canvas.getPointer(options.e);
  			if (pointer.x >= 567 && pointer.y >= 620 && pointer.x <= 600 && pointer.y <= 670){
  				canvas.getActiveObject().remove();
3ab3e50f8   TRUONG   update, fix trash...
170
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
171
172
173
174
  				return;
  			}
  			
  			//
aff3eb043   TRUONG   update illustrati...
175
  			var objOffset = canvas.getActiveObject().getBoundingRect();
c3bee6bb3   TRUONG   fix trash icon ef...
176
  			var cH = canvas.height, cW = canvas.width, H0 = 20, W0 = 20;
1d6ddfa62   TRUONG   merge
177
  			//console.log(objOffset,canvas.height,canvas.width);
aff3eb043   TRUONG   update illustrati...
178
179
180
181
182
183
184
185
186
187
  			if (objOffset.left<W0-objOffset.width || objOffset.left>cW-W0 || objOffset.top<H0-objOffset.height || objOffset.top>cH-H0){
  				if (confirm('削除してもよろしいですか')){
  					canvas.getActiveObject().remove();
  				}else{
  					undoCanvas();
  					return;
  				}
  			}
  			
  			var object = options.target;
aff3eb043   TRUONG   update illustrati...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
  		    if (actionObj === true) {
  		        stateObj = [stateObj[indexCurr2]];
  		        listObj = [listObj[indexCurr2]];
  		
  		        actionObj = false;
  		        console.log(stateObj);
  		        indexCurr = 1;
  		    }
  		
  		    object.saveState();
  		
  		    stateObj[indexCurr] = JSON.stringify(object.originalState);
  		    listObj[indexCurr] = object;
  		    indexCurr++;
  		    indexCurr2 = indexCurr - 1;
aff3eb043   TRUONG   update illustrati...
203
204
205
  		    refreshObj = true;
  		}
  		
6f105dbd5   Truong LD   add source code i...
206
  		function onIllustrationChange(options) {
e872619e5   Dang YoungWorld   delete comment
207

6f105dbd5   Truong LD   add source code i...
208
  		}
c3bee6bb3   TRUONG   fix trash icon ef...
209
210
  		
  		function onIllustrationMoving(options) {
d7aae10e2   TRUONG   update fix delete...
211
  			var object = options.target;
c3bee6bb3   TRUONG   fix trash icon ef...
212
213
  			var pointer = canvas.getPointer(options.e);
  			if (pointer.x >= 567 && pointer.y >= 620 && pointer.x <= 600 && pointer.y <= 670){
3ab3e50f8   TRUONG   update, fix trash...
214
  				$('.design-content .trash-design img').attr({'src':'images/trash-hover.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
215
  			}else{
3ab3e50f8   TRUONG   update, fix trash...
216
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
217
  			}
d7aae10e2   TRUONG   update fix delete...
218
219
220
221
222
  			
  			console.log(object.oCoords,object.originalState);
  			object.setCoords();
  			var Coords = object.oCoords;
  			var diffX = 55, diffY=50;
c674a3608   TRUONG   fix delete effect
223
224
225
226
227
228
  			var xAngle = Math.cos(object.getAngle() * (Math.PI / 180))/2;
  			var yAngle = Math.sin(object.getAngle() * (Math.PI / 180))/2;
  			$('#object-border-left').css({'height':Math.ceil(object.originalState.height*object.scaleY), top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-right').css({'height':Math.ceil(object.originalState.height*object.scaleY), top: Coords.tr.y+diffY, left: Coords.tr.x+diffX});
  			$('#object-border-top').css({'width':Math.ceil(object.originalState.width*object.scaleX), top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-bottom').css({'width':Math.ceil(object.originalState.width*object.scaleX), top: Coords.bl.y+diffY, left: Coords.bl.x+diffX});
d7aae10e2   TRUONG   update fix delete...
229
230
231
232
233
234
  			$('.object-border').css({
  				'-ms-transform': 'rotate('+object.getAngle()+'deg)', /* IE 9 */
      			'-webkit-transform': 'rotate('+object.getAngle()+'deg)', /* Safari */
      			'transform': 'rotate('+object.getAngle()+'deg)' /* Standard syntax */
  			});
  			$('.object-border').show();
c3bee6bb3   TRUONG   fix trash icon ef...
235
  		}
6f105dbd5   Truong LD   add source code i...
236

92271fd7c   DANG   add event
237
238
239
  		function onObjectOut() {
  			delete currentObj;
  			$scope.designTextValue = '';
aff3eb043   TRUONG   update illustrati...
240
  		}
6f105dbd5   Truong LD   add source code i...
241

aff3eb043   TRUONG   update illustrati...
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
  		function undoCanvas() {
  		    if (indexCurr <= 0) {
  		        indexCurr = 0;
  		        return;
  		    }
  		
  		    if (refreshObj === true) {
  		        indexCurr--;
  		        refreshObj = false;
  		    }
  		
  		    console.log('undo');
  		
  		    indexCurr2 = indexCurr - 1;
  		    currentObj = listObj[indexCurr2];
  		    if (currentObj){
  		    	currentObj.setOptions(JSON.parse(indexCurr[indexCurr2]));
  		    }
  		
  		    indexCurr--;
  		    currentObj.setCoords();
  		    canvas.renderAll();
  		    actionObj = true;
  		}
  		
  		function redoCanvas() {
  		    actionObj = true;
  		    if (indexCurr >= stateObj.length - 1) {
  		        return;
  		    }
  		
  		    console.log('redo');
  		
  		    indexCurr2 = indexCurr + 1;
  		    currentObj = listObj[indexCurr2];
  		    currentObj.setOptions(JSON.parse(indexCurr[indexCurr2]));
  		
  		    indexCurr++;
  		    currentObj.setCoords();
  		    canvas.renderAll();
6f105dbd5   Truong LD   add source code i...
282
  		}
80ff9bbd4   TRUONG   fix bugs and optimal
283
284
  		
  		$scope.canvasClearAll = function(){
60b61386b   TRUONG   fix text
285
  			if (confirm('配置されたすべての文字や画像を消去します')){
80ff9bbd4   TRUONG   fix bugs and optimal
286
287
288
  				canvas.clear();
  			}
  		}
92271fd7c   DANG   add event
289
290
291
  
  		function onObjectSelected(options) {
  			var currentObj = options.target;
2f4c31749   DANG   Fix text design a...
292

92271fd7c   DANG   add event
293
  			$scope.typeObject = currentObj.type;
c8bfdfd96   DANG   event click object
294
295
  			switch ($scope.typeObject) {
  				case 'i-text' :
c8bfdfd96   DANG   event click object
296
  					$rootScope.isShowLeftPanel = 'text';
92271fd7c   DANG   add event
297
298
299
300
301
  					var text = currentObj.text;
  					if(text != '') {
  						$scope.designText = text;
  						$scope.designTextValue = text;
  					}
c8bfdfd96   DANG   event click object
302
303
304
305
306
  					break;
  
  				case 'path-group' :
  					$rootScope.isShowLeftPanel = 'illustration';
  					break;
e5669639a   TRUONG   merge #1759
307
308
309
310
  					
  				case 'image':
  					$rootScope.isShowLeftPanel = 'image';
  					break;
c8bfdfd96   DANG   event click object
311
312
313
314
315
316
  
  				default :
  					$rootScope.isShowLeftPanel = 'default';
  					break;
  			}
  			$rootScope.safeApply();
6f105dbd5   Truong LD   add source code i...
317
318
319
320
321
  		}
  
  		// Illustration process
  		$scope.changeIllustrationCategory = function(currentIllustration){
  			$scope.currentIllustrationCate = $illustration.getList(currentIllustration);
422e7837d   DANG   Change color t-shirt
322
  		};
6f105dbd5   Truong LD   add source code i...
323
324
325
326
  
  		$scope.insertSvg = function(item){
  			fabric.loadSVGFromURL(item.path, function(objects, options) {
  				var shape = fabric.util.groupSVGElements(objects, options);
6f105dbd5   Truong LD   add source code i...
327
328
329
330
331
  				canvas.add(shape.scale(0.6));
  				shape.set({ left: 150, top: 200 }).setCoords();
  				canvas.renderAll();
  				canvas.setActiveObject(shape);
  			});
422e7837d   DANG   Change color t-shirt
332
  		};
6f105dbd5   Truong LD   add source code i...
333
334
  
  		// color pattern
6f105dbd5   Truong LD   add source code i...
335
  		$scope.listColorPatterns = [
aff3eb043   TRUONG   update illustrati...
336
337
338
339
  			'#000000','#ffff00','#ff6600','#ff0000','#ff6262','#ffa19c','#ff9933','#c45d01','#5d2b03','#ffffcc',
  			'#ffff99','#ffd500','#c0db50','#21a52a','#00663f','#abfcab','#36ffaa','#89eaea','#00938c','#005450',
  			'#0badff','#006cff','#839aff','#0410a0','#ffb2ff','#f93fff','#6600ca','#ff6699','#999999','#666666',
  			'#333333'
422e7837d   DANG   Change color t-shirt
340
  		];
80ff9bbd4   TRUONG   fix bugs and optimal
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
  		
  		$scope.changeColorPattern = function(color){
  			var obj = canvas.getActiveObject();
  			if (!color){
  				color = 'none';
  			}
  			if (obj instanceof fabric.PathGroup) {
  			  obj.getObjects().forEach(function(o) {
  			  	o.fill = color;
  			  });
  			}
  			else {
  			  obj.fill = color;
  			}
  			canvas.renderAll();
80ff9bbd4   TRUONG   fix bugs and optimal
356
357
  		};
  		
04cbb68af   DANG   design text basic
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
  		//Font
  		$scope.listFontFamily = [
  			{
  				name : 'GN Aki iro Sesami Cookies',
  				slug : 'gn_aki_iro_sesami_cookies',
  			},
  			{
  				name : 'GN-Fuyu-iro_Script_Bold',
  				slug : 'gn_fuyu_iro_script_bold'
  			},
  			{
  				name : 'GN Killgothic U Kanana',
  				slug : 'gn_killgothic_u_kanana'
  			},
  			{
  				name : 'GN-Kin-iro_Alphabet_Cookies',
  				slug : 'gn_kin_iro_alphabet_cookies'
  
  			},
  			{
  				name : 'GN-Kin-iro_SansSerif',
  				slug : 'gn_kin_iro_sansserif'
  
  			},
  			{
  				name : 'GN-Koharuiro_Sunray',
  				slug : 'gn_koharuiro_sunray'
  
  			},
  			{
  				name : 'GN-Kyu-pin',
  				slug : 'gn_kyu_pin'
  			},
  			{
  				name : 'gn_natsu_iro_schedule',
  				slug : 'gn_natsu_iro_schedule'
  
  			},
  			{
  				name : 'gnkana_kiniro_sansserif_l',
  				slug : 'gnkana_kiniro_sansserif_l'
  
  			},
  			{
  				name : 'gnkana_kiniro_sansserif_st',
  				slug : 'gnkana_kiniro_sansserif_st'
  			},
  			{
  				name : 'gnkana_kon_iro_nightfall',
  				slug : 'gnkana_kon_iro_nightfall'
  
  			},
  			{
  				name : 'ms_gothic',
  				slug : 'ms_gothic'
  
  			},
  			{
  				name : 'msmincho',
  				slug : 'msmincho'
  			},
  			{
  				name : 'ufonts_com_ms_pgothic',
  				slug : 'ufonts_com_ms_pgothic'
  			}
  		];
682a3b12d   TRUONG   fix illustration ...
424
  		
682a3b12d   TRUONG   fix illustration ...
425
  		// layer process
92271fd7c   DANG   add event
426
427
428
  		$scope.layerProcess = function(mode) {
  			// console.log('layerProcess');
  			var activeObject = canvas.getActiveObject();
682a3b12d   TRUONG   fix illustration ...
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
  			if (activeObject){
  				switch (mode) {
  					case 1:
  						activeObject.bringForward();
  						break;
  					case 2:
  						activeObject.sendBackwards();
  						break;
  					case 3:
  						activeObject.bringToFront();
  						break;
  					case 4:
  						activeObject.sendToBack();
  						break;
  				}
e0ee74c15   TRUONG   update fix layer ...
444
  				canvas.deactivateAll().renderAll();
682a3b12d   TRUONG   fix illustration ...
445
  			}
04cbb68af   DANG   design text basic
446
  		};
422e7837d   DANG   Change color t-shirt
447

92271fd7c   DANG   add event
448
449
450
  		$scope.focusInputText = function(text) {
  			currentObj = canvas.getActiveObject();
  			if(typeof currentObj == 'undefined' || currentObj == null) {
ba689b493   DANG   canvas font text
451
452
453
  				$scope.iText = new fabric.IText('', {
  					left: 150,
  					top: 200,
ee675eec1   DANG   Update font
454
  					fontFamily: typeof $scope.itemFont != 'undefined' ? $scope.listFontFamily[$scope.itemFont].slug : $scope.listFontFamily[0].slug,
ba689b493   DANG   canvas font text
455
  					fontWeight: 'normal',
92271fd7c   DANG   add event
456
  					textAlign:  'center',
ba689b493   DANG   canvas font text
457
  					fontSize: 28,
83f7186e9   DANG   fix bug reponsive
458
459
  					fill: 'black',
  					editable: false
ba689b493   DANG   canvas font text
460
  				});
92271fd7c   DANG   add event
461
462
463
464
465
  			} else {
  				if(currentObj.type != 'i-text') {
  					$scope.iText = new fabric.IText('', {
  						left: 150,
  						top: 200,
ee675eec1   DANG   Update font
466
  						fontFamily: typeof $scope.itemFont != 'undefined' ? $scope.listFontFamily[$scope.itemFont].slug : $scope.listFontFamily[0].slug,
92271fd7c   DANG   add event
467
468
469
  						fontWeight: 'normal',
  						textAlign:  'center',
  						fontSize: 28,
83f7186e9   DANG   fix bug reponsive
470
471
  						fill: 'black',
  						editable: false
92271fd7c   DANG   add event
472
473
474
475
476
  					});
  				} else{
  					$scope.iText = currentObj;
  				}
  			}
c8bfdfd96   DANG   event click object
477
  		};
422e7837d   DANG   Change color t-shirt
478

98acd3acd   DANG   Change text
479
480
  		//Design text
  		$scope.inputText = function(e) {
92271fd7c   DANG   add event
481
482
  			if(typeof $scope.iText != "undefined") {
  				var iText = $scope.iText;
ba689b493   DANG   canvas font text
483
  				iText.text = e;
ba689b493   DANG   canvas font text
484
485
486
487
  				canvas.add(iText);
  				canvas.renderAll();
  				canvas.setActiveObject(iText);
  			}
c8bfdfd96   DANG   event click object
488
  		};
2f4c31749   DANG   Fix text design a...
489
490
  		$scope.setFontFamily = function(font,index) {
  			$scope.itemFont = index;
ba689b493   DANG   canvas font text
491
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
492
493
494
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					currentObj.set('fontFamily', font);
ba689b493   DANG   canvas font text
495
  					canvas.renderAll();
92271fd7c   DANG   add event
496
  					canvas.setActiveObject(currentObj);
ba689b493   DANG   canvas font text
497
498
499
  				}
  
  			}
04cbb68af   DANG   design text basic
500
501
  		};
  		//Set letter spacing text
04cbb68af   DANG   design text basic
502
503
  		$scope.setLetterSpacingText = function(e) {
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
504
505
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
04cbb68af   DANG   design text basic
506
507
  					if(e == 'plus')
  						spacingNum = spacingNum + 30;
2f4c31749   DANG   Fix text design a...
508
  					else if (spacingNum >= -30){
04cbb68af   DANG   design text basic
509
510
  						spacingNum = spacingNum - 30;
  					}
83f7186e9   DANG   fix bug reponsive
511
512
  					if(e == 'default')
  						spacingNum = 0;
2f4c31749   DANG   Fix text design a...
513

2f4c31749   DANG   Fix text design a...
514
515
516
517
518
519
  					currentObj.set('charSpacing', spacingNum);
  					canvas.renderAll();
  					canvas.setActiveObject(currentObj);
  				}
  			}
  		};
e5669639a   TRUONG   merge #1759
520
521
522
  		
  		
  		/**** process insert image */
bd0414901   TRUONG   update store rece...
523
524
525
526
527
  		if (typeof($window.localStorage.recentImages) != 'undefined'){
  			$scope.recentImages = JSON.parse($window.localStorage.recentImages);
  		}else{
  			$scope.recentImages = {};
  		}
2f4c31749   DANG   Fix text design a...
528

bd0414901   TRUONG   update store rece...
529
530
531
532
533
534
  		var addToRecentImage = function(name, data){
  			if (typeof($window.localStorage.recentImages) != 'undefined'){
  				$scope.recentImages = JSON.parse($window.localStorage.recentImages);
  			}else{
  				$scope.recentImages = {};
  			}
2f4c31749   DANG   Fix text design a...
535

bd0414901   TRUONG   update store rece...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
  			if (typeof($scope.recentImages[name]) == 'undefined'){
  				var ii=0;
  				var II = 0;
  				for(var item in $scope.recentImages){
  					if (II==0){
  						II = item;
  					}
  					ii++;
  				}
  				if (ii>16 && II!=0){
  					delete $scope.recentImages[II];
  				}
  				$scope.recentImages[name] = data;
  				$window.localStorage.recentImages = JSON.stringify($scope.recentImages);
  			}
  		}
  		$scope.chooseImage = function(e){//console.log(e);
0181c19ff   TRUONG   fix bugs and opti...
553
  			if (e.target.files[0] && e.target.files[0].size > 5*1024*1024){
60b61386b   TRUONG   fix text
554
  				alert('アップロードできませんでした');
0181c19ff   TRUONG   fix bugs and opti...
555
556
  				return;
  			}
e5669639a   TRUONG   merge #1759
557
  			var reader = new FileReader();
0181c19ff   TRUONG   fix bugs and opti...
558
  		    reader.onload = function (event) {
bd0414901   TRUONG   update store rece...
559
560
  		    	addToRecentImage ($('#imgLoader').val(), event.target.result);
  		        var imgObj = new Image();//console.log($('#imgLoader').val());
e5669639a   TRUONG   merge #1759
561
562
563
564
565
566
567
568
569
  		        imgObj.src = event.target.result;
  		        imgObj.onload = function () {
  		            // start fabricJS stuff
  		            
  		            var image = new fabric.Image(imgObj);
  		            image.set({
  		                left: 50,
  		                top: 50
  		            });
2f4c31749   DANG   Fix text design a...
570
  		            //image.scale(getRandomNum(0.1, 0.25)).setCoords();
e5669639a   TRUONG   merge #1759
571
572
573
574
575
576
  		            image.scaleToWidth(200);
  		            canvas.add(image);
  		        }
  		    }
      		reader.readAsDataURL(e.target.files[0]);
  		}
2f4c31749   DANG   Fix text design a...
577

bd0414901   TRUONG   update store rece...
578
579
580
581
582
  		$scope.insertRecentImage = function(data){
  	        var imgObj = new Image();
  	        imgObj.src = data;
  	        imgObj.onload = function () {
  	            // start fabricJS stuff
2f4c31749   DANG   Fix text design a...
583

bd0414901   TRUONG   update store rece...
584
585
586
587
588
589
590
591
592
  	            var image = new fabric.Image(imgObj);
  	            image.set({
  	                left: 50,
  	                top: 50
  	            });
  	            image.scaleToWidth(200);
  	            canvas.add(image);
  	        }
  		}
2f4c31749   DANG   Fix text design a...
593

92271fd7c   DANG   add event
594
595
596
597
598
599
600
601
602
603
604
  		//Traslation text
  		$scope.rotateText =  function(style) {
  			if(canvas.getActiveObject()) {
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					currentObj.set('rotate', Math.PI / 4);
  					canvas.renderAll();
  					canvas.setActiveObject(currentObj);
  				}
  			}
  		};
80ff9bbd4   TRUONG   fix bugs and optimal
605
606
607
608
609
610
611
612
  		
  		
  		/* Process output */
  		$scope.outputDesign = function(){
  			$rootScope.outputImage = canvas.toDataURL('png');
  			// console.log();
  			$('#tshirt-design').modal('hide');
  		}
6f105dbd5   Truong LD   add source code i...
613
614
  	});
  });