mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-02 11:42:42 +01:00
ea8faedf0b
Summary: - Add a query parameter to select the diff renderer. - When we populate diffs, use the 1-up renderer if the device isn't a desktop. Don't switch renderers once the page has loaded since it will be a tremendous mess. We can add an "always use 1-up" preference later. - Tweak JX.Device so we avoid a race condition, where `JX.Device.getDevice()` may not be valid when other behaviors run. - Implement enough of the 1-up HTML renderer to provide a vague hint that it actually works. - Fix a couple of bugs with primitive construction. Test Plan: {F29168} {F29169} Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2009 Differential Revision: https://secure.phabricator.com/D4423
132 lines
3.4 KiB
JavaScript
132 lines
3.4 KiB
JavaScript
/**
|
|
* @provides javelin-behavior-differential-populate
|
|
* @requires javelin-behavior
|
|
* javelin-workflow
|
|
* javelin-util
|
|
* javelin-dom
|
|
* javelin-stratcom
|
|
* javelin-behavior-device
|
|
* phabricator-tooltip
|
|
*/
|
|
|
|
JX.behavior('differential-populate', function(config) {
|
|
|
|
function onresponse(target, response) {
|
|
JX.DOM.replace(JX.$(target), JX.$H(response.changeset));
|
|
if (response.coverage) {
|
|
for (var k in response.coverage) {
|
|
try {
|
|
JX.DOM.replace(JX.$(k), JX.$H(response.coverage[k]));
|
|
} catch (ignored) {
|
|
// Not terribly important.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// NOTE: If you load the page at one device resolution and then resize to
|
|
// a different one we don't re-render the diffs, because it's a complicated
|
|
// mess and you could lose inline comments, cursor positions, etc.
|
|
var renderer = (JX.Device.getDevice() == 'desktop') ? '2up' : '1up';
|
|
|
|
for (var k in config.registry) {
|
|
var data = {
|
|
ref : config.registry[k],
|
|
whitespace: config.whitespace,
|
|
renderer: renderer
|
|
};
|
|
|
|
new JX.Workflow(config.uri, data)
|
|
.setHandler(JX.bind(null, onresponse, k))
|
|
.start();
|
|
}
|
|
|
|
var highlighted = null;
|
|
var highlight_class = null;
|
|
|
|
JX.Stratcom.listen(
|
|
'click',
|
|
'differential-load',
|
|
function(e) {
|
|
var meta = e.getNodeData('differential-load');
|
|
var diff;
|
|
try {
|
|
diff = JX.$(meta.id);
|
|
} catch (e) {
|
|
// Already loaded.
|
|
}
|
|
if (diff) {
|
|
JX.DOM.setContent(
|
|
diff,
|
|
JX.$H('<div class="differential-loading">Loading...</div>'));
|
|
var data = {
|
|
ref : meta.ref,
|
|
whitespace : config.whitespace
|
|
};
|
|
new JX.Workflow(config.uri, data)
|
|
.setHandler(JX.bind(null, onresponse, meta.id))
|
|
.start();
|
|
}
|
|
if (meta.kill) {
|
|
e.kill();
|
|
}
|
|
});
|
|
|
|
JX.Stratcom.listen(
|
|
['mouseover', 'mouseout'],
|
|
['differential-changeset', 'tag:td'],
|
|
function(e) {
|
|
var t = e.getTarget();
|
|
|
|
// NOTE: Using className is not best practice, but the diff UI is perf
|
|
// sensitive.
|
|
if (!t.className.match(/cov|copy/)) {
|
|
return;
|
|
}
|
|
|
|
if (e.getType() == 'mouseout') {
|
|
JX.Tooltip.hide();
|
|
if (highlighted) {
|
|
JX.DOM.alterClass(highlighted, highlight_class, false);
|
|
highlighted = null;
|
|
}
|
|
} else {
|
|
highlight_class = null;
|
|
var msg;
|
|
var align = 'W';
|
|
var sibling = 'previousSibling';
|
|
var width = 120;
|
|
if (t.className.match(/cov-C/)) {
|
|
msg = 'Covered';
|
|
highlight_class = 'source-cov-C';
|
|
} else if (t.className.match(/cov-U/)) {
|
|
msg = 'Not Covered';
|
|
highlight_class = 'source-cov-U';
|
|
} else if (t.className.match(/cov-N/)) {
|
|
msg = 'Not Executable';
|
|
highlight_class = 'source-cov-N';
|
|
} else {
|
|
var match = /new-copy|new-move/.exec(t.className);
|
|
if (match) {
|
|
sibling = 'nextSibling';
|
|
width = 500;
|
|
msg = JX.Stratcom.getData(t).msg;
|
|
highlight_class = match[0];
|
|
}
|
|
}
|
|
|
|
if (msg) {
|
|
JX.Tooltip.show(t, width, align, msg);
|
|
}
|
|
|
|
if (highlight_class) {
|
|
highlighted = t[sibling];
|
|
JX.DOM.alterClass(highlighted, highlight_class, true);
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|