annotate webapp/src/main/webapp/jquery/jquery.digilib.arrows.js @ 1000:f7bfc40bffea

IE still doesn't like commas
author hertzhaft
date Mon, 13 Feb 2012 15:30:06 +0100
parents 0b63093d598e
children 1e4f4964e9c2
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,
1000
f7bfc40bffea IE still doesn't like commas
hertzhaft
parents: 996
diff changeset
25 'arrowSet' : [ "up", "down", "left", "right" ]
989
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,
1000
f7bfc40bffea IE still doesn't like commas
hertzhaft
parents: 996
diff changeset
30 'arrowSet' : [ "up", "down", "left", "right" ]
989
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;
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
151 var cssPrefix = settings.cssPrefix;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
152 var imagePath = settings.buttonSettings[mode].imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
153 // make relative imagePath absolute
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
154 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
155 imagePath = settings.digilibBaseUrl + '/jquery/' + imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
156 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
157 var buttonConfig = settings.buttons[buttonName];
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
158 // button properties
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
159 var action = buttonConfig.onclick;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
160 var tooltip = buttonConfig.tooltip;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
161 var icon = imagePath + buttonConfig.icon;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
162 // construct the button html
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
163 var $button = $('<div class="'+cssPrefix+'keep"><a href=""><img class="'+cssPrefix+'button" src="' + icon + '"/></a></div>');
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
164 if (!show) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
165 $button.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
166 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
167 $div.append($button);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
168 // add attributes and bindings
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
169 $button.attr('title', tooltip);
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
170 $button.addClass(cssPrefix+'arrow-' + buttonName);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
171 // 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
172 // scroll arrows)
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
173 $div.on('click.digilib', function(evt) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
174 // 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
175 console.debug('click action=', action, ' evt=', evt);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
176 $elem.digilib.apply($elem, action);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
177 return false;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
178 });
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
179 return $button;
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 /**
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
183 * create arrows for moving the zoomed area.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
184 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
185 var setupZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
186 var $elem = data.$elem;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
187 var settings = data.settings;
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
188 var cssPrefix = settings.cssPrefix;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
189 var show = settings.showZoomArrows;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
190 console.log('zoom arrows:', show);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
191 if (!show)
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
192 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
193 var mode = settings.interactionMode;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
194 var arrowNames = settings.buttonSettings[mode].arrowSet;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
195 if (arrowNames == null) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
196 console.error("No buttons for scroll arrows!");
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
197 settings.showZoomArrows = false;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
198 return;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
199 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
200 // wrap scaler img in table
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
201 data.$scaler.wrap('<table class="'+cssPrefix+'scalertable"><tbody><tr class="'+cssPrefix+'midrow"><td/></tr></tbody></table>');
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
202 // middle row with img has three elements
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
203 data.$scaler.parent().before('<td class="'+cssPrefix+'arrow '+cssPrefix+'left" valign="middle"/>')
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
204 .after('<td class="'+cssPrefix+'arrow '+cssPrefix+'right" valign="middle"/>');
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
205 // first and last row has only one
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
206 var $table = $elem.find('table.'+cssPrefix+'scalertable');
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
207 $table.find('tr.'+cssPrefix+'midrow')
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
208 .before('<tr class="'+cssPrefix+'firstrow"><td colspan="3" class="'+cssPrefix+'arrow '+cssPrefix+'up" align="center"/></tr>')
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
209 .after('<tr class="'+cssPrefix+'lasttrow"><td colspan="3" class="'+cssPrefix+'arrow '+cssPrefix+'down" align="center"/></tr>');
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
210 // add arrow buttons
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
211 var ar = {};
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
212 ar.$up = createButton(data, $table.find('td.'+cssPrefix+'up'), 'up', digilib.fn.canMove(data, 0, -1));
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
213 ar.$down = createButton(data, $table.find('td.'+cssPrefix+'down'), 'down', digilib.fn.canMove(data, 0, 1));
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
214 ar.$left = createButton(data, $table.find('td.'+cssPrefix+'left'), 'left', digilib.fn.canMove(data, -1, 0));
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
215 ar.$right = createButton(data, $table.find('td.'+cssPrefix+'right'), 'right', digilib.fn.canMove(data, 1, 0));
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
216 data.arrows = ar;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
217
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 /**
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
221 * show or hide arrows, called after scaler img is loaded.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
222 *
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
223 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
224 var renderZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
225 var settings = data.settings;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
226 var arrows = data.arrows;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
227 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
228 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
229 arrows.$down.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
230 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
231 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
232 data.currentInsets['arrows'] = {'x' : 0, 'y' : 0};
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
233 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
234 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
235 if (digilib.fn.canMove(data, 0, -1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
236 arrows.$up.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
237 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
238 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
239 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
240 if (digilib.fn.canMove(data, 0, 1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
241 arrows.$down.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
242 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
243 arrows.$down.hide();
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
244 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
245 if (digilib.fn.canMove(data, -1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
246 arrows.$left.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
247 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
248 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
249 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
250 if (digilib.fn.canMove(data, 1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
251 arrows.$right.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
252 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
253 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
254 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
255 // adjust insets
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
256 data.currentInsets['arrows'] = getInsets(data);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
257 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
258
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
259 // plugin object with name and init
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
260 // shared objects filled by digilib on registration
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
261 var plugin = {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
262 name : 'arrows',
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
263 install : install,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
264 init : init,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
265 buttons : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
266 actions : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
267 fn : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
268 plugins : {}
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
269 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
270
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
271 if ($.fn.digilib == null) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
272 $.error("jquery.digilib.arrows must be loaded after jquery.digilib!");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
273 } else {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
274 $.fn.digilib('plugin', plugin);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
275 }
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
276 })(jQuery);