-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductViewManager.js
185 lines (128 loc) · 4.78 KB
/
productViewManager.js
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
//bir cache sistemi yapabilirim unutma.
class ProductViewManager {
constructor(products,baseURL) {
this.products = products;
this.baseURL = baseURL;
this.imageCount = 0;
this.counter = 0;
}
imageLoaded(){
this.counter++;
}
getFrameStatus(){
/*********Gostermelik fonksyon***********/
var status;
if($('#isFramed').val() === "true"){
status=true;
}
else{
status=false;
}
/****************************************/
// bu variable a senin sisteminde frame durumunu Boolean seklinde
// veren bir fonksyon yazmalisin
return status;
}
getFrameColor(){
/*********Gostermelik fonksyon***********/
if($('#isFramed').val() === "true"){
var color = $("#frameColor").val();
}
/****************************************/
// senin sisteminde frame rengini string seklinde
// veren bir fonksyon yazmalisin
return color;
}
getCanvasIdentifier(){
/*********Gostermelik fonksyon***********/
let identifier = $('#identifier').val();
/****************************************/
// bu variable a senin sisteminde frame durumunu string seklinde
// veren bir fonksyon yazmalisin
return identifier;
}
getCanvasSize(){
/********Gostermelik fonksyon***********/
let size = $('#size').val();
/***************************************/
// bu variable a senin sisteminde frame rengini string seklinde
// veren bir fonksyon yazmalisin
return size;
}
setFrameColor(){
if(this.getFrameStatus()){
let frameColorId = "#" + this.getFrameColor();
d3.select(".loadedFrames")
.selectAll("*")
.classed('visible',false);
d3.select(frameColorId).classed('visible',true);
}
}
setFrameStatus(){
if(this.getFrameStatus()){
let frameColorId = "#" + this.getFrameColor();
d3.select(frameColorId).classed('visible',true);
d3.select("#ShadowCanvasAlpha").classed('visible',false);
d3.select("#ShadowFrameAlpha").classed('visible',true);
}
else
{
d3.select(".loadedFrames")
.selectAll("*")
.classed('visible',false);
d3.select("#ShadowCanvasAlpha").classed('visible',true);
d3.select("#ShadowFrameAlpha").classed('visible',false);
}
}
setCanvasIdentifier(animation1WithCallback,animation2WithCallback){
var pvm = this;
animation1WithCallback(pvm,function(){
var size = pvm.getCanvasSize();
var identifier = pvm.getCanvasIdentifier();
var product = _.find(pvm.products, function(o) {
return o.identifier === identifier
&& o.size === size;
});
var dimension = product.renderDimension;
var urlPart = "/"+identifier+"/"+dimension+"-"+size+"-";
d3.select("#current").selectAll("image").each( function(d, i){
var newUrl = d3.select(this).attr("xlink:href").replace(/\/\w+\/\d+x\d+-\w-/,urlPart);
d3.select(this).attr("xlink:href",newUrl);
});
//catch the load event!
pvm.imageCount = d3.selectAll("#current > image").size();
var poll = setInterval(function(){
console.log(console.log( pvm.imageCount));
if(pvm.imageCount === pvm.counter){
animation2WithCallback();
clearInterval(poll);
}
},20);
});
}
setCanvasSize(animation1WithCallback,animation2WithCallback){
var pvm = this;
animation1WithCallback(pvm,function(){
var size = pvm.getCanvasSize();
var identifier = pvm.getCanvasIdentifier();
var product = _.find(pvm.products, function(o) {
return o.identifier === identifier
&& o.size === size;
});
var dimension = product.renderDimension;
var urlPart = dimension+"-"+size+"-";
d3.select("#current").selectAll("image").each( function(d, i){
var newUrl = d3.select(this).attr("xlink:href").replace(/\d+x\d+-\w-/,urlPart);
d3.select(this).attr("xlink:href",newUrl);
});
//catch the load event!
pvm.imageCount = d3.selectAll("#current > image").size();
var poll = setInterval(function(){
if(pvm.imageCount === pvm.counter){
animation2WithCallback();
clearInterval(poll);
}
},20);
});
}
}