main.js
3.66 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
define(['app'], function (app) {
'use strict';
app.controller('MainCtrl', function ($rootScope, $scope, $timeout, $illustration, $t_shirt, $routeParams) {
//Define and init var
$rootScope.API_URL = 'http://domain.com';
$scope.designFrameView = 'views/tshirt-design.html?ver='+VERSION;
$scope.designPartIllustration = 'views/design_part/illustration.html?ver='+VERSION;
$scope.designPartImage = 'views/design_part/image.html?ver='+VERSION;
$scope.designPartText = 'views/design_part/text.html?ver='+VERSION;
$scope.designPartDefault = 'views/design_part/default.html?ver='+VERSION;
var currentTShirtKey = 0;
var placeTShirtKey = '';
var tShirtColorFirstKey = 0;
$scope.tShirtChoiceBackFrontKey = 'front';
$scope.tShirtColorKey = tShirtColorFirstKey;
/**
* Get param route
* @type {any}
* @private
*/
var _routeParams = $routeParams;
if(typeof _routeParams.tShirt != 'undefined')
currentTShirtKey = _routeParams.tShirt - 1;
if(typeof _routeParams.place != 'undefined')
placeTShirtKey = _routeParams.place;
/**
* Get all info TShirt
* @param: id
* @return: object
*/
$rootScope.placeTshirt = $t_shirt.getTShirtPlace(currentTShirtKey, placeTShirtKey);
$scope.tShirtColor = $t_shirt.getTShirtColor(currentTShirtKey);
$rootScope.tShirtColorCode = $scope.tShirtColor[tShirtColorFirstKey].code;
$scope.tShirtColorName = $scope.tShirtColor[tShirtColorFirstKey].name;
$scope.tShirtImgFront = $scope.tShirtColor[tShirtColorFirstKey].img.front;
$scope.tShirtImgBack = $scope.tShirtColor[tShirtColorFirstKey].img.back;
$scope.tShirtImg = $scope.tShirtImgFront;
/**
* Set preview size and position
*/
function setSizePreViewDesign() {
var _widthTShirtImage = $('.tshirt-image').width();
if(typeof $rootScope.placeTshirt.place == 'undefined')
return;
var place = $rootScope.placeTshirt.place;
switch (place) {
case 't_shirt_p_1' :
var widthPreview = _widthTShirtImage/2.5;
var heihtPreview = _widthTShirtImage/2.5;
break;
case 't_shirt_p_2' :
var widthPreview = _widthTShirtImage/2.5;
var heihtPreview = _widthTShirtImage/4.5;
break;
default:
break;
}
$('#preview-design').css({width: widthPreview, height: heihtPreview});
}
setSizePreViewDesign();
$(window).resize(function () {
setSizePreViewDesign();
});
/**
* Choice color t-shirt
* @param key
*/
$scope.choiceTShirtColor = function(key) {
$scope.tShirtColorKey = key;
var tShirtColor = $scope.tShirtColor[key];
$rootScope.tShirtColorCode = tShirtColor.code;
$scope.tShirtColorName = tShirtColor.name;
$scope.tShirtImgFront = tShirtColor.img.front;
$scope.tShirtImgBack = tShirtColor.img.back;
if($scope.tShirtChoiceBackFrontKey == 'front') {
$scope.tShirtImg = $scope.tShirtImgFront;
} else {
$scope.tShirtImg = $scope.tShirtImgBack;
}
};
/**
* Choice back or front t-shirt
* @param choice
*/
$scope.choiceTShirtBackFront = function(choice) {
if(choice == 'front') {
$scope.tShirtImg = $scope.tShirtImgFront;
} else {
$scope.tShirtImg = $scope.tShirtImgBack;
}
$scope.tShirtChoiceBackFrontKey = choice;
};
//safeApply
$rootScope.safeApply = function(fn) {
var phase = this.$root.$$phase;
if(phase == '$apply' || phase == '$digest') {
if(fn && (typeof(fn) === 'function')) {
fn();
}
} else {
this.$apply(fn);
}
};
/**
* Open modal design
*/
$scope.modalTShirtDesign = function() {
$('#tshirt-design').modal(
{
backdrop: 'static',
keyboard: false
}
);
};
/**
* Close modal design
*/
$scope.modalClose = function(){
$('#tshirt-design').modal('hide');
};
});
});