blob: 459a40dd90a793e00a5bd56d92bdca0c64a6a501 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import './toggle-files-button.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import features from '../libs/features';
import * as icons from '../libs/icons';
import observeEl from '../libs/simplified-element-observer';
function addButton(): void {
const filesHeader = select('.commit-tease');
if (!filesHeader || select.exists('.rgh-toggle-files')) {
return;
}
filesHeader.append(
<button
className="btn-octicon rgh-toggle-files"
aria-label="Toggle files section"
aria-expanded="true">
{icons.chevronDown()}
</button>
);
}
function init(): void {
const repoContent = select('.repository-content')!;
observeEl(repoContent, addButton);
delegate('.rgh-toggle-files', 'click', ({delegateTarget}) => {
delegateTarget.setAttribute('aria-expanded', String(!repoContent.classList.toggle('rgh-files-hidden')));
});
}
features.add({
id: 'toggle-files-button',
description: 'Add a "Toggle all files" button to file lists in repositories',
include: [
features.isRepoTree
],
load: features.onAjaxedPages,
init
});
|