annotate client/digitallibrary/jquery/jquery.digilib.birdseye.js @ 788:040e9bc1602e jquery

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