Index: trunk/extensions/ProofreadPage/proofread.js |
— | — | @@ -392,8 +392,15 @@ |
393 | 393 | * |
394 | 394 | ********************************/ |
395 | 395 | |
| 396 | +/* width and margin of the scan */ |
| 397 | +var margin_x = 0; |
| 398 | +var margin_y = 0; |
| 399 | +var img_width = 0; |
| 400 | + |
| 401 | +/* initial mouse position during a drag */ |
396 | 402 | var init_x = 0; |
397 | 403 | var init_y = 0; |
| 404 | + |
398 | 405 | var is_drag = false; |
399 | 406 | var is_zoom = false; |
400 | 407 | var pr_container = false; |
— | — | @@ -402,22 +409,31 @@ |
403 | 410 | /* size of the window */ |
404 | 411 | var pr_width = 0, pr_height = 0; |
405 | 412 | |
406 | | -function set_container_css(show_scrollbars,default_cursor){ |
| 413 | +function set_container_css(show_scrollbars){ |
| 414 | + var sl = pr_container.scrollLeft;//read scrollbar values |
| 415 | + var st = pr_container.scrollTop; |
407 | 416 | if(show_scrollbars) { |
408 | 417 | self.container_css = self.container_css.replace("overflow:hidden","overflow:auto"); |
| 418 | + self.container_css = self.container_css.replace("cursor:crosshair","cursor:default"); |
| 419 | + //we should check if the sb is going to be shown |
| 420 | + if(margin_x<0) { sl = - Math.round(margin_x); margin_x=0; } |
| 421 | + if(margin_y<0) { st = - Math.round(margin_y); margin_y=0; } |
409 | 422 | } else { |
410 | 423 | self.container_css = self.container_css.replace("overflow:auto","overflow:hidden"); |
411 | | - } |
412 | | - if(default_cursor) { |
413 | | - self.container_css = self.container_css.replace("cursor:crosshair","cursor:default"); |
414 | | - } else { |
415 | 424 | self.container_css = self.container_css.replace("cursor:default","cursor:crosshair"); |
| 425 | + if(sl) { |
| 426 | + margin_x -= sl; |
| 427 | + sl = 0; |
| 428 | + } |
| 429 | + if(st) { |
| 430 | + margin_y -= st; |
| 431 | + st = 0; |
| 432 | + } |
416 | 433 | } |
417 | | - sl = pr_container.scrollLeft;//save scrollbar value for Opera, Chrome |
418 | | - st = pr_container.scrollTop; |
419 | | - pr_container.style.cssText = self.container_css; |
| 434 | + pr_set_margins(margin_x, margin_y, false); |
420 | 435 | pr_container.scrollLeft = sl; |
421 | 436 | pr_container.scrollTop = st; |
| 437 | + |
422 | 438 | } |
423 | 439 | |
424 | 440 | function pr_drop(evt){ |
— | — | @@ -434,22 +450,18 @@ |
435 | 451 | if(is_zoom) { |
436 | 452 | is_zoom=false; |
437 | 453 | if(boxWidth*boxWidth+boxHeight*boxHeight >= 2500){ |
438 | | - var zp_img = document.getElementById("ProofReadImage"); |
439 | | - ratio_x = Math.abs( pr_container.offsetWidth/self.boxWidth ); |
440 | | - zp_img.width = zp_img.width*ratio_x; |
441 | | - pr_container.scrollLeft = (pr_container.scrollLeft + xMin)*ratio_x; |
442 | | - pr_container.scrollTop = (pr_container.scrollTop + yMin)*ratio_x; |
| 454 | + var ratio_x = Math.abs( pr_container.offsetWidth/self.boxWidth ); |
| 455 | + pr_set_margins( (margin_x - xMin)*ratio_x, (margin_y - yMin)*ratio_x, img_width*ratio_x ) ; |
443 | 456 | } |
444 | 457 | } |
445 | 458 | } |
446 | 459 | is_drag = false; |
447 | 460 | pr_rect.style.cssText = "display:none"; |
448 | | - set_container_css(!is_zoom,!is_zoom); |
| 461 | + set_container_css(!is_zoom); |
449 | 462 | return false; |
450 | 463 | } |
451 | 464 | |
452 | 465 | function pr_grab(evt){ |
453 | | - |
454 | 466 | evt = evt?evt:window.event?window.event:null; if(!evt){ return false;} |
455 | 467 | get_xy(evt); if(xx>pr_container.offsetWidth-20 || yy>pr_container.offsetHeight-20) return false; |
456 | 468 | |
— | — | @@ -476,10 +488,14 @@ |
477 | 489 | lastyy=evt.clientY - ieoy; |
478 | 490 | } |
479 | 491 | |
480 | | - init_x = pr_container.scrollLeft + lastxx; |
481 | | - init_y = pr_container.scrollTop + lastyy; |
| 492 | + if(is_zoom){ |
| 493 | + init_x = - margin_x + lastxx; |
| 494 | + init_y = - margin_y + lastyy; |
| 495 | + } else { |
| 496 | + init_x = pr_container.scrollLeft + lastxx; |
| 497 | + init_y = pr_container.scrollTop + lastyy; |
| 498 | + } |
482 | 499 | is_drag = false; |
483 | | - set_container_css(!is_zoom,!is_zoom); |
484 | 500 | return false; |
485 | 501 | |
486 | 502 | } |
— | — | @@ -494,15 +510,14 @@ |
495 | 511 | function pr_drag(evt) { |
496 | 512 | evt = evt?evt:window.event?window.event:null; if(!evt){ return false;} |
497 | 513 | get_xy(evt); if(xx>pr_container.offsetWidth-20 || yy>pr_container.offsetHeight-20) return false; |
498 | | - |
499 | 514 | if(!is_zoom) { |
500 | 515 | pr_container.scrollLeft = (init_x-xx); |
501 | 516 | pr_container.scrollTop = (init_y-yy); |
502 | 517 | } else { |
503 | | - self.xMin = Math.min( init_x - pr_container.scrollLeft, xx ); |
504 | | - self.yMin = Math.min( init_y - pr_container.scrollTop , yy ); |
505 | | - self.xMax = Math.max( init_x - pr_container.scrollLeft, xx ); |
506 | | - self.yMax = Math.max( init_y - pr_container.scrollTop , yy ); |
| 518 | + self.xMin = Math.min( init_x + margin_x, xx ); |
| 519 | + self.yMin = Math.min( init_y + margin_y, yy ); |
| 520 | + self.xMax = Math.max( init_x + margin_x, xx ); |
| 521 | + self.yMax = Math.max( init_y + margin_y, yy ); |
507 | 522 | self.boxWidth = Math.max( xMax-xMin, 1 ); |
508 | 523 | self.boxHeight = Math.max( yMax-yMin, 1 ); |
509 | 524 | if(boxWidth*boxWidth+boxHeight*boxHeight < 2500){ |
— | — | @@ -511,10 +526,10 @@ |
512 | 527 | ratio = pr_container.offsetWidth/pr_container.offsetHeight; |
513 | 528 | if(boxWidth/boxHeight < ratio ) { |
514 | 529 | boxWidth = boxHeight*ratio; |
515 | | - if(xx==xMin) xMin = init_x - pr_container.scrollLeft - boxWidth; |
| 530 | + if(xx==xMin) xMin = init_x + margin_x - boxWidth; |
516 | 531 | } else { |
517 | 532 | boxHeight = boxWidth/ratio; |
518 | | - if(yy==yMin) yMin = init_y - pr_container.scrollTop - boxHeight; |
| 533 | + if(yy==yMin) yMin = init_y + margin_y - boxHeight; |
519 | 534 | } |
520 | 535 | pr_rect.style.cssText = "cursor:crosshair;opacity:0.5;position:absolute;left:"+ xMin +"px;top:"+ yMin +"px;width:"+boxWidth+"px;height:"+boxHeight+"px;background:#000000;"; |
521 | 536 | } |
— | — | @@ -526,40 +541,43 @@ |
527 | 542 | } |
528 | 543 | |
529 | 544 | |
530 | | -function pr_zoom(delta){ |
| 545 | +function pr_set_margins(mx, my, new_width) { |
| 546 | + var zp_img = document.getElementById("ProofReadImage"); |
| 547 | + if(zp_img) { |
| 548 | + margin_x = mx; |
| 549 | + margin_y = my; |
| 550 | + zp_img.style.margin = Math.round(margin_y) + 'px 0px 0px ' + Math.round(margin_x) + 'px'; |
| 551 | + if(new_width) { |
| 552 | + img_width = Math.round(new_width); |
| 553 | + zp_img.width = img_width; |
| 554 | + } |
| 555 | + pr_container.style.cssText = self.container_css; //needed by IE6 |
| 556 | + } |
| 557 | +} |
531 | 558 | |
532 | | - var zp_img = document.getElementById("ProofReadImage"); |
533 | | - if(!zp_img) return; |
| 559 | + |
| 560 | +function pr_zoom(delta) { |
534 | 561 | |
535 | 562 | if (delta == 0) { |
536 | 563 | //reduce width by 20 pixels in order to prevent horizontal scrollbar from showing up |
537 | | - zp_img.width = pr_container.offsetWidth-20; |
538 | | - pr_container.style.cssText = self.container_css; //needed by IE6 |
539 | | - } |
540 | | - else{ |
541 | | - var old_width = zp_img.width; |
542 | | - var new_width = Math.round(zp_img.width*Math.pow(1.1,delta)); |
| 564 | + pr_set_margins(0, 0, pr_container.offsetWidth-20); |
| 565 | + } else { |
| 566 | + var old_margin_x = margin_x; |
| 567 | + var old_margin_y = margin_y; |
| 568 | + var old_width = img_width; |
| 569 | + var new_width = Math.round(old_width*Math.pow(1.1,delta)); |
543 | 570 | var delta_w = new_width - old_width; |
544 | 571 | if(delta_w==0) return; |
545 | 572 | var s = (delta_w>0)?1:-1; |
546 | | - |
547 | | - var ptx = xx + pr_container.scrollLeft; |
548 | | - var pty = yy + pr_container.scrollTop; |
549 | | - |
550 | 573 | for(var dw=s; dw != delta_w; dw=dw+s){ |
551 | | - zp_img.width = old_width + dw;//this adds 1 pixel |
552 | | - pr_container.style.cssText = self.container_css; //needed by IE6 |
553 | | - if(xx){ |
554 | | - //magnification factor |
555 | | - var lambda = (old_width+dw)/old_width; |
556 | | - pr_container.scrollLeft = Math.round(lambda*ptx - xx); |
557 | | - pr_container.scrollTop = Math.round(lambda*pty - yy); |
558 | | - } |
| 574 | + var lambda = (old_width + dw)/old_width; |
| 575 | + pr_set_margins(xx - lambda*(xx - old_margin_x), yy - lambda*(yy - old_margin_y), old_width+dw); |
559 | 576 | } |
560 | 577 | } |
561 | 578 | } |
562 | 579 | |
563 | | -function pr_zoom_wheel(evt){ |
| 580 | +function pr_zoom_wheel(evt) { |
| 581 | + |
564 | 582 | evt = evt?evt:window.event?window.event:null; if(!evt){ return false;} |
565 | 583 | var delta = 0; |
566 | 584 | if (evt.wheelDelta) { |
— | — | @@ -687,10 +705,10 @@ |
688 | 706 | pr_container.style.cssText = "overflow:hidden;width:"+self.DisplayWidth+"px;"; |
689 | 707 | } else { |
690 | 708 | //prevent the container from being resized once the image is downloaded. |
691 | | - img_w = pr_horiz?0:parseInt(pr_width/2-70)-20; |
| 709 | + img_width = pr_horiz?0:parseInt(pr_width/2-70)-20; |
692 | 710 | pr_container.innerHTML = "<img id=\"ProofReadImage\" src=\"" |
693 | 711 | + escapeQuotesHTML(proofreadPageViewURL) |
694 | | - + "\" width=\"" + img_w + "\" />"; |
| 712 | + + "\" width=\"" + img_width + "\" />"; |
695 | 713 | pr_container.onmousedown = pr_grab; |
696 | 714 | pr_container.onmousemove = pr_move; |
697 | 715 | if (pr_container.addEventListener) |