Mercurial > hg > digilib
annotate client/digitallibrary/jquery/jquery.digilib.birdseye.js @ 788:040e9bc1602e jquery
birds eye view now as a plugin.
digilib now 200 lines less!
author | robcast |
---|---|
date | Fri, 18 Feb 2011 18:58:52 +0100 |
parents | 912519475259 |
children | 32d1d6601968 |
rev | line source |
---|---|
784 | 1 /** required digilib geometry plugin |
2 */ | |
3 | |
4 (function($) { | |
5 | |
6 // affine geometry plugin stub | |
7 var geom; | |
8 | |
9 var FULL_AREA; | |
10 | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
11 var buttons = { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
12 bird : { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
13 onclick : "showBirdDiv", |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
14 tooltip : "show bird's eye view", |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
15 icon : "birds-eye.png" |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
16 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
17 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
18 |
788 | 19 var defaults = { |
20 // is birdView shown? | |
21 'isBirdDivVisible' : false, | |
22 // dimensions of bird's eye div | |
23 'birdDivWidth' : 200, | |
24 'birdDivHeight' : 200, | |
25 // parameters used by bird's eye div | |
26 'birdDivParams' : ['fn','pn','dw','dh'] | |
27 }; | |
28 | |
784 | 29 var actions = { |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
30 // event handler: toggles the visibility of the bird's eye window |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
31 showBirdDiv : function (data, show) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
32 var settings = data.settings; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
33 if (data.$birdDiv == null) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
34 // no bird div -> create |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
35 setupBirdDiv(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
36 } |
788 | 37 var on = digilib.fn.showDiv(settings.isBirdDivVisible, data.$birdDiv, show); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
38 settings.isBirdDivVisible = on; |
788 | 39 digilib.fn.highlightButtons(data, 'bird', on); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
40 updateBirdDiv(data); |
788 | 41 digilib.fn.storeOptions(data); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
42 } |
784 | 43 }; |
44 | |
788 | 45 // plugin installation called by digilib on plugin object. |
46 var install = function(digilib) { | |
784 | 47 // import geometry classes |
788 | 48 geom = digilib.fn.geometry; |
49 FULL_AREA = geom.rectangle(0,0,1,1); | |
50 // add defaults | |
51 $.extend(digilib.defaults, defaults); | |
52 // add actions | |
53 $.extend(digilib.actions, actions); | |
54 // add buttons | |
55 $.extend(digilib.buttons, buttons); | |
56 // insert in button list -- not elegant | |
57 digilib.defaults.buttonSettings.fullscreen.standardSet.splice(9, 0, 'bird'); | |
58 digilib.defaults.buttonSettings.embedded.standardSet.splice(5, 0, 'bird'); | |
59 }; | |
60 | |
61 // plugin initialization | |
62 var init = function (data) { | |
63 var $data = $(data); | |
64 // install event handler | |
65 $data.bind('setup', handleSetup); | |
66 $data.bind('update', handleUpdate); | |
67 $data.bind('dragZoom', handleDragZoom); | |
784 | 68 }; |
69 | |
788 | 70 |
71 var handleSetup = function (evt) { | |
72 console.debug("birdseye: handleSetup"); | |
73 data = this; | |
74 // bird's eye view creation | |
75 if (data.settings.isBirdDivVisible) { | |
76 setupBirdDiv(data); | |
77 data.$birdDiv.show(); | |
78 } | |
79 }; | |
80 | |
81 var handleUpdate = function (evt) { | |
82 console.debug("birdseye: handleUpdate"); | |
83 data = this; | |
84 if (data.settings.isBirdDivVisible) { | |
85 renderBirdArea(data); | |
86 setupBirdDrag(data); | |
87 } | |
88 }; | |
89 | |
90 var handleDragZoom = function (evt, zoomArea) { | |
91 //console.debug("birdseye: handleDragZoom za="+zoomArea); | |
92 data = this; | |
93 if (data.settings.isBirdDivVisible) { | |
94 setBirdZoom(data, zoomArea); | |
95 } | |
96 }; | |
97 | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
98 // returns URL for bird's eye view image |
788 | 99 var getBirdImgUrl = function (data) { |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
100 var settings = data.settings; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
101 var birdDivOptions = { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
102 dw : settings.birdDivWidth, |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
103 dh : settings.birdDivHeight |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
104 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
105 var birdSettings = $.extend({}, settings, birdDivOptions); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
106 // use only the relevant parameters |
788 | 107 var params = digilib.fn.getParamString(birdSettings, settings.birdDivParams, digilib.defaults); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
108 var url = settings.scalerBaseUrl + '?' + params; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
109 return url; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
110 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
111 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
112 // creates HTML structure for the bird's eye view in elem |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
113 var setupBirdDiv = function (data) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
114 var $elem = data.$elem; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
115 // the bird's eye div |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
116 var $birdDiv = $('<div class="birdview" style="display:none"/>'); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
117 // the detail indicator frame |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
118 var $birdZoom = $('<div class="birdzoom" style="display:none; background-color:transparent;"/>'); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
119 // the small image |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
120 var $birdImg = $('<img class="birdimg"/>'); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
121 data.$birdDiv = $birdDiv; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
122 data.$birdZoom = $birdZoom; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
123 data.$birdImg = $birdImg; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
124 $elem.append($birdDiv); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
125 $birdDiv.append($birdZoom); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
126 $birdDiv.append($birdImg); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
127 // $birdZoom.css(data.settings.birdIndicatorStyle); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
128 var birdUrl = getBirdImgUrl(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
129 $birdImg.load(birdImgLoadedHandler(data)); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
130 $birdImg.error(function () {console.error("error loading birdview image");}); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
131 $birdImg.attr('src', birdUrl); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
132 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
133 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
134 // update bird's eye view |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
135 var updateBirdDiv = function (data) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
136 if (!data.settings.isBirdDivVisible) return; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
137 var $birdImg = data.$birdImg; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
138 var oldsrc = $birdImg.attr('src'); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
139 var newsrc = getBirdImgUrl(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
140 if (oldsrc !== newsrc) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
141 $birdImg.attr('src', newsrc); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
142 // onload handler re-renders |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
143 } else { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
144 // re-render |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
145 renderBirdArea(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
146 // enable click and drag |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
147 setupBirdDrag(data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
148 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
149 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
150 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
151 // returns function for load event of bird's eye view img |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
152 var birdImgLoadedHandler = function (data) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
153 return function () { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
154 var $birdImg = $(this); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
155 var birdRect = geom.rectangle($birdImg); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
156 console.debug("birdImg loaded!", $birdImg, "rect=", birdRect, "data=", data); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
157 if (birdRect.width === 0) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
158 // malheureusement IE7 calls load handler when there is no size info yet |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
159 setTimeout(function () { $birdImg.triggerHandler('load'); }, 200); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
160 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
161 // update display (zoom area indicator) |
788 | 162 digilib.fn.updateDisplay(data); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
163 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
164 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
165 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
166 // show zoom area indicator on bird's eye view |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
167 var renderBirdArea = function (data) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
168 if (data.$birdImg == null || ! data.$birdImg.get(0).complete) return; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
169 var $birdZoom = data.$birdZoom; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
170 var zoomArea = data.zoomArea; |
788 | 171 var normalSize = digilib.fn.isFullArea(zoomArea); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
172 if (normalSize) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
173 $birdZoom.hide(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
174 return; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
175 } else { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
176 $birdZoom.show(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
177 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
178 // create Transform from current area and picsize |
788 | 179 data.birdTrafo = digilib.fn.getImgTrafo(data.$birdImg, FULL_AREA); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
180 var zoomRect = data.birdTrafo.transform(zoomArea); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
181 console.debug("renderBirdArea:", zoomRect, "zoomArea:", zoomArea, "$birdTrafo:", data.birdTrafo); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
182 // acount for border width |
788 | 183 var bw = digilib.fn.getBorderWidth($birdZoom); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
184 zoomRect.addPosition({x : -bw, y : -bw}); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
185 if (data.settings.interactionMode === 'fullscreen') { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
186 // no animation for fullscreen |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
187 zoomRect.adjustDiv($birdZoom); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
188 } else { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
189 // nice animation for embedded mode :-) |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
190 // correct offsetParent because animate doesn't use offset |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
191 var ppos = $birdZoom.offsetParent().offset(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
192 var dest = { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
193 left : (zoomRect.x - ppos.left) + 'px', |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
194 top : (zoomRect.y - ppos.top) + 'px', |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
195 width : zoomRect.width, |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
196 height : zoomRect.height |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
197 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
198 $birdZoom.animate(dest); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
199 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
200 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
201 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
202 // bird's eye view zoom area click and drag handler |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
203 var setupBirdDrag = function(data) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
204 var $birdImg = data.$birdImg; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
205 var $birdZoom = data.$birdZoom; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
206 var $document = $(document); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
207 var $scaler = data.$scaler; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
208 var startPos, newRect, birdImgRect, birdZoomRect, fullRect, scalerPos; |
788 | 209 var bw = digilib.fn.getBorderWidth($birdZoom); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
210 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
211 // mousedown handler: start dragging bird zoom to a new position |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
212 var birdZoomStartDrag = function(evt) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
213 startPos = geom.position(evt); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
214 // position may have changed |
788 | 215 data.birdTrafo = digilib.fn.getImgTrafo($birdImg, FULL_AREA); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
216 birdImgRect = geom.rectangle($birdImg); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
217 birdZoomRect = geom.rectangle($birdZoom); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
218 scalerPos = geom.position($scaler); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
219 newRect = null; |
788 | 220 fullRect = digilib.fn.setZoomBG(data); // setup zoom background image |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
221 $document.bind("mousemove.dlBirdMove", birdZoomMove); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
222 $document.bind("mouseup.dlBirdMove", birdZoomEndDrag); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
223 return false; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
224 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
225 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
226 // mousemove handler: drag |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
227 var birdZoomMove = function(evt) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
228 var pos = geom.position(evt); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
229 var delta = startPos.delta(pos); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
230 // move birdZoom div, keeping size |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
231 newRect = birdZoomRect.copy(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
232 newRect.addPosition(delta); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
233 newRect.stayInside(birdImgRect); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
234 // reflect birdview zoom position in scaler image |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
235 var area = data.birdTrafo.invtransform(newRect); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
236 var imgArea = data.imgTrafo.transform(area); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
237 var offset = imgArea.getPosition().neg(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
238 offset.add(scalerPos); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
239 if (fullRect) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
240 var bgPos = fullRect.getPosition().add(offset); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
241 } else { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
242 var bgPos = offset; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
243 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
244 // move the background image to the new position |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
245 data.$scaler.css({ |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
246 'background-position' : bgPos.x + "px " + bgPos.y + "px" |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
247 }); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
248 // acount for border width |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
249 newRect.addPosition({x : -bw, y : -bw}); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
250 newRect.adjustDiv($birdZoom); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
251 return false; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
252 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
253 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
254 // mouseup handler: reload page |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
255 var birdZoomEndDrag = function(evt) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
256 var settings = data.settings; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
257 $document.unbind("mousemove.dlBirdMove", birdZoomMove); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
258 $document.unbind("mouseup.dlBirdMove", birdZoomEndDrag); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
259 if (newRect == null) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
260 // no movement happened - set center to click position |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
261 startPos = birdZoomRect.getCenter(); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
262 birdZoomMove(evt); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
263 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
264 // ugly, but needed to prevent double border width compensation |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
265 newRect.addPosition({x : bw, y : bw}); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
266 var newArea = data.birdTrafo.invtransform(newRect); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
267 data.zoomArea = newArea; |
788 | 268 digilib.fn.redisplay(data); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
269 return false; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
270 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
271 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
272 // clear old handler |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
273 $document.unbind(".dlBirdMove"); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
274 $birdImg.unbind(".dlBirdMove"); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
275 $birdZoom.unbind(".dlBirdMove"); |
788 | 276 if (! digilib.fn.isFullArea(data.zoomArea)) { |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
277 // set new handler |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
278 $birdImg.bind("mousedown.dlBirdMove", birdZoomStartDrag); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
279 $birdZoom.bind("mousedown.dlBirdMove", birdZoomStartDrag); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
280 } |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
281 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
282 |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
283 // move bird zoom indicator to reflect zoomed detail area |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
284 var setBirdZoom = function(data, rect) { |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
285 var part = data.imgTrafo.invtransform(rect); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
286 // area = FULL_AREA.fit(part); // no, we want to see where we transcend the borders |
788 | 287 birdTrafo = digilib.fn.getImgTrafo(data.$birdImg, FULL_AREA); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
288 var birdRect = birdTrafo.transform(part); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
289 var $birdZoom = data.$birdZoom; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
290 // acount for border width |
788 | 291 var bw = digilib.fn.getBorderWidth($birdZoom); |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
292 birdRect.addPosition({x : -bw, y : -bw}); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
293 birdRect.adjustDiv(data.$birdZoom); |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
294 }; |
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
295 |
784 | 296 // plugin object with name and init |
297 // shared objects filled by digilib on registration | |
298 var digilib = { | |
299 name : 'birdseye', | |
786
912519475259
documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents:
784
diff
changeset
|
300 install : install, |
788 | 301 init : init, |
784 | 302 buttons : {}, |
303 actions : {}, | |
304 fn : {}, | |
305 plugins : {} | |
306 }; | |
307 | |
308 if ($.fn.digilib == null) { | |
309 $.error("jquery.digilib.birdview must be loaded after jquery.digilib!"); | |
310 } else { | |
311 $.fn.digilib('plugin', digilib); | |
312 } | |
313 })(jQuery); |