2014-12-02 22:10:29 +01:00
|
|
|
/**
|
|
|
|
* @provides javelin-behavior-phabricator-show-older-transactions
|
|
|
|
* @requires javelin-behavior
|
|
|
|
* javelin-stratcom
|
|
|
|
* javelin-dom
|
|
|
|
* phabricator-busy
|
|
|
|
*/
|
|
|
|
|
|
|
|
JX.behavior('phabricator-show-older-transactions', function(config) {
|
|
|
|
|
|
|
|
function get_hash() {
|
|
|
|
return window.location.hash.replace(/^#/, '');
|
|
|
|
}
|
|
|
|
|
|
|
|
function hash_is_hidden() {
|
|
|
|
var hash = get_hash();
|
|
|
|
if (!hash) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
var id = 'anchor-'+hash;
|
|
|
|
try {
|
|
|
|
JX.$(id);
|
|
|
|
} catch (not_found_exception) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function check_hash() {
|
|
|
|
if (hash_is_hidden()) {
|
2014-12-10 21:12:38 +01:00
|
|
|
load_older(load_hidden_hash_callback);
|
2014-12-02 22:10:29 +01:00
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
var target = JX.$(get_hash());
|
|
|
|
JX.DOM.scrollTo(target);
|
|
|
|
} catch (ignored) {
|
|
|
|
// We did our best.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-10 21:12:38 +01:00
|
|
|
function load_older(callback) {
|
|
|
|
var showOlderBlock = null;
|
|
|
|
try {
|
|
|
|
showOlderBlock = JX.DOM.find(
|
|
|
|
JX.$(config.timelineID),
|
|
|
|
'div',
|
|
|
|
'show-older-block');
|
|
|
|
} catch (not_found_exception) {
|
|
|
|
// we loaded everything...!
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var showOlderLink = JX.DOM.find(
|
|
|
|
showOlderBlock,
|
|
|
|
'a',
|
|
|
|
'show-older-link');
|
|
|
|
var workflow = fetch_older_workflow(
|
|
|
|
showOlderLink.href,
|
|
|
|
callback,
|
|
|
|
showOlderBlock);
|
|
|
|
var routable = workflow.getRoutable()
|
|
|
|
.setPriority(2000)
|
|
|
|
.setType('workflow');
|
|
|
|
JX.Router.getInstance().queue(routable);
|
|
|
|
}
|
|
|
|
|
2014-12-02 22:10:29 +01:00
|
|
|
var show_older = function(swap, r) {
|
|
|
|
JX.DOM.replace(swap, JX.$H(r.timeline).getFragment());
|
|
|
|
};
|
|
|
|
|
2014-12-10 21:12:38 +01:00
|
|
|
var load_hidden_hash_callback = function(swap, r) {
|
2014-12-02 22:10:29 +01:00
|
|
|
show_older(swap, r);
|
|
|
|
check_hash();
|
|
|
|
};
|
|
|
|
|
2014-12-10 21:12:38 +01:00
|
|
|
var load_all_older_callback = function(swap, r) {
|
|
|
|
show_older(swap, r);
|
|
|
|
load_older(load_all_older_callback);
|
|
|
|
};
|
|
|
|
|
2014-12-02 22:10:29 +01:00
|
|
|
var fetch_older_workflow = function(href, callback, swap) {
|
2014-12-04 22:58:52 +01:00
|
|
|
return new JX.Workflow(href, config.renderData)
|
2014-12-02 22:10:29 +01:00
|
|
|
.setHandler(JX.bind(null, callback, swap));
|
|
|
|
};
|
|
|
|
|
|
|
|
JX.Stratcom.listen(
|
|
|
|
'click',
|
2014-12-10 21:12:38 +01:00
|
|
|
['show-older-block'],
|
2014-12-02 22:10:29 +01:00
|
|
|
function(e) {
|
|
|
|
e.kill();
|
2014-12-10 21:12:38 +01:00
|
|
|
var workflow = fetch_older_workflow(
|
|
|
|
JX.DOM.find(
|
|
|
|
e.getNode('show-older-block'),
|
|
|
|
'a',
|
|
|
|
'show-older-link').href,
|
2014-12-02 22:10:29 +01:00
|
|
|
show_older,
|
2014-12-10 21:12:38 +01:00
|
|
|
e.getNode('show-older-block'));
|
|
|
|
var routable = workflow.getRoutable()
|
|
|
|
.setPriority(2000)
|
|
|
|
.setType('workflow');
|
|
|
|
JX.Router.getInstance().queue(routable);
|
2014-12-02 22:10:29 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
JX.Stratcom.listen('hashchange', null, check_hash);
|
|
|
|
check_hash();
|
|
|
|
|
2014-12-12 20:23:56 +01:00
|
|
|
new JX.KeyboardShortcut(['@'], 'Show all older changes in the timeline.')
|
2014-12-10 21:12:38 +01:00
|
|
|
.setHandler(JX.bind(null, load_older, load_all_older_callback))
|
|
|
|
.register();
|
2014-12-02 22:10:29 +01:00
|
|
|
});
|