1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-21 04:50:55 +01:00
phorge-phorge/webroot/rsrc/js/application/differential/behavior-comment-preview.js

100 lines
2.5 KiB
JavaScript
Raw Normal View History

2011-02-01 03:05:20 +01:00
/**
* @provides javelin-behavior-differential-feedback-preview
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
* javelin-request
* javelin-util
* phabricator-shaped-request
2011-02-01 03:05:20 +01:00
*/
JX.behavior('differential-feedback-preview', function(config) {
var action = JX.$(config.action);
var content = JX.$(config.content);
var previewTokenizers = {};
var field;
for (field in config.previewTokenizers) {
var tokenizer = JX.$(config.previewTokenizers[field]);
previewTokenizers[field] = JX.Stratcom.getData(tokenizer).tokenizer;
}
2011-02-01 03:05:20 +01:00
var callback = function(r) {
var preview = JX.$(config.preview);
JX.DOM.setContent(preview, JX.$H(r));
JX.Stratcom.invoke('differential-preview-update', null, {
container: preview
});
};
2011-02-01 03:05:20 +01:00
var getdata = function() {
var data = {
content : content.value,
action : action.value
};
for (var field in previewTokenizers) {
data[field] = JX.keys(previewTokenizers[field].getTokens()).join(',');
}
return data;
};
2011-02-01 03:05:20 +01:00
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
var trigger = JX.bind(request, request.trigger);
2011-02-01 03:05:20 +01:00
JX.DOM.listen(content, 'keydown', null, trigger);
JX.DOM.listen(action, 'change', null, trigger);
for (field in previewTokenizers) {
previewTokenizers[field].listen('change', trigger);
}
2011-02-01 03:05:20 +01:00
request.start();
2011-02-03 04:38:43 +01:00
function refreshInlinePreview() {
new JX.Request(config.inlineuri, function(r) {
var inline = JX.$(config.inline);
JX.DOM.setContent(inline, JX.$H(r));
JX.Stratcom.invoke('differential-preview-update', null, {
container: inline
});
updateLinks();
})
.setTimeout(5000)
.send();
}
function updateLinks() {
var inline = JX.$(config.inline);
var links = JX.DOM.scry(
inline,
'a',
'differential-inline-preview-jump');
for (var ii = 0; ii < links.length; ii++) {
var data = JX.Stratcom.getData(links[ii]);
try {
JX.$(data.anchor);
links[ii].href = '#' + data.anchor;
JX.DOM.setContent(links[ii], 'View');
} catch (ignored) {
// This inline comment isn't visible, e.g. on some other diff.
}
}
2011-02-03 04:38:43 +01:00
}
2011-02-03 04:38:43 +01:00
JX.Stratcom.listen(
'differential-inline-comment-update',
null,
refreshInlinePreview);
JX.Stratcom.listen(
'differential-inline-comment-refresh',
null,
updateLinks);
refreshInlinePreview();
2011-02-01 03:05:20 +01:00
});