TeaWeb/shared/js/ui/elements/tab.ts

161 lines
5.7 KiB
TypeScript
Raw Normal View History

2019-04-04 21:47:52 +02:00
/// <reference path="../../i18n/localize.ts" />
2018-02-27 17:20:49 +01:00
2018-12-04 18:48:54 +01:00
interface JQuery<TElement = HTMLElement> {
asTabWidget(copy?: boolean) : JQuery<TElement>;
2018-09-30 21:50:59 +02:00
tabify(copy?: boolean) : this;
2018-02-27 17:20:49 +01:00
2018-12-04 18:48:54 +01:00
changeElementType(type: string) : JQuery<TElement>;
2018-02-27 17:20:49 +01:00
}
2019-01-19 13:03:51 +01:00
2018-04-16 20:38:35 +02:00
if(typeof (customElements) !== "undefined") {
2019-01-19 13:03:51 +01:00
try {
class X_Tab extends HTMLElement {}
class X_Entry extends HTMLElement {}
class X_Tag extends HTMLElement {}
class X_Content extends HTMLElement {}
customElements.define('x-tab', X_Tab, { extends: 'div' });
customElements.define('x-entry', X_Entry, { extends: 'div' });
customElements.define('x-tag', X_Tag, { extends: 'div' });
customElements.define('x-content', X_Content, { extends: 'div' });
} catch(error) {
console.warn("failed to define costum elements");
}
2018-04-16 20:38:35 +02:00
} else {
console.warn(tr("Could not defied tab customElements!"));
2018-04-16 20:38:35 +02:00
}
2018-02-27 17:20:49 +01:00
var TabFunctions = {
2018-09-30 21:50:59 +02:00
tabify(template: JQuery, copy: boolean = true) : JQuery {
console.log("Tabify: copy=" + copy);
2018-02-27 17:20:49 +01:00
console.log(template);
let tag = $.spawn("div");
tag.addClass("tab");
let header = $.spawn("div");
header.addClass("tab-header");
let content = $.spawn("div");
content.addClass("tab-content");
2019-03-17 12:15:39 +01:00
content.append($.spawn("div").addClass("height-watcher"));
2018-03-07 19:06:52 +01:00
let silentContent = $.spawn("div");
silentContent.addClass("tab-content-invisible");
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 16:08:10 +01:00
/* add some kind of min height */
const update_height = () => {
2019-03-17 12:15:39 +01:00
const height_watcher = tag.find("> .tab-content .height-watcher");
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 16:08:10 +01:00
const entries: JQuery = tag.find("> .tab-content-invisible x-content, > .tab-content x-content");
console.error(entries);
let max_height = 0;
entries.each((_, _e) => {
const entry = $(_e);
const height = entry.visible_height();
if(height > max_height)
max_height = height;
});
2019-03-17 12:15:39 +01:00
height_watcher.css('min-height', max_height + "px");
2019-04-29 19:35:16 +02:00
tag.find(".window-resize-listener").trigger('resize');
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 16:08:10 +01:00
};
template.find("x-entry").each( (_, _entry) => {
const entry = $(_entry);
2019-04-29 19:35:16 +02:00
const tag_header = $.spawn("div").addClass("entry");
const tag_content = copy ? entry.find("x-content").clone(true, true) : entry.find("x-content");
2019-04-29 19:35:16 +02:00
{
const header_tag = entry.find("x-tag");
const header_data = copy ? header_tag.contents().clone(true, true) : header_tag.contents();
if(header_tag.attr("x-entry-class"))
tag_header.addClass(header_tag.attr("x-entry-class"));
2019-08-21 10:00:01 +02:00
if(header_tag.attr("x-entry-id"))
tag_header.attr("x-id", header_tag.attr("x-entry-id"));
2019-04-29 19:35:16 +02:00
tag_header.append(header_data);
/* listener if the tab might got removed */
tag_header.addClass("window-resize-listener");
tag_header.on('resize', event => {
if(!tag_header.is(':visible') && tag_header.hasClass('selected')) {
let element = tag_header.next('.entry:visible');
if(element.length == 0)
element = tag_header.prev('.entry:visible');
if(element.length == 0) {
tag_header.removeClass("selected");
tag_content.hide();
} else {
element.first().trigger('click');
}
console.log("Next: %o", tag_header.next('.entry:visible'));
console.log("prev: %o", tag_header.prev('.entry:visible'));
}
});
}
content.append(tag_content.hide());
tag_header.on("click", () => {
if(tag_header.hasClass("selected")) return;
2018-02-27 17:20:49 +01:00
tag.find(".tab-header .selected").removeClass("selected");
tag_header.addClass("selected");
content.find("> x-content").hide();
/* don't show many nodes at once */
let entries = tag_content.find(".tab-show-partitional");
entries.hide();
const show_next = index => {
console.log("Show " + index);
if(index >= entries.length) return;
entries.eq(index).show();
setTimeout(show_next.bind(undefined, index + 1), 0);
};
show_next(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 16:08:10 +01:00
tag_content.trigger('show');
tag_content.show();
2018-02-27 17:20:49 +01:00
});
console.log(this);
header.append(tag_header);
2018-02-27 17:20:49 +01:00
});
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 16:08:10 +01:00
setTimeout(() => header.find(".entry").first().trigger("click"), 0);
2018-02-27 17:20:49 +01:00
tag.append(header);
tag.append(content);
2018-03-07 19:06:52 +01:00
tag.append(silentContent);
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 16:08:10 +01:00
tag.on('tab.resize', update_height);
2018-02-27 17:20:49 +01:00
return tag;
}
2019-04-04 21:47:52 +02:00
};
2018-02-27 17:20:49 +01:00
if(!$.fn.asTabWidget) {
2018-09-30 21:50:59 +02:00
$.fn.asTabWidget = function (copy?: boolean) : JQuery {
2018-02-27 17:20:49 +01:00
if($(this).prop("tagName") == "X-TAB")
2018-09-30 21:50:59 +02:00
return TabFunctions.tabify($(this), typeof(copy) === "boolean" ? copy : true);
2018-02-27 17:20:49 +01:00
else {
throw "Invalid tag! " + $(this).prop("tagName");
}
}
}
if(!$.fn.tabify) {
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 16:08:10 +01:00
$.fn.tabify = function (this: JQuery, copy?: boolean) {
const wrapped_tag = $.spawn("div").append(this);
wrapped_tag.find("x-tab").each((_, _element) => {
const element = $(_element);
element.replaceWith(element.asTabWidget(copy));
2018-02-27 17:20:49 +01:00
});
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 16:08:10 +01:00
return wrapped_tag.children();
2018-02-27 17:20:49 +01:00
}
}