Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Merge #1361
Browse files Browse the repository at this point in the history
1361: Hide and show commit on narrow screens r=notriddle a=notriddle



Co-authored-by: Michael Howell <michael@notriddle.com>
  • Loading branch information
bors[bot] and notriddle committed Oct 29, 2021
2 parents 960d181 + 95f5d2e commit 5977787
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 7 deletions.
15 changes: 15 additions & 0 deletions assets/css/app.css
Expand Up @@ -260,6 +260,21 @@ footer {
.table tr:target {
background: #EEE;
}
table tr.exp {
display: none;
}
table tr.exp td {
padding: 0 1em;
}
.exp-indicator-close::before {
content: '▸';
}
.exp-indicator-open::before {
content: '▾';
}
table tr.exp:target {
display: table-row;
}
.table tbody tr[role="row"]:hover {
background: #EEE;
}
Expand Down
1 change: 1 addition & 0 deletions assets/js/app.js
Expand Up @@ -28,4 +28,5 @@ import "./alert"
import "./socket"
import "./drop-down-menu"
import "./time-convert"
import "./expand-row"
import "./pagination"
114 changes: 114 additions & 0 deletions assets/js/expand-row.js
@@ -0,0 +1,114 @@
const items = document.querySelectorAll("td.expand-row");
Array.prototype.forEach.call(items, convertExpandRow);

window.addEventListener("resize", function() {
const items = document.querySelectorAll("td.expand-row");
Array.prototype.forEach.call(items, convertExpandRow);
convertIndicator();
});

window.addEventListener("popstate", convertIndicator);
window.addEventListener("DOMContentLoaded", convertIndicator);

function convertIndicator() {
var h = Array.prototype.slice.call(document.querySelectorAll("[data-exp-hash]"));
var l = h.length;
for (var i = 0; i < l; ++i) {
h[i].classList.remove("exp-indicator-open");
h[i].classList.add("exp-indicator-close");
h[i].setAttribute("aria-expanded", "false");
}
if (window.location.hash) {
h = document.querySelector("[data-exp-hash=\"" + window.location.hash + "\"]");
if (h && h.hash === window.location.hash) {
h.classList.add("exp-indicator-open");
h.classList.remove("exp-indicator-close");
h.setAttribute("aria-expanded", "true");
}
}
}

function getNewID() {
let fullID;
do {
if (!window.borsExpNewID) {
window.borsExpNewID = 0;
}
window.borsExpNewID += 1;
fullID = "row-" + window.borsExpNewID.toString();
} while (document.getElementById(fullID));
return fullID;
}

function convertExpandRow(td) {
if (td.borsExp) {
return;
}
var row = td.parentElement;
if (!row.id) {
row.id = getNewID();
}
td.classList.add("fill-link");
let item;
if (item = doExpandRow(td)) {
const a = document.createElement("a");
a.href = item;
a.hash = item;
a.setAttribute("data-exp-hash", item);
a.addEventListener("click", function(e) {
if (window.location.hash === this.hash && window.history && window.history.state && window.history.state.borsExp) {
window.history.back();
e.preventDefault();
} else if (window.location.hash !== this.hash) {
window.location = this.hash;
window.history.replaceState({borsExp: true}, window.title);
e.preventDefault();
}
convertIndicator();
});
while (item = td.firstChild) {
td.removeChild(item);
a.appendChild(item);
}
td.appendChild(a);
}
}

function doExpandRow(td) {
const row = td.parentElement;
const table = row.parentElement.parentElement;
const headRow = table.querySelector("thead tr[role=\"row\"]");
const headItems = Array.prototype.slice.call(headRow.children);
const colSpan = row.children.length;
const items = Array.prototype.slice.call(row.children);
const l = items.length;
const borsExp = document.createElement("tr");
borsExp.className = "exp";
const borsExpInternal = document.createElement("td");
borsExp.appendChild(borsExpInternal);
borsExpInternal.setAttribute("colspan", l);
const borsExpDl = document.createElement("dl");
borsExpInternal.appendChild(borsExpDl);
let foundOne = false;
for (var i = 0; i !== l; ++i) {
if (items[i].scrollHeight === 0) {
foundOne = true;
const dt = document.createElement("dt");
dt.appendChild(document.createTextNode(headItems[i].innerText));
const dd = document.createElement("dd");
dd.appendChild(document.createTextNode(items[i].innerText));
borsExpDl.appendChild(dt)
borsExpDl.appendChild(dd);
}
}
if (foundOne) {
row.parentElement.insertBefore(borsExp, row.nextElementSibling);
td.borsExp = borsExp;
borsExp.id = "exp-" + row.id;
return "#" + borsExp.id;
} else {
return false;
}
}

export { convertExpandRow };
2 changes: 1 addition & 1 deletion assets/js/pagination.js
Expand Up @@ -2,7 +2,7 @@ import { convertTime } from './time-convert.js';

var pathParts = window.location.pathname.match(/\/\d+\//);

if (pathParts.length > 0) {
if (pathParts && pathParts.length > 0) {
activateRepo(pathParts[0]);
}

Expand Down
12 changes: 6 additions & 6 deletions lib/web/templates/project/show.html.eex
Expand Up @@ -34,8 +34,8 @@
</thead>
<tbody>
<%= for patch <- batch.patches do %>
<tr role="row">
<td>
<tr role="row" id="prrow-<%= patch.pr_xref %>">
<td class=expand-row>
<%= patch.pr_xref %>
</td>
<td class=span--<%= if patch.is_mergeable do %>ok<% else %>error<% end %> aria-label="<%= if patch.is_mergeable do %><%= if patch.is_draft do %>Draft<% else %>Yes<% end %><% else %>No<% end %>" title="<%= if patch.is_mergeable do %><%= if patch.is_draft do %>Draft<% else %>Yes<% end %><% else %>No<% end %>">
Expand All @@ -59,7 +59,7 @@
<%= if patch.is_single do %>S<% end %>
</td>
<td class=hide-on-super-narrow>
<%= truncate_commit(patch.commit) %>
<code><%= truncate_commit(patch.commit) %></code>
</td>
</tr>
<% end %>
Expand All @@ -77,8 +77,8 @@
</thead>
<tbody>
<%= for patch <- @unbatched_patches do %>
<tr role="row">
<td>
<tr role="row" id="prrow-<%= patch.pr_xref %>">
<td class=expand-row>
<%= patch.pr_xref %>
</td>
<td class=span--<%= if patch.is_mergeable do %>ok<% else %>error<% end %> aria-label="<%= if patch.is_mergeable do %><%= if patch.is_draft do %>Draft<% else %>Yes<% end %><% else %>No<% end %>" title="<%= if patch.is_mergeable do %><%= if patch.is_draft do %>Draft<% else %>Yes<% end %><% else %>No<% end %>">
Expand All @@ -102,7 +102,7 @@
<%= if patch.is_single do %>S<% end %>
</td>
<td class=hide-on-super-narrow>
<%= truncate_commit(patch.commit) %>
<code><%= truncate_commit(patch.commit) %></code>
</td>
</tr>
<% end %>
Expand Down

0 comments on commit 5977787

Please sign in to comment.