forked from neshte/jquery-canvas-area-draw
-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
266 lines (261 loc) · 11.9 KB
/
demo.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Canvas Area Draw</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap.min.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0/css/font-awesome.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0/css/font-awesome-ie7.css" rel="stylesheet">
<style type="text/css">
ul.sortable{
margin:0;
padding:0;
list-style:none;
}
</style>
</head>
<body>
<div class="span6" id="htmlimagemap_cs">
<h2> Image CS </h2>
<textarea id="html_cs" rows=3 name="coords_cs" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="rem_cs">remove</button><button class="btn" id="reset_cs">reset</button><button class="btn" id="add_cs">add area</button></div><br />
<div id="layers_cs">
<ul class="sortable">
</ul>
</div>
</div>
<div class="span6" id="htmlimagemap1">
<h2> Image 1 </h2>
<textarea id="html1" rows=3 name="coords1" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="rem1">remove</button><button class="btn" id="reset1">reset</button><button class="btn" id="add1">add area</button></div><br />
<div id="layers1">
<ul class="sortable">
</ul>
</div>
</div>
<div class="span6" id="htmlimagemap2">
<h2> Image 2 </h2>
<textarea id="html2" rows=3 name="coords2" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="rem2">remove</button><button class="btn" id="reset2">reset</button><button class="btn" id="add2">add area</button></div><br />
<div id="layers2">
<ul class="sortable">
</ul>
</div>
</div>
<!--[if IE]><script type="text/javascript" src="excanvas.js"></script><![endif]-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script type="text/javascript" src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script>
<script type="text/javascript" src="jquery.canvasAreaDraw.js"></script>
<script type="text/javascript">
(function($){
$(document).ready(function(){
//HTMLMAP Continious Selection
var refreshHtmlCodeCS = function(){
var areas = htmlmap_cs.htmlimagemap("getAreas");
var htmlcode = '<map name="htmlmap_cs">\n';
for(var i=0; i<areas.length; i++){
htmlcode += '\t<area shape="poly" coords="'+areas[i].coords+'" href="'+encodeURI(areas[i].href)+'">\n';
}
htmlcode = htmlcode += '</map>';
$("#html_cs").text(htmlcode);
};
var initareas_cs = [{
href:"",
coords:[208,221,208,202,198,199,201,191,218,176,229,155,221,132,196,117,169,131,157,158,163,172,177,164,173,180,190,185,192,199,187,201,185,222]
}];
var htmlmap_cs = $("#htmlimagemap_cs").htmlimagemap({
imageUrl: "http://farm8.staticflickr.com/7259/6956772778_2fa755a228.jpg",
areas: initareas_cs,
mode: "continiousSelect",
approximationStep: 5,
onMove: function(area){
},
onUpdateArea: function(area){
$("#layers_cs .sortable li").eq(htmlmap_cs.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshHtmlCodeCS();
}
});
$("#rem_cs").click(function(){
var i = htmlmap_cs.htmlimagemap("getActiveAreaIndex");
htmlmap_cs.htmlimagemap("removeActiveArea");
$("#layers_cs .sortable li").eq(i).remove();
});
$("#reset_cs").click(function(){
htmlmap_cs.htmlimagemap("resetActiveArea");
});
$("#add_cs").click(function(){
var i = htmlmap_cs.htmlimagemap("getAreas").length;
htmlmap_cs.htmlimagemap("setActiveAreaIndex",i);
$("#layers_cs .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":htmlmap1.htmlimagemap("getActiveArea").coords.join()}).val(htmlmap1.htmlimagemap("getActiveArea").href)));
});
$("#layers_cs .sortable").on("input focus propertychange change keyup paste", "input", function(){
var i = $(this).parent().index();
var area = htmlmap_cs.htmlimagemap("getArea",i);
area.href = $(this).val();
htmlmap_cs.htmlimagemap("setActiveAreaIndex",i);
htmlmap_cs.htmlimagemap("setArea",i,area);
refreshHtmlCodeCS();
});
$("#layers_cs .sortable").sortable({
update: function(e,ui){
$("#layers_cs .sortable li").each(function(i,v){
var area = htmlmap_cs.htmlimagemap("getArea",i);
var coords = $(v).find("input").attr("data-coords").split(',');
if(coords.length % 2 == 0){
area.coords = $.map(coords, function(value){
return parseInt(value, 10);
});
}else{
area.coords = [];
}
area.href = $(v).find("input").val();
htmlmap_cs.htmlimagemap("setArea",i,area);
});
refreshHtmlCodeCS();
}
});
for(var i=0; i<initareas_cs.length; i++){
$("#layers_cs .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":initareas_cs[i].coords.join()}).val(initareas_cs[i].href)));
}
refreshHtmlCodeCS();
//HTMLMAP 1
var refreshHtmlCode1 = function(){
var areas = htmlmap1.htmlimagemap("getAreas");
var htmlcode = '<map name="htmlmap1">\n';
for(var i=0; i<areas.length; i++){
htmlcode += '\t<area shape="poly" coords="'+areas[i].coords+'" href="'+encodeURI(areas[i].href)+'">\n';
}
htmlcode = htmlcode += '</map>';
$("#html1").text(htmlcode);
};
var initareas1 = [{
href:"",
coords:[208,221,208,202,198,199,201,191,218,176,229,155,221,132,196,117,169,131,157,158,163,172,177,164,173,180,190,185,192,199,187,201,185,222]
}];
var htmlmap1 = $("#htmlimagemap1").htmlimagemap({
imageUrl: "http://farm8.staticflickr.com/7259/6956772778_2fa755a228.jpg",
areas: initareas1,
onMove: function(area){
},
onUpdateArea: function(area){
$("#layers1 .sortable li").eq(htmlmap1.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshHtmlCode1();
}
});
$("#rem1").click(function(){
var i = htmlmap1.htmlimagemap("getActiveAreaIndex");
htmlmap1.htmlimagemap("removeActiveArea");
$("#layers1 .sortable li").eq(i).remove();
});
$("#reset1").click(function(){
htmlmap1.htmlimagemap("resetActiveArea");
});
$("#add1").click(function(){
var i = htmlmap1.htmlimagemap("getAreas").length;
htmlmap1.htmlimagemap("setActiveAreaIndex",i);
$("#layers1 .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":htmlmap1.htmlimagemap("getActiveArea").coords.join()}).val(htmlmap1.htmlimagemap("getActiveArea").href)));
});
$("#layers1 .sortable").on("input focus propertychange change keyup paste", "input", function(){
var i = $(this).parent().index();
var area = htmlmap1.htmlimagemap("getArea",i);
area.href = $(this).val();
htmlmap1.htmlimagemap("setActiveAreaIndex",i);
htmlmap1.htmlimagemap("setArea",i,area);
refreshHtmlCode1();
});
$("#layers1 .sortable").sortable({
update: function(e,ui){
$("#layers1 .sortable li").each(function(i,v){
var area = htmlmap1.htmlimagemap("getArea",i);
var coords = $(v).find("input").attr("data-coords").split(',');
if(coords.length % 2 == 0){
area.coords = $.map(coords, function(value){
return parseInt(value, 10);
});
}else{
area.coords = [];
}
area.href = $(v).find("input").val();
htmlmap1.htmlimagemap("setArea",i,area);
});
refreshHtmlCode1();
}
});
for(var i=0; i<initareas1.length; i++){
$("#layers1 .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":initareas1[i].coords.join()}).val(initareas1[i].href)));
}
refreshHtmlCode1();
//HTMLMAP 2
var refreshHtmlCode2 = function(){
var areas = htmlmap2.htmlimagemap("getAreas");
var htmlcode = '<map name="htmlmap2">\n';
for(var i=0; i<areas.length; i++){
htmlcode += '\t<area shape="poly" coords="'+areas[i].coords+'" href="'+encodeURI(areas[i].href)+'">\n';
}
htmlcode = htmlcode += '</map>';
$("#html2").text(htmlcode);
};
var initareas2 = [{
href:"",
coords:[299,84,297,92,285,98,275,109,271,123,273,141,287,156,311,162,333,156,345,142,346,126,340,107,321,92,314,89,309,81]
}];
var htmlmap2 = $("#htmlimagemap2").htmlimagemap({
imageUrl: "http://farm6.staticflickr.com/5010/5295769404_1a221cbb5e_z.jpg",
areas: initareas2,
onMove: function(area){
},
onUpdateArea: function(area){
$("#layers2 .sortable li").eq(htmlmap2.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshHtmlCode2();
}
});
$("#rem2").click(function(){
var i = htmlmap2.htmlimagemap("getActiveAreaIndex");
htmlmap2.htmlimagemap("removeActiveArea");
$("#layers2 .sortable li").eq(i).remove();
});
$("#reset2").click(function(){
htmlmap2.htmlimagemap("resetActiveArea");
});
$("#add2").click(function(){
var i = htmlmap2.htmlimagemap("getAreas").length;
htmlmap2.htmlimagemap("setActiveAreaIndex",i);
$("#layers2 .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":htmlmap2.htmlimagemap("getActiveArea").coords.join()}).val(htmlmap2.htmlimagemap("getActiveArea").href)));
});
$("#layers2 .sortable").on("input focus propertychange change keyup paste", "input", function(){
var i = $(this).parent().index();
var area = htmlmap2.htmlimagemap("getArea",i);
area.href = $(this).val();
htmlmap2.htmlimagemap("setActiveAreaIndex",i);
htmlmap2.htmlimagemap("setArea",i,area);
refreshHtmlCode2();
});
$("#layers2 .sortable").sortable({
update: function(e,ui){
$("#layers2 .sortable li").each(function(i,v){
var area = htmlmap2.htmlimagemap("getArea",i);
var coords = $(v).find("input").attr("data-coords").split(',');
if(coords.length % 2 == 0){
area.coords = $.map(coords, function(value){
return parseInt(value, 10);
});
}else{
area.coords = [];
}
area.href = $(v).find("input").val();
htmlmap2.htmlimagemap("setArea",i,area);
});
refreshHtmlCode2();
}
});
for(var i=0; i<initareas2.length; i++){
$("#layers2 .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":initareas2[i].coords.join()}).val(initareas2[i].href)));
}
refreshHtmlCode2();
});
})(jQuery);
</script>
</body>
</html>