From 25517f3ad7a04dd8252001ab50228e9b88b23291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Fri, 15 Dec 2017 22:37:19 -0500 Subject: [PATCH] Move the user list client code to its own file --- client/js/lounge.js | 29 ----------------------------- client/js/userlist.js | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 client/js/userlist.js diff --git a/client/js/lounge.js b/client/js/lounge.js index 80d59cdf..cbe2852b 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -5,7 +5,6 @@ require("jquery-ui/ui/widgets/sortable"); const $ = require("jquery"); const moment = require("moment"); const URI = require("urijs"); -const fuzzy = require("fuzzy"); // our libraries require("./libs/jquery/inputhistory"); @@ -585,34 +584,6 @@ $(function() { contextMenuActions.execute(contextAction, itemData); }); - chat.on("input", ".search", function() { - const value = $(this).val(); - const parent = $(this).closest(".users"); - const names = parent.find(".names-original"); - const container = parent.find(".names-filtered"); - - if (!value.length) { - container.hide(); - names.show(); - return; - } - - const fuzzyOptions = { - pre: "", - post: "", - extract: (el) => $(el).text(), - }; - - const result = fuzzy.filter( - value, - names.find(".user").toArray(), - fuzzyOptions - ); - - names.hide(); - container.html(templates.user_filtered({matches: result})).show(); - }); - if ($(document.body).hasClass("public") && (window.location.hash === "#connect" || window.location.hash === "")) { $("#connect").one("show", function() { const params = URI(document.location.search).search(true); diff --git a/client/js/userlist.js b/client/js/userlist.js new file mode 100644 index 00000000..bbd770d3 --- /dev/null +++ b/client/js/userlist.js @@ -0,0 +1,36 @@ +"use strict"; + +const $ = require("jquery"); +const fuzzy = require("fuzzy"); + +const templates = require("../views"); + +const chat = $("#chat"); + +chat.on("input", ".users .search", function() { + const value = $(this).val(); + const parent = $(this).closest(".users"); + const names = parent.find(".names-original"); + const container = parent.find(".names-filtered"); + + if (!value.length) { + container.hide(); + names.show(); + return; + } + + const fuzzyOptions = { + pre: "", + post: "", + extract: (el) => $(el).text(), + }; + + const result = fuzzy.filter( + value, + names.find(".user").toArray(), + fuzzyOptions + ); + + names.hide(); + container.html(templates.user_filtered({matches: result})).show(); +});