621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
|
621
622
623
624
625
626
627
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|
new ChunkLoadControls(D.addClass(tr, 'jchunk'));
});
});
return F;
};
Diff.setupDiffContextLoad();
});
/* Refinements to the display of unified and side-by-side diffs.
**
** In all cases, the table columns tagged with "difftxt" are expanded,
** where possible, to fill the width of the screen.
**
** For a side-by-side diff, if either column is two wide to fit on the
** display, scrollbars are added. The scrollbars are linked, so that
** both sides scroll together. Left and right arrows also scroll.
*/
window.fossil.onPageLoad(function(){
const SCROLL_LEN = 25;
const F = window.fossil, D = F.dom, Diff = F.diff;
var lastWidth;
Diff.checkTableWidth = function f(force){
if(1){
return this;
/**
What follows is largely obsolete but we will want parts of it
if we decide to retain the synchronous-scroll feature of
SBS diffs (which we otherwise lose in the CSS-based reimplementation).
*/
}
if(undefined === f.contentNode){
f.contentNode = document.querySelector('div.content');
}
force = true;
const parentCS = window.getComputedStyle(f.contentNode);
const parentWidth = (
//document.body.clientWidth;
//parentCS.width;
f.contentNode.clientWidth
- parseFloat(parentCS.marginLeft) - parseFloat(parentCS.marginRight)
);
if( !force && parentWidth===lastWidth ) return this;
lastWidth = parentWidth;
let w = lastWidth*0.5 - 100;
//console.debug( "w = ",w,", lastWidth =",lastWidth," body = ",document.body.clientWidth);
if(force || !f.colsL){
f.colsL = document.querySelectorAll('td.difftxtl pre');
}
f.colsL.forEach(function(e){
e.style.width = w + "px";
e.style.maxWidth = w + "px";
});
if(force || !f.colsR){
f.colsR = document.querySelectorAll('td.difftxtr pre');
}
f.colsR.forEach(function(e){
e.style.width = w + "px";
e.style.maxWidth = w + "px";
});
if(force || !f.colsU){
f.colsU = document.querySelectorAll('td.difftxtu pre');
}
f.colsU.forEach(function(e){
w = lastWidth - 3; // Outer border
var k = e.parentElement/*TD*/;
while(k = k.previousElementSibling/*TD*/) w -= k.scrollWidth;
e.style.width = w + "px";
e.style.maxWidth = w + "px";
});
if(0){ // seems to be unnecessary
if(!f.allDiffs){
f.allDiffs = document.querySelectorAll('table.diff');
}
w = lastWidth;
f.allDiffs.forEach(function f(e){
if(0 && !f.$){
f.$ = e.getClientRects()[0];
console.debug("diff table w =",w," f.$x",f.$);
w - 2*f.$.x /* left margin (assume right==left, for simplicity) */;
}
e.style.maxWidth = w + "px";
});
//console.debug("checkTableWidth(",force,") lastWidth =",lastWidth);
}
return this;
};
const scrollLeft = function(event){
//console.debug("scrollLeft",this,event);
const table = this.parentElement/*TD*/.parentElement/*TR*/.
parentElement/*TBODY*/.parentElement/*TABLE*/;
table.$txtPres.forEach((e)=>(e===this) ? 1 : (e.scrollLeft = this.scrollLeft));
return false;
};
Diff.initTableDiff = function f(diff, unifiedDiffs){
if(!diff){
let i, diffs;
diffs = document.querySelectorAll('table.splitdiff');
for(i=0; i<diffs.length; ++i){
f.call(this, diffs[i], false);
}
diffs = document.querySelectorAll('table.udiff');
for(i=0; i<diffs.length; ++i){
f.call(this, diffs[i], true);
}
return this;
}
diff.$txtCols = diff.querySelectorAll('td.difftxt');
diff.$txtPres = diff.querySelectorAll('td.difftxt pre');
var width = 0;
diff.$txtPres.forEach(function(e){
if(width < e.scrollWidth) width = e.scrollWidth;
});
//console.debug("diff.$txtPres =",diff.$txtPres);
diff.$txtCols.forEach((e)=>e.style.width = width + 'px');
diff.$txtPres.forEach(function(e){
e.style.maxWidth = width + 'px';
e.style.width = width + 'px';
if(!unifiedDiffs && !e.classList.contains('scroller')){
D.addClass(e, 'scroller');
e.addEventListener('scroll', scrollLeft, false);
}
});
if(!unifiedDiffs){
diff.tabIndex = 0;
if(!diff.classList.contains('scroller')){
D.addClass(diff, 'scroller');
diff.addEventListener('keydown', function(e){
e = e || event;
const len = {37: -SCROLL_LEN, 39: SCROLL_LEN}[e.keyCode];
if( !len ) return;
this.$txtPres[0].scrollLeft += len;
/* ^^^ bug: if there is a 2nd column and it has a scrollbar
but txtPres[0] does not, no scrolling happens here. We need
to find the widest of txtPres and scroll that one. Example:
Checkin a7fbefee38a1c522 file diff.c */
return false;
}, false);
}
}
return this;
}
if(0){
window.fossil.page.tweakSbsDiffs = function(){
document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff(e));
Diff.checkTableWidth();
};
Diff.initTableDiff().checkTableWidth();
window.addEventListener('resize', F.debounce(()=>Diff.checkTableWidth()));
}else{
/* tweakSbsDiffs() is called by /fileedit and /wikieedit when it
runs an SBS diff. We _might_ want to retain this function to
re-enable synchronized sbs diff scrolling. If we decided to not
retain that feature with the CSS-based SBS diff, we can remove
this block and the corresponding calls to this function in
fossil.page.{wikiedit,fileedit}.js. */
window.fossil.page.tweakSbsDiffs = function(){};
}
}, false);
|