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