diff --git a/assets/css/components/incognito/ui.css b/assets/css/components/incognito/ui.css new file mode 100644 index 00000000..a75caa56 --- /dev/null +++ b/assets/css/components/incognito/ui.css @@ -0,0 +1,23 @@ +/** + * Incognito mode stylesheet + * + * @author Pierre HUBERT + */ + +#incognito-block { + position: fixed; + left: 10px; + bottom: 54px; + text-align: center; + background-color: #001F3F; + padding: 10px; + color: white; +} + +#incognito-block i { + font-size: 200%; +} + +#incognito-block span { + display: block; +} \ No newline at end of file diff --git a/assets/js/common/api.js b/assets/js/common/api.js index 27200798..da18fc91 100644 --- a/assets/js/common/api.js +++ b/assets/js/common/api.js @@ -33,6 +33,10 @@ ComunicWeb.common.api = { } + //Enable incognito mode if required + if(ComunicWeb.components.incognito.management.isEnabled()) + params.incognito = true; + //Prepare data to send in request var count = 0; var datas = ""; @@ -90,7 +94,11 @@ ComunicWeb.common.api = { data.append('userToken2', tokens.token2); } - } + } + + //Enable incognito mode if required + if(ComunicWeb.components.incognito.management.isEnabled()) + data.append("incognito", true); //Create request var apiXHR = new XMLHttpRequest(); diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 750de49a..b6562427 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -1107,7 +1107,35 @@ var ComunicWeb = { */ darkTheme: { //TODO : implement - } + }, + + /** + * Incognito mode component + */ + incognito: { + + /** + * Keyboard catcher + */ + keyboard: { + //TODO : implement + }, + + /** + * Incognito management + */ + management: { + //TODO : implement + }, + + /** + * UI management + */ + ui: { + //TODO : implement + }, + + }, }, /** diff --git a/assets/js/common/page.js b/assets/js/common/page.js index 012eacf6..e6de2715 100644 --- a/assets/js/common/page.js +++ b/assets/js/common/page.js @@ -277,6 +277,11 @@ ComunicWeb.common.page = { //Call the method related to the page eval(pageInfos.methodHandler + ("(additionnalData, pageTarget);")); + + //Propagate information + SendEvent("openPage", { + page: pageURI + }); //Success return true; diff --git a/assets/js/common/system.js b/assets/js/common/system.js index 0bb43b47..6f6c5a59 100644 --- a/assets/js/common/system.js +++ b/assets/js/common/system.js @@ -48,6 +48,16 @@ ComunicWeb.common.system = { */ ComunicWeb.common.langs.initLanguages(); + /** + * Initialize incognito mode detection + */ + ComunicWeb.components.incognito.management.init(); + + /** + * Refresh dark theme mode + */ + ComunicWeb.components.darkTheme.refresh(); + /** * What to do after login refresh */ @@ -81,11 +91,6 @@ ComunicWeb.common.system = { }), 25000); ComunicWeb.common.cacheManager.registerInterval(autoRefresh); - /** - * Refresh dark theme mode - */ - ComunicWeb.components.darkTheme.refresh(); - //Success return true; }, diff --git a/assets/js/common/utils.js b/assets/js/common/utils.js index 0b1838d5..260d4915 100644 --- a/assets/js/common/utils.js +++ b/assets/js/common/utils.js @@ -682,4 +682,22 @@ function ApplySceditorStyle(textarea){ //Apply new styles to body iframeDOM.body.className += " sceditor-iframe-body"; +} + +/** + * Send a new javascript event + * + * @param {String} name The name of the event to create + * @param {Object} details Information about the event to create + */ +function SendEvent(name, details){ + + var event = new CustomEvent(name, { + detail: details, + bubbles: true, + cancelable: false + }); + + document.dispatchEvent(event); + } \ No newline at end of file diff --git a/assets/js/components/incognito/keyboard.js b/assets/js/components/incognito/keyboard.js new file mode 100644 index 00000000..bec22fa9 --- /dev/null +++ b/assets/js/components/incognito/keyboard.js @@ -0,0 +1,31 @@ +/** + * Incognito mode keyboard catcher + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.incognito.keyboard = { + + /** + * Initialize incognito mode requests detection + */ + init: function(){ + + //We need to catch keyboard press to check if F6 key is pressed + window.addEventListener("keydown", function(e){ + + //Filter key + if(e.keyCode != 117) + return; + + //If incognito mode is enabled, disable it + if(ComunicWeb.components.incognito.management.isEnabled()) + ComunicWeb.components.incognito.management.setEnabled(false); + + //Else we ask user confirmation + else + ComunicWeb.components.incognito.ui.confirmEnable(); + + }); + } +} \ No newline at end of file diff --git a/assets/js/components/incognito/management.js b/assets/js/components/incognito/management.js new file mode 100644 index 00000000..7efa8cbe --- /dev/null +++ b/assets/js/components/incognito/management.js @@ -0,0 +1,59 @@ +/** + * Incognito mode management + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.incognito.management = { + + /** + * This variable is use to check if incognito mode + * has already be initialized or not + */ + _is_init: false, + + /** + * Specify whether incognito mode should be enabled or not + */ + _local_storage_name: "incognito_mode", + + /** + * Initialize incognito component + */ + init: function(){ + + //This code should be run only once + if(this._is_init) + return; + this._is_init = true; + + log("Initialize incognito mode"); + + //Initialize components + ComunicWeb.components.incognito.keyboard.init(); + ComunicWeb.components.incognito.ui.init(); + }, + + /** + * Check out whether incognito mode is enabled or not + * + * @return {Boolean} TRUE if incognito mode is enabled / FALSE else + */ + isEnabled: function(){ + return localStorage.getItem(this._local_storage_name) === "true"; + }, + + /** + * Update status of incognito mode + * + * @param {Boolean} enable TRUE to enable incognito mode / FALSE else + */ + setEnabled: function(enable){ + localStorage.setItem(this._local_storage_name, enable ? "true" : "false"); + + //Propagate information + SendEvent("incognitoStatusChanged", { + enabled: enable + }); + } +} \ No newline at end of file diff --git a/assets/js/components/incognito/ui.js b/assets/js/components/incognito/ui.js new file mode 100644 index 00000000..2aab383c --- /dev/null +++ b/assets/js/components/incognito/ui.js @@ -0,0 +1,97 @@ +/** + * Incognito mode management + * + * @author Pierre HUBERT + */ + +ComunicWeb.components.incognito.ui = { + + /** + * Initialize UI component + */ + init: function(){ + + //Initialize incognito mode updates detection + document.addEventListener("incognitoStatusChanged", function(e){ + ComunicWeb.components.incognito.ui.statusChanged(); + }) + + document.addEventListener("openPage", function(){ + ComunicWeb.components.incognito.ui.statusChanged(); + }); + }, + + /** + * Show confirmation dialog to enable incognito mode + */ + confirmEnable: function(){ + + //Ask user confirmation + ComunicWeb.common.messages.confirm( + "Are you sure do you want to enable incognito mode? When this mode is enabled, you can use Comunic while appearing as disconnected for your friends...", + function(confirm){ + + if(!confirm) + return; + + //Enable incognito mode + ComunicWeb.components.incognito.management.setEnabled(true); + + }); + + }, + + /** + * Function called each time incognito status is updated + */ + statusChanged: function(){ + + var enabled = ComunicWeb.components.incognito.management.isEnabled(); + var incognitoBlock = byId("incognito-block"); + + //Check if incognito mode is disabled + if(!enabled){ + + if(incognitoBlock != null) + //Remove incognito block + incognitoBlock.remove(); + + return; + } + + //Nothing has to done if incognito block is already visible + if(incognitoBlock) + return; + + //Create incognito block + incognitoBlock = createElem2({ + type: "div", + appendTo: document.body, + id: "incognito-block", + }); + + createElem2({ + type: "i", + appendTo: incognitoBlock, + class: "fa fa-user-secret", + }); + + createElem2({ + type: "span", + appendTo: incognitoBlock, + innerHTML: "Incognito mode" + }); + + var disableLink = createElem2({ + type: "span", + appendTo: incognitoBlock, + class: "a", + innerHTML: "Disable" + }); + + disableLink.addEventListener("click", function(){ + ComunicWeb.components.incognito.management.setEnabled(false); + }) + } + +} \ No newline at end of file diff --git a/system/config/dev.config.php b/system/config/dev.config.php index b2194be2..d2b804d1 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -215,6 +215,9 @@ class Dev { "css/components/notifications/dropdown.css", "css/components/notifications/ui.css", + //Incognito mode component + "css/components/incognito/ui.css", + //Pages stylesheets //User Page "css/pages/userPage/main.css", @@ -425,6 +428,11 @@ class Dev { //Dark theme component "js/components/darkTheme.js", + //Incognito mode component + "js/components/incognito/ui.js", + "js/components/incognito/management.js", + "js/components/incognito/keyboard.js", + //User scripts "js/user/loginTokens.js", "js/user/userLogin.js",