From b4ce9fbff5833bf40e9b8d57827615cbf526784e Mon Sep 17 00:00:00 2001 From: Brenden Tuck Date: Mon, 12 Oct 2020 00:06:44 -0400 Subject: [PATCH] Codacy updates --- .../static/webclient/js/plugins/default_in.js | 1 - .../static/webclient/js/plugins/font.js | 99 +++++++----- .../webclient/js/plugins/goldenlayout.js | 146 +++++++++--------- .../static/webclient/js/plugins/hotbuttons.js | 2 +- 4 files changed, 133 insertions(+), 115 deletions(-) diff --git a/evennia/web/webclient/static/webclient/js/plugins/default_in.js b/evennia/web/webclient/static/webclient/js/plugins/default_in.js index d5996685cb..51b200f707 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/default_in.js +++ b/evennia/web/webclient/static/webclient/js/plugins/default_in.js @@ -73,7 +73,6 @@ let defaultInPlugin = (function () { // // allow other UI elements to toggle this focus behavior on/off var setKeydownFocus = function (bool) { - console.log("Focus = " + bool); focusOnKeydown = bool; } diff --git a/evennia/web/webclient/static/webclient/js/plugins/font.js b/evennia/web/webclient/static/webclient/js/plugins/font.js index 9b691f6f66..82008b4930 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/font.js +++ b/evennia/web/webclient/static/webclient/js/plugins/font.js @@ -18,51 +18,84 @@ let font_plugin = (function () { }; // + // + var setStartingFont = function () { + var fontfamily = localStorage.getItem("evenniaFontFamily"); + if( !fontfamily ) { + $(document.body).css("font-family", fontfamily); + } + + var fontsize = localStorage.getItem("evenniaFontSize"); + if( !fontsize ) { + $(document.body).css("font-size", fontsize+"em"); + } + } + + // + // + var getActiveFontFamily = function () { + var family = "DejaVu Sans Mono"; + var fontfamily = localStorage.getItem("evenniaFontFamily"); + if( fontfamily != null ) { + family = fontfamily; + } + return family; + } + + // + // + var getActiveFontSize = function () { + var size = "0.9"; + var fontsize = localStorage.getItem("evenniaFontSize"); + if( fontsize != null ) { + size = fontsize; + } + return size; + } + + // + // + var onFontFamily = function (evnt) { + var family = $(evnt.target).val(); + $(document.body).css('font-family', family); + localStorage.setItem('evenniaFontFamily', family); + } + + // + // + var onFontSize = function (evnt) { + var size = $(evnt.target).val(); + $(document.body).css("font-size", size+"em"); + localStorage.setItem("evenniaFontSize", size); + } + // // var onOptionsUI = function (parentdiv) { - var fontfamily = localStorage.getItem('evenniaFontFamily'); - var fontsize = localStorage.getItem('evenniaFontSize'); - var fontselect = $(''); + var fontselect = $(""); var fonts = Object.keys(font_urls); for (var x = 0; x < fonts.length; x++) { - var option = $(''); + var option = $(""); fontselect.append(option); } for (var x = 4; x < 21; x++) { var val = (x/10.0); - var option = $(''); + var option = $(""); sizeselect.append(option); } - if( fontfamily != null ) { - fontselect.val( fontfamily ); - } else { - fontselect.val('DejaVu Sans Mono'); // default value - } - - if( fontsize != null ) { - sizeselect.val( fontsize ); - } else { - sizeselect.val('0.9'); // default scaling factor - } + fontselect.val( getActiveFontFamily() ); + sizeselect.val( getActiveFontSize() ); // font change callbacks - fontselect.on('change', function () { - $(document.body).css('font-family', $(this).val()); - localStorage.setItem('evenniaFontFamily', $(this).val() ); - }); - - sizeselect.on('change', function () { - $(document.body).css('font-size', $(this).val()+"em"); - localStorage.setItem('evenniaFontSize', $(this).val() ); - }); + fontselect.on("change", onFontFamily); + sizeselect.on("change", onFontSize); // add the font selection dialog control to our parentdiv - parentdiv.append('
Font Selection:
'); + parentdiv.append("
Font Selection:
"); parentdiv.append(fontselect); parentdiv.append(sizeselect); } @@ -71,26 +104,18 @@ let font_plugin = (function () { // Font plugin init function (adds the urls for the webfonts to the page) // var init = function () { - var fontfamily = localStorage.getItem('evenniaFontFamily'); - var fontsize = localStorage.getItem('evenniaFontSize'); var head = $(document.head); var fonts = Object.keys(font_urls); for (var x = 0; x < fonts.length; x++) { if ( fonts[x] != "Monospace" ) { var url = font_urls[ fonts[x] ]; - var link = $(''); + var link = $(""); head.append( link ); } } - if( !fontfamily ) { - $(document.body).css('font-family', fontfamily); - } - - if( !fontsize ) { - $(document.body).css('font-size', fontsize+"em"); - } + setStartingFont(); } return { diff --git a/evennia/web/webclient/static/webclient/js/plugins/goldenlayout.js b/evennia/web/webclient/static/webclient/js/plugins/goldenlayout.js index 29dd136b77..d0037f27d5 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/goldenlayout.js +++ b/evennia/web/webclient/static/webclient/js/plugins/goldenlayout.js @@ -267,56 +267,14 @@ let goldenlayout = (function () { } } - - // - // - var resetUI = function (newLayout) { - var mainsub = document.getElementById("main-sub"); - - // rebuild the original HTML stacking - var messageDiv = $("#messagewindow").detach(); - messageDiv.prependTo( mainsub ); - - // out with the old - myLayout.destroy(); - - // in with the new - myLayout = new GoldenLayout( newLayout, mainsub ); - - // re-register our main, input and generic evennia components. - registerComponents( myLayout ); - - // call all other plugins to give them a chance to registerComponents. - for( let plugin in window.plugins ) { - if( "onLayoutChanged" in window.plugins[plugin] ) { - window.plugins[plugin].onLayoutChanged(); - } - } - - // finish the setup and actually start GoldenLayout - myLayout.init(); - - // work out which types are untagged based on our pre-configured layout - calculateUntaggedTypes(); - - // Set the Event handler for when the client window changes size - $(window).bind("resize", scrollAll); - - // Set Save State callback - myLayout.on( "stateChanged", onStateChanged ); - } - - // // var onSwitchLayout = function (evnt) { // get the new layout name from the select box - var name = $('#layoutInput').val(); + var name = $("#layoutInput").val(); // check to see if the layout is in the list of known layouts if( name in evenniaGoldenLayouts ) { - console.log( evenniaGoldenLayouts ); - var newLayout = evenniaGoldenLayouts[name]; activeLayoutName = name; @@ -330,28 +288,27 @@ let goldenlayout = (function () { // var onSaveLayout = function (evnt) { // get the name from the select box - var name = $('#layoutName').val(); - var input = $('#layoutInput'); + var name = $("#layoutName").val(); + var input = $("#layoutInput"); if( name === "" ) { return; } // Can't save without a valid name // Is this name new or pre-existing? if( !(name in evenniaGoldenLayouts) ) { // add the new evenniaGoldenLayout to the listed dropdown options - var option = $(''); + var option = $(""); input.append(option); } // store the current layout to the local list of layouts - evenniaGoldenLayouts[ name ] = myLayout.toConfig(); + Object.assign( evenniaGoldenLayouts, { [name] : myLayout.toConfig() }); activeLayoutName = name; // upload it to the server - if( Evennia.isConnected() && myLayout.isInitialised ) { + if( window.Evennia.isConnected() && myLayout.isInitialised ) { window.options["webclientActiveLayout"] = name; window.options["webclientLayouts"] = JSON.stringify( evenniaGoldenLayouts ); - console.log("Saving layout to server..."); - Evennia.msg("webclient_options", [], window.options); + window.Evennia.msg("webclient_options", [], window.options); } } @@ -426,22 +383,6 @@ let goldenlayout = (function () { tab.header.parent.on( "activeContentItemChanged", onActiveTabChange ); } - // - // - var scrollAll = function () { - let components = myLayout.root.getItemsByType("component"); - components.forEach( function (component) { - if( component.hasId("inputComponent") ) { return; } // ignore input components - - let textDiv = component.container.getElement().children(".content"); - let scrollHeight = textDiv.prop("scrollHeight"); - let clientHeight = textDiv.prop("clientHeight"); - textDiv.scrollTop( scrollHeight - clientHeight ); - }); - myLayout.updateSize(); - } - - // // var initComponent = function (div, container, state, defaultTypes, updateMethod) { @@ -504,6 +445,61 @@ let goldenlayout = (function () { } + // + // + var scrollAll = function () { + let components = myLayout.root.getItemsByType("component"); + components.forEach( function (component) { + if( component.hasId("inputComponent") ) { return; } // ignore input components + + let textDiv = component.container.getElement().children(".content"); + let scrollHeight = textDiv.prop("scrollHeight"); + let clientHeight = textDiv.prop("clientHeight"); + textDiv.scrollTop( scrollHeight - clientHeight ); + }); + myLayout.updateSize(); + } + + + // + // + var resetUI = function (newLayout) { + var mainsub = document.getElementById("main-sub"); + + // rebuild the original HTML stacking + var messageDiv = $("#messagewindow").detach(); + messageDiv.prependTo( mainsub ); + + // out with the old + myLayout.destroy(); + + // in with the new + myLayout = new window.GoldenLayout( newLayout, mainsub ); + + // re-register our main, input and generic evennia components. + registerComponents( myLayout ); + + // call all other plugins to give them a chance to registerComponents. + for( let plugin in window.plugins ) { + if( "onLayoutChanged" in window.plugins[plugin] ) { + window.plugins[plugin].onLayoutChanged(); + } + } + + // finish the setup and actually start GoldenLayout + myLayout.init(); + + // work out which types are untagged based on our pre-configured layout + calculateUntaggedTypes(); + + // Set the Event handler for when the client window changes size + $(window).bind("resize", scrollAll); + + // Set Save State callback + myLayout.on( "stateChanged", onStateChanged ); + } + + // // Public // @@ -600,8 +596,6 @@ let goldenlayout = (function () { var onGotOptions = function (args, kwargs) { // Reset the UI if the JSON layout sent from the server doesn't match the client's current JSON if( "webclientLayouts" in kwargs ) { - console.log("Got evennia GoldenLayouts"); - evenniaGoldenLayouts = JSON.parse( kwargs["webclientLayouts"] ); } } @@ -610,13 +604,13 @@ let goldenlayout = (function () { // // var onOptionsUI = function (parentdiv) { - var layoutInput = $(''); - var saveButton = $(''); + var layoutInput = $(""); + var saveButton = $(""); var layouts = Object.keys( evenniaGoldenLayouts ); for (var x = 0; x < layouts.length; x++) { - var option = $(''); + var option = $(""); layoutInput.append(option); } @@ -628,7 +622,7 @@ let goldenlayout = (function () { saveButton.on('click', onSaveLayout); // add the selection dialog control to our parentdiv - parentdiv.append('
UI Layout Selection (This list may be longer after login):
'); + parentdiv.append("
UI Layout Selection (This list may be longer after login):
"); parentdiv.append(layoutInput); parentdiv.append(layoutName); parentdiv.append(saveButton); @@ -679,7 +673,7 @@ let goldenlayout = (function () { var mainsub = document.getElementById("main-sub"); // pre-load the evenniaGoldenLayouts with the hard-coded default - evenniaGoldenLayouts[ "default" ] = window.goldenlayout_config; + Object.assign( evenniaGoldenLayouts, { "default" : window.goldenlayout_config } ); if( activeName !== null ) { activeLayoutName = activeName; @@ -689,10 +683,10 @@ let goldenlayout = (function () { // Overwrite the global-variable configuration from // webclient/js/plugins/goldenlayout_default_config.js // with the version from localstorage - evenniaGoldenLayouts[ activeLayoutName ] = JSON.parse( savedState ); + Object.assign( evenniaGoldenLayouts, { activeLayoutName : JSON.parse(savedState) } ); } - myLayout = new GoldenLayout( evenniaGoldenLayouts[activeLayoutName], mainsub ); + myLayout = new window.GoldenLayout( evenniaGoldenLayouts[activeLayoutName], mainsub ); $("#prompt").remove(); // remove the HTML-defined prompt div $("#inputcontrol").remove(); // remove the cluttered, HTML-defined input divs diff --git a/evennia/web/webclient/static/webclient/js/plugins/hotbuttons.js b/evennia/web/webclient/static/webclient/js/plugins/hotbuttons.js index 6b7af9b2af..c486663aea 100644 --- a/evennia/web/webclient/static/webclient/js/plugins/hotbuttons.js +++ b/evennia/web/webclient/static/webclient/js/plugins/hotbuttons.js @@ -144,7 +144,7 @@ let hotbuttons = (function () { } return { - init: function() {}, + init: function() {}, postInit: postInit, onGotOptions: onGotOptions, onLayoutChanged: onLayoutChanged,