annotate webapp/src/main/webapp/jquery/jquery.digilib.birdseye.js @ 1118:f0474c1faaff

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