-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
minimize-upload-bar.tsx
40 lines (36 loc) · 1.14 KB
/
minimize-upload-bar.tsx
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
import './minimize-upload-bar.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate, {DelegateEvent} from 'delegate-it';
import features from '../libs/features';
import * as icons from '../libs/icons';
function addButton(): void {
for (const toolbarButton of select.all('md-ref')) {
toolbarButton.after(
<button type="button" className="toolbar-item tooltipped tooltipped-n rgh-upload-btn" aria-label="Attach files">
{icons.cloudUpload()}
</button>
);
toolbarButton.closest('form')!.classList.add('rgh-minimize-upload-bar');
}
}
function triggerUpload(event: DelegateEvent<Event, HTMLButtonElement>): void {
event.delegateTarget
.form!
.querySelector<HTMLInputElement>('.js-manual-file-chooser')!
.click(); // Open UI
}
function init(): void {
addButton();
delegate('.rgh-upload-btn', 'click', triggerUpload);
}
features.add({
id: __featureName__,
description: 'Reduces the upload bar to a small button.',
screenshot: 'https://user-images.githubusercontent.com/55841/59802383-3d994180-92e9-11e9-835d-60de67611c30.png',
include: [
features.hasRichTextEditor
],
load: features.onAjaxedPages,
init
});