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