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