2017-11-13 01:23:39 -05:00
'use strict' ;
// ============================================================================
// Menu Module
// ============================================================================
import Module from 'utilities/module' ;
2018-04-01 18:24:08 -04:00
import { createElement } from 'utilities/dom' ;
2017-11-13 01:23:39 -05:00
2017-11-14 18:48:05 -05:00
import THEME _CSS _URL from 'site/styles/theme.scss' ;
2017-11-13 01:23:39 -05:00
export default class ThemeEngine extends Module {
constructor ( ... args ) {
super ( ... args ) ;
this . inject ( 'site' ) ;
this . inject ( 'settings' ) ;
this . should _enable = true ;
2017-11-14 18:48:05 -05:00
this . settings . add ( 'theme.dark' , {
requires : [ 'context.ui.theme' ] ,
2017-11-13 01:23:39 -05:00
default : false ,
2017-11-14 18:48:05 -05:00
process ( ctx , val ) {
return ctx . get ( 'context.ui.theme' ) === 1 ? val : false
} ,
2017-11-13 01:23:39 -05:00
ui : {
2017-11-14 18:48:05 -05:00
path : 'Appearance @{"description": "Personalize the appearance of Twitch. Change the color scheme and fonts and tune the layout to optimize your experience."} > Theme >> General' ,
title : 'Gray (no Purple)' ,
description : '<em>Requires Dark Theme to be Enabled.</em><br>I see my website and I want it painted black...<br>This is a very early feature and will change as there is time.' ,
2017-11-13 01:23:39 -05:00
component : 'setting-check-box'
2017-11-14 18:48:05 -05:00
} ,
changed : val => this . updateSetting ( val )
} ) ;
2017-11-13 01:23:39 -05:00
this . settings . add ( 'theme.is-dark' , {
requires : [ 'context.ui.theme' ] ,
process ( ctx ) {
return ctx . get ( 'context.ui.theme' ) === 1 ;
2018-03-24 04:19:41 -04:00
} ,
changed : val => document . body . classList . toggle ( 'tw-theme--dark' , val )
2017-11-13 01:23:39 -05:00
} ) ;
2017-11-28 02:03:59 -05:00
this . settings . add ( 'theme.tooltips-dark' , {
requires : [ 'theme.is-dark' ] ,
process ( ctx ) {
return ! ctx . get ( 'theme.is-dark' )
}
} ) ;
2017-11-13 01:23:39 -05:00
this . _style = null ;
}
2017-11-14 18:48:05 -05:00
toggleStyle ( enable ) {
if ( ! this . _style ) {
if ( ! enable )
return ;
2018-04-01 18:24:08 -04:00
this . _style = createElement ( 'link' , {
2017-11-14 18:48:05 -05:00
rel : 'stylesheet' ,
type : 'text/css' ,
href : THEME _CSS _URL
} ) ;
} else if ( ! enable ) {
2017-12-01 15:36:18 -05:00
this . _style . remove ( ) ;
2017-11-14 18:48:05 -05:00
return ;
}
2017-11-13 01:23:39 -05:00
document . head . appendChild ( this . _style ) ;
}
2017-11-14 18:48:05 -05:00
updateSetting ( enable ) {
this . toggleStyle ( enable ) ;
2017-12-13 17:35:20 -05:00
document . body . classList . toggle ( 'tw-theme--ffz' , enable ) ;
2017-11-13 01:23:39 -05:00
}
2017-11-14 18:48:05 -05:00
onEnable ( ) {
this . updateSetting ( this . settings . get ( 'theme.dark' ) ) ;
2018-03-24 04:19:41 -04:00
document . body . classList . toggle ( 'tw-theme--dark' , this . settings . get ( 'theme.is-dark' ) ) ;
2017-11-13 01:23:39 -05:00
}
}