Blame view

app/scripts/controllers/tshirtdesign.js 16.2 KB
6f105dbd5   Truong LD   add source code i...
1
  define(['app'], function (app) {
c8bfdfd96   DANG   event click object
2
  	//'use strict';
2f4c31749   DANG   Fix text design a...
3
  	app.controller('TshirtdesignCtrl', function ($scope, $rootScope, $window, $timeout, $illustration) {
6f105dbd5   Truong LD   add source code i...
4

6f105dbd5   Truong LD   add source code i...
5
  		var canvas = new fabric.Canvas('main-design-container');
2f4c31749   DANG   Fix text design a...
6
7
8
9
10
11
12
13
  		//Set width and height canvas
  		var _modalWidth = $('.modal-dialog').width();
  		var _windowWidth = window.innerWidth;
  		if(_windowWidth > 762) {
  			var _contentCanvasWidth = _modalWidth*8/12 - 100;
  		} else {
  			var _contentCanvasWidth = _windowWidth-70;
  		}
39a1e279b   DANG   update
14
  		console.log(canvas);
2f4c31749   DANG   Fix text design a...
15
16
  		canvas.setWidth(_contentCanvasWidth);
  		canvas.setHeight(650);
39a1e279b   DANG   update
17
18
19
  		canvas._onMouseDown = function () {
  			alert('in mouse up');
  		};
2f4c31749   DANG   Fix text design a...
20
  		//Custom control
21a01f6ac   Dang YoungWorld   fix bug action "O...
21
  		fabric.Object.prototype.transparentCorners = true;
cc65fa102   DANG   Custom control
22
  		fabric.Object.prototype.hasRotatingPoint = false;
21a01f6ac   Dang YoungWorld   fix bug action "O...
23
  		// fabric.Object.prototype.selectable = false;
e6cd2bf54   DANG   update version
24
25
26
27
  
  		// fabric.Canvas.prototype.__onMouseDown = function (e) {
  		// 	// return false;
  		// };
cc65fa102   DANG   Custom control
28
29
30
31
  		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
32

cc65fa102   DANG   Custom control
33
34
35
36
37
38
39
40
41
  		fabric.Object.prototype.customiseCornerIcons({
  			settings: {
  				borderColor: '#0000ff',
  				cornerSize: 25,
  				cornerShape: 'circle',
  				cornerBackgroundColor: '#0171b4',
  				cornerPadding: 6
  			},
  			mt: {
39a1e279b   DANG   update
42
  				icon: 'images/control-icon/ok.png'
cc65fa102   DANG   Custom control
43
44
45
46
47
48
49
50
51
52
53
54
  			},
  			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...
55
  				action: function(e, target) {
21a01f6ac   Dang YoungWorld   fix bug action "O...
56
57
58
59
60
  					fabric.Object.prototype.selectable = false;
  					canvas.deactivateAll();
  					$timeout(function(){
  						fabric.Object.prototype.selectable = true;
  					},20);
cc65fa102   DANG   Custom control
61
62
63
64
65
66
67
68
69
70
  				}
  			},
  			br: {
  
  			},
  			tr: {
  				action: 'rotate',
  				cursor: 'crosshair'
  			}
  		});
6f105dbd5   Truong LD   add source code i...
71
72
  
  		canvas.on('after:render', function() {
0181c19ff   TRUONG   fix bugs and opti...
73
  			// console.log('after render');
6f105dbd5   Truong LD   add source code i...
74
75
  		});
  		canvas.on({
92271fd7c   DANG   add event
76
  			'object:added'      : onIllustrationAdded,
c3bee6bb3   TRUONG   fix trash icon ef...
77
  			'object:moving'     : onIllustrationMoving,
92271fd7c   DANG   add event
78
79
80
81
82
  			'object:scaling'    : onIllustrationChange,
  			'object:rotating'   : onIllustrationChange,
  			'object:selected'   : onObjectSelected,
  			'object:modified'   : onIllustrationModifield,
  			'selection:cleared' : onObjectOut,
6f105dbd5   Truong LD   add source code i...
83
  		});
aff3eb043   TRUONG   update illustrati...
84
85
86
87
88
89
90
91
  		
  		var currentObj;
  		var listObj = [];
  		var stateObj = [];
  		var indexCurr = 0;
  		var indexCurr2 = 0;
  		var actionObj = false;
  		var refreshObj = true;
92271fd7c   DANG   add event
92
  		var spacingNum = 0;
2f4c31749   DANG   Fix text design a...
93
  		$scope.itemFont = 0;
cc65fa102   DANG   Custom control
94

2f4c31749   DANG   Fix text design a...
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
  
  		$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
  						});
  						// console.log('here');
  					},1000);
  					break;
  				}
  				case 'text': {
  					break;
  				}
  			}
  		};
  		$scope.showDesignTab('default');
cc65fa102   DANG   Custom control
122

aff3eb043   TRUONG   update illustrati...
123
124
125
  		
  		function onIllustrationAdded(options){
  			var object = options.target;
0181c19ff   TRUONG   fix bugs and opti...
126
  		    // console.log('object:added');
aff3eb043   TRUONG   update illustrati...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
  		
  		    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
146
  		function onIllustrationModifield(options){
d7aae10e2   TRUONG   update fix delete...
147
  			$('.object-border').hide();
c3bee6bb3   TRUONG   fix trash icon ef...
148
149
150
151
  			//
  		    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...
152
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
153
154
155
156
  				return;
  			}
  			
  			//
aff3eb043   TRUONG   update illustrati...
157
  			var objOffset = canvas.getActiveObject().getBoundingRect();
c3bee6bb3   TRUONG   fix trash icon ef...
158
  			var cH = canvas.height, cW = canvas.width, H0 = 20, W0 = 20;
1d6ddfa62   TRUONG   merge
159
  			//console.log(objOffset,canvas.height,canvas.width);
aff3eb043   TRUONG   update illustrati...
160
161
162
163
164
165
166
167
168
169
  			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;
0181c19ff   TRUONG   fix bugs and opti...
170
  		    // console.log('object:modified');
aff3eb043   TRUONG   update illustrati...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  		    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;
80ff9bbd4   TRUONG   fix bugs and optimal
186
  		    // console.log(stateObj);
aff3eb043   TRUONG   update illustrati...
187
188
189
  		    refreshObj = true;
  		}
  		
6f105dbd5   Truong LD   add source code i...
190
  		function onIllustrationChange(options) {
d75c45c56   Truong LD   remove test showcase
191
192
193
194
195
  			// options.target.setCoords();
  			// canvas.forEachObject(function(obj) {
  			// if (obj === options.target) return;
  			// 	obj.setOpacity(options.target.intersectsWithObject(obj) ? 0.5 : 1);
  			// });
6f105dbd5   Truong LD   add source code i...
196
  		}
c3bee6bb3   TRUONG   fix trash icon ef...
197
198
  		
  		function onIllustrationMoving(options) {
d7aae10e2   TRUONG   update fix delete...
199
  			var object = options.target;
c3bee6bb3   TRUONG   fix trash icon ef...
200
201
  			var pointer = canvas.getPointer(options.e);
  			if (pointer.x >= 567 && pointer.y >= 620 && pointer.x <= 600 && pointer.y <= 670){
3ab3e50f8   TRUONG   update, fix trash...
202
  				$('.design-content .trash-design img').attr({'src':'images/trash-hover.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
203
  			}else{
3ab3e50f8   TRUONG   update, fix trash...
204
  				$('.design-content .trash-design img').attr({'src':'images/trash.png'});
c3bee6bb3   TRUONG   fix trash icon ef...
205
  			}
d7aae10e2   TRUONG   update fix delete...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
  			
  			console.log(object.oCoords,object.originalState);
  			object.setCoords();
  			var Coords = object.oCoords;
  			var diffX = 55, diffY=50;
  			$('#object-border-left').css({'height':object.originalState.height*object.scaleY, top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-right').css({'height':object.originalState.height*object.scaleY, top: Coords.tr.y+diffY, left: Coords.tr.x+diffX});
  			$('#object-border-top').css({'width':object.originalState.width*object.scaleX, top: Coords.tl.y+diffY, left: Coords.tl.x+diffX});
  			$('#object-border-bottom').css({'width':object.originalState.width*object.scaleX, top: Coords.bl.y+diffY, left: Coords.bl.x+diffX});
  			$('.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...
221
  		}
6f105dbd5   Truong LD   add source code i...
222

92271fd7c   DANG   add event
223
224
225
  		function onObjectOut() {
  			delete currentObj;
  			$scope.designTextValue = '';
aff3eb043   TRUONG   update illustrati...
226
  		}
6f105dbd5   Truong LD   add source code i...
227

aff3eb043   TRUONG   update illustrati...
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
  		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...
268
  		}
80ff9bbd4   TRUONG   fix bugs and optimal
269
270
  		
  		$scope.canvasClearAll = function(){
60b61386b   TRUONG   fix text
271
  			if (confirm('配置されたすべての文字や画像を消去します')){
80ff9bbd4   TRUONG   fix bugs and optimal
272
273
274
  				canvas.clear();
  			}
  		}
92271fd7c   DANG   add event
275
276
277
  
  		function onObjectSelected(options) {
  			var currentObj = options.target;
2f4c31749   DANG   Fix text design a...
278

39a1e279b   DANG   update
279

92271fd7c   DANG   add event
280
  			$scope.typeObject = currentObj.type;
c8bfdfd96   DANG   event click object
281
282
  			switch ($scope.typeObject) {
  				case 'i-text' :
c8bfdfd96   DANG   event click object
283
  					$rootScope.isShowLeftPanel = 'text';
92271fd7c   DANG   add event
284
285
286
287
288
  					var text = currentObj.text;
  					if(text != '') {
  						$scope.designText = text;
  						$scope.designTextValue = text;
  					}
c8bfdfd96   DANG   event click object
289
290
291
292
293
  					break;
  
  				case 'path-group' :
  					$rootScope.isShowLeftPanel = 'illustration';
  					break;
e5669639a   TRUONG   merge #1759
294
295
296
297
  					
  				case 'image':
  					$rootScope.isShowLeftPanel = 'image';
  					break;
c8bfdfd96   DANG   event click object
298
299
300
301
302
303
  
  				default :
  					$rootScope.isShowLeftPanel = 'default';
  					break;
  			}
  			$rootScope.safeApply();
6f105dbd5   Truong LD   add source code i...
304
305
306
307
308
  		}
  
  		// Illustration process
  		$scope.changeIllustrationCategory = function(currentIllustration){
  			$scope.currentIllustrationCate = $illustration.getList(currentIllustration);
c8bfdfd96   DANG   event click object
309
  			//console.log($scope.currentIllustrationCate);
422e7837d   DANG   Change color t-shirt
310
  		};
6f105dbd5   Truong LD   add source code i...
311
312
313
314
  
  		$scope.insertSvg = function(item){
  			fabric.loadSVGFromURL(item.path, function(objects, options) {
  				var shape = fabric.util.groupSVGElements(objects, options);
80ff9bbd4   TRUONG   fix bugs and optimal
315
  				//shape.setFill('green');
6f105dbd5   Truong LD   add source code i...
316
317
318
319
320
  				canvas.add(shape.scale(0.6));
  				shape.set({ left: 150, top: 200 }).setCoords();
  				canvas.renderAll();
  				canvas.setActiveObject(shape);
  			});
422e7837d   DANG   Change color t-shirt
321
  		};
6f105dbd5   Truong LD   add source code i...
322
323
  
  		// color pattern
6f105dbd5   Truong LD   add source code i...
324
  		$scope.listColorPatterns = [
aff3eb043   TRUONG   update illustrati...
325
326
327
328
  			'#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
329
  		];
80ff9bbd4   TRUONG   fix bugs and optimal
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  		
  		$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();
  			// if (canvas.getActiveObject()){
  			// 	canvas.getActiveObject().set("fill", color);
  				// canvas.renderAll();
  			// }
  		};
  		
04cbb68af   DANG   design text basic
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
  		//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 ...
417
  		
682a3b12d   TRUONG   fix illustration ...
418
  		// layer process
92271fd7c   DANG   add event
419
420
421
422
423
  		$scope.layerProcess = function(mode) {
  			// console.log('layerProcess');
  			var activeObject = canvas.getActiveObject();
  
  			console.log(activeObject);
682a3b12d   TRUONG   fix illustration ...
424
425
426
  			if (activeObject){
  				switch (mode) {
  					case 1:
92271fd7c   DANG   add event
427
  						// canvas.bringForward(activeObject);
682a3b12d   TRUONG   fix illustration ...
428
429
430
  						activeObject.bringForward();
  						break;
  					case 2:
92271fd7c   DANG   add event
431
  						// canvas.sendBackwards(activeObject);
682a3b12d   TRUONG   fix illustration ...
432
433
434
  						activeObject.sendBackwards();
  						break;
  					case 3:
92271fd7c   DANG   add event
435
  						// canvas.bringToFront(activeObject);
682a3b12d   TRUONG   fix illustration ...
436
437
438
  						activeObject.bringToFront();
  						break;
  					case 4:
92271fd7c   DANG   add event
439
  						// canvas.sendToBack(activeObject);
682a3b12d   TRUONG   fix illustration ...
440
441
442
  						activeObject.sendToBack();
  						break;
  				}
e0ee74c15   TRUONG   update fix layer ...
443
  				canvas.deactivateAll().renderAll();
682a3b12d   TRUONG   fix illustration ...
444
  			}
04cbb68af   DANG   design text basic
445
  		};
422e7837d   DANG   Change color t-shirt
446

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

98acd3acd   DANG   Change text
476
477
  		//Design text
  		$scope.inputText = function(e) {
92271fd7c   DANG   add event
478
479
  			if(typeof $scope.iText != "undefined") {
  				var iText = $scope.iText;
ba689b493   DANG   canvas font text
480
  				iText.text = e;
ba689b493   DANG   canvas font text
481
482
483
484
  				canvas.add(iText);
  				canvas.renderAll();
  				canvas.setActiveObject(iText);
  			}
c8bfdfd96   DANG   event click object
485
  		};
2f4c31749   DANG   Fix text design a...
486
487
  		$scope.setFontFamily = function(font,index) {
  			$scope.itemFont = index;
ba689b493   DANG   canvas font text
488
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
489
490
491
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					currentObj.set('fontFamily', font);
ba689b493   DANG   canvas font text
492
  					canvas.renderAll();
92271fd7c   DANG   add event
493
  					canvas.setActiveObject(currentObj);
ba689b493   DANG   canvas font text
494
495
496
  				}
  
  			}
04cbb68af   DANG   design text basic
497
498
  		};
  		//Set letter spacing text
04cbb68af   DANG   design text basic
499
500
  		$scope.setLetterSpacingText = function(e) {
  			if(canvas.getActiveObject()) {
92271fd7c   DANG   add event
501
502
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
04cbb68af   DANG   design text basic
503
504
  					if(e == 'plus')
  						spacingNum = spacingNum + 30;
2f4c31749   DANG   Fix text design a...
505
  					else if (spacingNum >= -30){
04cbb68af   DANG   design text basic
506
507
  						spacingNum = spacingNum - 30;
  					}
92271fd7c   DANG   add event
508
  					currentObj.set('charSpacing', spacingNum);
04cbb68af   DANG   design text basic
509
  					canvas.renderAll();
92271fd7c   DANG   add event
510
  					canvas.setActiveObject(currentObj);
04cbb68af   DANG   design text basic
511
  				}
04cbb68af   DANG   design text basic
512
  			}
2f4c31749   DANG   Fix text design a...
513
514
515
516
517
518
519
520
521
522
523
524
525
  		};
  
  		$scope.setLetterSpacingTextDefault = function() {
  			if(canvas.getActiveObject()) {
  				var currentObj = canvas.getActiveObject();
  				if(currentObj.type == 'i-text') {
  					spacingNum = 0;
  					currentObj.set('charSpacing', spacingNum);
  					canvas.renderAll();
  					canvas.setActiveObject(currentObj);
  				}
  			}
  		};
e5669639a   TRUONG   merge #1759
526
527
528
  		
  		
  		/**** process insert image */
bd0414901   TRUONG   update store rece...
529
530
531
532
533
  		if (typeof($window.localStorage.recentImages) != 'undefined'){
  			$scope.recentImages = JSON.parse($window.localStorage.recentImages);
  		}else{
  			$scope.recentImages = {};
  		}
2f4c31749   DANG   Fix text design a...
534

bd0414901   TRUONG   update store rece...
535
536
537
538
539
540
  		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...
541

bd0414901   TRUONG   update store rece...
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
  			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...
559
  			if (e.target.files[0] && e.target.files[0].size > 5*1024*1024){
60b61386b   TRUONG   fix text
560
  				alert('アップロードできませんでした');
0181c19ff   TRUONG   fix bugs and opti...
561
562
  				return;
  			}
e5669639a   TRUONG   merge #1759
563
  			var reader = new FileReader();
0181c19ff   TRUONG   fix bugs and opti...
564
  		    reader.onload = function (event) {
bd0414901   TRUONG   update store rece...
565
566
  		    	addToRecentImage ($('#imgLoader').val(), event.target.result);
  		        var imgObj = new Image();//console.log($('#imgLoader').val());
e5669639a   TRUONG   merge #1759
567
568
569
570
571
572
573
574
575
  		        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...
576
  		            //image.scale(getRandomNum(0.1, 0.25)).setCoords();
e5669639a   TRUONG   merge #1759
577
578
579
580
581
582
  		            image.scaleToWidth(200);
  		            canvas.add(image);
  		        }
  		    }
      		reader.readAsDataURL(e.target.files[0]);
  		}
2f4c31749   DANG   Fix text design a...
583

bd0414901   TRUONG   update store rece...
584
585
586
587
588
  		$scope.insertRecentImage = function(data){
  	        var imgObj = new Image();
  	        imgObj.src = data;
  	        imgObj.onload = function () {
  	            // start fabricJS stuff
2f4c31749   DANG   Fix text design a...
589

bd0414901   TRUONG   update store rece...
590
591
592
593
594
595
596
597
598
  	            var image = new fabric.Image(imgObj);
  	            image.set({
  	                left: 50,
  	                top: 50
  	            });
  	            image.scaleToWidth(200);
  	            canvas.add(image);
  	        }
  		}
2f4c31749   DANG   Fix text design a...
599

92271fd7c   DANG   add event
600
601
602
603
604
605
606
607
608
609
610
  		//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
611
612
613
614
615
616
617
618
  		
  		
  		/* Process output */
  		$scope.outputDesign = function(){
  			$rootScope.outputImage = canvas.toDataURL('png');
  			// console.log();
  			$('#tshirt-design').modal('hide');
  		}
6f105dbd5   Truong LD   add source code i...
619
620
  	});
  });