mirror of
				https://github.com/pierre42100/ComunicWeb
				synced 2025-11-04 12:14:12 +00:00 
			
		
		
		
	Basic integration of dark theme.
This commit is contained in:
		@@ -1094,6 +1094,13 @@ var ComunicWeb = {
 | 
			
		||||
			},
 | 
			
		||||
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
		/**
 | 
			
		||||
		 * Dark Theme component
 | 
			
		||||
		 */
 | 
			
		||||
		darkTheme: {
 | 
			
		||||
			//TODO : implement
 | 
			
		||||
		}
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										58
									
								
								assets/js/components/darkTheme.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								assets/js/components/darkTheme.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Dark theme component
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
ComunicWeb.components.darkTheme = {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * This variable contains the dark theme status
 | 
			
		||||
	 */
 | 
			
		||||
	_enabled: false,
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * CSS element that contains dark theme CSS rules
 | 
			
		||||
	 */
 | 
			
		||||
	_cssElem: null,
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check out whether dark theme is enabled or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @return {boolean} TRUE if enabled / FALSE else
 | 
			
		||||
	 */
 | 
			
		||||
	isEnabled: function(){
 | 
			
		||||
		return this._enabled;
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Specify whether dark theme should be enabled or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {boolean} enable TRUE to enable / FALSE else
 | 
			
		||||
	 */
 | 
			
		||||
	setEnabled: function(enable){
 | 
			
		||||
		this._enabled = enable;
 | 
			
		||||
 | 
			
		||||
		//Check if the theme has to be disabled
 | 
			
		||||
		if(!this._enabled){
 | 
			
		||||
			if(this._cssElem != null)
 | 
			
		||||
				this._cssElem.disabled = true;
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		//Check if CSS element is already loaded
 | 
			
		||||
		else if(this._cssElem != null)
 | 
			
		||||
			this._cssElem.disabled = false;
 | 
			
		||||
		
 | 
			
		||||
		//We need to load dark theme
 | 
			
		||||
		else {
 | 
			
		||||
 | 
			
		||||
			this._cssElem = createElem2({
 | 
			
		||||
				type: "link",
 | 
			
		||||
				href: ComunicWeb.__config.assetsURL + "css/dark_theme.css"
 | 
			
		||||
			});
 | 
			
		||||
			this._cssElem.setAttribute("rel", "stylesheet");
 | 
			
		||||
			document.head.appendChild(this._cssElem);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -121,6 +121,9 @@ ComunicWeb.components.menuBar.authenticated = {
 | 
			
		||||
			openPage("settings");
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
		//Add dark theme button
 | 
			
		||||
		this.addDarkThemeButton(dropdownContent);
 | 
			
		||||
 | 
			
		||||
		//Add logout link
 | 
			
		||||
		var logoutButton = createElem("li", dropdownContent);
 | 
			
		||||
		var logoutButtonLink = createElem("a", logoutButton);
 | 
			
		||||
@@ -131,11 +134,54 @@ ComunicWeb.components.menuBar.authenticated = {
 | 
			
		||||
		return dropdownContent;
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Add DarkTheme for the button
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {HTMLElement} target The target for the button
 | 
			
		||||
	 */
 | 
			
		||||
	addDarkThemeButton: function(target){
 | 
			
		||||
 | 
			
		||||
		var darkThemeButton = createElem2({
 | 
			
		||||
			appendTo: target,
 | 
			
		||||
			type: "li"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		var darkThemeLink = createElem2({
 | 
			
		||||
			appendTo: darkThemeButton,
 | 
			
		||||
			type: "a",
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
		var darkThemeIcon = createElem2({
 | 
			
		||||
			appendTo: darkThemeLink,
 | 
			
		||||
			type: "span"
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		createElem2({
 | 
			
		||||
			appendTo: darkThemeLink,
 | 
			
		||||
			type: "span",
 | 
			
		||||
			innerHTML: "Dark Theme"
 | 
			
		||||
		});
 | 
			
		||||
		
 | 
			
		||||
		/**
 | 
			
		||||
		 * Refresh icon states accordingly to
 | 
			
		||||
		 * dark theme status
 | 
			
		||||
		 */
 | 
			
		||||
		var RefreshIcon = function(){
 | 
			
		||||
			darkThemeIcon.className =  "fa " + (ComunicWeb.components.darkTheme.isEnabled() ? "fa-moon-o" : "fa-sun-o");
 | 
			
		||||
		}
 | 
			
		||||
		RefreshIcon();
 | 
			
		||||
 | 
			
		||||
		darkThemeLink.addEventListener("click", function(){
 | 
			
		||||
			ComunicWeb.components.darkTheme.setEnabled(!ComunicWeb.components.darkTheme.isEnabled());
 | 
			
		||||
			RefreshIcon();
 | 
			
		||||
		});
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Add alternate latest posts button 
 | 
			
		||||
	 * (if the screen is too small to display "Comunic")
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param {HTMLElement} target The target for the ubutton
 | 
			
		||||
	 * @param {HTMLElement} target The target for the button
 | 
			
		||||
	 */
 | 
			
		||||
	addAlternateLatestPostsButton: function(target){
 | 
			
		||||
		//Create button
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4
									
								
								builder
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								builder
									
									
									
									
									
								
							@@ -176,6 +176,7 @@ if(file_exists(OUTPUT_DIRECTORY))
 | 
			
		||||
	delDir(OUTPUT_DIRECTORY);
 | 
			
		||||
mkdir(OUTPUT_DIRECTORY, 0777, true);
 | 
			
		||||
mkdir($path_release_assets, 0777, true);
 | 
			
		||||
mkdir($path_release_assets."/css", 0777, true);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -230,6 +231,9 @@ rcopy($path_debug_assets."img/", $path_release_assets."img/");
 | 
			
		||||
rcopy($path_debug_assets."templates/", $path_release_assets."templates/");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
//Copy dark theme
 | 
			
		||||
rcopy($path_debug_assets."css/dark_theme.css", $path_release_assets."css/dark_theme.css");
 | 
			
		||||
 | 
			
		||||
//Create main HTML file
 | 
			
		||||
notice("Generate PHP root file");
 | 
			
		||||
$page_src = '<?php
 | 
			
		||||
 
 | 
			
		||||
@@ -421,6 +421,9 @@ class Dev {
 | 
			
		||||
			//Virtual directory component
 | 
			
		||||
			"js/components/virtualDirectory/interface.js",
 | 
			
		||||
 | 
			
		||||
			//Dark theme component
 | 
			
		||||
			"js/components/darkTheme.js",
 | 
			
		||||
 | 
			
		||||
		//User scripts
 | 
			
		||||
		"js/user/loginTokens.js",
 | 
			
		||||
		"js/user/userLogin.js",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user