diff --git a/src/static/js/chat.js b/src/static/js/chat.js index a00ac9d92..ca488fe5f 100755 --- a/src/static/js/chat.js +++ b/src/static/js/chat.js @@ -47,6 +47,9 @@ var chat = (function() }, stickToScreen: function(fromInitialCall) // Make chat stick to right hand side of screen { + if(pad.settings.hideChat){ + return; + } chat.show(); isStuck = (!isStuck || fromInitialCall); $('#chatbox').hide(); diff --git a/src/static/js/pad.js b/src/static/js/pad.js index aeeca15c6..b5e772d15 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: "true", callback: function(val) { $('#editbar').css('display', 'flex') } }, - { name: "showChat", checkVal: "true", callback: function(val) { $('#chaticon').show(); } }, + { 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); } } ]; @@ -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) { @@ -286,6 +286,8 @@ function handshake() $('#chaticon').hide(); $('#options-chatandusers').parent().hide(); $('#options-stickychat').parent().hide(); + }else{ + if(!settings.hideChat) $('#chaticon').show(); } $("body").addClass(clientVars.readonly ? "readonly" : "readwrite") diff --git a/tests/frontend/helper.js b/tests/frontend/helper.js index b9327f289..21cdacd9d 100644 --- a/tests/frontend/helper.js +++ b/tests/frontend/helper.js @@ -99,6 +99,11 @@ var helper = {}; 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.clearSessionCookies(); @@ -106,7 +111,7 @@ var helper = {}; 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 8eaf08a95..84b9344ef 100644 --- a/tests/frontend/specs/chat.js +++ b/tests/frontend/specs/chat.js @@ -131,4 +131,41 @@ describe("Chat messages and UI", function(){ }, 10) }, 10) }); + + 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); + + }); + }); diff --git a/tests/frontend/specs/helper.js b/tests/frontend/specs/helper.js index 051e9a17d..1cb712a00 100644 --- a/tests/frontend/specs/helper.js +++ b/tests/frontend/specs/helper.js @@ -36,7 +36,6 @@ describe("the test helper", function(){ done(); }); }); - // Make sure the cookies are cleared, and make sure that the cookie // clearing has taken effect at this point in the code. It has been // observed that the former can happen without the latter if there @@ -105,7 +104,7 @@ describe("the test helper", function(){ // confirm that the session was actually cleared var $usernameInput = chrome$("#myusernameedit"); - expect($usernameInput.val()).to.be('Enter your name'); + expect($usernameInput.val()).to.be(''); done(); });