diff options
| author | RblSb <msrblsb@gmail.com> | 2020-05-20 18:17:03 +0300 |
|---|---|---|
| committer | RblSb <msrblsb@gmail.com> | 2020-05-20 19:59:56 +0300 |
| commit | 844048b21f34b066bc003a13fae9fca92872c746 (patch) | |
| tree | 4719f5805ac387a550f2a3345d46bbd816e0223f | |
| parent | 8c995a8e206950d7dbb2c2eced641f70b38e44f8 (diff) | |
Fix chat word wrap
closes #6
| -rw-r--r-- | res/client.js | 26 | ||||
| -rw-r--r-- | res/index.html | 2 | ||||
| -rw-r--r-- | src/client/Buttons.hx | 26 | ||||
| -rw-r--r-- | src/client/Main.hx | 4 |
4 files changed, 32 insertions, 26 deletions
diff --git a/res/client.js b/res/client.js index 1c8691d..307266e 100644 --- a/res/client.js +++ b/res/client.js @@ -405,10 +405,10 @@ client_Buttons.__name__ = true; client_Buttons.init = function(main) { client_Buttons.settings = main.settings; if(client_Buttons.settings.isSwapped) { - window.document.body.classList.add("swap"); + client_Buttons.swapPlayerAndChat(); } client_Buttons.initSplit(); - client_Buttons.setSplitSize(client_Buttons.settings.playerSize,client_Buttons.settings.chatSize); + client_Buttons.setSplitSize(client_Buttons.settings.chatSize); client_Buttons.initChatInput(main); var passIcon = window.document.querySelector("#guestpass_icon"); passIcon.onclick = function(e) { @@ -563,10 +563,7 @@ client_Buttons.init = function(main) { return client_Buttons.toggleGroup(showOptions); }; window.document.querySelector("#swapLayoutBtn").onclick = function(e) { - client_Buttons.settings.isSwapped = window.document.querySelector("body").classList.toggle("swap"); - var sizes = window.document.body.style.gridTemplateColumns.split(" "); - sizes.reverse(); - window.document.body.style.gridTemplateColumns = sizes.join(" "); + client_Buttons.swapPlayerAndChat(); client_Settings.write(client_Buttons.settings); }; }; @@ -592,16 +589,24 @@ client_Buttons.toggleGroup = function(el) { window.document.querySelector(id).classList.toggle("collapse"); return el.classList.toggle("active"); }; +client_Buttons.swapPlayerAndChat = function() { + client_Buttons.settings.isSwapped = window.document.querySelector("body").classList.toggle("swap"); + var sizes = window.document.body.style.gridTemplateColumns.split(" "); + sizes.reverse(); + window.document.body.style.gridTemplateColumns = sizes.join(" "); +}; client_Buttons.initSplit = function() { if(client_Buttons.split != null) { client_Buttons.split.destroy(); } client_Buttons.split = new Split({ columnGutters : [{ element : window.document.querySelector(".gutter"), track : 1}], minSize : 200, snapOffset : 0, onDragEnd : client_Buttons.saveSplitSize}); }; -client_Buttons.setSplitSize = function(playerSize,chatSize) { +client_Buttons.setSplitSize = function(chatSize) { + if(chatSize < 200) { + return; + } var sizes = window.document.body.style.gridTemplateColumns.split(" "); - sizes[client_Buttons.settings.isSwapped ? sizes.length - 1 : 0] = "" + playerSize + "fr"; - sizes[client_Buttons.settings.isSwapped ? 0 : sizes.length - 1] = "" + chatSize + "fr"; + sizes[client_Buttons.settings.isSwapped ? 0 : sizes.length - 1] = "" + chatSize + "px"; window.document.body.style.gridTemplateColumns = sizes.join(" "); }; client_Buttons.saveSplitSize = function() { @@ -609,7 +614,6 @@ client_Buttons.saveSplitSize = function() { if(client_Buttons.settings.isSwapped) { sizes.reverse(); } - client_Buttons.settings.playerSize = parseFloat(sizes[0]); var tmp = parseFloat(sizes[sizes.length - 1]); client_Buttons.settings.chatSize = tmp; client_Settings.write(client_Buttons.settings); @@ -863,7 +867,7 @@ var client_Main = function(host,port) { if(port == "") { port = "80"; } - client_Settings.init({ version : 2, name : "", hash : "", isExtendedPlayer : false, playerSize : 70, chatSize : 30, synchThreshold : 2, isSwapped : false, isUserListHidden : true, latestLinks : [], hotkeysEnabled : true},$bind(this,this.settingsPatcher)); + client_Settings.init({ version : 2, name : "", hash : "", isExtendedPlayer : false, playerSize : 1, chatSize : 300, synchThreshold : 2, isSwapped : false, isUserListHidden : true, latestLinks : [], hotkeysEnabled : true},$bind(this,this.settingsPatcher)); this.settings = client_Settings.read(); this.initListeners(); this.onTimeGet = new haxe_Timer(this.settings.synchThreshold * 1000); diff --git a/res/index.html b/res/index.html index 074c283..b5128eb 100644 --- a/res/index.html +++ b/res/index.html @@ -12,7 +12,7 @@ <script type="module" src="https://cdn.jsdelivr.net/npm/ionicons@5.0.0/dist/ionicons/ionicons.esm.js"></script> <script nomodule="" src="https://cdn.jsdelivr.net/npm/ionicons@5.0.0/dist/ionicons/ionicons.js"></script> </head> -<body style="grid-template-columns: 70fr 4px 30fr;"> +<body style="grid-template-columns: 1fr 4px 300px;"> <!-- Video --> <main id="video" data-simplebar> <!-- Player --> diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index 1377b09..ffc7667 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -8,18 +8,18 @@ import js.html.Element; import client.Main.ge; import js.Browser.window; import js.Browser.document; -import js.html.Event; class Buttons { + static inline var CHAT_MIN_SIZE = 200; static var split:Split; static var settings:ClientSettings; public static function init(main:Main):Void { settings = main.settings; - if (settings.isSwapped) document.body.classList.add("swap"); + if (settings.isSwapped) swapPlayerAndChat(); initSplit(); - setSplitSize(settings.playerSize, settings.chatSize); + setSplitSize(settings.chatSize); initChatInput(main); final passIcon = ge("#guestpass_icon"); @@ -164,10 +164,7 @@ class Buttons { final swapLayoutBtn = ge("#swapLayoutBtn"); swapLayoutBtn.onclick = e -> { - settings.isSwapped = ge("body").classList.toggle("swap"); - final sizes = document.body.style.gridTemplateColumns.split(" "); - sizes.reverse(); - document.body.style.gridTemplateColumns = sizes.join(" "); + swapPlayerAndChat(); Settings.write(settings); } } @@ -188,6 +185,13 @@ class Buttons { return el.classList.toggle("active"); } + static function swapPlayerAndChat():Void { + settings.isSwapped = ge("body").classList.toggle("swap"); + final sizes = document.body.style.gridTemplateColumns.split(" "); + sizes.reverse(); + document.body.style.gridTemplateColumns = sizes.join(" "); + } + static function initSplit():Void { if (split != null) split.destroy(); split = new Split({ @@ -201,19 +205,17 @@ class Buttons { }); } - static function setSplitSize(playerSize:Float, chatSize:Float):Void { + static function setSplitSize(chatSize:Float):Void { + if (chatSize < CHAT_MIN_SIZE) return; final sizes = document.body.style.gridTemplateColumns.split(" "); - final playerId = settings.isSwapped ? sizes.length - 1 : 0; final chatId = settings.isSwapped ? 0 : sizes.length - 1; - sizes[playerId] = '${playerSize}fr'; - sizes[chatId] = '${chatSize}fr'; + sizes[chatId] = '${chatSize}px'; document.body.style.gridTemplateColumns = sizes.join(" "); } static function saveSplitSize():Void { final sizes = document.body.style.gridTemplateColumns.split(" "); if (settings.isSwapped) sizes.reverse(); - settings.playerSize = Std.parseFloat(sizes[0]); settings.chatSize = Std.parseFloat(sizes[sizes.length - 1]); Settings.write(settings); } diff --git a/src/client/Main.hx b/src/client/Main.hx index 0ae48b0..76e1009 100644 --- a/src/client/Main.hx +++ b/src/client/Main.hx @@ -54,8 +54,8 @@ class Main { name: "", hash: "", isExtendedPlayer: false, - playerSize: 70, - chatSize: 30, + playerSize: 1, + chatSize: 300, synchThreshold: 2, isSwapped: false, isUserListHidden: true, |
