TeaWeb/shared/js/utils/tab.ts
WolverinDEV 664f8b2abd
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

137 lines
No EOL
4.4 KiB
TypeScript

/// <reference path="../i18n/localize.ts" />
interface JQuery<TElement = HTMLElement> {
asTabWidget(copy?: boolean) : JQuery<TElement>;
tabify(copy?: boolean) : this;
changeElementType(type: string) : JQuery<TElement>;
}
if(typeof (customElements) !== "undefined") {
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");
}
} else {
console.warn(tr("Could not defied tab customElements!"));
}
var TabFunctions = {
tabify(template: JQuery, copy: boolean = true) : JQuery {
console.log("Tabify: copy=" + copy);
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");
let silentContent = $.spawn("div");
silentContent.addClass("tab-content-invisible");
/* add some kind of min height */
const update_height = () => {
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;
});
console.error("HIGHT: " + max_height);
entries.each((_, _e) => {
const entry = $(_e);
entry.animate({
'min-height': max_height + "px"
}, 250);
})
};
template.find("x-entry").each( (_, _entry) => {
const entry = $(_entry);
let tag_header = $.spawn("div").addClass("entry");
if(copy)
tag_header.append(entry.find("x-tag").clone(true, true));
else
tag_header.append(entry.find("x-tag"));
const tag_content = copy ? entry.find("x-content").clone(true, true) : entry.find("x-content");
content.append(tag_content.hide());
tag_header.on("click", () => {
if(tag_header.hasClass("selected")) return;
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);
tag_content.trigger('show');
tag_content.show();
});
console.log(this);
header.append(tag_header);
});
setTimeout(() => header.find(".entry").first().trigger("click"), 0);
tag.append(header);
tag.append(content);
tag.append(silentContent);
tag.on('tab.resize', update_height);
return tag;
}
}
if(!$.fn.asTabWidget) {
$.fn.asTabWidget = function (copy?: boolean) : JQuery {
if($(this).prop("tagName") == "X-TAB")
return TabFunctions.tabify($(this), typeof(copy) === "boolean" ? copy : true);
else {
throw "Invalid tag! " + $(this).prop("tagName");
}
}
}
if(!$.fn.tabify) {
$.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));
});
return wrapped_tag.children();
}
}