@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix issues with Differential file toggling

Summary:
See D2714#15.

# Give anchors an `id` equal to their `name` so JX.$ can find them.
# Listen for `click` s on `<a>` s instead of `hashchange` s to make
toggling a bit more correct and consistent.
# Add a placeholder menu item when the file is unloaded. A previous
patch by @jungejason had left the item blank in that case.
# In fixing (1) I found another exception when clicking on ToC links.
Since those links are `differential-load`, they try to load the file
before jumping to it. However, loading destroys the node it's looking
for, so if you jump to an already-loaded file JX.$ complains at you.

Test Plan: Make a giant diff. Click on links and try toggling files.

Reviewers: epriestley, vrana

Reviewed By: vrana

CC: vrana, aran, Korvin

Maniphest Tasks: T370

Differential Revision: https://secure.phabricator.com/D3185

+37 -11
+3
webroot/rsrc/js/application/differential/behavior-dropdown-menus.js
··· 101 101 reveal_item.setName('Entire File Shown'); 102 102 } 103 103 104 + visible_item.setDisabled(true); 105 + visible_item.setName("Can't Toggle Unloaded File"); 104 106 var diffs = JX.DOM.scry(JX.$(data.containerID), 105 107 'table', 'differential-diff'); 106 108 if (diffs.length > 1) { ··· 109 111 data.containerID+'."'); 110 112 } else if (diffs.length == 1) { 111 113 diff = diffs[0]; 114 + visible_item.setDisabled(false); 112 115 if (JX.Stratcom.getData(diff).hidden) { 113 116 visible_item.setName('Expand File'); 114 117 } else {
+34 -11
webroot/rsrc/js/application/differential/behavior-toggle-files.js
··· 33 33 function(e) { 34 34 var elt = e.getData().element; 35 35 while (elt !== document.body) { 36 - if (JX.Stratcom.hasSigil(elt, 'differential-diff') && 37 - JX.Stratcom.getData(elt).hidden) { 38 - JX.Stratcom.invoke('differential-toggle-file', null, { 39 - diff: [ elt ], 40 - }); 36 + if (JX.Stratcom.hasSigil(elt, 'differential-changeset')) { 37 + var diffs = JX.DOM.scry(elt, 'table', 'differential-diff'); 38 + for (var i = 0; i < diffs.length; ++i) { 39 + if (JX.Stratcom.getData(diffs[i]).hidden) { 40 + JX.Stratcom.invoke('differential-toggle-file', null, { 41 + diff: [ diffs[i] ], 42 + }); 43 + } 44 + } 41 45 return; 42 46 } 43 47 elt = elt.parentNode; ··· 45 49 }); 46 50 47 51 JX.Stratcom.listen( 48 - 'hashchange', 49 - null, 52 + 'click', 53 + 'tag:a', 50 54 function(e) { 51 - var id = window.location.hash; 52 - if (!id.match(/^#/)) { 55 + var link = e.getNode('tag:a'); 56 + var id = link.getAttribute('href'); 57 + if (!id.match(/^#.+/)) { 53 58 return; 54 59 } 60 + // The target may have either a matching name or a matching id. 61 + var target; 62 + try { 63 + target = JX.$(id.substr(1)); 64 + } catch(err) { 65 + var named = document.getElementsByName(id.substr(1)); 66 + var matches = []; 67 + for (var i = 0; i < named.length; ++i) { 68 + if (named[i].tagName.toLowerCase() == 'a') { 69 + matches.push(named[i]); 70 + } 71 + } 72 + if (matches.length == 1) { 73 + target = matches[0]; 74 + } else { 75 + return; 76 + } 77 + } 55 78 JX.Stratcom.invoke('differential-toggle-file-request', null, { 56 - element: JX.$(id.substr(1)), 79 + element: target, 57 80 }); 58 81 // This event is processed after the hash has changed, so it doesn't 59 82 // automatically jump there like we want. 60 - JX.DOM.scrollTo(JX.$(id.substr(1))); 83 + JX.DOM.scrollTo(target); 61 84 }); 62 85 });