Skip to content
This repository was archived by the owner on Mar 6, 2020. It is now read-only.

Commit 9398267

Browse files
committed
convert remaining hooks (playback-events/popout-style) to plugins, closes #26
1 parent b9f45ee commit 9398267

7 files changed

Lines changed: 75 additions & 58 deletions

File tree

src/ExtPlug.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import TooltipsPlugin from './plugins/TooltipsPlugin';
2020
import GuestPlugin from './plugins/GuestPlugin';
2121
import SocketEventsPlugin from './plugins/SocketEventsPlugin';
2222
import WaitlistEventsPlugin from './plugins/WaitlistEventsPlugin';
23+
import PlaybackEventsPlugin from './plugins/PlaybackEventsPlugin';
2324
import PlugSettingsPlugin from './plugins/PlugSettingsPlugin';
25+
import PopoutStylePlugin from './plugins/PopoutStylePlugin';
2426

2527
import * as packageMeta from '../package.json';
2628

27-
import hooks from './hooks/index';
28-
2929
import badgeStyles from './styles/badge';
3030
import inlineChatStyles from './styles/inline-chat';
3131
import settingsPaneStyles from './styles/settings-pane';
@@ -98,7 +98,9 @@ const ExtPlug = Plugin.extend({
9898
new TooltipsPlugin('extplug:tooltips', this),
9999
new SocketEventsPlugin('extplug:socket-events', this),
100100
new WaitlistEventsPlugin('extplug:waitlist-events', this),
101+
new PlaybackEventsPlugin('extplug:playback-events', this),
101102
new PlugSettingsPlugin('extplug:plug-settings', this),
103+
new PopoutStylePlugin('extplug:popout-style', this),
102104
];
103105

104106
this.guestPlugin = new GuestPlugin('extplug:guest', this);
@@ -273,11 +275,6 @@ const ExtPlug = Plugin.extend({
273275

274276
this.appView = getApplicationView();
275277

276-
// install extra events
277-
hooks.forEach(hook => {
278-
hook.install();
279-
});
280-
281278
this.corePlugins.forEach(plugin => {
282279
plugin.enable();
283280
});
@@ -317,9 +314,6 @@ const ExtPlug = Plugin.extend({
317314
this.corePlugins.forEach(plugin => {
318315
plugin.disable();
319316
});
320-
hooks.forEach(hook => {
321-
hook.uninstall();
322-
});
323317

324318
this.guestPlugin.disable();
325319

src/hooks/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/hooks/playback.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/hooks/popout-style.js

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import $ from 'jquery';
2+
import Events from 'plug/core/Events';
3+
import Plugin from '../Plugin';
4+
5+
const PlaybackEventsPlugin = Plugin.extend({
6+
name: 'Playback Events',
7+
description: 'Add internal events for some playback-related actions: refresh, snooze, toggling HD video.',
8+
9+
init(id, ext) {
10+
this._super(id, ext);
11+
12+
this.onRefresh = this.onRefresh.bind(this);
13+
this.onHd = this.onHd.bind(this);
14+
this.onSnooze = this.onSnooze.bind(this);
15+
},
16+
17+
enable() {
18+
$('#playback .refresh.button').on('click', this.onRefresh);
19+
$('#playback .hd.button').on('click', this.onHd);
20+
$('#playback .snooze.button').on('click', this.onSnooze);
21+
},
22+
23+
disable() {
24+
$('#playback .refresh.button').off('click', this.onRefresh);
25+
$('#playback .hd.button').off('click', this.onHd);
26+
$('#playback .snooze.button').off('click', this.onSnooze);
27+
},
28+
29+
onRefresh() {
30+
Events.trigger('playback:refresh');
31+
},
32+
33+
onHd() {
34+
Events.trigger('playback:hdVideo');
35+
},
36+
37+
onSnooze() {
38+
Events.trigger('playback:snooze');
39+
},
40+
});
41+
42+
export default PlaybackEventsPlugin;

src/plugins/PopoutStylePlugin.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import $ from 'jquery';
2+
import { defer } from 'underscore';
3+
import Events from 'plug/core/Events';
4+
import popoutView from 'plug/views/rooms/popout/PopoutView';
5+
import Plugin from '../Plugin';
6+
7+
const PopoutStylePlugin = Plugin.extend({
8+
name: 'Popout Style',
9+
description: 'Synchronises custom stylesheets between popout chat and the main window.',
10+
11+
enable() {
12+
Events.on('popout:show', this.sync, this);
13+
},
14+
15+
disable() {
16+
Events.off('popout:show', this.sync);
17+
},
18+
19+
sync() {
20+
defer(() => {
21+
const stylesheets = $('.extplug-style').clone();
22+
popoutView.$document.find('head').append(stylesheets);
23+
});
24+
},
25+
});
26+
27+
export default PopoutStylePlugin;

src/readme.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ deobfuscate plug.dj's internal module names.
2222
All of that is then executed by [loader.js](./loader.js.template) when plug.dj
2323
is ready.
2424

25-
Files in the [hooks/](./hooks/) directory add new event types to the plug.dj API
26-
or synchronise data between ExtPlug and plug.dj.
27-
2825
The [plugins/](./plugins/) directory contains core plugins that add more
29-
advanced default functionality, such as the core ExtPlug chat commands or the
30-
plugin management views.
26+
functionality to plug.dj, such as event types, the core ExtPlug chat commands,
27+
and the plugin management views.

0 commit comments

Comments
 (0)