-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagging.js
117 lines (103 loc) · 2.21 KB
/
tagging.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
prePopulated = ["Mike", "Sean", "Andrew", "Jackie", "Nick"];
data = [
{ name: 'Sean', x: '294', y: '391' },
{ name: 'Nick', x: '372', y: '366' },
{ name: 'Mike', x: '99', y: '293' }
];
$(function(){
canvas = $('.photo_container')
tagList(canvas);
createTagsFromData();
buttonHandler = makeToggleHandler(canvas);
buttonHandler.toggleHide();
usersInPhoto();
});
// add user store like niranjan's code
function userStore() {
this.users = [],
this.seed = []
}
function tagList(canvas) {
$(canvas).click(function(event){
// debug
// alert(event.pageX);
// alert(event.pageY);
$('.click_container')
.css("left", event.pageX - 40)
.css("top", event.pageY - 40)
// don't forget to fade the div out when you make another selection
.fadeIn();
$('.click_container')
.empty()
.append(
$('<div></div>')
.addClass('pretag')
);
$('.click_container')
.append(
$('<div></div>')
.addClass('choice_container')
);
$(prePopulated).each(function(){
$('.choice_container')
.append(
$('<div></div>')
.addClass('choice')
.html(this)
);
});
createTagData();
});
}
function createTagsFromData() {
// takes the existing data and places a tag there
console.log('I got called!');
$(data).each(function(){
$('.tag_container')
.append(
$('<div></div>')
.addClass('tag')
.html(
$('<div></div>')
.addClass('name')
.html(this.name)
)
.css('left', this.x + 'px')
.css('top', this.y - 80 + 'px')
.hide()
);
});
}
function usersInPhoto() {
$(data).each(function(){
$('.info')
.append(this.name)
});
}
function makeToggleHandler(canvas) {
return {
toggleHide: function() {
$(canvas).mouseenter(this.showTags);
$(canvas).mouseleave(this.hideTags);
},
hideTags: function() {
$('.tag_container .tag')
.fadeOut();
},
showTags: function() {
$('.tag_container .tag')
.fadeIn();
}
}
}
function createTagData() {
$('.choice').click(function(){
var x = parseInt(($('.click_container').css('left')),'px');
var y = parseInt(($('.click_container').css('top')), 'px');
data.push(
{name: $(this).html(), x: x, y: y}
);
$('.click_container').fadeOut();
createTagsFromData();
});
}