comparison client/digitallibrary/jquery/jquery.digilib.js @ 886:cb23fe100d7e jquery

make getFullscreenImgSize more robust. put button width in settings.
author robcast
date Wed, 06 Apr 2011 10:11:03 +0200
parents b2ec8244b86e
children 65ad22044e13
comparison
equal deleted inserted replaced
882:07926f0b9a1a 886:cb23fe100d7e
235 // defaults for digilib buttons 235 // defaults for digilib buttons
236 'buttonSettings' : { 236 'buttonSettings' : {
237 'fullscreen' : { 237 'fullscreen' : {
238 // path to button images (must end with a slash) 238 // path to button images (must end with a slash)
239 'imagePath' : 'img/fullscreen/', 239 'imagePath' : 'img/fullscreen/',
240 'buttonSetWidth' : 36,
240 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","help","reset","toggleoptions"], 241 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","pagewidth","back","fwd","page","help","reset","toggleoptions"],
241 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","lessoptions"], 242 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","size","calibrationx","scale","lessoptions"],
242 'arrowSet' : ["up", "down", "left", "right"], 243 'arrowSet' : ["up", "down", "left", "right"],
243 'buttonSets' : ['standardSet', 'specialSet'] 244 'buttonSets' : ['standardSet', 'specialSet']
244 }, 245 },
245 'embedded' : { 246 'embedded' : {
246 'imagePath' : 'img/embedded/16/', 247 'imagePath' : 'img/embedded/16/',
248 'buttonSetWidth' : 18,
247 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","help","reset","toggleoptions"], 249 'standardSet' : ["reference","zoomin","zoomout","zoomarea","zoomfull","help","reset","toggleoptions"],
248 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","scale","lessoptions"], 250 'specialSet' : ["mark","delmark","hmir","vmir","rot","brgt","cont","rgb","quality","scale","lessoptions"],
249 'arrowSet' : ["up", "down", "left", "right"], 251 'arrowSet' : ["up", "down", "left", "right"],
250 'buttonSets' : ['standardSet', 'specialSet'] 252 'buttonSets' : ['standardSet', 'specialSet']
251 }, 253 },
927 var url = getDigilibUrl(data); 929 var url = getDigilibUrl(data);
928 var history = window.history; 930 var history = window.history;
929 if (typeof history.pushState === 'function') { 931 if (typeof history.pushState === 'function') {
930 console.debug("faking reload to "+url); 932 console.debug("faking reload to "+url);
931 // change url without reloading (stateObj, title, url) 933 // change url without reloading (stateObj, title, url)
934 // TODO: we really need to put the state in stateObj and listen to pop-events
935 // TODO: use replace-state(?)
932 history.pushState({}, '', url); 936 history.pushState({}, '', url);
933 // change img src 937 // change img src
934 var imgurl = getScalerUrl(data); 938 var imgurl = getScalerUrl(data);
935 data.$img.attr('src', imgurl); 939 data.$img.attr('src', imgurl);
936 highlightButtons(data); 940 highlightButtons(data);
960 $(data).trigger('update'); 964 $(data).trigger('update');
961 }; 965 };
962 966
963 // returns maximum size for scaler img in fullscreen mode 967 // returns maximum size for scaler img in fullscreen mode
964 var getFullscreenImgSize = function (data) { 968 var getFullscreenImgSize = function (data) {
969 var mode = data.settings.interactionMode;
965 var $win = $(window); 970 var $win = $(window);
966 var winH = $win.height(); 971 var winH = $win.height();
967 var winW = $win.width(); 972 var winW = $win.width();
968 var $body = $('body'); 973 var $body = $('body');
969 // include standard body margins 974 // include standard body margins and check plausibility
970 var borderW = $body.outerWidth(true) - $body.width(); 975 var borderW = $body.outerWidth(true) - $body.width();
976 if (borderW === 0 || borderW > 100) {
977 console.debug("fixing border width for getFullscreenImgSize!");
978 borderW = data.settings.scalerInset;
979 }
971 var borderH = $body.outerHeight(true) - $body.height(); 980 var borderH = $body.outerHeight(true) - $body.height();
972 // get width of first button div 981 if (borderH === 0 || borderH > 100) {
982 console.debug("fixing border height for getFullscreenImgSize!");
983 borderH = 5;
984 }
973 var buttonsW = 0; 985 var buttonsW = 0;
974 if (data.$buttonSets) { 986 if (data.settings.visibleButtonSets) {
975 buttonsW = data.$buttonSets[0].outerWidth(); 987 // get button width from settings
988 buttonsW = data.settings.buttonSettings[mode].buttonSetWidth;
989 // TODO: leave space for all button sets?
976 } 990 }
977 // account for left/right border, body margins and additional requirements 991 // account for left/right border, body margins and additional requirements
978 var calcW = winW - borderW - buttonsW - data.settings.scalerInset; 992 var imgW = winW - borderW - buttonsW;
979 var calcH = winH - borderH; 993 var imgH = winH - borderH;
980 console.debug(winW, winH, 'winW:', $win.width(), 'border:', borderW, 'buttonsW:', buttonsW, 'calc:', calcW); 994 console.debug(winW, winH, 'winW:', $win.width(), 'border:', borderW, 'buttonsW:', buttonsW, 'calc:', imgW);
981 return geom.size(calcW, calcH); 995 return geom.size(imgW, imgH);
982 }; 996 };
983 997
984 // creates HTML structure for digilib in elem 998 // creates HTML structure for digilib in elem
985 var setupScalerDiv = function (data) { 999 var setupScalerDiv = function (data) {
986 var settings = data.settings; 1000 var settings = data.settings;
1166 rect : geom.rectangle(r.x, r.y + r.height - aw, r.width, aw), 1180 rect : geom.rectangle(r.x, r.y + r.height - aw, r.width, aw),
1167 show : canMove(data, 0, 1) 1181 show : canMove(data, 0, 1)
1168 }, { 1182 }, {
1169 name : 'left', 1183 name : 'left',
1170 rect : geom.rectangle(r.x, r.y, aw, r.height), 1184 rect : geom.rectangle(r.x, r.y, aw, r.height),
1171 show : canMove(data, -1, 0), 1185 show : canMove(data, -1, 0)
1172 }, { 1186 }, {
1173 name : 'right', 1187 name : 'right',
1174 rect : geom.rectangle(r.x + r.width - aw, r.y, aw, r.height), 1188 rect : geom.rectangle(r.x + r.width - aw, r.y, aw, r.height),
1175 show : canMove(data, 1, 0) 1189 show : canMove(data, 1, 0)
1176 }]; 1190 }];
1200 // creates HTML structure for the about view in elem 1214 // creates HTML structure for the about view in elem
1201 var setupAboutDiv = function (data) { 1215 var setupAboutDiv = function (data) {
1202 var $elem = data.$elem; 1216 var $elem = data.$elem;
1203 var settings = data.settings; 1217 var settings = data.settings;
1204 var $aboutDiv = $('<div class="about" style="display:none"/>'); 1218 var $aboutDiv = $('<div class="about" style="display:none"/>');
1205 var $header = $('<p>Digilib Graphic Viewer</p>'); 1219 var $header = $('<p>Digilib Image Viewer</p>');
1206 var $link = $('<a/>'); 1220 var $link = $('<a/>');
1207 var $logo = $('<img class="logo" title="digilib"/>'); 1221 var $logo = $('<img class="logo" title="digilib"/>');
1208 var $content = $('<p/>'); 1222 var $content = $('<p/>');
1209 $elem.append($aboutDiv); 1223 $elem.append($aboutDiv);
1210 $aboutDiv.append($header); 1224 $aboutDiv.append($header);
1239 }; 1253 };
1240 1254
1241 // display more (or less) button sets 1255 // display more (or less) button sets
1242 var showButtons = function (data, more, setIdx, animated) { 1256 var showButtons = function (data, more, setIdx, animated) {
1243 var atime = animated ? 'fast': 0; 1257 var atime = animated ? 'fast': 0;
1258 // get button width from settings
1259 var mode = data.settings.interactionMode;
1260 var btnWidth = data.settings.buttonSettings[mode].buttonSetWidth;
1244 if (more) { 1261 if (more) {
1245 // add set 1262 // add set
1246 var $otherSets = data.$elem.find('div.buttons:visible'); 1263 var $otherSets = data.$elem.find('div.buttons:visible');
1247 var $set; 1264 var $set;
1248 if (data.$buttonSets && data.$buttonSets[setIdx]) { 1265 if (data.$buttonSets && data.$buttonSets[setIdx]) {
1251 } else { 1268 } else {
1252 $set = createButtons(data, setIdx); 1269 $set = createButtons(data, setIdx);
1253 } 1270 }
1254 if ($set == null) return false; 1271 if ($set == null) return false;
1255 // include border in calculation 1272 // include border in calculation
1256 var btnWidth = $set.outerWidth(); 1273 //var btnWidth = $set.outerWidth();
1257 // console.debug("btnWidth", btnWidth); 1274 // console.debug("btnWidth", btnWidth);
1258 // move remaining sets left and show new set 1275 // move remaining sets left and show new set
1259 if ($otherSets.length > 0) { 1276 if ($otherSets.length > 0) {
1260 $otherSets.animate({right : '+='+btnWidth+'px'}, atime, 1277 $otherSets.animate({right : '+='+btnWidth+'px'}, atime,
1261 function () {$set.show();}); 1278 function () {$set.show();});
1264 } 1281 }
1265 } else { 1282 } else {
1266 // remove set 1283 // remove set
1267 var $set = data.$buttonSets[setIdx]; 1284 var $set = data.$buttonSets[setIdx];
1268 if ($set == null) return false; 1285 if ($set == null) return false;
1269 var btnWidth = $set.outerWidth(); 1286 //var btnWidth = $set.outerWidth();
1270 // hide last set 1287 // hide last set
1271 $set.hide(); 1288 $set.hide();
1272 // take remaining sets and move right 1289 // take remaining sets and move right
1273 var $otherSets = data.$elem.find('div.buttons:visible'); 1290 var $otherSets = data.$elem.find('div.buttons:visible');
1274 $otherSets.animate({right : '-='+btnWidth+'px'}, atime); 1291 $otherSets.animate({right : '-='+btnWidth+'px'}, atime);