Fossil SCM

Exposed the JS code which initializes diff context loading, for eventual use in /wikiedit and /fileedit (currently missing required metadata in the diff for those apps). Removed a now-extraneous PRE.udiff wrapper element in ajax response diffs.

stephan 2021-09-13 04:20 trunk
Commit 0cbfc02b4bbc114fc7f72aefa3a9888574d331a056af0b9ace0859ea08fac03a
+1 -3
--- src/ajax.c
+++ src/ajax.c
@@ -158,14 +158,12 @@
158158
159159
diff_config_init(&DCfg, diffFlags);
160160
text_diff(pOrig, pContent, &out, &DCfg);
161161
if(blob_size(&out)==0){
162162
/* nothing to do */
163
- }else if(DIFF_SIDEBYSIDE & diffFlags){
164
- CX("%b",&out);
165163
}else{
166
- CX("<pre class='udiff'>%b</pre>",&out);
164
+ CX("%b",&out);
167165
}
168166
blob_reset(&out);
169167
}
170168
171169
/*
172170
--- src/ajax.c
+++ src/ajax.c
@@ -158,14 +158,12 @@
158
159 diff_config_init(&DCfg, diffFlags);
160 text_diff(pOrig, pContent, &out, &DCfg);
161 if(blob_size(&out)==0){
162 /* nothing to do */
163 }else if(DIFF_SIDEBYSIDE & diffFlags){
164 CX("%b",&out);
165 }else{
166 CX("<pre class='udiff'>%b</pre>",&out);
167 }
168 blob_reset(&out);
169 }
170
171 /*
172
--- src/ajax.c
+++ src/ajax.c
@@ -158,14 +158,12 @@
158
159 diff_config_init(&DCfg, diffFlags);
160 text_diff(pOrig, pContent, &out, &DCfg);
161 if(blob_size(&out)==0){
162 /* nothing to do */
 
 
163 }else{
164 CX("%b",&out);
165 }
166 blob_reset(&out);
167 }
168
169 /*
170
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -632,24 +632,41 @@
632632
Diff.fetchArtifactChunk(fOpt);
633633
return this;
634634
}
635635
};
636636
637
- const addDiffSkipHandlers = function(){
638
- const tables = document.querySelectorAll('table.diff[data-lefthash]:not(.diffskipped)');
637
+ /**
638
+ Adds context-loading buttons to one or more tables. The argument
639
+ may be a forEach-capable list of diff table elements, a query
640
+ selector string matching 0 or more diff tables, or falsy, in
641
+ which case all relevant diff tables are set up. It tags each
642
+ table it processes to that it will not be processed multiple
643
+ times by subsequent calls to this function.
644
+
645
+ Note that this only works for diffs which have been marked up
646
+ with certain state, namely table.dataset.lefthash and TR
647
+ entries which hold state related to browsing context.
648
+ */
649
+ Diff.setupDiffContextLoad = function(tables){
650
+ if('string'===typeof tables){
651
+ tables = document.querySelectorAll(tables);
652
+ }else if(!tables){
653
+ tables = document.querySelectorAll('table.diff[data-lefthash]:not(.diffskipped)');
654
+ }
639655
/* Potential performance-related TODO: instead of installing all
640656
of these at once, install them as the corresponding TR is
641657
scrolled into view. */
642658
tables.forEach(function(table){
659
+ if(!table.dataset.lefthash) return;
643660
D.addClass(table, 'diffskipped'/*avoid processing these more than once */);
644661
table.querySelectorAll('tr.diffskip[data-startln]').forEach(function(tr){
645662
new ChunkLoadControls(D.addClass(tr, 'jchunk'));
646663
});
647664
});
648665
return F;
649666
};
650
- addDiffSkipHandlers();
667
+ Diff.setupDiffContextLoad();
651668
});
652669
653670
/* Refinements to the display of unified and side-by-side diffs.
654671
**
655672
** In all cases, the table columns tagged with "difftxt" are expanded,
@@ -763,6 +780,5 @@
763780
document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff);
764781
};
765782
Diff.initTableDiff().checkTableWidth();
766783
window.addEventListener('resize', ()=>Diff.checkTableWidth());
767784
}, false);
768
-
769785
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -632,24 +632,41 @@
632 Diff.fetchArtifactChunk(fOpt);
633 return this;
634 }
635 };
636
637 const addDiffSkipHandlers = function(){
638 const tables = document.querySelectorAll('table.diff[data-lefthash]:not(.diffskipped)');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
639 /* Potential performance-related TODO: instead of installing all
640 of these at once, install them as the corresponding TR is
641 scrolled into view. */
642 tables.forEach(function(table){
 
643 D.addClass(table, 'diffskipped'/*avoid processing these more than once */);
644 table.querySelectorAll('tr.diffskip[data-startln]').forEach(function(tr){
645 new ChunkLoadControls(D.addClass(tr, 'jchunk'));
646 });
647 });
648 return F;
649 };
650 addDiffSkipHandlers();
651 });
652
653 /* Refinements to the display of unified and side-by-side diffs.
654 **
655 ** In all cases, the table columns tagged with "difftxt" are expanded,
@@ -763,6 +780,5 @@
763 document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff);
764 };
765 Diff.initTableDiff().checkTableWidth();
766 window.addEventListener('resize', ()=>Diff.checkTableWidth());
767 }, false);
768
769
--- src/fossil.diff.js
+++ src/fossil.diff.js
@@ -632,24 +632,41 @@
632 Diff.fetchArtifactChunk(fOpt);
633 return this;
634 }
635 };
636
637 /**
638 Adds context-loading buttons to one or more tables. The argument
639 may be a forEach-capable list of diff table elements, a query
640 selector string matching 0 or more diff tables, or falsy, in
641 which case all relevant diff tables are set up. It tags each
642 table it processes to that it will not be processed multiple
643 times by subsequent calls to this function.
644
645 Note that this only works for diffs which have been marked up
646 with certain state, namely table.dataset.lefthash and TR
647 entries which hold state related to browsing context.
648 */
649 Diff.setupDiffContextLoad = function(tables){
650 if('string'===typeof tables){
651 tables = document.querySelectorAll(tables);
652 }else if(!tables){
653 tables = document.querySelectorAll('table.diff[data-lefthash]:not(.diffskipped)');
654 }
655 /* Potential performance-related TODO: instead of installing all
656 of these at once, install them as the corresponding TR is
657 scrolled into view. */
658 tables.forEach(function(table){
659 if(!table.dataset.lefthash) return;
660 D.addClass(table, 'diffskipped'/*avoid processing these more than once */);
661 table.querySelectorAll('tr.diffskip[data-startln]').forEach(function(tr){
662 new ChunkLoadControls(D.addClass(tr, 'jchunk'));
663 });
664 });
665 return F;
666 };
667 Diff.setupDiffContextLoad();
668 });
669
670 /* Refinements to the display of unified and side-by-side diffs.
671 **
672 ** In all cases, the table columns tagged with "difftxt" are expanded,
@@ -763,6 +780,5 @@
780 document.querySelectorAll('table.splitdiff').forEach((e)=>Diff.initTableDiff);
781 };
782 Diff.initTableDiff().checkTableWidth();
783 window.addEventListener('resize', ()=>Diff.checkTableWidth());
784 }, false);
 
785
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -1512,10 +1512,11 @@
15121512
//pre.removeAttribute('style');
15131513
//console.debug("pre width =",pre.style.width);
15141514
}
15151515
);
15161516
}
1517
+ F.diff.setupDiffContextLoad();
15171518
this.tweakSbsDiffs();
15181519
};
15191520
15201521
/**
15211522
Fetches the content diff based on the contents and settings of
15221523
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -1512,10 +1512,11 @@
1512 //pre.removeAttribute('style');
1513 //console.debug("pre width =",pre.style.width);
1514 }
1515 );
1516 }
 
1517 this.tweakSbsDiffs();
1518 };
1519
1520 /**
1521 Fetches the content diff based on the contents and settings of
1522
--- src/fossil.page.wikiedit.js
+++ src/fossil.page.wikiedit.js
@@ -1512,10 +1512,11 @@
1512 //pre.removeAttribute('style');
1513 //console.debug("pre width =",pre.style.width);
1514 }
1515 );
1516 }
1517 F.diff.setupDiffContextLoad();
1518 this.tweakSbsDiffs();
1519 };
1520
1521 /**
1522 Fetches the content diff based on the contents and settings of
1523

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button