comparison client/digitallibrary/jquery/jquery.digilib.js @ 733:25f2898696a2 jquery

fixed setupZoomDrag
author robcast
date Tue, 01 Feb 2011 19:30:59 +0100
parents 55f2dd197ca9
children 609e5bf29d1a 790a7673bef0
comparison
equal deleted inserted replaced
732:55f2dd197ca9 733:25f2898696a2
1108 console.debug("img loaded! this=", this, " data=", data); 1108 console.debug("img loaded! this=", this, " data=", data);
1109 // create Transform from current area and picsize 1109 // create Transform from current area and picsize
1110 data.imgTrafo = getImgTrafo($img, data.zoomArea, 1110 data.imgTrafo = getImgTrafo($img, data.zoomArea,
1111 data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir); 1111 data.settings.rot, data.scalerFlags.hmir, data.scalerFlags.vmir);
1112 console.debug("imgTrafo=", data.imgTrafo); 1112 console.debug("imgTrafo=", data.imgTrafo);
1113 // set scaler div size explicitly in case $img is hidden (for zoomDrag) 1113 // adjust scaler div size
1114 var $imgRect = geom.rectangle(data.$img); 1114 var imgRect = geom.rectangle(data.$img);
1115 console.debug("imgrect=", $imgRect); 1115 console.debug("imgrect=", imgRect);
1116 $imgRect.adjustDiv(data.$scaler); 1116 imgRect.adjustDiv(data.$scaler);
1117 // show image in case it was hidden (for example in zoomDrag) 1117 // show image in case it was hidden (for example in zoomDrag)
1118 $img.show(); 1118 $img.css('visibility', 'visible');
1119 // display marks 1119 // display marks
1120 renderMarks(data); 1120 renderMarks(data);
1121 // TODO: digilib.showArrows(); // show arrow overlays for zoom navigation 1121 // TODO: digilib.showArrows(); // show arrow overlays for zoom navigation
1122 }; 1122 };
1123 }; 1123 };
1284 var $birdImg = data.$birdImg; 1284 var $birdImg = data.$birdImg;
1285 var $birdZoom = data.$birdZoom; 1285 var $birdZoom = data.$birdZoom;
1286 var $document = $(document); 1286 var $document = $(document);
1287 var startPos, newRect, birdImgRect, birdZoomRect; 1287 var startPos, newRect, birdImgRect, birdZoomRect;
1288 1288
1289 // mousemove handler: drag
1289 var birdZoomMove = function(evt) { 1290 var birdZoomMove = function(evt) {
1290 // mousemove handler: drag
1291 var pos = geom.position(evt); 1291 var pos = geom.position(evt);
1292 var delta = startPos.delta(pos); 1292 var delta = startPos.delta(pos);
1293 // move birdZoom div, keeping size 1293 // move birdZoom div, keeping size
1294 newRect = birdZoomRect.copy(); 1294 newRect = birdZoomRect.copy();
1295 newRect.addPt1(delta); 1295 newRect.addPosition(delta);
1296 // stay within birdimage 1296 // stay within birdimage
1297 newRect.stayInside(birdImgRect); 1297 newRect.stayInside(birdImgRect);
1298 newRect.adjustDiv($birdZoom); 1298 newRect.adjustDiv($birdZoom);
1299 return false; 1299 return false;
1300 }; 1300 };
1301 1301
1302 // mouseup handler: reload page
1302 var birdZoomEndDrag = function(evt) { 1303 var birdZoomEndDrag = function(evt) {
1303 // mouseup handler: reload page
1304 var settings = data.settings; 1304 var settings = data.settings;
1305 $document.unbind("mousemove.dlBirdMove", birdZoomMove); 1305 $document.unbind("mousemove.dlBirdMove", birdZoomMove);
1306 $document.unbind("mouseup.dlBirdMove", birdZoomEndDrag); 1306 $document.unbind("mouseup.dlBirdMove", birdZoomEndDrag);
1307 $birdZoom.unbind("mousemove.dlBirdMove", birdZoomMove); 1307 $birdZoom.unbind("mousemove.dlBirdMove", birdZoomMove);
1308 $birdZoom.unbind("mouseup.dlBirdMove", birdZoomEndDrag); 1308 $birdZoom.unbind("mouseup.dlBirdMove", birdZoomEndDrag);
1315 data.zoomArea = newArea; 1315 data.zoomArea = newArea;
1316 redisplay(data); 1316 redisplay(data);
1317 return false; 1317 return false;
1318 }; 1318 };
1319 1319
1320 // mousedown handler: start dragging bird zoom to a new position
1320 var birdZoomStartDrag = function(evt) { 1321 var birdZoomStartDrag = function(evt) {
1321 // mousedown handler: start dragging bird zoom to a new position
1322 startPos = geom.position(evt); 1322 startPos = geom.position(evt);
1323 // position may have changed 1323 // position may have changed
1324 data.birdTrafo = getImgTrafo($birdImg, MAX_ZOOMAREA); 1324 data.birdTrafo = getImgTrafo($birdImg, MAX_ZOOMAREA);
1325 birdImgRect = geom.rectangle($birdImg); 1325 birdImgRect = geom.rectangle($birdImg);
1326 birdZoomRect = geom.rectangle($birdZoom); 1326 birdZoomRect = geom.rectangle($birdZoom);
1341 $birdZoom.bind("mousedown.dlBirdMove", birdZoomStartDrag); 1341 $birdZoom.bind("mousedown.dlBirdMove", birdZoomStartDrag);
1342 } 1342 }
1343 }; 1343 };
1344 1344
1345 var setupZoomDrag = function(data) { 1345 var setupZoomDrag = function(data) {
1346 // setup handlers for dragging the zoomed image 1346 // setup handlers for dragging the zoomed image
1347 var pt1, pt2; 1347 var startPos, delta;
1348 var dx = 0; 1348 var $document = $(document);
1349 var dy = 0;
1350 var $elem = data.$elem; 1349 var $elem = data.$elem;
1351 var $scaler = data.$scaler; 1350 var $scaler = data.$scaler;
1352 var $img = data.$img; 1351 var $img = data.$img;
1353 1352
1353 // drag the image and load a new detail on mouse up
1354 var dragStart = function (evt) { 1354 var dragStart = function (evt) {
1355 // drag the image and load a new detail on mouse up 1355 startPos = geom.position(evt);
1356 // useless if not zoomed
1357 if (isFullArea(data.zoomArea)) return false;
1358 pt1 = geom.position(evt);
1359 $imgRect = geom.rectangle($img); 1356 $imgRect = geom.rectangle($img);
1360 // keep scaler div size while $img is hidden (for embedded mode)
1361 $imgRect.adjustDiv($scaler);
1362 // hide the scaler image, show it as background of div instead 1357 // hide the scaler image, show it as background of div instead
1363 $scaler.css({ 1358 $scaler.css({
1364 'background-image' : 'url(' + $img.attr('src') + ')', 1359 'background-image' : 'url(' + $img.attr('src') + ')',
1365 'background-repeat' : 'no-repeat', 1360 'background-repeat' : 'no-repeat',
1366 'background-position' : 'top left', 1361 'background-position' : 'top left',
1367 'cursor' : 'move' 1362 'cursor' : 'move'
1368 }); 1363 });
1369 $img.css('visibility', 'hidden'); 1364 $img.css('visibility', 'hidden');
1370 $(document).bind("mousemove.digilib", dragMove); 1365 $document.bind("mousemove.dlZoomDrag", dragMove);
1371 $(document).bind("mouseup.digilib", dragEnd); 1366 $document.bind("mouseup.dlZoomDrag", dragEnd);
1372 return false; 1367 return false;
1373 }; 1368 };
1374 1369
1370 // mousemove handler: drag zoomed image
1375 var dragMove = function (evt) { 1371 var dragMove = function (evt) {
1376 // mousemove handler: drag zoomed image
1377 var pos = geom.position(evt); 1372 var pos = geom.position(evt);
1378 dx = pos.x - pt1.x; 1373 delta = pos.delta(startPos);
1379 dy = pos.y - pt1.y;
1380 // move the background image to the new position 1374 // move the background image to the new position
1381 $scaler.css({ 1375 $scaler.css({
1382 'background-position' : dx + "px " + dy + "px" 1376 'background-position' : (-delta.x) + "px " + (-delta.y) + "px"
1383 }); 1377 });
1384 return false; 1378 return false;
1385 }; 1379 };
1386 1380
1381 // mouseup handler: reload zoomed image in new position
1387 var dragEnd = function (evt) { 1382 var dragEnd = function (evt) {
1388 // mouseup handler: reload zoomed image in new position
1389 $scaler.css({ 1383 $scaler.css({
1390 'background-image' : 'none', 1384 'background-image' : 'none',
1391 'cursor' : 'default' 1385 'cursor' : 'default'
1392 }); 1386 });
1393 $(document).unbind("mousemove.digilib", dragMove); 1387 $document.unbind("mousemove.dlZoomDrag", dragMove);
1394 $(document).unbind("mouseup.digilib", dragEnd); 1388 $document.unbind("mouseup.dlZoomDrag", dragEnd);
1395 // calculate relative offset 1389 if (delta == null || delta.distance() < 2) {
1396 if (dx === 0 && dy === 0) return false; // no movement 1390 // no movement
1397 // reload with scaler image showing the new ausschnitt 1391 $img.css('visibility', 'visible');
1398 // digilib.moveBy(x, y); 1392 return false;
1399 var pos = geom.position(-dx, -dy); 1393 }
1400 var newPos = data.imgTrafo.invtransform(pos); 1394 // get old zoom area (screen coordinates)
1401 var newArea = data.zoomArea.setPt1(newPos); 1395 var za = data.imgTrafo.transform(data.zoomArea);
1396 // move
1397 za.addPosition(delta);
1398 // transform back
1399 var newArea = data.imgTrafo.invtransform(za);
1402 data.zoomArea = MAX_ZOOMAREA.fit(newArea); 1400 data.zoomArea = MAX_ZOOMAREA.fit(newArea);
1403 redisplay(data); 1401 redisplay(data);
1404 return false; 1402 return false;
1405 }; 1403 };
1406 1404
1407 $scaler.bind("mousedown.digilib", dragStart); 1405 // clear old handler
1406 $document.unbind(".dlZoomDrag");
1407 $scaler.unbind(".dlBirdMove");
1408 if (! isFullArea(data.zoomArea)) {
1409 // set new handler
1410 $scaler.bind("mousedown.dlZoomDrag", dragStart);
1411 }
1408 }; 1412 };
1409 1413
1410 // get image quality as a number (0..2) 1414 // get image quality as a number (0..2)
1411 var getQuality = function (data) { 1415 var getQuality = function (data) {
1412 var flags = data.scalerFlags; 1416 var flags = data.scalerFlags;