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
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
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
10 var FULL_AREA;
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
20 var defaults = {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
21 // is birdView shown?
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
22 'isBirdDivVisible' : false,
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
23 // dimensions of bird's eye div
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
24 'birdDivWidth' : 200,
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
25 'birdDivHeight' : 200,
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
26 // parameters used by bird's eye div
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
27 'birdDivParams' : ['fn','pn','dw','dh']
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
28 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 796
diff changeset
29
791
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
46 // plugin installation called by digilib on plugin object.
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
47 var install = function(digilib) {
791
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
48 // import geometry classes
795
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
49 geom = digilib.fn.geometry;
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
50 FULL_AREA = geom.rectangle(0,0,1,1);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
51 // add defaults
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
52 $.extend(digilib.defaults, defaults);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
53 // add actions
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
54 $.extend(digilib.actions, actions);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
55 // add buttons
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
56 $.extend(digilib.buttons, buttons);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
57 // insert in button list -- not elegant
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
58 digilib.defaults.buttonSettings.fullscreen.standardSet.splice(9, 0, 'bird');
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
59 digilib.defaults.buttonSettings.embedded.standardSet.splice(5, 0, 'bird');
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
60 };
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
61
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
62 // plugin initialization
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
63 var init = function (data) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
64 var $data = $(data);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
65 // install event handler
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
66 $data.bind('setup', handleSetup);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
69 $data.bind('dragZoom', handleDragZoom);
791
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
70 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 796
diff changeset
71
795
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
72
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
73 var handleSetup = function (evt) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
74 console.debug("birdseye: handleSetup");
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
75 data = this;
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
76 // bird's eye view creation
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
77 if (data.settings.isBirdDivVisible) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
78 setupBirdDiv(data);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
79 data.$birdDiv.show();
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
80 }
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
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 var handleUpdate = function (evt) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
84 console.debug("birdseye: handleUpdate");
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
85 data = this;
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
86 if (data.settings.isBirdDivVisible) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
87 renderBirdArea(data);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
88 setupBirdDrag(data);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
89 }
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
100 var handleDragZoom = function (evt, zoomArea) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
101 //console.debug("birdseye: handleDragZoom za="+zoomArea);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
102 data = this;
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
103 if (data.settings.isBirdDivVisible) {
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
104 setBirdZoom(data, zoomArea);
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
105 }
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
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
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
306 // plugin object with name and init
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
307 // shared objects filled by digilib on registration
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
308 var digilib = {
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
309 name : 'birdseye',
793
63c1b33e38b1 documentation for new plugin api in jquery-digilib-plugin.txt.
robcast
parents: 791
diff changeset
310 install : install,
795
00d37112d062 birds eye view now as a plugin.
robcast
parents: 793
diff changeset
311 init : init,
791
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
312 buttons : {},
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
313 actions : {},
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
314 fn : {},
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
315 plugins : {}
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
316 };
799
12f790cb30de started to adapt regions plugin to new plugin mechanism
hertzhaft
parents: 796
diff changeset
317
791
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
318 if ($.fn.digilib == null) {
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
319 $.error("jquery.digilib.birdview must be loaded after jquery.digilib!");
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
320 } else {
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
321 $.fn.digilib('plugin', digilib);
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
322 }
304488c72344 first step to birdseye view as a plugin.
robcast
parents:
diff changeset
323 })(jQuery);