-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
312 lines (244 loc) · 7.43 KB
/
index.html
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
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="js/raphael-min.js"></script>
<script type="text/javascript" src="js/masonry.pkgd.min.js"></script>
<style>
.item { width: 25%;
border: 1px solid black;
margin: 5px;
padding: 5px;
}
.item.w1 { width: 20%; }
.item.w2 { width: 50%; }
.item.w3 { width: 70%; }
.item.w4 { width: 100%; }
</style>
<script>
var app_path = "cascader/";
$(document).ready(function() {
var pageController = {
container : null,
msnry : null,
paper : null,
foo: "bar",
initialImageUrl : "http://images.metmuseum.org/CRDImages/ep/web-large/DP164836.jpg",
init : function(){
this.container = document.querySelector('#maincontainer');
this.msnry = new Masonry( this.container, {
// options
columnWidth: 150,
itemSelector: '.item'
});
},
startIt : function(){
var realthis = this;
this.setupCanvas(function(){
realthis.setupClickables();
realthis.setupStartingImage(function(){
});
});
},
setupCanvas : function(callback){
var realthis = this;
Raphael("imageholder", 400, 600, function(context){
realthis.paper = this;
console.log(realthis.paper);
callback();
});
},
setupClickables : function(){
var realthis = this;
$(".clicker").click(function(){
var url=$("#urlvalue").val();
var path = app_path + "?imageurl="+encodeURIComponent(url);
realthis.setImageInPaper(url, function(queueImage){
console.log(realthis.paper.scaleFactor);
realthis.callCascader(path, function(data){
realthis.placeIdentifiers(data, ralthis.paper.scaleFactor);
});
});
});
},
setupStartingImage : function(callback){
var path = app_path + "?imageurl="+encodeURIComponent(this.initialImageUrl);
var realthis = this;
this.setImageInPaper(this.initialImageUrl, function(queueImage){
console.log(realthis.paper.scaleFactor);
realthis.callCascader(path, function(data){
realthis.placeIdentifiers(data, realthis.paper.scaleFactor);
});
});
callback();
},
placeIdentifiers : function(data, scaleFactor){
$(".controls").empty();
var _scaleFactor = scaleFactor;
var realthis = this;
var rects = {};
var checkids = [];
for(key in data){
var values = data[key];
var num_matches = values.length;
var idname = "controlspan" + key;
var checkid = "controlcheck" + key;
checkids.push(checkid);
rects[checkid] = [];
if(num_matches > 0){
var control = $("<span id='"+checkid+"' class='control'>"+key+"("+num_matches+") </span>");
$(".controls").append(control);
}
if(key != "_links"){
// if(key == "smile"){
for(key2 in values){
var value = values[key2];
var x = value.x * _scaleFactor.scaleX;
var y = value.y * _scaleFactor.scaleY;
var w = value.w * _scaleFactor.scaleX;
var h = value.h * _scaleFactor.scaleY;
//var rect = _paper.rect(value.x, value.y, value.w, value.h);
var rect = realthis.paper.rect(x, y, w, h);
rect.attr("stroke","#f00");
rect.attr("stroke-width",1);
rect.attr("fill", "#5f5");
rect.attr("fill-opacity",".2");
rect.toFront();
rect.hide();
rects[checkid].push(rect);
}
}
}
for(checkidi in checkids){
var checkid = checkids[checkidi];
$("#"+checkid).data("clickedon", false);
(function(_checkid){
$(document).on("click", "#"+_checkid, function(){
$("#"+_checkid).data('clickedon', !$("#"+_checkid).data('clickedon'));
if($("#"+_checkid).data('clickedon') ){
$(this).css("font-weight","Bold");
}else{
$(this).css("font-weight","Normal");
}
});
$(document).on("mouseover", "#"+_checkid, function(){
$(this).css("font-weight","Bold");
});
$(document).on("mouseout", "#"+_checkid, function(){
if(!$("#"+_checkid).data('clickedon') ){
$(this).css("font-weight","Normal");
}else{
console.log("not hiding");
}
});
})(checkid);
for(recti in rects[checkid]){
var rectx = rects[checkid][recti];
realthis.attachRectToController(rectx.id, checkid);
}
}
},
attachRectToController : function (rectid, checkid){
var realthis = this;
$(document).on("mouseover", "#"+checkid, function(){
var _rect= realthis.paper.getById(rectid);
_rect.show();
});
$(document).on("mouseout", "#"+checkid, function(){
console.log(checkid + $("#"+checkid).data('clickedon'));
if(!$("#"+checkid).data('clickedon') ){
var _rect= realthis.paper.getById(rectid);
_rect.hide();
}else{
}
});
},
callCascader : function(url, callback){
$.ajax(
url,
{
success : function(data, status, jqXHR){
callback(data);
},
error : function(jqHXR, status, error){
console.log("error");
console.log(error);
},
}
);
},
setImageInPaper : function(url, callback){
this.paper.clear();
var queueObject = {};
var data = {image: url};
queueObject.data= data;
var realthis = this;
var theimage= data.image;
queueObject.image = theimage;
queueObject.imageObj = new Image();
queueObject.imageObj.onload = function(){
queueObject.origWidth = queueObject.width;
queueObject.origHeight = queueObject.height;
var result = realthis.ScaleImage(queueObject.imageObj.width, queueObject.imageObj.height, 400, 600, true);
queueObject.paperimage = realthis.paper.image(queueObject.image, 0,0, result.width, result.height);
queueObject.width = result.width;
queueObject.height = result.height;
realthis.paper.scaleFactor = result;
callback(queueObject, result);
}
queueObject.imageObj.src = queueObject.image;
},
ScaleImage : function(srcwidth, srcheight, targetwidth, targetheight, fLetterBox) {
var result = { width: 0, height: 0, fScaleToTargetWidth: true };
if ((srcwidth <= 0) || (srcheight <= 0) || (targetwidth <= 0) || (targetheight <= 0)) {
return result;
}
// scale to the target width
var scaleX1 = targetwidth;
var scaleY1 = (srcheight * targetwidth) / srcwidth;
// scale to the target height
var scaleX2 = (srcwidth * targetheight) / srcheight;
var scaleY2 = targetheight;
var scaleX;
var scaleY;
// now figure out which one we should use
var fScaleOnWidth = (scaleX2 > targetwidth);
if (fScaleOnWidth) {
fScaleOnWidth = fLetterBox;
}
else {
fScaleOnWidth = !fLetterBox;
}
if (fScaleOnWidth) {
result.width = Math.floor(scaleX1);
result.height = Math.floor(scaleY1);
result.fScaleToTargetWidth = true;
}
else {
result.width = Math.floor(scaleX2);
result.height = Math.floor(scaleY2);
result.fScaleToTargetWidth = false;
}
result.scaleX = result.width / srcwidth;
result.scaleY = result.height / srcheight;
result.targetleft = Math.floor((targetwidth - result.width) / 2);
result.targettop = Math.floor((targetheight - result.height) / 2);
return result;
}
};
// var pageController = new PageController();
pageController.init();
pageController.startIt();
});
</script>
</head>
<body>
<div id="maincontainer">
<div class="urlinput item w4"><input id="urlvalue" type="text" size="120"/><span class="clicker">find stuff!</span></div>
<div class="item w2">
<div id="imageholder"></div>
</div>
<div class="controls item w1">controls</div>
</div>
</body>
</html>