forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex3.html
More file actions
173 lines (144 loc) · 6.74 KB
/
Copy pathindex3.html
File metadata and controls
173 lines (144 loc) · 6.74 KB
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jquery.iviewer test</title>
<script type="text/javascript" src="jquery.js" ></script>
<script type="text/javascript" src="jqueryui.js" ></script>
<script type="text/javascript" src="jquery.mousewheel.min.js" ></script>
<script type="text/javascript" src="../jquery.iviewer.js" ></script>
<script type="text/javascript">
jQuery(function($){
var viewer;
function isInCircle(x, y) {
var relative_x = x - this.x;
var relative_y = y - this.y;
return Math.sqrt(relative_x*relative_x + relative_y*relative_y) <= this.r;
}
function isInRectangle(x, y) {
return (this.x1 <= x && x <= this.x2) && (this.y1 <= y && y<= this.y2);
}
function getCircleCenter() { return {x: this.x, y: this.y}; }
function getRectangleCenter() { return {x: (this.x2+this.x1)/2, y: (this.y2+this.y1)/2}; }
var objects = [
{x: 100, y: 100, r: 50, isInObject: isInCircle, title: 'big circle', getCenter: getCircleCenter },
{x: 150, y: 250, r: 35, isInObject: isInCircle, title: 'middle circle', getCenter: getCircleCenter },
{x: 500, y: 300, r: 10, isInObject: isInCircle, title: 'small circle', getCenter: getCircleCenter },
{x1: 200, y1: 400, x2: 300, y2: 500, isInObject: isInRectangle, title: 'rectangle', getCenter: getRectangleCenter }
]
function whereIam(x, y) {
for (var i=0; i<objects.length; i++) {
var obj = objects[i];
if (obj.isInObject(x, y))
return obj;
}
return null;
}
function showMe(ev, a) {
$.each(objects, function(i, object) {
if (object.title == $(a).html()) {
var center = object.getCenter();
var offset = viewer.iviewer('imageToContainer', center.x, center.y);
var containerOffset = viewer.iviewer('getContainerOffset');
var pointer = $('#pointer');
offset.x += containerOffset.left - 20;
offset.y += containerOffset.top - 40;
pointer.css('display', 'block');
pointer.css('left', offset.x+'px');
pointer.css('top', offset.y+'px');
}
});
ev.preventDefault();
}
window.showMe = showMe;
viewer = $("#viewer1").iviewer({
src: "test_active_with_objects.GIF",
onClick: function(ev, coords) {
var object = whereIam(coords.x, coords.y);
if (object)
alert('Clicked at ('+coords.x+', '+coords.y+'). This is '+object.title);
},
onMouseMove: function(ev, coords) {
var object = whereIam(coords.x, coords.y);
if (object) {
$('#status').html('You are in ('+coords.x.toFixed(1)+', '+coords.y.toFixed(1)+'). This is '+object.title);
this.container.css('cursor', 'crosshair');
} else {
$('#status').html('You are in ('+coords.x.toFixed(1)+', '+coords.y.toFixed(1)+'). This is empty space');
this.container.css('cursor', null);
}
},
onBeforeDrag: function(ev, coords) {
// remove pointer if image is getting moving
// because it's not actual anymore
$('#pointer').css('display', 'none');
// forbid dragging when cursor is whithin the object
return whereIam(coords.x, coords.y) ? false : true;
},
onZoom: function(ev) {
// remove pointer if image is resizing
// because it's not actual anymore
$('#pointer').css('display', 'none');
},
initCallback: function(ev) {
this.container.context.iviewer = this;
}
});
});
</script>
<link rel="stylesheet" href="../jquery.iviewer.css" />
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
}
.viewer
{
height: 100%;
position: relative;
background-color: lightgreen;
}
.wrapper
{
border: 1px solid black;
position: absolute;
top: 5em;
left: 1em;
bottom: 1em;
right: 1em;
overflow: hidden; /*for opera*/
}
.toolbar
{
border: 1px solid black;
position: absolute;
top: 1em;
left: 1em;
right: 1em;
height: 3em;
}
#pointer
{
background-image: url('arrow.png');
width: 40px;
height: 40px;
position: absolute;
display: none;
}
</style>
</head>
<body>
<div class="toolbar">
<span id="status"></span>|Show me:
<a href="#" onclick="showMe(event, this)">big circle</a>,
<a href="#" onclick="showMe(event, this)">middle circle</a>,
<a href="#" onclick="showMe(event, this)">small circle</a>,
<a href="#" onclick="showMe(event, this)">rectangle</a>
</div>
<div class="wrapper">
<div id="viewer1" class="viewer"></div>
</div>
<div id="pointer"></div>
</body>
</html>