annotate webapp/src/main/webapp/jquery/jquery.digilib.arrows.js @ 1131:c1e7821d3c68

fix bug in path of arrow-images and problem with nested options.
author robcast
date Tue, 13 Nov 2012 17:35:32 +0100
parents e1b29f51d224
children
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,
1075
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
17 // by what fraction should the arrows move the zoomed area?
983
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)
1131
c1e7821d3c68 fix bug in path of arrow-images and problem with nested options.
robcast
parents: 1087
diff changeset
23 'imagePath' : 'img/fullscreen/32/',
1087
e1b29f51d224 adjust to arrow size.
robcast
parents: 1075
diff changeset
24 'arrowSetSize' : 16,
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/',
1087
e1b29f51d224 adjust to arrow size.
robcast
parents: 1075
diff changeset
29 'arrowSetSize' : 8,
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;
1075
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
69 // rotate and mirror change direction of cooordinate system
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
70 var trafo = data.imgTrafo;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
71 var tdx = (trafo.m00 > 0) ? dx : -dx;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
72 var tdy = (trafo.m11 > 0) ? dy : -dy;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
73 if (Math.abs(trafo.m00) < Math.abs(trafo.m01)) {
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
74 tdx = (trafo.m01 > 0) ? -dy : dy;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
75 tdy = (trafo.m10 > 0) ? -dx : dx;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
76 }
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
77 var deltaX = tdx * factor * za.width;
1e4f4964e9c2 CLOSED - # 25: scroll arrows have wrong direction with mirror and rot
robcast
parents: 1000
diff changeset
78 var deltaY = tdy * factor * za.height;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
79 var delta = geom.position(deltaX, deltaY);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
80 za.addPosition(delta);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
81 za = FULL_AREA.fit(za);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
82 digilib.fn.setZoomArea(data, za);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
83 digilib.fn.redisplay(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
84 }
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
85
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
86 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
87
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
88 // plugin installation called by digilib on plugin object.
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
89 var install = function(plugin) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
90 digilib = plugin;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
91 console.debug('installing arrows plugin. digilib:', digilib);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
92 // import geometry classes
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
93 geom = digilib.fn.geometry;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
94 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
95 // add defaults, actions
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
96 $.extend(true, digilib.defaults, defaults); // make deep copy
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
97 $.extend(digilib.buttons, buttons);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
98 $.extend(digilib.actions, actions);
994
8be56a27db58 fixed problem when using arrows.js without buttons.js.
robcast
parents: 990
diff changeset
99 // update buttons reference in defaults
8be56a27db58 fixed problem when using arrows.js without buttons.js.
robcast
parents: 990
diff changeset
100 digilib.defaults.buttons = digilib.buttons;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
101 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
102
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
103 // plugin initialization
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
104 var init = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
105 console.debug('initialising arrows plugin. data:', data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
106 var $data = $(data);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
107 // adjust insets
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
108 data.currentInsets['arrows'] = getInsets(data);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
109 // install event handler
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
110 $data.bind('setup', handleSetup);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
111 $data.bind('update', handleUpdate);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
112 // $data.bind('redisplay', handleRedisplay);
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
113 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
114
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
115 var handleSetup = function(evt) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
116 console.debug("arrows: handleSetup");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
117 var data = this;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
118 setupZoomArrows(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
119 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
120
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
121 var handleUpdate = function(evt) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
122 console.debug("arrows: handleUpdate");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
123 var data = this;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
124 renderZoomArrows(data);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
125 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
126
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
127
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
128 /**
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
129 * 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
130 */
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
131 var getInsets = function(data) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
132 var settings = data.settings;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
133 var insets = {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
134 'x' : 0,
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
135 'y' : 0
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
136 };
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
137 if (settings.showZoomArrows) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
138 var mode = settings.interactionMode;
990
2feb71b40e10 new, less wide scroll arrows.
robcast
parents: 989
diff changeset
139 var bw = settings.buttonSettings[mode].arrowSetSize;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
140 if (digilib.fn.canMove(data, 0, -1))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
141 insets.y += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
142 if (digilib.fn.canMove(data, 0, 1))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
143 insets.y += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
144 if (digilib.fn.canMove(data, -1, 0))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
145 insets.x += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
146 if (digilib.fn.canMove(data, 1, 0))
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
147 insets.x += bw;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
148 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
149 return insets;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
150 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
151
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
152 /**
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
153 * creates HTML structure for a single button
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
154 */
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
155 var createButton = function(data, $div, buttonName, show) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
156 var $elem = data.$elem;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
157 var settings = data.settings;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
158 var mode = settings.interactionMode;
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
159 var cssPrefix = settings.cssPrefix;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
160 var imagePath = settings.buttonSettings[mode].imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
161 // make relative imagePath absolute
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
162 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
163 imagePath = settings.digilibBaseUrl + '/jquery/' + imagePath;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
164 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
165 var buttonConfig = settings.buttons[buttonName];
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
166 // button properties
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
167 var action = buttonConfig.onclick;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
168 var tooltip = buttonConfig.tooltip;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
169 var icon = imagePath + buttonConfig.icon;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
170 // construct the button html
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
171 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
172 if (!show) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
173 $button.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
174 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
175 $div.append($button);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
176 // add attributes and bindings
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
177 $button.attr('title', tooltip);
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
178 $button.addClass(cssPrefix+'arrow-' + buttonName);
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
179 // 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
180 // scroll arrows)
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
181 $div.on('click.digilib', function(evt) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
182 // 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
183 console.debug('click action=', action, ' evt=', evt);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
184 $elem.digilib.apply($elem, action);
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
185 return false;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
186 });
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
187 return $button;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
188 };
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
189
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
190 /**
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
191 * create arrows for moving the zoomed area.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
192 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
193 var setupZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
194 var $elem = data.$elem;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
195 var settings = data.settings;
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
196 var cssPrefix = settings.cssPrefix;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
197 var show = settings.showZoomArrows;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
198 console.log('zoom arrows:', show);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
199 if (!show)
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
200 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
201 var mode = settings.interactionMode;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
202 var arrowNames = settings.buttonSettings[mode].arrowSet;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
203 if (arrowNames == null) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
204 console.error("No buttons for scroll arrows!");
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
205 settings.showZoomArrows = false;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
206 return;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
207 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
208 // wrap scaler img in table
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
209 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
210 // middle row with img has three elements
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
211 data.$scaler.parent().before('<td class="'+cssPrefix+'arrow '+cssPrefix+'left" valign="middle"/>')
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
212 .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
213 // first and last row has only one
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
214 var $table = $elem.find('table.'+cssPrefix+'scalertable');
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
215 $table.find('tr.'+cssPrefix+'midrow')
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
216 .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
217 .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
218 // add arrow buttons
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
219 var ar = {};
996
0b63093d598e cssPrefix works now.
robcast
parents: 994
diff changeset
220 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
221 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
222 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
223 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
224 data.arrows = ar;
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
225
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
226 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
227
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
228 /**
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
229 * show or hide arrows, called after scaler img is loaded.
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
230 *
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
231 */
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
232 var renderZoomArrows = function(data) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
233 var settings = data.settings;
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
234 var arrows = data.arrows;
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
235 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
236 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
237 arrows.$down.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
238 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
239 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
240 data.currentInsets['arrows'] = {'x' : 0, 'y' : 0};
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
241 return;
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
242 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
243 if (digilib.fn.canMove(data, 0, -1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
244 arrows.$up.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
245 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
246 arrows.$up.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
247 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
248 if (digilib.fn.canMove(data, 0, 1)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
249 arrows.$down.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
250 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
251 arrows.$down.hide();
983
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
252 }
989
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
253 if (digilib.fn.canMove(data, -1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
254 arrows.$left.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
255 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
256 arrows.$left.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
257 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
258 if (digilib.fn.canMove(data, 1, 0)) {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
259 arrows.$right.show();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
260 } else {
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
261 arrows.$right.hide();
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
262 }
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
263 // adjust insets
f4757bf6ab65 new arrows plugin for scroll arrows next to the image.
robcast
parents: 983
diff changeset
264 data.currentInsets['arrows'] = getInsets(data);
983
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 // plugin object with name and init
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
268 // shared objects filled by digilib on registration
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
269 var plugin = {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
270 name : 'arrows',
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
271 install : install,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
272 init : init,
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
273 buttons : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
274 actions : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
275 fn : {},
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
276 plugins : {}
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
277 };
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
278
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
279 if ($.fn.digilib == null) {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
280 $.error("jquery.digilib.arrows must be loaded after jquery.digilib!");
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
281 } else {
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
282 $.fn.digilib('plugin', plugin);
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
283 }
66db81af85e1 moved scroll arrows to separate plugin.
robcast
parents:
diff changeset
284 })(jQuery);