Codacy updates
This commit is contained in:
parent
599bf30daa
commit
b4ce9fbff5
4 changed files with 133 additions and 115 deletions
|
|
@ -73,7 +73,6 @@ let defaultInPlugin = (function () {
|
||||||
//
|
//
|
||||||
// allow other UI elements to toggle this focus behavior on/off
|
// allow other UI elements to toggle this focus behavior on/off
|
||||||
var setKeydownFocus = function (bool) {
|
var setKeydownFocus = function (bool) {
|
||||||
console.log("Focus = " + bool);
|
|
||||||
focusOnKeydown = bool;
|
focusOnKeydown = bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 onOptionsUI = function (parentdiv) {
|
||||||
var fontfamily = localStorage.getItem('evenniaFontFamily');
|
var fontselect = $("<select>");
|
||||||
var fontsize = localStorage.getItem('evenniaFontSize');
|
var sizeselect = $("<select>");
|
||||||
var fontselect = $('<select>');
|
|
||||||
var sizeselect = $('<select>');
|
|
||||||
|
|
||||||
var fonts = Object.keys(font_urls);
|
var fonts = Object.keys(font_urls);
|
||||||
for (var x = 0; x < fonts.length; x++) {
|
for (var x = 0; x < fonts.length; x++) {
|
||||||
var option = $('<option value="'+fonts[x]+'">'+fonts[x]+'</option>');
|
var option = $("<option value='"+fonts[x]+"'>"+fonts[x]+"</option>");
|
||||||
fontselect.append(option);
|
fontselect.append(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var x = 4; x < 21; x++) {
|
for (var x = 4; x < 21; x++) {
|
||||||
var val = (x/10.0);
|
var val = (x/10.0);
|
||||||
var option = $('<option value="'+val+'">'+x+'</option>');
|
var option = $("<option value='"+val+"'>"+x+"</option>");
|
||||||
sizeselect.append(option);
|
sizeselect.append(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( fontfamily != null ) {
|
fontselect.val( getActiveFontFamily() );
|
||||||
fontselect.val( fontfamily );
|
sizeselect.val( getActiveFontSize() );
|
||||||
} else {
|
|
||||||
fontselect.val('DejaVu Sans Mono'); // default value
|
|
||||||
}
|
|
||||||
|
|
||||||
if( fontsize != null ) {
|
|
||||||
sizeselect.val( fontsize );
|
|
||||||
} else {
|
|
||||||
sizeselect.val('0.9'); // default scaling factor
|
|
||||||
}
|
|
||||||
|
|
||||||
// font change callbacks
|
// font change callbacks
|
||||||
fontselect.on('change', function () {
|
fontselect.on("change", onFontFamily);
|
||||||
$(document.body).css('font-family', $(this).val());
|
sizeselect.on("change", onFontSize);
|
||||||
localStorage.setItem('evenniaFontFamily', $(this).val() );
|
|
||||||
});
|
|
||||||
|
|
||||||
sizeselect.on('change', function () {
|
|
||||||
$(document.body).css('font-size', $(this).val()+"em");
|
|
||||||
localStorage.setItem('evenniaFontSize', $(this).val() );
|
|
||||||
});
|
|
||||||
|
|
||||||
// add the font selection dialog control to our parentdiv
|
// add the font selection dialog control to our parentdiv
|
||||||
parentdiv.append('<div style="font-weight: bold">Font Selection:</div>');
|
parentdiv.append("<div style='font-weight: bold'>Font Selection:</div>");
|
||||||
parentdiv.append(fontselect);
|
parentdiv.append(fontselect);
|
||||||
parentdiv.append(sizeselect);
|
parentdiv.append(sizeselect);
|
||||||
}
|
}
|
||||||
|
|
@ -71,26 +104,18 @@ let font_plugin = (function () {
|
||||||
// Font plugin init function (adds the urls for the webfonts to the page)
|
// Font plugin init function (adds the urls for the webfonts to the page)
|
||||||
//
|
//
|
||||||
var init = function () {
|
var init = function () {
|
||||||
var fontfamily = localStorage.getItem('evenniaFontFamily');
|
|
||||||
var fontsize = localStorage.getItem('evenniaFontSize');
|
|
||||||
var head = $(document.head);
|
var head = $(document.head);
|
||||||
|
|
||||||
var fonts = Object.keys(font_urls);
|
var fonts = Object.keys(font_urls);
|
||||||
for (var x = 0; x < fonts.length; x++) {
|
for (var x = 0; x < fonts.length; x++) {
|
||||||
if ( fonts[x] != "Monospace" ) {
|
if ( fonts[x] != "Monospace" ) {
|
||||||
var url = font_urls[ fonts[x] ];
|
var url = font_urls[ fonts[x] ];
|
||||||
var link = $('<link href="'+url+'" rel="stylesheet">');
|
var link = $("<link href='"+url+"' rel='stylesheet'>");
|
||||||
head.append( link );
|
head.append( link );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !fontfamily ) {
|
setStartingFont();
|
||||||
$(document.body).css('font-family', fontfamily);
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !fontsize ) {
|
|
||||||
$(document.body).css('font-size', fontsize+"em");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
var onSwitchLayout = function (evnt) {
|
||||||
// get the new layout name from the select box
|
// 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
|
// check to see if the layout is in the list of known layouts
|
||||||
if( name in evenniaGoldenLayouts ) {
|
if( name in evenniaGoldenLayouts ) {
|
||||||
console.log( evenniaGoldenLayouts );
|
|
||||||
|
|
||||||
var newLayout = evenniaGoldenLayouts[name];
|
var newLayout = evenniaGoldenLayouts[name];
|
||||||
activeLayoutName = name;
|
activeLayoutName = name;
|
||||||
|
|
||||||
|
|
@ -330,28 +288,27 @@ let goldenlayout = (function () {
|
||||||
//
|
//
|
||||||
var onSaveLayout = function (evnt) {
|
var onSaveLayout = function (evnt) {
|
||||||
// get the name from the select box
|
// get the name from the select box
|
||||||
var name = $('#layoutName').val();
|
var name = $("#layoutName").val();
|
||||||
var input = $('#layoutInput');
|
var input = $("#layoutInput");
|
||||||
|
|
||||||
if( name === "" ) { return; } // Can't save without a valid name
|
if( name === "" ) { return; } // Can't save without a valid name
|
||||||
|
|
||||||
// Is this name new or pre-existing?
|
// Is this name new or pre-existing?
|
||||||
if( !(name in evenniaGoldenLayouts) ) {
|
if( !(name in evenniaGoldenLayouts) ) {
|
||||||
// add the new evenniaGoldenLayout to the listed dropdown options
|
// add the new evenniaGoldenLayout to the listed dropdown options
|
||||||
var option = $('<option value="'+name+'">'+name+'</option>');
|
var option = $("<option value='"+name+"'>"+name+"</option>");
|
||||||
input.append(option);
|
input.append(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
// store the current layout to the local list of layouts
|
// store the current layout to the local list of layouts
|
||||||
evenniaGoldenLayouts[ name ] = myLayout.toConfig();
|
Object.assign( evenniaGoldenLayouts, { [name] : myLayout.toConfig() });
|
||||||
activeLayoutName = name;
|
activeLayoutName = name;
|
||||||
|
|
||||||
// upload it to the server
|
// upload it to the server
|
||||||
if( Evennia.isConnected() && myLayout.isInitialised ) {
|
if( window.Evennia.isConnected() && myLayout.isInitialised ) {
|
||||||
window.options["webclientActiveLayout"] = name;
|
window.options["webclientActiveLayout"] = name;
|
||||||
window.options["webclientLayouts"] = JSON.stringify( evenniaGoldenLayouts );
|
window.options["webclientLayouts"] = JSON.stringify( evenniaGoldenLayouts );
|
||||||
console.log("Saving layout to server...");
|
window.Evennia.msg("webclient_options", [], window.options);
|
||||||
Evennia.msg("webclient_options", [], window.options);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -426,22 +383,6 @@ let goldenlayout = (function () {
|
||||||
tab.header.parent.on( "activeContentItemChanged", onActiveTabChange );
|
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) {
|
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
|
// Public
|
||||||
//
|
//
|
||||||
|
|
@ -600,8 +596,6 @@ let goldenlayout = (function () {
|
||||||
var onGotOptions = function (args, kwargs) {
|
var onGotOptions = function (args, kwargs) {
|
||||||
// Reset the UI if the JSON layout sent from the server doesn't match the client's current JSON
|
// Reset the UI if the JSON layout sent from the server doesn't match the client's current JSON
|
||||||
if( "webclientLayouts" in kwargs ) {
|
if( "webclientLayouts" in kwargs ) {
|
||||||
console.log("Got evennia GoldenLayouts");
|
|
||||||
|
|
||||||
evenniaGoldenLayouts = JSON.parse( kwargs["webclientLayouts"] );
|
evenniaGoldenLayouts = JSON.parse( kwargs["webclientLayouts"] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -610,13 +604,13 @@ let goldenlayout = (function () {
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
var onOptionsUI = function (parentdiv) {
|
var onOptionsUI = function (parentdiv) {
|
||||||
var layoutInput = $('<select id="layoutInput" class="layoutInput">');
|
var layoutInput = $("<select id='layoutInput' class='layoutInput'>");
|
||||||
var layoutName = $('<input id="layoutName" type="text" class="layoutName">');
|
var layoutName = $("<input id='layoutName' type='text' class='layoutName'>");
|
||||||
var saveButton = $('<input type="button" class="savelayout" value="Save UI Layout">');
|
var saveButton = $("<input type='button' class='savelayout' value='Save UI Layout'>");
|
||||||
|
|
||||||
var layouts = Object.keys( evenniaGoldenLayouts );
|
var layouts = Object.keys( evenniaGoldenLayouts );
|
||||||
for (var x = 0; x < layouts.length; x++) {
|
for (var x = 0; x < layouts.length; x++) {
|
||||||
var option = $('<option value="'+layouts[x]+'">'+layouts[x]+'</option>');
|
var option = $("<option value='"+layouts[x]+"'>"+layouts[x]+"</option>");
|
||||||
layoutInput.append(option);
|
layoutInput.append(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -628,7 +622,7 @@ let goldenlayout = (function () {
|
||||||
saveButton.on('click', onSaveLayout);
|
saveButton.on('click', onSaveLayout);
|
||||||
|
|
||||||
// add the selection dialog control to our parentdiv
|
// add the selection dialog control to our parentdiv
|
||||||
parentdiv.append('<div style="font-weight: bold">UI Layout Selection (This list may be longer after login):</div>');
|
parentdiv.append("<div style='font-weight: bold'>UI Layout Selection (This list may be longer after login):</div>");
|
||||||
parentdiv.append(layoutInput);
|
parentdiv.append(layoutInput);
|
||||||
parentdiv.append(layoutName);
|
parentdiv.append(layoutName);
|
||||||
parentdiv.append(saveButton);
|
parentdiv.append(saveButton);
|
||||||
|
|
@ -679,7 +673,7 @@ let goldenlayout = (function () {
|
||||||
var mainsub = document.getElementById("main-sub");
|
var mainsub = document.getElementById("main-sub");
|
||||||
|
|
||||||
// pre-load the evenniaGoldenLayouts with the hard-coded default
|
// pre-load the evenniaGoldenLayouts with the hard-coded default
|
||||||
evenniaGoldenLayouts[ "default" ] = window.goldenlayout_config;
|
Object.assign( evenniaGoldenLayouts, { "default" : window.goldenlayout_config } );
|
||||||
|
|
||||||
if( activeName !== null ) {
|
if( activeName !== null ) {
|
||||||
activeLayoutName = activeName;
|
activeLayoutName = activeName;
|
||||||
|
|
@ -689,10 +683,10 @@ let goldenlayout = (function () {
|
||||||
// Overwrite the global-variable configuration from
|
// Overwrite the global-variable configuration from
|
||||||
// webclient/js/plugins/goldenlayout_default_config.js
|
// webclient/js/plugins/goldenlayout_default_config.js
|
||||||
// with the version from localstorage
|
// 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
|
$("#prompt").remove(); // remove the HTML-defined prompt div
|
||||||
$("#inputcontrol").remove(); // remove the cluttered, HTML-defined input divs
|
$("#inputcontrol").remove(); // remove the cluttered, HTML-defined input divs
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ let hotbuttons = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
init: function() {},
|
init: function() {},
|
||||||
postInit: postInit,
|
postInit: postInit,
|
||||||
onGotOptions: onGotOptions,
|
onGotOptions: onGotOptions,
|
||||||
onLayoutChanged: onLayoutChanged,
|
onLayoutChanged: onLayoutChanged,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue