Move the user list client code to its own file

This commit is contained in:
Jérémie Astori 2017-12-15 22:37:19 -05:00
parent fd4492ab41
commit 25517f3ad7
No known key found for this signature in database
GPG key ID: B9A4F245CD67BDE8
2 changed files with 36 additions and 29 deletions

View file

@ -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: "<b>",
post: "</b>",
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);

36
client/js/userlist.js Normal file
View file

@ -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: "<b>",
post: "</b>",
extract: (el) => $(el).text(),
};
const result = fuzzy.filter(
value,
names.find(".user").toArray(),
fuzzyOptions
);
names.hide();
container.html(templates.user_filtered({matches: result})).show();
});