From 0d058a5ef76ba3533029415b7966bba30961ce4b Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 5 Oct 2016 14:30:17 -0700 Subject: [PATCH] Begin work on overriding defaults in URL --- client/js/lounge.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/js/lounge.js b/client/js/lounge.js index cca024b9..5a10f9e0 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -993,7 +993,31 @@ $(function() { } }); }); + if ($("body").hasClass("public")) { + $("#connect").one("show", function() { + var params = window.URI(document.location.search); + params = params.search(true); + // Possible parameters: name, host, port, password, tls, nick, username, realname, join + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#Iterating_over_own_properties_only + for (var key in params) { + if (params.hasOwnProperty(key)) { + var value = params[key]; + // \W searches for non-word characters + key = key.replace(/\W/g, ""); + var element = $("#connect input[name='" + key + "']"); + // if the element exists, it isn't disabled, and it isn't hidden + if (element.length > 0 && !element.is(":disabled") && !element.is(":hidden")) { + if (element.is(":checkbox")) { + element.prop("checked", (value === "1" || value === "true") ? true : false); + } else { + element.val(value); + } + } + } + } + }); + } windows.on("show", "#settings", updateDesktopNotificationStatus); forms.on("submit", "form", function(e) {