annotate webapp/src/main/webapp/jquery/jquery.digilib.arrows.js @ 994:8be56a27db58

fixed problem when using arrows.js without buttons.js. handling of settings.buttons reference still not perfect.
author robcast
date Thu, 09 Feb 2012 17:54:59 +0100
parents 2feb71b40e10
children 0b63093d598e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
1 /**
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
2 * digilib pan arrows for scrolling the zoomed area.
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
3 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
4
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
5 (function($) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
6
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
7 // affine geometry
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
8 var geom = null;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
9 // plugin object with digilib data
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
10 var digilib = null;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
11
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
12 var FULL_AREA = null;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
13
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
14 var defaults = {
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
15 // arrow bars for moving the zoomed area
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
16 'showZoomArrows' : true,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
17 // by what percentage should the arrows move the zoomed area?
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
18 'zoomArrowMoveFactor' : 0.5,
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
19 // defaults for digilib buttons
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
20 'buttonSettings' : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
21 'fullscreen' : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
22 // path to button images (must end with a slash)
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
23 'imagePath' : 'img/fullscreen/',
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
24 'arrowSetSize' : 18,
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
25 'arrowSet' : [ "up", "down", "left", "right" ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
26 },
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
27 'embedded' : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
28 'imagePath' : 'img/embedded/16/',
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
29 'arrowSetSize' : 9,
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
30 'arrowSet' : [ "up", "down", "left", "right" ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
31 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
32 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
33 };
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
34
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
35 var buttons = {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
36 up : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
37 onclick : [ "moveZoomArea", 0, -1 ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
38 tooltip : "move zoom area up",
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
39 icon : "up.png"
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
40 },
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
41 down : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
42 onclick : [ "moveZoomArea", 0, 1 ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
43 tooltip : "move zoom area down",
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
44 icon : "down.png"
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
45 },
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
46 left : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
47 onclick : [ "moveZoomArea", -1, 0 ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
48 tooltip : "move zoom area left",
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
49 icon : "left.png"
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
50 },
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
51 right : {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
52 onclick : [ "moveZoomArea", 1, 0 ],
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
53 tooltip : "move zoom area right",
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
54 icon : "right.png"
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
55 }
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
56 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
57
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
58 var actions = {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
59 /**
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
60 * move zoomed area
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
61 *
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
62 * @param data
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
63 * @param dx
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
64 * @param dy
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
65 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
66 moveZoomArea : function(data, dx, dy) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
67 var za = data.zoomArea.copy();
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
68 var factor = data.settings.zoomArrowMoveFactor;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
69 var deltaX = dx * factor * za.width;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
70 var deltaY = dy * factor * za.height;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
71 var delta = geom.position(deltaX, deltaY);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
72 za.addPosition(delta);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
73 za = FULL_AREA.fit(za);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
74 digilib.fn.setZoomArea(data, za);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
75 digilib.fn.redisplay(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
76 }
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
77
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
78 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
79
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
80 // plugin installation called by digilib on plugin object.
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
81 var install = function(plugin) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
82 digilib = plugin;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
83 console.debug('installing arrows plugin. digilib:', digilib);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
84 // import geometry classes
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
85 geom = digilib.fn.geometry;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
86 FULL_AREA = geom.rectangle(0, 0, 1, 1);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
87 // add defaults, actions
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
88 $.extend(true, digilib.defaults, defaults); // make deep copy
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
89 $.extend(digilib.buttons, buttons);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
90 $.extend(digilib.actions, actions);
994
8be56a27db58 fixed problem when using arrows.js without buttons.js.
robcast
parents: 990
diff changeset
91 // update buttons reference in defaults
8be56a27db58 fixed problem when using arrows.js without buttons.js.
robcast
parents: 990
diff changeset
92 digilib.defaults.buttons = digilib.buttons;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
93 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
94
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
95 // plugin initialization
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
96 var init = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
97 console.debug('initialising arrows plugin. data:', data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
98 var $data = $(data);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
99 // adjust insets
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
100 data.currentInsets['arrows'] = getInsets(data);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
101 // install event handler
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
102 $data.bind('setup', handleSetup);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
103 $data.bind('update', handleUpdate);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
104 // $data.bind('redisplay', handleRedisplay);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
105 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
106
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
107 var handleSetup = function(evt) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
108 console.debug("arrows: handleSetup");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
109 var data = this;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
110 setupZoomArrows(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
111 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
112
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
113 var handleUpdate = function(evt) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
114 console.debug("arrows: handleUpdate");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
115 var data = this;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
116 renderZoomArrows(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
117 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
118
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
119
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
120 /**
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
121 * returns insets for arrows (based on canMove and arrowSetSize
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
122 */
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
123 var getInsets = function(data) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
124 var settings = data.settings;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
125 var insets = {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
126 'x' : 0,
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
127 'y' : 0
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
128 };
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
129 if (settings.showZoomArrows) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
130 var mode = settings.interactionMode;
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
131 var bw = settings.buttonSettings[mode].arrowSetSize;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
132 if (digilib.fn.canMove(data, 0, -1))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
133 insets.y += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
134 if (digilib.fn.canMove(data, 0, 1))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
135 insets.y += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
136 if (digilib.fn.canMove(data, -1, 0))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
137 insets.x += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
138 if (digilib.fn.canMove(data, 1, 0))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
139 insets.x += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
140 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
141 return insets;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
142 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
143
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
144 /**
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
145 * creates HTML structure for a single button
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
146 */
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
147 var createButton = function(data, $div, buttonName, show) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
148 var $elem = data.$elem;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
149 var settings = data.settings;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
150 var mode = settings.interactionMode;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
151 var imagePath = settings.buttonSettings[mode].imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
152 // make relative imagePath absolute
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
153 if (imagePath.charAt(0) !== '/' && imagePath.substring(0, 3) !== 'http') {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
154 imagePath = settings.digilibBaseUrl + '/jquery/' + imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
155 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
156 var buttonConfig = settings.buttons[buttonName];
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
157 // button properties
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
158 var action = buttonConfig.onclick;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
159 var tooltip = buttonConfig.tooltip;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
160 var icon = imagePath + buttonConfig.icon;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
161 // construct the button html
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
162 var $button = $('<div class="keep"><a href=""><img class="button" src="' + icon + '"/></a></div>');
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
163 if (!show) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
164 $button.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
165 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
166 $div.append($button);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
167 // add attributes and bindings
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
168 $button.attr('title', tooltip);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
169 $button.addClass('arrow-' + buttonName);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
170 // create handler for the buttons on the div (necessary for horizontal
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
171 // scroll arrows)
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
172 $div.on('click.digilib', function(evt) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
173 // the handler function calls digilib with action and parameters
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
174 console.debug('click action=', action, ' evt=', evt);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
175 $elem.digilib.apply($elem, action);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
176 return false;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
177 });
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
178 return $button;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
179 };
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
180
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
181 /**
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
182 * create arrows for moving the zoomed area.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
183 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
184 var setupZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
185 var $elem = data.$elem;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
186 var settings = data.settings;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
187 var show = settings.showZoomArrows;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
188 console.log('zoom arrows:', show);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
189 if (!show)
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
190 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
191 var mode = settings.interactionMode;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
192 var arrowNames = settings.buttonSettings[mode].arrowSet;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
193 if (arrowNames == null) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
194 console.error("No buttons for scroll arrows!");
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
195 settings.showZoomArrows = false;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
196 return;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
197 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
198 // wrap scaler img in table
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
199 data.$scaler.wrap('<table class="scalertable"><tbody><tr class="midrow"><td/></tr></tbody></table>');
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
200 // middle row with img has three elements
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
201 data.$scaler.parent().before('<td class="arrow left" valign="middle"/>').after('<td class="arrow right" valign="middle"/>');
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
202 // first and last row has only one
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
203 var $table = $elem.find('table.scalertable');
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
204 $table.find('tr.midrow').before('<tr class="firstrow"><td colspan="3" class="arrow up" align="center"/></tr>').after(
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
205 '<tr class="lasttrow"><td colspan="3" class="arrow down" align="center"/></tr>');
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
206 // add arrow buttons
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
207 var ar = {};
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
208 ar.$up = createButton(data, $table.find('td.up'), 'up', digilib.fn.canMove(data, 0, -1));
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
209 ar.$down = createButton(data, $table.find('td.down'), 'down', digilib.fn.canMove(data, 0, 1));
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
210 ar.$left = createButton(data, $table.find('td.left'), 'left', digilib.fn.canMove(data, -1, 0));
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
211 ar.$right = createButton(data, $table.find('td.right'), 'right', digilib.fn.canMove(data, 1, 0));
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
212 data.arrows = ar;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
213
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
214 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
215
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
216 /**
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
217 * show or hide arrows, called after scaler img is loaded.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
218 *
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
219 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
220 var renderZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
221 var settings = data.settings;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
222 var arrows = data.arrows;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
223 if (digilib.fn.isFullArea(data.zoomArea) || !settings.showZoomArrows) {
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
224 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
225 arrows.$down.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
226 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
227 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
228 data.currentInsets['arrows'] = {'x' : 0, 'y' : 0};
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
229 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
230 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
231 if (digilib.fn.canMove(data, 0, -1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
232 arrows.$up.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
233 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
234 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
235 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
236 if (digilib.fn.canMove(data, 0, 1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
237 arrows.$down.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
238 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
239 arrows.$down.hide();
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
240 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
241 if (digilib.fn.canMove(data, -1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
242 arrows.$left.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
243 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
244 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
245 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
246 if (digilib.fn.canMove(data, 1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
247 arrows.$right.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
248 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
249 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
250 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
251 // adjust insets
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
252 data.currentInsets['arrows'] = getInsets(data);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
253 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
254
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
255 // plugin object with name and init
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
256 // shared objects filled by digilib on registration
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
257 var plugin = {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
258 name : 'arrows',
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
259 install : install,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
260 init : init,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
261 buttons : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
262 actions : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
263 fn : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
264 plugins : {}
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
265 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
266
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
267 if ($.fn.digilib == null) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
268 $.error("jquery.digilib.arrows must be loaded after jquery.digilib!");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
269 } else {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
270 $.fn.digilib('plugin', plugin);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
271 }
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
272 })(jQuery);