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