update input based on hash

This commit is contained in:
scribu 2014-04-10 13:53:00 +03:00
parent 4d177e8295
commit bce80429d5
2 changed files with 20 additions and 2 deletions

View File

@ -9,7 +9,7 @@
<h1>Travis CI build stats</h1>
<form>
<label>Repository:</label>
<input id="repo-name" type="text" value="wp-cli/wp-cli" />
<input id="repo-name" type="text" placeholder="owner/repo" />
<input class="button" type="submit" value="Render" />
</form>

View File

@ -143,6 +143,12 @@ function getBuildDate(build) {
function updateChart() {
var repoName = document.getElementById('repo-name').value;
// need at least "a/a"
if (repoName.length < 3) {
return;
}
var baseUrl = 'https://travis-ci.org/' + repoName + '/builds/';
var buildsUrl = 'https://api.travis-ci.org/repos/' + repoName + '/builds?event_type=push';
@ -198,10 +204,22 @@ function updateChart() {
d3.json(buildsUrl, filterBuilds);
}
updateChart();
function updateInputViaHash() {
document.getElementById('repo-name').value = window.location.hash.substr(1);
}
function updateHashViaInput() {
window.location.hash = '#' + document.getElementById('repo-name').value;
}
d3.select(window).on('hashchange', updateInputViaHash);
d3.select('form').on('submit', function() {
d3.event.preventDefault();
updateHashViaInput();
updateChart();
});
updateInputViaHash();
updateChart();