r61205 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61204‎ | r61205 | r61206 >
Date:16:45, 18 January 2010
Author:thomasv
Status:ok
Tags:
Comment:
add new zoom mode: zoom on a rectangle drawn with the mouse; also, disable the wheel zoom for IE6
Modified paths:
  • /trunk/extensions/ProofreadPage/proofread.js (modified) (history)

Diff [purge]

Index: trunk/extensions/ProofreadPage/proofread.js
@@ -397,6 +397,7 @@
398398 var is_drag = false;
399399 var is_zoom = false;
400400 var pr_container = false;
 401+var pr_rect = false;
401402
402403 /* size of the window */
403404 var pr_width = 0, pr_height = 0;
@@ -429,8 +430,20 @@
430431 pr_container.onmousemove = pr_move;
431432 if( is_drag==false ) {
432433 is_zoom = !is_zoom;
 434+ } else {
 435+ if(is_zoom) {
 436+ is_zoom=false;
 437+ 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;
 443+ }
 444+ }
433445 }
434446 is_drag = false;
 447+ pr_rect.style.cssText = "display:none";
435448 set_container_css(!is_zoom,!is_zoom);
436449 return false;
437450 }
@@ -482,12 +495,33 @@
483496 evt = evt?evt:window.event?window.event:null; if(!evt){ return false;}
484497 get_xy(evt); if(xx>pr_container.offsetWidth-20 || yy>pr_container.offsetHeight-20) return false;
485498
486 - pr_container.scrollLeft = (init_x-xx);
487 - pr_container.scrollTop = (init_y-yy);
 499+ if(!is_zoom) {
 500+ pr_container.scrollLeft = (init_x-xx);
 501+ pr_container.scrollTop = (init_y-yy);
 502+ } 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 );
 507+ self.boxWidth = Math.max( xMax-xMin, 1 );
 508+ self.boxHeight = Math.max( yMax-yMin, 1 );
 509+ if(boxWidth*boxWidth+boxHeight*boxHeight < 2500){
 510+ pr_rect.style.cssText = "display:none;";
 511+ } else {
 512+ ratio = pr_container.offsetWidth/pr_container.offsetHeight;
 513+ if(boxWidth/boxHeight < ratio ) {
 514+ boxWidth = boxHeight*ratio;
 515+ if(xx==xMin) xMin = init_x - pr_container.scrollLeft - boxWidth;
 516+ } else {
 517+ boxHeight = boxWidth/ratio;
 518+ if(yy==yMin) yMin = init_y - pr_container.scrollTop - boxHeight;
 519+ }
 520+ 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+ }
 522+ }
488523 if (evt.preventDefault) evt.preventDefault();
489524 evt.returnValue = false;
490525 is_drag = true;
491 - set_container_css(true,!is_zoom);
492526 return false;
493527 }
494528
@@ -522,7 +556,6 @@
523557 pr_container.scrollTop = Math.round(lambda*pty - yy);
524558 }
525559 }
526 -
527560 }
528561 }
529562
@@ -541,11 +574,12 @@
542575 delta = -evt.detail/3;
543576 }
544577 if(is_zoom && delta) {
545 - pr_zoom(delta);
 578+ //disable wheel zoom for IE6.
 579+ if( navigator.appName.indexOf("Microsoft")==-1 || navigator.appVersion.indexOf("MSIE 6.")==-1)
 580+ pr_zoom(delta);
546581 if(evt.preventDefault) evt.preventDefault();
547582 evt.returnValue = false;
548583 }
549 -
550584 }
551585
552586
@@ -572,15 +606,14 @@
573607 t_row.setAttribute("valign","top");
574608 cell_left.style.cssText = "width:50%; padding-right:0.5em;vertical-align:top;";
575609 cell_right.setAttribute("rowspan","3");
 610+ cell_right.style.cssText = "vertical-align:top;";
576611 t_row.appendChild(cell_left);
577612 t_row.appendChild(cell_right);
578613 t_body.appendChild(t_row);
579 -
580614 cell_right.appendChild(pr_container_parent);
581615 cell_left.appendChild(self.text_container);
582616 self.table.appendChild(t_table);
583 - }
584 - else {
 617+ } else {
585618 self.table.appendChild(self.text_container);
586619 form = document.getElementById("editform");
587620 tb = document.getElementById("toolbar");
@@ -592,14 +625,14 @@
593626 if(!pr_horiz){
594627 self.DisplayHeight = Math.ceil(pr_height*0.85);
595628 self.DisplayWidth = parseInt(pr_width/2-70);
596 - img_w = self.DisplayWidth-20;
597629 css_wh = "width:"+self.DisplayWidth+"px; height:"+self.DisplayHeight+"px;";
 630+ pr_container_parent.style.cssText="position:relative;width:"+self.DisplayWidth+"px;";
598631 } else {
599632 self.DisplayHeight = Math.ceil(pr_height*0.4);
600 - img_w = 0; //prevent the container from being resized when the image is downloaded.
601633 css_wh = "width:100%; height:"+self.DisplayHeight+"px;";
 634+ pr_container_parent.style.cssText="position:relative;height:"+self.DisplayHeight+"px;";
602635 }
603 - self.container_css = "cursor:default; background:#000000; overflow:auto; " + css_wh;
 636+ self.container_css = "position:absolute;top:0px;cursor:default; background:#000000; overflow:auto; " + css_wh;
604637 pr_container.style.cssText = self.container_css;
605638 }
606639 pr_zoom(0);
@@ -652,16 +685,8 @@
653686 pr_container.appendChild(image);
654687 pr_container.style.cssText = "overflow:hidden;width:"+self.DisplayWidth+"px;";
655688 } else {
656 - if(!pr_horiz){
657 - self.DisplayHeight = Math.ceil(pr_height*0.85);
658 - self.DisplayWidth = parseInt(pr_width/2-70);
659 - img_w = self.DisplayWidth-20;
660 - }
661 - else{
662 - self.DisplayHeight = Math.ceil(pr_height*0.4);
663 - img_w = 0; //prevent the container from being resized once the image is downloaded.
664 - }
665 -
 689+ //prevent the container from being resized once the image is downloaded.
 690+ img_w = pr_horiz?0:parseInt(pr_width/2-70)-20;
666691 pr_container.innerHTML = "<img id=\"ProofReadImage\" src=\""
667692 + escapeQuotesHTML(proofreadPageViewURL)
668693 + "\" width=\"" + img_w + "\" />";
@@ -761,14 +786,13 @@
762787 image1.style.cursor = "pointer";
763788 image1.onclick = pr_toggle_layout;
764789
 790+ pr_rect = document.createElement("div");
 791+ pr_container_parent.appendChild(pr_rect);
 792+
765793 if( (!toolbar) || (self.wgWikiEditorPreferences && self.wgWikiEditorPreferences["toolbar"] ) ) {
766 - var mb = document.createElement("div");
767 - mb.style.cssText="position:relative;";
768794 toolbar = document.createElement("div");
769795 toolbar.style.cssText="position:absolute;";
770 - mb.appendChild(toolbar);
771 - var p = pr_container.parentNode;
772 - p.insertBefore(mb,p.firstChild);
 796+ pr_container_parent.appendChild(toolbar);
773797 }
774798 toolbar.appendChild(image);
775799 toolbar.appendChild(image3);

Status & tagging log