mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	gear_menu: Allow user to configure preferred theme.
We save the preferred theme in localstorage so that user doesn't have to re-select the theme on every reload. Users on slow computers might see flash of a theme change, if it happens.
This commit is contained in:
		
							
								
								
									
										26
									
								
								static/js/dark_theme.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								static/js/dark_theme.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
import $ from "jquery";
 | 
			
		||||
 | 
			
		||||
import {localstorage} from "./localstorage";
 | 
			
		||||
import {page_params} from "./page_params";
 | 
			
		||||
 | 
			
		||||
export function enable() {
 | 
			
		||||
    $("body").removeClass("color-scheme-automatic").addClass("dark-theme");
 | 
			
		||||
 | 
			
		||||
    if (page_params.is_spectator) {
 | 
			
		||||
        const ls = localstorage();
 | 
			
		||||
        ls.set("spectator-theme-preference", "dark");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function disable() {
 | 
			
		||||
    $("body").removeClass("color-scheme-automatic").removeClass("dark-theme");
 | 
			
		||||
 | 
			
		||||
    if (page_params.is_spectator) {
 | 
			
		||||
        const ls = localstorage();
 | 
			
		||||
        ls.set("spectator-theme-preference", "light");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export function default_preference_checker() {
 | 
			
		||||
    $("body").removeClass("dark-theme").addClass("color-scheme-automatic");
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user