f21d45fd526c464fbdf1e9c9cddf5ba94d0cfe78
2 * © 2007 Benoît Pin – Centre de recherche en informatique – École des mines de Paris
4 * Licence Creative Commons http://creativecommons.org/licenses/by-nc/2.0/
9 function Navigateur(mosaique
) {
10 this.mosaique
= mosaique
;
11 var m
= this.mosaique
; // shortcut alias
17 this._ddHandlers
= {'down' : function(evt
){thisNav
._mouseDownHandler(evt
);},
18 'move' : function(evt
){thisNav
._mouseMoveHandler(evt
);},
19 'up' : function(evt
){thisNav
._mouseUpHandler(evt
);}};
22 if (m
.zoomIndex
== m
.zoomTable
.length
- 1)
23 this.zoomInButton
.src
= this.zoomInButton
.src
.replace('zoom_in.gif', 'zoom_disabled.gif');
25 this.zoomOutButton
.src
= this.zoomOutButton
.src
.replace('zoom_out.gif', 'zoom_disabled.gif');
27 this.currentZoomLevel
.nodeValue
= m
.zoomLevel
+ ' %';
29 this._listeners
= new Array();
30 this._listeners
.push([this.zoomOutButton
, 'click', function(evt
){thisNav
.zoomOut(evt
);}]);
31 this._listeners
.push([this.zoomInButton
, 'click', function(evt
){thisNav
.zoomIn(evt
);}]);
32 this._listeners
.push([document
, 'keypress', function(evt
){thisNav
.zoomByKeybord(evt
);}]);
35 for (var i
= 0 ; i
<this._listeners
.length
; i
++) {
36 _l
= this._listeners
[i
];
37 addListener(_l
[0], _l
[1], _l
[2]);
41 Navigateur
.prototype.unload = function() {
43 for (var i
= 0 ; i
<this._listeners
.length
; i
++) {
44 _l
= this._listeners
[i
];
45 removeListener(_l
[0], _l
[1], _l
[2]);
49 Navigateur
.prototype.drawPanel = function() {
50 var m
= this.mosaique
;
52 var panel
= document
.createElement('div');
54 position
= 'absolute';
55 width
= this.mosaique
.thumbnailWidth
+ 2 + 'px';
56 height
= this.mosaique
.thumbnailHeight
+ 38 + 'px';
59 border
= '1px solid #4c4c4c';
65 var thumbnail
= document
.createElement('img');
66 thumbnail
.src
= m
.imgUrlBase
+ '/getThumbnail';
67 thumbnail
.width
= String(m
.thumbnailWidth
);
68 thumbnail
.height
= String(m
.thumbnailHeight
);
69 panel
.appendChild(thumbnail
);
72 var frame
= this.frame
= document
.createElement('div');
74 position
= 'absolute';
77 border
= '1px solid red';
81 panel
.appendChild(frame
);
85 var fill
= document
.createElement('img');
86 fill
.src
= portal_url() + '/transparent.gif';
91 frame
.appendChild(fill
);
93 // table with -/+ buttons and current zoom level
94 var table
= document
.createElement('table');
97 background
= '#808080';
98 verticalAlign
= 'middle';
100 panel
.appendChild(table
);
102 var tbody
= document
.createElement('tbody');
103 table
.appendChild(tbody
);
105 var tr
= document
.createElement('tr');
106 tbody
.appendChild(tr
);
108 var td
= document
.createElement('td');
111 var img
= this.zoomOutButton
= document
.createElement('img');
114 img
.src
= portal_url() + '/zoom_out.gif';
117 var td
= document
.createElement('td');
120 var text
= this.currentZoomLevel
= document
.createTextNode('10%');
121 td
.appendChild(text
);
123 var td
= document
.createElement('td');
126 var img
= this.zoomInButton
= document
.createElement('img');
129 img
.src
= portal_url() + '/zoom_in.gif';
132 this.display
= panel
;
133 this.mosaique
.rootElement
.appendChild(panel
);
136 Navigateur
.prototype.resizeFrame = function() {
137 var m
= this.mosaique
;
140 if (m
.screenWidth
>= m
.imageWidth
) {
141 width
= m
.thumbnailWidth
+ 'px';
144 var wRatio
= m
.screenWidth
/ m
.imageWidth
;
145 width
= Math
.round(wRatio
* m
.thumbnailWidth
) + 'px';
148 if (m
.screenHeight
>= m
.imageHeight
) {
149 height
= m
.thumbnailHeight
+ 'px';
152 var hRatio
= m
.screenHeight
/ m
.imageHeight
;
153 height
= Math
.round(hRatio
* m
.thumbnailHeight
) + 'px';
156 var frmStyle
= this.frame
.style
;
157 frmStyle
.width
= width
;
158 frmStyle
.height
= height
;
162 Navigateur
.prototype.alignFrame = function() {
163 var m
= this.mosaique
;
164 var iPosition
= m
.getImagePosition();
165 iPosition
.x
= Math
.max(0, iPosition
.x
);
166 iPosition
.y
= Math
.max(0, iPosition
.y
);
168 var frmPosition
= new Point(iPosition
.x
* (m
.thumbnailWidth
/ m
.imageWidth
),
169 iPosition
.y
* (m
.thumbnailHeight
/ m
.imageHeight
)
171 this.setFramePosition(frmPosition
);
174 Navigateur
.prototype.alignImage = function() {
175 var m
= this.mosaique
;
176 var frmPosition
= this.getFramePosition();
177 var iPosition
= new Point(frmPosition
.x
* (m
.imageWidth
/ m
.thumbnailWidth
),
178 frmPosition
.y
* (m
.imageHeight
/ m
.thumbnailHeight
)
180 this.mosaique
.loadScreen(iPosition
);
183 Navigateur
.prototype.getFramePosition = function() {
184 var x
= parseInt(this.frame
.style
.left
);
185 var y
= parseInt(this.frame
.style
.top
);
186 var p
= new Point(x
, y
);
190 Navigateur
.prototype.setFramePosition = function(point
) {
191 with(this.frame
.style
) {
192 left
= point
.x
+ 'px';
193 top
= point
.y
+ 'px';
198 Navigateur
.prototype._mouseDownHandler = function(evt
) {
199 this.initialClickPoint
= new Point(evt
.clientX
, evt
.clientY
);
200 this.initialPosition
= this.getFramePosition();
201 this.dragInProgress
= true;
204 Navigateur
.prototype._mouseMoveHandler = function(evt
) {
206 if(!this.dragInProgress
)
209 evt
= getEventObject(evt
);
210 var currentPoint
= new Point(evt
.clientX
, evt
.clientY
);
211 var displacement
= currentPoint
.diff(this.initialClickPoint
);
212 this.setFramePosition(this.initialPosition
.add(displacement
));
215 Navigateur
.prototype._mouseUpHandler = function(evt
) {
216 this.dragInProgress
= false;
220 Navigateur
.prototype.zoomIn = function(evt
) {
221 var m
= this.mosaique
;
222 var maxZoomIndex
= m
.zoomTable
.length
- 1
223 if (m
.zoomIndex
< maxZoomIndex
) {
224 var targetZoomIndex
= m
.zoomIndex
+ 1;
225 m
.loadZoomLevel(targetZoomIndex
);
226 this.currentZoomLevel
.nodeValue
= m
.zoomLevel
+ ' %';
229 if (targetZoomIndex
== maxZoomIndex
)
230 this.zoomInButton
.src
= this.zoomInButton
.src
.replace('zoom_in.gif', 'zoom_disabled.gif');
231 if (targetZoomIndex
> 0)
232 this.zoomOutButton
.src
= this.zoomOutButton
.src
.replace('zoom_disabled.gif', 'zoom_out.gif');
236 Navigateur
.prototype.zoomOut = function(evt
) {
237 var m
= this.mosaique
;
238 if (m
.zoomIndex
> 0 ) {
239 var targetZoomIndex
= m
.zoomIndex
- 1;
240 m
.loadZoomLevel(targetZoomIndex
);
241 this.currentZoomLevel
.nodeValue
= m
.zoomLevel
+ ' %';
244 if (targetZoomIndex
== 0)
245 this.zoomOutButton
.src
= this.zoomOutButton
.src
.replace('zoom_out.gif', 'zoom_disabled.gif');
246 if (targetZoomIndex
< m
.zoomTable
.length
- 1)
247 this.zoomInButton
.src
= this.zoomInButton
.src
.replace('zoom_disabled.gif', 'zoom_in.gif');
251 Navigateur
.prototype.zoomByKeybord = function(evt
){
252 evt
= getEventObject(evt
);
253 var charPress
= String
.fromCharCode((evt
.keyCode
) ? evt
.keyCode
: evt
.which
);