From e0cfa58388a378c5e893135464d53e016ac34c59 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 15 Mar 2020 12:32:35 +0000 Subject: [PATCH 1/3] allow chat to be hidden with URI --- src/static/js/pad.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 69fa659026c..1e16e3af2e2 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -74,7 +74,7 @@ function randomString() var getParameters = [ { name: "noColors", checkVal: "true", callback: function(val) { settings.noColors = true; $('#clearAuthorship').hide(); } }, { name: "showControls", checkVal: "false", callback: function(val) { $('#editbar').addClass('hideControlsEditbar'); $('#editorcontainer').addClass('hideControlsEditor'); } }, - { name: "showChat", checkVal: "true", callback: function(val) { $('#chaticon').show(); } }, + { name: "showChat", checkVal: null, callback: function(val) { if(val === "true"){$('#chaticon').show();} if(val==="false"){chat.hide();$('#chaticon').hide()} } }, { name: "showLineNumbers", checkVal: "false", callback: function(val) { settings.LineNumbersDisabled = true; } }, { name: "useMonospaceFont", checkVal: "true", callback: function(val) { settings.useMonospaceFontGlobal = true; } }, // If the username is set as a parameter we should set a global value that we can call once we have initiated the pad. @@ -92,7 +92,7 @@ function getParams() // Tries server enforced options first.. for(var i = 0; i < getParameters.length; i++) { - var setting = getParameters[i]; + var setting = getParameters[i]; var value = clientVars.padOptions[setting.name]; if(value.toString() === setting.checkVal) { @@ -102,12 +102,10 @@ function getParams() // Then URL applied stuff var params = getUrlVars() - for(var i = 0; i < getParameters.length; i++) { var setting = getParameters[i]; var value = params[setting.name]; - if(value && (value == setting.checkVal || setting.checkVal == null)) { setting.callback(value); From 0bdf330ca07c24ba534f9deaff65a0fa1dbb0784 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 25 Mar 2020 13:17:39 +0000 Subject: [PATCH 2/3] working solution, needs test coverage --- src/static/css/pad.css | 1 - src/static/js/chat.js | 3 +++ src/static/js/pad.js | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/static/css/pad.css b/src/static/css/pad.css index 10dd69eaaec..b4c72609096 100644 --- a/src/static/css/pad.css +++ b/src/static/css/pad.css @@ -643,7 +643,6 @@ table#otheruserstable { border-top-right-radius: 5px; background-color: #fff; cursor: pointer; - display: none; } #chaticon a { text-decoration: none diff --git a/src/static/js/chat.js b/src/static/js/chat.js index f9bb47c1b2c..57dafc102fd 100644 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -45,6 +45,9 @@ var chat = (function() }, stickToScreen: function(fromInitialCall) // Make chat stick to right hand side of screen { + if(pad.settings.hideChat){ + return; + } chat.show(); if(!isStuck || fromInitialCall) { // Stick it to padcookie.setPref("chatAlwaysVisible", true); diff --git a/src/static/js/pad.js b/src/static/js/pad.js index 1e16e3af2e2..484fc66f185 100644 --- a/src/static/js/pad.js +++ b/src/static/js/pad.js @@ -74,7 +74,7 @@ function randomString() var getParameters = [ { name: "noColors", checkVal: "true", callback: function(val) { settings.noColors = true; $('#clearAuthorship').hide(); } }, { name: "showControls", checkVal: "false", callback: function(val) { $('#editbar').addClass('hideControlsEditbar'); $('#editorcontainer').addClass('hideControlsEditor'); } }, - { name: "showChat", checkVal: null, callback: function(val) { if(val === "true"){$('#chaticon').show();} if(val==="false"){chat.hide();$('#chaticon').hide()} } }, + { name: "showChat", checkVal: null, callback: function(val) { if(val==="false"){settings.hideChat = true;chat.hide();$('#chaticon').hide()} } }, { name: "showLineNumbers", checkVal: "false", callback: function(val) { settings.LineNumbersDisabled = true; } }, { name: "useMonospaceFont", checkVal: "true", callback: function(val) { settings.useMonospaceFontGlobal = true; } }, // If the username is set as a parameter we should set a global value that we can call once we have initiated the pad. @@ -82,7 +82,7 @@ var getParameters = [ // If the userColor is set as a parameter, set a global value to use once we have initiated the pad. { name: "userColor", checkVal: null, callback: function(val) { settings.globalUserColor = decodeURIComponent(val); clientVars.userColor = decodeURIComponent(val); } }, { name: "rtl", checkVal: "true", callback: function(val) { settings.rtlIsTrue = true } }, - { name: "alwaysShowChat", checkVal: "true", callback: function(val) { chat.stickToScreen(); } }, + { name: "alwaysShowChat", checkVal: "true", callback: function(val) { if(!settings.hideChat) chat.stickToScreen(); } }, { name: "chatAndUsers", checkVal: "true", callback: function(val) { chat.chatAndUsers(); } }, { name: "lang", checkVal: null, callback: function(val) { window.html10n.localize([val, 'en']); createCookie('language', val); } } ]; From aa5042b7c5f537b4376e673f36889131259c411c Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 25 Mar 2020 13:49:33 +0000 Subject: [PATCH 3/3] working testing coverage for showChat --- tests/frontend/helper.js | 9 +++++++-- tests/frontend/specs/chat.js | 37 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index 800dfb29315..696f4e693ef 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -75,20 +75,25 @@ var helper = {}; helper.newPad = function(cb, padName){ //build opts object var opts = {clearCookies: true} + if(typeof cb === 'function'){ opts.cb = cb } else { opts = _.defaults(cb, opts); } + // if opts.params is set we manipulate the URL to include URL parameters IE ?foo=Bah. + if(opts.params){ + var encodedParams = "?" + $.param(opts.params); + } + //clear cookies if(opts.clearCookies){ helper.clearCookies(); } - if(!padName) padName = "FRONTEND_TEST_" + helper.randomString(20); - $iframe = $(""); + $iframe = $(""); //clean up inner iframe references helper.padChrome$ = helper.padOuter$ = helper.padInner$ = null; diff --git a/tests/frontend/specs/chat.js b/tests/frontend/specs/chat.js index e48dad8b02f..869d616c677 100644 --- a/tests/frontend/specs/chat.js +++ b/tests/frontend/specs/chat.js @@ -127,4 +127,41 @@ describe("Chat messages and UI", function(){ done(); }); + + it("Checks showChat=false URL Parameter hides chat then when removed it shows chat", function(done) { + this.timeout(60000); + var inner$ = helper.padInner$; + var chrome$ = helper.padChrome$; + + setTimeout(function(){ //give it a second to save the username on the server side + helper.newPad({ // get a new pad, but don't clear the cookies + clearCookies: false, + params:{ + showChat: "false" + }, cb: function(){ + var chrome$ = helper.padChrome$; + var chaticon = chrome$("#chaticon"); + // chat should be hidden. + expect(chaticon.is(":visible")).to.be(false); + + + setTimeout(function(){ //give it a second to save the username on the server side + helper.newPad({ // get a new pad, but don't clear the cookies + clearCookies: false + , cb: function(){ + var chrome$ = helper.padChrome$; + var chaticon = chrome$("#chaticon"); + // chat should be visible. + expect(chaticon.is(":visible")).to.be(true); + done(); + } + }); + }, 1000); + + } + }); + }, 1000); + + }); + });