TeaWeb/shared/js/ui/client_move.ts

167 lines
5.6 KiB
TypeScript
Raw Normal View History

2020-03-30 11:44:18 +00:00
import {ChannelTree} from "tc-shared/ui/view";
import * as log from "tc-shared/log";
import {LogCategory} from "tc-shared/log";
import {ClientEntry} from "tc-shared/ui/client";
import {ChannelEntry} from "tc-shared/ui/channel";
2020-03-30 11:44:18 +00:00
export class ClientMover {
2018-11-03 23:39:29 +00:00
static readonly listener_root = $(document);
static readonly move_element = $("#mouse-move");
readonly channel_tree: ChannelTree;
2019-01-19 14:21:37 +00:00
selected_client: ClientEntry | ClientEntry[];
2018-11-03 23:39:29 +00:00
hovered_channel: HTMLDivElement;
callback: (channel?: ChannelEntry) => any;
2019-04-25 22:32:19 +00:00
enabled: boolean = true;
2018-11-03 23:39:29 +00:00
private _bound_finish;
private _bound_move;
private _active: boolean = false;
private origin_point: {x: number, y: number} = undefined;
constructor(tree: ChannelTree) {
this.channel_tree = tree;
}
2019-01-19 14:21:37 +00:00
is_active() { return this._active; }
private hover_text() {
if($.isArray(this.selected_client)) {
2019-01-20 17:43:14 +00:00
return this.selected_client.filter(client => !!client).map(client => client.clientNickName()).join(", ");
2019-01-19 14:21:37 +00:00
} else if(this.selected_client) {
return (<ClientEntry>this.selected_client).clientNickName();
} else
return "";
}
2019-01-20 17:43:14 +00:00
private bbcode_text() {
if($.isArray(this.selected_client)) {
return this.selected_client.filter(client => !!client).map(client => client.create_bbcode()).join(", ");
} else if(this.selected_client) {
return (<ClientEntry>this.selected_client).create_bbcode();
} else
return "";
}
2019-01-19 14:21:37 +00:00
activate(client: ClientEntry | ClientEntry[], callback: (channel?: ChannelEntry) => any, event: any) {
2018-11-03 23:39:29 +00:00
this.finish_listener(undefined);
2019-04-25 22:32:19 +00:00
if(!this.enabled)
return false;
2018-11-03 23:39:29 +00:00
this.selected_client = client;
this.callback = callback;
2019-08-30 21:06:39 +00:00
log.debug(LogCategory.GENERAL, tr("Starting mouse move"));
2018-11-03 23:39:29 +00:00
ClientMover.listener_root.on('mouseup', this._bound_finish = this.finish_listener.bind(this)).on('mousemove', this._bound_move = this.move_listener.bind(this));
{
const content = ClientMover.move_element.find(".container");
content.empty();
2019-01-19 14:21:37 +00:00
content.append($.spawn("a").text(this.hover_text()));
2018-11-03 23:39:29 +00:00
}
this.move_listener(event);
}
private move_listener(event) {
2019-04-25 22:32:19 +00:00
if(!this.enabled)
return;
2018-11-03 23:39:29 +00:00
//console.log("Mouse move: " + event.pageX + " - " + event.pageY);
if(!event.pageX || !event.pageY) return;
if(!this.origin_point)
this.origin_point = {x: event.pageX, y: event.pageY};
ClientMover.move_element.css({
"top": (event.pageY - 1) + "px",
"left": (event.pageX + 10) + "px"
});
if(!this._active) {
const d_x = this.origin_point.x - event.pageX;
const d_y = this.origin_point.y - event.pageY;
this._active = Math.sqrt(d_x * d_x + d_y * d_y) > 5 * 5;
if(this._active) {
2019-01-19 14:21:37 +00:00
if($.isArray(this.selected_client)) {
this.channel_tree.onSelect(this.selected_client[0], true);
for(const client of this.selected_client.slice(1))
this.channel_tree.onSelect(client, false, true);
} else {
this.channel_tree.onSelect(this.selected_client, true);
}
2018-11-03 23:39:29 +00:00
ClientMover.move_element.show();
}
2018-11-03 23:39:29 +00:00
}
const elements = document.elementsFromPoint(event.pageX, event.pageY);
while(elements.length > 0) {
Implemented the Material Design and fixed some bugs (#33) * cleaned up some files * Fundamental style update * Redesigned some style * fixed hostbanner popup * Removed old identity stuff * fixed close listener * Fixed changelog date * fixed release chat icons * fixed url * Fixed hostbanner * Uploaded missing images * Improved update handling * Improved script files * Fixed loading error and icon error * fixed Yes/No modal * Fixed loader issues with MS Edge * fixed modal style bug * Fixed control bar overflow for small devices * Improved error handling on identity creation * Logging generate error to terminal * fixed possible php error * fixed some possible loading errors when other files have'nt been already loaded. * removed debug message * Changed emsrcypten flags * Improved codec error handling * removed webassembly as required dependency * Improved and fixed channel tree issues * Improved the sliders * Removed unneeded files * fixed loader versions cache * second slight performance improved (dont animate elements anymore if they are not shown) * Fixed query visibility setting * not showing useless client infos for query clients * Added an auto reconnect system * Added a canceled message and increased reconnect interval * removed implemented todo * fixed repetitive channel names * Reworked the channel tree selected lines * Fixed channel tree names * Fixed name alignment * fixed the native client * added min width to the server select groups to avoid a disappearing effect on shrink * fixed bugged downloaded icons
2019-02-17 15:08:10 +00:00
if(elements[0].classList.contains("container-channel")) break;
2018-11-03 23:39:29 +00:00
elements.pop_front();
}
if(this.hovered_channel) {
this.hovered_channel.classList.remove("move-selected");
this.hovered_channel = undefined;
}
if(elements.length > 0) {
elements[0].classList.add("move-selected");
this.hovered_channel = elements[0] as HTMLDivElement;
}
}
private finish_listener(event) {
ClientMover.move_element.hide();
2019-08-30 21:06:39 +00:00
log.debug(LogCategory.GENERAL, tr("Finishing mouse move"));
2018-11-03 23:39:29 +00:00
const channel_id = this.hovered_channel ? parseInt(this.hovered_channel.getAttribute("channel-id")) : 0;
ClientMover.listener_root.unbind('mouseleave', this._bound_finish);
ClientMover.listener_root.unbind('mouseup', this._bound_finish);
ClientMover.listener_root.unbind('mousemove', this._bound_move);
if(this.hovered_channel) {
this.hovered_channel.classList.remove("move-selected");
this.hovered_channel = undefined;
}
this.origin_point = undefined;
if(!this._active) {
this.selected_client = undefined;
this.callback = undefined;
return;
}
this._active = false;
if(this.callback) {
if(!channel_id)
this.callback(undefined);
else {
this.callback(this.channel_tree.findChannel(channel_id));
}
this.callback = undefined;
}
2019-01-20 17:43:14 +00:00
/* test for the chat box */
{
const elements = document.elementsFromPoint(event.pageX, event.pageY);
console.error(elements);
while(elements.length > 0) {
if(elements[0].classList.contains("client-chat-box-field")) break;
elements.pop_front();
}
if(elements.length > 0) {
const element = $(<HTMLTextAreaElement>elements[0]);
element.val((element.val() || "") + this.bbcode_text());
}
}
2018-11-03 23:39:29 +00:00
}
deactivate() {
this.callback = undefined;
this.finish_listener(undefined);
}
}