comparison client/digitallibrary/jquery/jquery.digilib.js @ 877:971b7122930f jquery

arrows: got basic functionality working
author hertzhaft
date Thu, 17 Mar 2011 16:43:59 +0100
parents a5a460afb912
children f6e2e6831aaf
comparison
equal deleted inserted replaced
876:a5a460afb912 877:971b7122930f
166 tooltip : "less options", 166 tooltip : "less options",
167 icon : "options.png" 167 icon : "options.png"
168 }, 168 },
169 up : { 169 up : {
170 onclick : ["moveZoomArea", 0, -1], 170 onclick : ["moveZoomArea", 0, -1],
171 tooltip : "move up", 171 tooltip : "move zoom area up",
172 icon : "up.png" 172 icon : "up.png"
173 }, 173 },
174 down : { 174 down : {
175 onclick : ["moveZoomArea", 0, 1], 175 onclick : ["moveZoomArea", 0, 1],
176 tooltip : "move down", 176 tooltip : "move zoom area down",
177 icon : "down.png" 177 icon : "down.png"
178 }, 178 },
179 left : { 179 left : {
180 onclick : ["moveZoomArea", -1, 0], 180 onclick : ["moveZoomArea", -1, 0],
181 tooltip : "move left", 181 tooltip : "move zoom area left",
182 icon : "left.png" 182 icon : "left.png"
183 }, 183 },
184 right : { 184 right : {
185 onclick : ["moveZoomArea", 1, 0], 185 onclick : ["moveZoomArea", 1, 0],
186 tooltip : "move right", 186 tooltip : "move zoom area right",
187 icon : "right.png" 187 icon : "right.png"
188 }, 188 },
189 SEP : { 189 SEP : {
190 icon : "sep.png" 190 icon : "sep.png"
191 } 191 }
1059 // add attributes and bindings 1059 // add attributes and bindings
1060 $button.attr('title', tooltip); 1060 $button.attr('title', tooltip);
1061 $button.addClass('button-' + buttonName); 1061 $button.addClass('button-' + buttonName);
1062 $img.attr('src', icon); 1062 $img.attr('src', icon);
1063 // create handler for the buttons 1063 // create handler for the buttons
1064 $a.bind('click.digilib', (function () { 1064 $button.bind('click.digilib', (function () {
1065 // we create a new closure to capture the value of action 1065 // we create a new closure to capture the value of action
1066 if ($.isArray(action)) { 1066 if ($.isArray(action)) {
1067 // the handler function calls digilib with action and parameters 1067 // the handler function calls digilib with action and parameters
1068 return function (evt) { 1068 return function (evt) {
1069 console.debug('click action=', action, ' evt=', evt); 1069 console.debug('click action=', action, ' evt=', evt);
1118 1118
1119 // creates arrow overlays for moving the zoomed area 1119 // creates arrow overlays for moving the zoomed area
1120 var setupZoomArrows = function (data) { 1120 var setupZoomArrows = function (data) {
1121 var $elem = data.$elem; 1121 var $elem = data.$elem;
1122 var settings = data.settings; 1122 var settings = data.settings;
1123 var show = settings.zoomArrows; 1123 var show = settings.showZoomArrows;
1124 console.log('zoom arrows:', show); 1124 console.log('zoom arrows:', show);
1125 if (!show) return; 1125 if (!show) return;
1126 data.$arrows = {}; 1126 var mode = settings.interactionMode;
1127 var $arrows = data.$arrows; 1127 var arrowNames = settings.buttonSettings[mode].arrowSet;
1128 var info = settings.zoomArrowsInfo; 1128 // arrow divs are marked with class "keep"
1129 $.each(['up','down','left','right'], function(i, s){ 1129 var $arrowsDiv = $('<div class="keep arrows"/>');
1130 var src = info.imagePath + info[s]; 1130 $elem.append($arrowsDiv);
1131 var $div = $('<div class="keep arrow arrow-' + s + '"/>'); 1131 // create all arrow buttons
1132 var $img = $('<img src="' + src + '"/>'); 1132 $.each(arrowNames, function(i, arrowName){
1133 $div.attr('title', s); 1133 createButton(data, $arrowsDiv, arrowName);
1134 $img.attr('alt', s); 1134 });
1135 $div.append($img);
1136 $elem.append($div);
1137 $arrows[s] = $div;
1138 });
1139 $arrows.up.bind('click.digilib', function(event) {
1140 //za.addPosition(delta.neg());
1141 // transform back
1142 // var newArea = data.imgTrafo.invtransform(za);
1143 // data.zoomArea = FULL_AREA.fit(newArea);
1144 redisplay(data);
1145 });
1146 $arrows.down.bind('click.digilib', function(event) {
1147 redisplay(data);
1148 });
1149 $arrows.left.bind('click.digilib', function(event) {
1150 redisplay(data);
1151 });
1152 $arrows.right.bind('click.digilib', function(event) {
1153 redisplay(data);
1154 });
1155 }; 1135 };
1156 1136
1157 // size and show arrow overlays, called after scaler img is loaded 1137 // size and show arrow overlays, called after scaler img is loaded
1158 var renderZoomArrows = function (data) { 1138 var renderZoomArrows = function (data) {
1159 if (!data.settings.zoomArrows) return; 1139 var settings = data.settings;
1160 if (isFullArea(data)) return; 1140 if (isFullArea(data) || !settings.showZoomArrows) return;
1161 var $arrows = data.$arrows; 1141 var $arrowsDiv = data.$elem.find('div.arrows');
1162 var r = FULL_AREA.copy(); 1142 var r = geom.rectangle(data.$scaler);
1163 r.height = 0.05; 1143 // calculate arrow bar width
1164 data.imgTrafo.transform(r).adjustDiv($arrows.up); 1144 var aw = settings.zoomArrowWidth;
1165 r.y = 0.95; 1145 var minWidth = settings.zoomArrowMinWidth;
1166 data.imgTrafo.transform(r).adjustDiv($arrows.down); 1146 // arrow bar width should not exceed 10% of scaler width/height
1167 r = FULL_AREA.copy(); 1147 var maxWidth = Math.min(r.width, r.height)/10;
1168 r.width = 0.05; 1148 if (aw > maxWidth) {
1169 data.imgTrafo.transform(r).adjustDiv($arrows.left); 1149 aw = maxWidth;
1170 r.x = 0.95; 1150 if (aw < minWidth) {
1171 data.imgTrafo.transform(r).adjustDiv($arrows.right); 1151 aw = minWidth;
1172 }; 1152 }
1173 1153 }
1154 $arrowsDiv.show();
1155 renderZoomArrow($arrowsDiv, 'up', geom.rectangle(r.x, r.y, r.width, aw));
1156 renderZoomArrow($arrowsDiv, 'down', geom.rectangle(r.x, r.y + r.height - aw, r.width));
1157 renderZoomArrow($arrowsDiv, 'left', geom.rectangle(r.x, r.y, aw, r.height));
1158 renderZoomArrow($arrowsDiv, 'right', geom.rectangle(r.x + r.width - aw, r.y, aw, r.height));
1159 };
1160
1161 // render a single zoom Arrow
1162 var renderZoomArrow = function ($div, name, rect) {
1163 var $arrow = $div.find('div.button-' + name);
1164 rect.adjustDiv($arrow);
1165 };
1174 1166
1175 // creates HTML structure for the about view in elem 1167 // creates HTML structure for the about view in elem
1176 var setupAboutDiv = function (data) { 1168 var setupAboutDiv = function (data) {
1177 var $elem = data.$elem; 1169 var $elem = data.$elem;
1178 var settings = data.settings; 1170 var settings = data.settings;