Skip to content

Commit ab26fe3

Browse files
committed
Update heading
1 parent e3b7867 commit ab26fe3

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

site/static/compare.html

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,9 @@
160160
</div>
161161
<br />
162162
<div id="app">
163-
<h1>Comparing <span id="stat-header">instructions:u</span> between <span id="before">???</span> and <span
164-
id="after">???</span></h1>
163+
<h1>Comparing <span id="stat-header">{{stat}}</span> between <span id="before">{{before}}</span> and
164+
<span id="after">{{after}}</span>
165+
</h1>
165166
<fieldset id="settings">
166167
<legend id="search-toggle" class="section-heading">Do another comparison<span
167168
id="search-toggle-indicator"></span></legend>
@@ -349,6 +350,13 @@ <h1>Comparing <span id="stat-header">instructions:u</span> between <span id="bef
349350
<script src="https://cdnjs.cloudflare.com/ajax/libs/msgpack-lite/0.1.26/msgpack.min.js"></script>
350351
<script src="shared.js"></script>
351352
<script>
353+
function findQueryParam(name) {
354+
let urlParams = window.location.search.substring(1).split("&").map(x => x.split("="));
355+
let pair = urlParams.find(x => x[0] === name)
356+
if (pair) {
357+
return unescape(pair[1]);
358+
}
359+
}
352360
let app = new Vue({
353361
el: '#app',
354362
data: {
@@ -461,6 +469,21 @@ <h1>Comparing <span id="stat-header">instructions:u</span> between <span id="bef
461469
};
462470
}).sort((a, b) => Math.abs(b.percent) - Math.abs(a.percent));
463471
},
472+
before() {
473+
if (!this.data) {
474+
return findQueryParam("start").substring(0, 7);
475+
}
476+
return `#${this.data.a.pr}` || this.formatDate(this.data.a.date) || this.data.a.commit.substring(0, 7);
477+
},
478+
after() {
479+
if (!this.data) {
480+
return findQueryParam("end").substring(0, 7);
481+
}
482+
return `#${this.data.b.pr}` || this.formatDate(this.data.b.date) || this.data.b.commit.substring(0, 7);
483+
},
484+
stat() {
485+
return findQueryParam("stat");
486+
}
464487
},
465488
methods: {
466489
short(comparison) {
@@ -575,31 +598,10 @@ <h1>Comparing <span id="stat-header">instructions:u</span> between <span id="bef
575598
stat: "instructions:u",
576599
}, state);
577600
makeRequest("/get", values).then(function (data) {
578-
updateHeader(data.a.commit, data.b.commit);
579601
app.data = data;
580602
});
581603
}
582604

583-
function updateHeader(a, b, stat) {
584-
let shorten = (text) => {
585-
return text.substring(0, 7);
586-
}
587-
a && (document.getElementById("before").innerHTML = shorten(a));
588-
b && (document.getElementById("after").innerHTML = shorten(b));
589-
stat && (document.getElementById("stat-header").innerHTML = stat);
590-
}
591-
592-
function findQueryParam(name) {
593-
let urlParams = window.location.search.substring(1).split("&").map(x => x.split("="));
594-
let pair = urlParams.find(x => x[0] === name)
595-
if (pair) {
596-
return unescape(pair[1]);
597-
}
598-
}
599-
let start = findQueryParam("start");
600-
let end = findQueryParam("end");
601-
let stat = findQueryParam("stat")
602-
updateHeader(start, end, stat);
603605

604606
function submitSettings() {
605607
let start = document.getElementById("start-bound").value;

0 commit comments

Comments
 (0)