blob: 336708f140e71d9580ad50cdc961d349eca0bb5d (
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
42
43
44
45
46
47
|
import './toggle-files-button.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import ChevronDownIcon from 'octicon/chevron-down.svg';
import features from '.';
import observeElement from '../helpers/simplified-element-observer';
function addButton(): void {
// `div` excludes `include-fragment`, which means the list is still loading. #2160
const filesHeader = select('div.commit-tease');
if (!filesHeader || select.exists('.rgh-toggle-files')) {
return;
}
filesHeader.append(
<button
type="button"
className="btn-octicon rgh-toggle-files"
aria-label="Toggle files section"
aria-expanded="true"
>
<ChevronDownIcon/>
</button>
);
}
function init(): void {
const repoContent = select('.repository-content')!;
observeElement(repoContent, addButton);
delegate(document, '.rgh-toggle-files', 'click', ({delegateTarget}) => {
delegateTarget.setAttribute('aria-expanded', String(!repoContent.classList.toggle('rgh-files-hidden')));
});
}
void features.add({
id: __filebasename,
description: 'Adds a button to toggle the repo file list.',
screenshot: 'https://user-images.githubusercontent.com/1402241/35480123-68b9af1a-043a-11e8-8934-3ead3cff8328.gif'
}, {
include: [
pageDetect.isRepoTree
],
init
});
|