forked from dmitryt/jquery-canvas-area-draw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
172 lines (165 loc) · 7.31 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
<!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="demo1_htmlimagemap">
<h2>Demo1: Image (Continuous Select) </h2>
<textarea id="demo1_html" rows=3 name="demo1_coords" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="demo1_rem">remove</button><button class="btn" id="demo1_reset">reset</button><button class="btn" id="demo1_add">add area</button></div><br />
<div id="demo1_layers">
<ul class="sortable">
</ul>
</div>
</div>
<div class="span6" id="demo2_htmlimagemap">
<h2> Image 1 </h2>
<textarea id="demo2_html" rows=3 name="demo2_coords" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="demo2_rem">remove</button><button class="btn" id="demo2_reset">reset</button><button class="btn" id="demo2_add">add area</button></div><br />
<div id="demo2_layers">
<ul class="sortable">
</ul>
</div>
</div>
<div class="span6" id="demo3_htmlimagemap">
<h2> Image 2 </h2>
<textarea id="demo3_html" rows=3 name="demo3_coords" class="canvas-area input-xxlarge" placeholder="Shape Coordinates"></textarea>
<div><button class="btn" id="demo3_rem">remove</button><button class="btn" id="demo3_reset">reset</button><button class="btn" id="demo3_add">add area</button></div><br />
<div id="demo3_layers">
<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">
var demo1_areas = [{
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 demo2_areas = [{
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 demo3_areas = [{
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]
}];
function refreshCode ( htmlmap,elname ){
var areas = htmlmap.htmlimagemap("getAreas");
var htmlcode = '<map name="map_'+elname+'">\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>';
$("#"+elname+"_html").text(htmlcode);
};
function bindButtons( htmlmap,elname ){
$("#"+elname+"_rem").click(function(){
var i = htmlmap.htmlimagemap("getActiveAreaIndex");
htmlmap.htmlimagemap("removeActiveArea");
$("#layers_cs .sortable li").eq(i).remove();
});
$("#"+elname+"_reset").click(function(){
htmlmap.htmlimagemap("resetActiveArea");
});
$("#"+elname+"_add").click(function(){
var i = htmlmap.htmlimagemap("getAreas").length;
htmlmap.htmlimagemap("setActiveAreaIndex",i);
$("#"+elname+"_layers .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":htmlmap.htmlimagemap("getActiveArea").coords.join()}).val(htmlmap.htmlimagemap("getActiveArea").href)));
});
$("#"+elname+"_layers .sortable").on("input focus propertychange change keyup paste", "input", function(){
var i = $(this).parent().index();
var area = htmlmap.htmlimagemap("getArea",i);
area.href = $(this).val();
htmlmap.htmlimagemap("setActiveAreaIndex",i);
htmlmap.htmlimagemap("setArea",i,area);
refreshCode ( htmlmap,elname );
});
$("#"+elname+"_layers .sortable").sortable({
update: function(e,ui){
$("#"+elname+"_layers .sortable li").each(function(i,v){
var area = htmlmap.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.htmlimagemap("setArea",i,area);
});
refreshCode ( htmlmap,elname );
}
});
for(var i=0; i<window[elname+'_areas'].length; i++){
$("#"+elname+"_layers .sortable").append($("<li>").append($("<span>",{"class":"icon-resize-vertical"})).append($("<input>",{"type":"text","data-coords":window[elname+'_areas'][i].coords.join()}).val(window[elname+'_areas'][i].href)));
}
refreshCode ( htmlmap,elname );
}
(function($){
$(document).ready(function(){
var htmlmap_cs = $("#demo1_htmlimagemap").htmlimagemap({
imageUrl: "http://farm8.staticflickr.com/7259/6956772778_2fa755a228.jpg",
areas: demo1_areas,
mode: "continiousSelect",
approximationStep: 5,
onMove: function(area){
},
onUpdateArea: function(area){
$("#demo1_layers .sortable li").eq(htmlmap_cs.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshCode ( htmlmap_cs,'demo1' );
//refreshHtmlCodeCS();
}
});
bindButtons( htmlmap_cs,'demo1' );
var htmlmap1 = $("#demo2_htmlimagemap").htmlimagemap({
imageUrl: "http://farm8.staticflickr.com/7259/6956772778_2fa755a228.jpg",
areas: demo2_areas,
label: "Demo2",
activeColor: '#ff9911',
fillOpacity: '0.6',
lineWidth: 4,
onMove: function(area){
},
onUpdateArea: function(area){
$("#demo2_layers .sortable li").eq(htmlmap1.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshCode ( htmlmap1,'demo2' );
}
});
bindButtons( htmlmap1,'demo2' );
var htmlmap2 = $("#demo3_htmlimagemap").htmlimagemap({
imageUrl: "http://farm6.staticflickr.com/5010/5295769404_1a221cbb5e_z.jpg",
areas: demo3_areas,
label: "Demo3 Big Label",
onMove: function(area){
},
onUpdateArea: function(area){
$("#demo3_layers .sortable li").eq(htmlmap2.htmlimagemap("getActiveAreaIndex")).find("input").attr("data-coords",area.coords.join());
refreshCode ( htmlmap1,'demo3' );
}
});
bindButtons( htmlmap2,'demo3' );
});
})(jQuery);
</script>
</body>
</html>