lint - code style:
* signature
* double quote strings
* no parameter reassignment
* no var
* no double empty lines
issue: TOBAGO-1633: TS refactoring
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/ext-bootstrap.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/ext-bootstrap.ts
index ecd323c..e796f3a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/ext-bootstrap.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/ext-bootstrap.ts
@@ -19,7 +19,7 @@
export class BootstrapUtils {
- static modal(element: Element, data?: any, options?: any) {
+ static modal(element: Element, data?: any, options?: any): void {
jQuery(element).modal(data, options);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/hello-world.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/hello-world.ts
index 80b355d..b715e81 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/hello-world.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/hello-world.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-export const hello = () => 'Hello world!';
+export const hello = () => "Hello world!";
export function es6test(): any {
return [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16].map((n) => n * n);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
index a3d896a..e072628 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-calendar.ts
@@ -21,7 +21,7 @@
class DateTime {
- static init(element: HTMLElement) {
+ static init(element: HTMLElement): void {
for (const e of DomUtils.selfOrQuerySelectorAll(element, ".tobago-date:not([readonly]):not([disabled])")) {
const date: HTMLInputElement = e as HTMLInputElement;
@@ -30,18 +30,18 @@
format: analyzed,
showTodayButton: date.dataset.tobagoTodayButton === "data-tobago-today-button",
icons: {
- time: 'fa fa-clock-o',
- date: 'fa fa-calendar',
- up: 'fa fa-chevron-up',
- down: 'fa fa-chevron-down',
- previous: 'fa fa-chevron-left',
- next: 'fa fa-chevron-right',
- today: 'fa fa-calendar-check-o',
- clear: 'fa fa-trash',
- close: 'fa fa-times'
+ time: "fa fa-clock-o",
+ date: "fa fa-calendar",
+ up: "fa fa-chevron-up",
+ down: "fa fa-chevron-down",
+ previous: "fa fa-chevron-left",
+ next: "fa fa-chevron-right",
+ today: "fa fa-calendar-check-o",
+ clear: "fa fa-trash",
+ close: "fa fa-times"
},
keyBinds: {
- left: function ($widget) {
+ left: function ($widget): void {
const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
if (widget === undefined) {
if (date.selectionStart === date.selectionEnd) {
@@ -53,10 +53,10 @@
date.selectionEnd = date.selectionStart;
}
} else if (DomUtils.isVisible(widget.querySelector(".datepicker"))) {
- this.date(this.date().clone().subtract(1, 'd'));
+ this.date(this.date().clone().subtract(1, "d"));
}
},
- right: function ($widget) {
+ right: function ($widget): void {
const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
if (widget === undefined) {
if (date.selectionStart === date.selectionEnd) {
@@ -68,10 +68,10 @@
date.selectionStart = date.selectionEnd;
}
} else if (DomUtils.isVisible(widget.querySelector(".datepicker"))) {
- this.date(this.date().clone().add(1, 'd'));
+ this.date(this.date().clone().add(1, "d"));
}
},
- enter: function ($widget) {
+ enter: function ($widget): void {
const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
if (widget !== undefined && DomUtils.isVisible(widget.querySelector(".datepicker"))) {
this.hide();
@@ -84,14 +84,14 @@
}));
}
},
- escape: function ($widget) {
+ escape: function ($widget): void {
const widget: HTMLDivElement = $widget[0] as HTMLDivElement;
if (widget !== undefined && DomUtils.isVisible(widget.querySelector(".datepicker"))) {
this.hide();
fixKey(27);
}
},
- 'delete': function () {
+ "delete": function (): void {
if (date.selectionStart < date.value.length) {
const selectionStart = date.selectionStart;
let selectionEnd = date.selectionEnd;
@@ -107,14 +107,14 @@
}
}
},
- widgetParent: '.tobago-page-menuStore'
+ widgetParent: ".tobago-page-menuStore"
};
/**
* After ESC or ENTER is pressed we need to fire the keyup event manually.
* see: https://github.com/tempusdominus/bootstrap-4/issues/159
*/
- function fixKey(keyCode) {
+ function fixKey(keyCode): void {
let keyupEvent = jQuery.Event("keyup");
keyupEvent.which = keyCode;
jQuery(date).trigger(keyupEvent);
@@ -155,7 +155,7 @@
// in line 1307 of bootstrap-datetimepicker.js
// the 'stopImmediatePropagation()' stops the change-event
// execution of line 686 in tobago.js
- $dateParent.on('dp.change', function (event) {
+ $dateParent.on("dp.change", function (event: Event): void {
let input: HTMLInputElement = this.querySelector("input");
let commands = input.dataset.tobagoCommands ? JSON.parse(input.dataset.tobagoCommands) : undefined;
if (commands && commands.change) {
@@ -177,7 +177,7 @@
});
// set position
- $dateParent.on('dp.show', function () {
+ $dateParent.on("dp.show", function (): void {
let datepicker: HTMLDivElement = document.querySelector(".bootstrap-datetimepicker-widget");
let div: HTMLDivElement = this;
let top, left;
@@ -198,12 +198,12 @@
});
// set css class in update - like changing the month
- $dateParent.on('dp.update', function () {
+ $dateParent.on("dp.update", function (): void {
DateTime.addPastClass(date);
});
// fix for bootstrap-datetimepicker v4.17.45
- $dateParent.on('dp.show', function () {
+ $dateParent.on("dp.show", function (): void {
const collapseIn = document.querySelector(".bootstrap-datetimepicker-widget .collapse.in");
const pickerSwitch = document.querySelector(".bootstrap-datetimepicker-widget .picker-switch a");
@@ -212,7 +212,7 @@
}
if (pickerSwitch !== null) {
pickerSwitch.addEventListener(
- "click", function () {
+ "click", function (): void {
// the click is executed before togglePicker() function
let datetimepicker: HTMLDivElement = document.querySelector(".bootstrap-datetimepicker-widget");
datetimepicker.querySelector(".collapse.in").classList.remove("in");
@@ -223,7 +223,7 @@
}
}
- static addPastClass(date: HTMLInputElement) {
+ static addPastClass(date: HTMLInputElement): void {
let today = date.dataset.tobagoToday;
if (today.length === 10) {
const todayArray = today.split("-");
@@ -249,11 +249,14 @@
and convert it to 'moment.js'.
Attention: Not every pattern char is supported.
*/
- static analyzePattern = function (pattern) {
+ static analyzePattern = function (originalPattern: string): string {
- if (!pattern || pattern.length > 100) {
- console.warn("Pattern not supported: " + pattern);
+ let pattern;
+ if (!originalPattern || originalPattern.length > 100) {
+ console.warn("Pattern not supported: " + originalPattern);
pattern = "";
+ } else {
+ pattern = originalPattern;
}
let analyzedPattern = "";
@@ -293,7 +296,9 @@
return analyzedPattern;
};
- static analyzePatternPart = function (pattern) {
+ static analyzePatternPart = function (originalPattern: string): string {
+
+ let pattern = originalPattern;
if (pattern.search("G") > -1 || pattern.search("W") > -1 || pattern.search("F") > -1
|| pattern.search("K") > -1 || pattern.search("z") > -1 || pattern.search("X") > -1) {
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
index bef2cfc..68b116a 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-command.ts
@@ -27,7 +27,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
switch (this.event) {
case "load": // this is a special case, because the "load" is too late now.
this.callback();
@@ -40,7 +40,7 @@
}
}
- callback(event?: Event) {
+ callback(event?: Event): void {
if (this.collapseAction && this.collapseTarget) {
const target = this.getRootNode() as ShadowRoot | Document;
@@ -69,7 +69,7 @@
}
}
- submit() {
+ submit(): void {
const actionId = this.action != null ? this.action : this.element.id;
CommandHelper.submitAction(this, actionId, !this.decoupled, this.target);
}
@@ -183,8 +183,8 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-behavior', Behavior);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-behavior", Behavior);
});
export class CommandHelper {
@@ -198,9 +198,9 @@
* @param target
*/
public static submitAction = function (
- source: HTMLElement, actionId: string, decoupled: boolean = true, target?: string) {
+ source: HTMLElement, actionId: string, decoupled: boolean = true, target?: string): void {
- Transport.request(function () {
+ Transport.request(function (): void {
if (!CommandHelper.isSubmit) {
CommandHelper.isSubmit = true;
const form = document.getElementsByTagName("form")[0] as HTMLFormElement;
@@ -211,12 +211,12 @@
if (target) {
form.setAttribute("target", target);
}
- var listenerOptions = {
+ const listenerOptions = {
source: source,
actionId: actionId/*,
options: commandHelper*/
};
- var onSubmitResult = CommandHelper.onSubmit(listenerOptions);
+ const onSubmitResult = CommandHelper.onSubmit(listenerOptions);
if (onSubmitResult) {
try {
form.submit();
@@ -226,7 +226,7 @@
} catch (e) {
Overlay.destroy(Page.page().id);
CommandHelper.isSubmit = false;
- alert('Submit failed: ' + e); // XXX localization, better error handling
+ alert("Submit failed: " + e); // XXX localization, better error handling
}
}
if (target) {
@@ -247,7 +247,7 @@
}, true);
};
- static onSubmit = function (listenerOptions) {
+ static onSubmit = function (listenerOptions: any): boolean {
Listener.executeBeforeSubmit();
/*
XXX check if we need the return false case
@@ -287,16 +287,16 @@
/**
* @return true if the request is queued.
*/
- static request = function (req, submitPage, actionId?) {
- var index = 0;
+ static request = function (req: () => void, submitPage: boolean, actionId?: string): boolean {
+ let index = 0;
if (submitPage) {
Transport.pageSubmitted = true;
index = Transport.requests.push(req);
//console.debug('index = ' + index)
} else if (!Transport.pageSubmitted) { // AJAX case
- console.debug('Current ActionId = ' + Transport.currentActionId + ' action= ' + actionId);
+ console.debug("Current ActionId = " + Transport.currentActionId + " action= " + actionId);
if (actionId && Transport.currentActionId === actionId) {
- console.info('Ignoring request');
+ console.info("Ignoring request");
// If actionId equals currentActionId assume double request: do nothing
return false;
}
@@ -307,27 +307,26 @@
console.debug("else case");
return false;
}
- console.debug('index = ' + index);
+ console.debug("index = " + index);
if (index === 1) {
- console.info('Execute request!');
+ console.info("Execute request!");
Transport.startTime = new Date();
Transport.requests[0]();
} else {
- console.info('Request queued!');
+ console.info("Request queued!");
}
return true;
};
-
// TBD XXX REMOVE is this called in non AJAX case?
- static requestComplete = function () {
+ static requestComplete = function ():void {
Transport.requests.shift();
Transport.currentActionId = null;
- console.debug('Request complete! Duration: ' + (new Date().getTime() - Transport.startTime.getTime()) + 'ms; '
- + 'Queue size : ' + Transport.requests.length);
+ console.debug("Request complete! Duration: " + (new Date().getTime() - Transport.startTime.getTime()) + "ms; "
+ + "Queue size : " + Transport.requests.length);
if (Transport.requests.length > 0) {
- console.debug('Execute request!');
+ console.debug("Execute request!");
Transport.startTime = new Date();
Transport.requests[0]();
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-config.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-config.ts
index ac1fcc4..6f79193 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-config.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-config.ts
@@ -19,7 +19,7 @@
private static map: Map<string, any> = new Map<string, any>();
- static set(key: string, value: any) {
+ static set(key: string, value: any): void {
this.map.set(key, value);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
index 0322e54..9940a22 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-core.ts
@@ -21,37 +21,20 @@
import {CommandHelper} from "./tobago-command";
import {Page} from "./tobago-page";
-/**
- * @deprecated since 5.0.0
- */
-export class Tobago {
- /**
- * Backward compatible listener registration. In the case of an AJAX call (phase = Phase.AFTER_UPDATE)
- * this listener will be called with a jQuery-object, the new one will get an HTMLElement.
- * @deprecated since 5.0.0
- */
- static registerListener(listener, phase, order) {
-
- Listener.register(function (element: HTMLElement) {
- listener(jQuery(element));
- }, phase, order);
- }
-}
-
export class Setup {
static transition: boolean;
static oldTransition: boolean;
- static init = function() {
+ static init = function (): void {
console.time("[tobago] init");
- document.querySelector("form").addEventListener('submit', CommandHelper.onSubmit);
- window.addEventListener('unload', Setup.onUnload);
+ document.querySelector("form").addEventListener("submit", CommandHelper.onSubmit);
+ window.addEventListener("unload", Setup.onUnload);
Listener.executeDocumentReady(document.documentElement);
console.timeEnd("[tobago] init");
};
- static onBeforeUnload = function () {
+ static onBeforeUnload = function (): void {
if (Setup.transition) {
new Overlay(Page.page());
}
@@ -61,8 +44,8 @@
/**
* Wrapper function to call application generated onunload function
*/
- static onUnload = function () {
- console.info('on onload');
+ static onUnload = function (): void {
+ console.info("on onload");
if (CommandHelper.isSubmit) {
if (Setup.transition) {
new Overlay(Page.page());
@@ -74,6 +57,6 @@
};
}
-document.addEventListener('DOMContentLoaded', Setup.init);
+document.addEventListener("DOMContentLoaded", Setup.init);
window.addEventListener("load", Listener.executeWindowLoad);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
index e107342..7041506 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
@@ -19,25 +19,24 @@
class Dropdown {
- static init(elements) {
- elements = elements.jQuery ? elements : jQuery(elements); // fixme jQuery -> ES5
- var $dropdownMenus = jQuery(":not(.tobago-page-menuStore) > .dropdown-menu");
- var $tobagoPageMenuStore = jQuery(".tobago-page-menuStore");
+ static init(element: HTMLElement): void {
+ const $dropdownMenus = jQuery(":not(.tobago-page-menuStore) > .dropdown-menu");
+ const $tobagoPageMenuStore = jQuery(".tobago-page-menuStore");
- $dropdownMenus.each(function () {
- var $dropdownMenu = jQuery(this);
- var $parent = $dropdownMenu.parent();
+ $dropdownMenus.each(function (): void {
+ const $dropdownMenu = jQuery(this);
+ const $parent = $dropdownMenu.parent();
- if (!$parent.hasClass('tobago-dropdown-submenu')
- && $parent.closest('.navbar').length === 0) {
+ if (!$parent.hasClass("tobago-dropdown-submenu")
+ && $parent.closest(".navbar").length === 0) {
// remove duplicated dropdown menus from menu store
// this could happen if the dropdown component is updated by ajax
removeDuplicates($dropdownMenu);
- $parent.on('shown.bs.dropdown', function (event) {
+ $parent.on("shown.bs.dropdown", function (event: Event): void {
$tobagoPageMenuStore.append($dropdownMenu.detach());
- }).on('hidden.bs.dropdown', function (event) {
+ }).on("hidden.bs.dropdown", function (event: Event): void {
$parent.append($dropdownMenu.detach());
});
}
@@ -45,15 +44,17 @@
}
}
-function removeDuplicates($dropdownMenu) {
- var $menuStoreDropdowns = jQuery(".tobago-page-menuStore .dropdown-menu");
- $menuStoreDropdowns.each(function () {
- var $menuStoreDropdown = jQuery(this);
+function removeDuplicates($dropdownMenu): void {
+ const $menuStoreDropdowns = jQuery(".tobago-page-menuStore .dropdown-menu");
+ // XXX todo: remove ts-ignore
+ // @ts-ignore
+ $menuStoreDropdowns.each(function (): boolean {
+ const $menuStoreDropdown = jQuery(this);
- var dropdownIds = getIds($dropdownMenu);
- var menuStoreIds = getIds($menuStoreDropdown);
+ const dropdownIds = getIds($dropdownMenu);
+ const menuStoreIds = getIds($menuStoreDropdown);
- for (var i = 0; i < dropdownIds.length; i++) {
+ for (let i = 0; i < dropdownIds.length; i++) {
if (jQuery.inArray(dropdownIds[i], menuStoreIds) >= 0) {
$menuStoreDropdown.remove();
return false;
@@ -62,8 +63,10 @@
});
}
+// XXX todo: remove tslint
+// tslint:disable-next-line:typedef
function getIds($dropdownMenu) {
- return $dropdownMenu.find("[id]").map(function () {
+ return $dropdownMenu.find("[id]").map(function (): string {
return this.id;
});
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
index 03cbdb7..a3a0287 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-file.ts
@@ -21,7 +21,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
this.input.form.enctype = "multipart/form-data";
this.input.addEventListener("change", this.select.bind(this));
@@ -35,7 +35,7 @@
return this.querySelector(".custom-file-label");
}
- select(event: MouseEvent) {
+ select(event: MouseEvent): void {
if (this.input.value === "") {
this.label.classList.add("tobago-file-placeholder");
this.label.textContent = this.input.placeholder;
@@ -49,7 +49,7 @@
} else {
text = this.input.value;
// remove path, if any. Some old browsers set the path, others like webkit uses the prefix "C:\path\".
- const pos: number = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
+ const pos: number = Math.max(text.lastIndexOf("/"), text.lastIndexOf("\\"));
if (pos >= 0) {
text = text.substr(pos + 1);
}
@@ -59,6 +59,6 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-file', File);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-file", File);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
index 006a8aa..eba35a2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-focus.ts
@@ -43,12 +43,12 @@
* - last (the element from the last request with same id gets the focus, not AJAX)
* - first (the first input element (without tabindex=-1) gets the focus, not AJAX)
*/
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
const activeInputs = Focus.activeInputs(element);
for (const focusable of activeInputs) {
- focusable.addEventListener("focus", function (event: FocusEvent) {
+ focusable.addEventListener("focus", function (event: FocusEvent): void {
const target = event.target as HTMLElement;
if (target.style.visibility !== "hidden" && target.style.display != "none") {
// remember the last focused element, for later
@@ -60,7 +60,7 @@
// autofocus in popups doesn't work automatically... so we fix that here
const modals = document.getElementsByClassName("modal");
for (let i = 0; i < modals.length; i++) {
- modals.item(i).addEventListener('shown.bs.modal', Focus.initAutoFocus);
+ modals.item(i).addEventListener("shown.bs.modal", Focus.initAutoFocus);
}
for (const hasDanger of DomUtils.selfOrElementsByClassName(element, ".has-danger")) {
@@ -97,7 +97,7 @@
}
};
- private static activeInputs(element: HTMLElement) {
+ private static activeInputs(element: HTMLElement): Array<HTMLElement> {
return DomUtils.selfOrQuerySelectorAll(element,
"input:not([type='hidden']):not([disabled]):not([tabindex='-1'])," +
"select:not([disabled]):not([tabindex='-1'])," +
@@ -107,7 +107,7 @@
&& element.style.display != "none");
}
- private static initAutoFocus(event) {
+ private static initAutoFocus(event): void {
const modal = event.currentTarget as HTMLElement;
(modal.querySelector("[autofocus]") as HTMLElement).focus();
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
index 446aeaa..81374fc 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-in.ts
@@ -40,7 +40,7 @@
this.element.addEventListener("change", this.checkValue.bind(this));
}
- checkValue(event: TextEvent) {
+ checkValue(event: TextEvent): void {
console.debug("changed: check if '%s' is okay!", this.regexp.toString());
if (!this.regexp.test(this.element.value)) {
this.element.classList.add("border-danger");
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
index 5629749..34f2588 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-jsf.ts
@@ -30,7 +30,7 @@
class Jsf {
- private static isId = function (id: string) {
+ private static isId = function (id: string): boolean {
switch (id) {
case JsfParameter.VIEW_STATE:
case JsfParameter.CLIENT_WINDOW:
@@ -44,7 +44,7 @@
}
};
- private static isBody = function (id) {
+ private static isBody = function (id): boolean {
switch (id) {
case JsfParameter.VIEW_ROOT:
case JsfParameter.VIEW_BODY:
@@ -54,13 +54,13 @@
}
};
- static init = function () {
- jsf.ajax.addOnEvent(function (event) {
+ static init = function (): void {
+ jsf.ajax.addOnEvent(function (event): void {
console.timeEnd("[tobago-jsf] jsf-ajax");
console.time("[tobago-jsf] jsf-ajax");
console.debug("[tobago-jsf] JSF event status: '%s'", event.status);
if (event.status === "success") {
- event.responseXML.querySelectorAll("update").forEach(function (update: Element) {
+ event.responseXML.querySelectorAll("update").forEach(function (update: Element): void {
const result = /<!\[CDATA\[(.*)]]>/gm.exec(update.innerHTML);
const id = update.id;
if (result !== null && result.length === 2 && result[1].startsWith("{\"reload\"")) {
@@ -80,7 +80,7 @@
}
});
} else if (event.status === "complete") {
- event.responseXML.querySelectorAll("update").forEach(function (update: Element) {
+ event.responseXML.querySelectorAll("update").forEach(function (update: Element): void {
const id = update.id;
if (Jsf.isId(id)) {
console.debug("[tobago-jsf] Update after jsf.ajax complete: #" + id);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-listener.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-listener.ts
index 7f7acd1..37f48c5 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-listener.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-listener.ts
@@ -48,11 +48,11 @@
[Order.LATER, []]
]);
- add(listener: (HTMLElement) => void, order: Order) {
+ add(listener: (HTMLElement) => void, order: Order): void {
this.map.get(order).push(listener);
}
- execute(element?: HTMLElement) {
+ execute(element?: HTMLElement): void {
this.map.forEach((listeners: Array<(HTMLElement) => void>, order: Order) => {
listeners.forEach(
@@ -86,7 +86,7 @@
static register(
listener: (HTMLElement) => void,
phase: Phase,
- order: Order = Order.NORMAL) {
+ order: Order = Order.NORMAL): void {
switch (phase) {
case Phase.DOCUMENT_READY:
@@ -112,37 +112,37 @@
}
}
- static executeDocumentReady(element: HTMLElement) {
+ static executeDocumentReady(element: HTMLElement): void {
console.time("[tobago] execute documentReady");
Listener.documentReady.execute(element);
console.timeEnd("[tobago] execute documentReady");
}
- static executeWindowLoad() {
+ static executeWindowLoad(): void {
console.time("[tobago] execute windowLoad");
Listener.windowLoad.execute();
console.timeEnd("[tobago] execute windowLoad");
}
- static executeBeforeSubmit() {
+ static executeBeforeSubmit(): void {
console.time("[tobago] execute beforeSubmit");
Listener.beforeSubmit.execute();
console.timeEnd("[tobago] execute beforeSubmit");
}
- static executeAfterUpdate(element: HTMLElement) {
+ static executeAfterUpdate(element: HTMLElement): void {
console.time("[tobago] execute afterUpdate");
Listener.afterUpdate.execute(element);
console.timeEnd("[tobago] execute afterUpdate");
}
- static executeBeforeUnload() {
+ static executeBeforeUnload(): void {
console.time("[tobago] execute beforeUnload");
Listener.beforeUnload.execute();
console.timeEnd("[tobago] execute beforeUnload");
}
- static executeBeforeExit() {
+ static executeBeforeExit(): void {
console.time("[tobago] execute beforeExit");
Listener.beforeExit.execute();
console.timeEnd("[tobago] execute beforeExit");
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
index 2be49b0..cdc4f2d 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-overlay.ts
@@ -53,7 +53,7 @@
overlay: HTMLDivElement;
- static destroy(id: string) {
+ static destroy(id: string): void {
console.debug("----> get overlay " + id);
const overlay = Overlay.overlayMap.get(id);
if (overlay) {
@@ -75,7 +75,7 @@
// create the overlay
- this.overlay = document.createElement('div');
+ this.overlay = document.createElement("div");
this.overlay.classList.add("tobago-page-overlay");
this.overlay.classList.add(
this.error ? "tobago-page-overlay-markup-error" : "tobago-page-overlay-markup-wait");
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts
index b7b595a..038e935 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-page.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-import {Tobago4Utils} from "./tobago-utils";
+import {DomUtils} from "./tobago-utils";
export class Page extends HTMLElement {
@@ -38,8 +38,8 @@
super();
}
- connectedCallback() {
- this.addEventListener("keypress", function (event: KeyboardEvent) {
+ connectedCallback(): void {
+ this.addEventListener("keypress", function (event: KeyboardEvent): boolean {
let code = event.which; // XXX deprecated
if (code === 0) {
code = event.keyCode;
@@ -62,7 +62,7 @@
command.dispatchEvent(new MouseEvent("click"));
break;
}
- id = Tobago4Utils.getNamingContainerId(id);
+ id = DomUtils.getNamingContainerId(id);
}
return false;
}
@@ -70,6 +70,6 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-page', Page);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-page", Page);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-panel.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-panel.ts
index 91620db..5ea5b14 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-panel.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-panel.ts
@@ -18,6 +18,6 @@
class Panel extends HTMLElement {
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-panel', Panel);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-panel", Panel);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popover.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popover.ts
index 795aea4..6a5c638 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popover.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popover.ts
@@ -19,17 +19,16 @@
class MessagePopover {
- static init = function (elements) {
- elements = elements.jQuery ? elements : jQuery(elements); // fixme jQuery -> ES5
- jQuery('[data-toggle="popover"]').popover({
+ static init = function (element: HTMLElement): void {
+ jQuery("[data-toggle=\"popover\"]").popover({
constraints: [
{
- to: 'window',
- attachment: 'together',
+ to: "window",
+ attachment: "together",
pin: true
}
],
- trigger: 'focus'
+ trigger: "focus"
});
};
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popup.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popup.ts
index d72f611..ba306cb 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popup.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-popup.ts
@@ -19,7 +19,7 @@
export class Popup extends HTMLElement {
- static close(button: HTMLElement) {
+ static close(button: HTMLElement): void {
BootstrapUtils.modal(button.closest(".modal"), "hide");
}
@@ -27,7 +27,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
const hidden = Collapse.findHidden(this);
if (hidden.value === "false") {
// XXX hack: this is needed for popups open by AJAX.
@@ -43,7 +43,7 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event: Event) {
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
window.customElements.define("tobago-popup", Popup);
});
@@ -53,7 +53,7 @@
return document.getElementById(element.id + "::collapse") as HTMLInputElement;
}
- static execute = function (action: string, target: HTMLElement) {
+ static execute = function (action: string, target: HTMLElement): void {
const hidden = Collapse.findHidden(target);
const isPopup = target.tagName === "TOBAGO-POPUP";
let newCollapsed;
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-reload.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-reload.ts
index ddc65e3..9ab43df 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-reload.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-reload.ts
@@ -37,7 +37,7 @@
this.timeouts = new Map<string, number>();
}
- public schedule(id: string, reloadMillis: number) {
+ public schedule(id: string, reloadMillis: number): void {
if (reloadMillis > 0) {
// may remove old schedule
@@ -49,7 +49,7 @@
}
// add new schedule
- let timeout = window.setTimeout(function () {
+ let timeout = window.setTimeout(function (): void {
console.debug("reloading #'" + id + "'");
jsf.ajax.request(
id,
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-scroll.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-scroll.ts
index 9a440f0..9b63452 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-scroll.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-scroll.ts
@@ -20,7 +20,7 @@
class Scroll {
- static initScrollPosition = function (element: HTMLElement) {
+ static initScrollPosition = function (element: HTMLElement): void {
for (const panel of DomUtils.selfOrQuerySelectorAll(element, "[data-tobago-scroll-panel]")) {
const hidden = panel.querySelector(":scope > [data-tobago-scroll-position]") as HTMLInputElement;
@@ -36,7 +36,7 @@
}
};
- static scroll = function (event: Event) {
+ static scroll = function (event: Event): void {
const panel = event.currentTarget as HTMLDivElement;
const scrollLeft = panel.scrollLeft;
const scrollTop = panel.scrollTop;
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-checkbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-checkbox.ts
index da659d8..23bf731 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-checkbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-checkbox.ts
@@ -20,7 +20,7 @@
class SelectBooleanCheckbox {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const checkbox of DomUtils.selfOrQuerySelectorAll(element, ".tobago-selectBooleanCheckbox input[readonly]")) {
checkbox.addEventListener("click", (event: Event) => {
// in the "readonly" case, prevent the default, which is changing the "checked" state
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-toggle.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-toggle.ts
index 1a6cab2..5da7e1b 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-toggle.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-boolean-toggle.ts
@@ -20,7 +20,7 @@
class SelectBooleanToggle {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const checkbox of DomUtils.selfOrQuerySelectorAll(element, ".tobago-selectBooleanCheckbox input[readonly]")) {
checkbox.addEventListener("click", (event: Event) => {
// in the "readonly" case, prevent the default, which is changing the "checked" state
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-checkbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-checkbox.ts
index 57000b6..01a04c0 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-checkbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-checkbox.ts
@@ -16,11 +16,11 @@
*/
import {Listener, Phase} from "./tobago-listener";
-import {DomUtils, Tobago4Utils} from "./tobago-utils";
+import {DomUtils} from "./tobago-utils";
class SelectManyCheckbox {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const checkbox of DomUtils.selfOrQuerySelectorAll(element, ".tobago-selectManyCheckbox input[readonly]")) {
checkbox.addEventListener("click", (event: Event) => {
// in the "readonly" case, prevent the default, which is changing the "checked" state
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-shuttle.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-shuttle.ts
index 061c76d..8db3da2 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-shuttle.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-many-shuttle.ts
@@ -20,7 +20,7 @@
class SelectManyShuttle {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const shuttle of DomUtils.selfOrQuerySelectorAll(
element, ".tobago-selectManyShuttle:not(.tobago-selectManyShuttle-disabled)")) {
@@ -56,17 +56,17 @@
}
};
- static moveSelectedItems = function (event: Event, direction: boolean, all: boolean) {
+ static moveSelectedItems = function (event: Event, direction: boolean, all: boolean): void {
const currentTarget = event.currentTarget as HTMLElement;
const shuttle = currentTarget.closest(".tobago-selectManyShuttle");
const unselected = shuttle.querySelector(".tobago-selectManyShuttle-unselected");
const selected = shuttle.querySelector(".tobago-selectManyShuttle-selected");
- var oldCount = selected.childElementCount;
+ const oldCount = selected.childElementCount;
const source = direction ? unselected : selected;
const target = direction ? selected : unselected;
const options = source.querySelectorAll(all ? "option:not(:disabled)" : "option:checked");
- var hidden = shuttle.querySelector(".tobago-selectManyShuttle-hidden");
- var hiddenOptions = hidden.querySelectorAll("option");
+ const hidden = shuttle.querySelector(".tobago-selectManyShuttle-hidden");
+ const hiddenOptions = hidden.querySelectorAll("option");
for (const option of options as NodeListOf<HTMLOptionElement>) {
source.removeChild(option);
target.appendChild(option);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-listbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-listbox.ts
index 8ac9294..2429e13 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-listbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-listbox.ts
@@ -16,11 +16,11 @@
*/
import {Listener, Phase} from "./tobago-listener";
-import {DomUtils, Tobago4Utils} from "./tobago-utils";
+import {DomUtils} from "./tobago-utils";
class SelectOneListbox {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const listbox of DomUtils.selfOrQuerySelectorAll(element, ".tobago-selectOneListbox:not(:required)")) {
listbox.addEventListener("change", (event: Event) => {
const target = event.currentTarget as HTMLSelectElement;
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-radio.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-radio.ts
index d0bc7f8..21c6edb 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-radio.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-select-one-radio.ts
@@ -16,14 +16,14 @@
*/
import {Listener, Phase} from "./tobago-listener";
-import {DomUtils, Tobago4Utils} from "./tobago-utils";
+import {DomUtils} from "./tobago-utils";
class SelectOneRadio {
- static init = function (element: HTMLElement) {
+ static init = function (element: HTMLElement): void {
for (const radio of DomUtils.selfOrQuerySelectorAll(element, ".tobago-selectOneRadio")) {
const id = radio.closest("[id]").id;
- const quotedId = id.replace(/([:.])/g, '\\$1');
+ const quotedId = id.replace(/([:.])/g, "\\$1");
const allConnected = document.querySelectorAll("input[name=" + quotedId + "]") as NodeListOf<HTMLInputElement>;
for (const connectedRadio of allConnected) {
connectedRadio.dataset["tobagoOldValue"] = String(connectedRadio.checked);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
index 451b092..d1401f3 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-sheet.ts
@@ -35,7 +35,7 @@
mousemoveData: any;
mousedownOnRowData: any;
- static init(element: HTMLElement) {
+ static init(element: HTMLElement): void {
console.time("[tobago-sheet] init");
for (const sheetElement of DomUtils.selfOrElementsByClassName(element, "tobago-sheet")) {
const sheet = new Sheet(sheetElement);
@@ -44,7 +44,7 @@
console.timeEnd("[tobago-sheet] init");
}
- private static getScrollBarSize() {
+ private static getScrollBarSize(): number {
const body = document.getElementsByTagName("body").item(0);
const outer = document.createElement("div");
@@ -63,7 +63,7 @@
return 100 - widthWithScroll;
}
- private static isInputElement(element: HTMLElement) {
+ private static isInputElement(element: HTMLElement): boolean {
return ["INPUT", "TEXTAREA", "SELECT", "A", "BUTTON"].indexOf(element.tagName) > -1;
}
@@ -151,7 +151,7 @@
// resize column: mouse events -------------------------------------------------------------------------------- //
for (const resizeElement of <NodeListOf<HTMLElement>>element.querySelectorAll(".tobago-sheet-headerResize")) {
- resizeElement.addEventListener("click", function () {
+ resizeElement.addEventListener("click", function (): boolean {
return false;
});
resizeElement.addEventListener("mousedown", this.mousedown.bind(this));
@@ -182,7 +182,7 @@
// todo: check if this works correctly
const sheet = Sheet.SHEETS.get(this.id);
if (sheet && sheet.dblClickActionId) {
- row.addEventListener("dblclick", function (event) {
+ row.addEventListener("dblclick", function (event: Event): void {
// todo: re-implement
sheet.doDblClick(event);
});
@@ -213,7 +213,7 @@
const pagingInput = pagingText.querySelector("input.tobago-sheet-pagingInput");
pagingInput.addEventListener("blur", this.blurPaging.bind(this));
- pagingInput.addEventListener("keydown", function (event: KeyboardEvent) {
+ pagingInput.addEventListener("keydown", function (event: KeyboardEvent): void {
if (event.keyCode === 13) {
event.stopPropagation();
event.preventDefault();
@@ -233,7 +233,7 @@
}
}
- saveColumnWidths(widths: number[]) {
+ saveColumnWidths(widths: number[]): void {
const hidden = document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "widths");
if (hidden) {
hidden.setAttribute("value", JSON.stringify(widths));
@@ -251,14 +251,14 @@
return JSON.parse(hidden.getAttribute("value"));
}
- addHeaderFillerWidth() {
+ addHeaderFillerWidth(): void {
const last = document.getElementById(this.id).querySelector(".tobago-sheet-headerTable col:last-child");
if (last) {
last.setAttribute("width", String(Sheet.SCROLL_BAR_SIZE));
}
}
- mousedown(event: MouseEvent) {
+ mousedown(event: MouseEvent): void {
Page.page().dataset["SheetMousedownData"] = this.id;
@@ -282,7 +282,7 @@
document.addEventListener("mouseup", mouseupListener);
}
- mousemove(event: MouseEvent) {
+ mousemove(event: MouseEvent): boolean {
console.debug("move");
let delta = event.clientX - this.mousemoveData.originalClientX;
delta = -Math.min(-delta, this.mousemoveData.originalHeaderColumnWidth - 10);
@@ -295,7 +295,7 @@
return false;
}
- mouseup(event: MouseEvent) {
+ mouseup(event: MouseEvent): boolean {
console.debug("up");
// switch off the mouse move listener
@@ -346,7 +346,7 @@
return false;
}
- scroll(event) {
+ scroll(event): void {
console.debug("scroll");
const sheetBody: HTMLElement = event.currentTarget;
@@ -359,7 +359,7 @@
JSON.stringify([Math.round(sheetBody.scrollLeft), Math.round(sheetBody.scrollTop)]));
}
- mousedownOnRow(event: MouseEvent) {
+ mousedownOnRow(event: MouseEvent): void {
console.debug("mousedownOnRow");
this.mousedownOnRowData = {
x: event.clientX,
@@ -367,7 +367,7 @@
};
}
- clickOnCheckbox(event: MouseEvent) {
+ clickOnCheckbox(event: MouseEvent): void {
const checkbox = event.currentTarget as HTMLInputElement;
if (checkbox.checked) {
this.selectAll();
@@ -376,7 +376,7 @@
}
}
- clickOnRow(event: MouseEvent) {
+ clickOnRow(event: MouseEvent): void {
const row = event.currentTarget as HTMLTableRowElement;
if (row.classList.contains("tobago-sheet-columnSelector") || !Sheet.isInputElement(row)) {
@@ -445,7 +445,7 @@
}
}
- clickOnPaging(event: MouseEvent) {
+ clickOnPaging(event: MouseEvent): void {
const element = event.currentTarget as HTMLElement;
const output = element.querySelector(".tobago-sheet-pagingOutput") as HTMLElement;
@@ -457,7 +457,7 @@
input.select();
}
- blurPaging(event: FocusEvent) {
+ blurPaging(event: FocusEvent): void {
const input = event.currentTarget as HTMLInputElement;
const output = input.parentElement.querySelector(".tobago-sheet-pagingOutput") as HTMLElement;
if (output.innerHTML !== input.value) {
@@ -479,7 +479,7 @@
}
}
- syncScrolling() {
+ syncScrolling(): void {
// sync scrolling of body to header
const header = this.getHeader();
if (header) {
@@ -515,11 +515,11 @@
return document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected") as HTMLInputElement;
}
- getHiddenScrollPosition() {
- return document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "scrollPosition");
+ getHiddenScrollPosition(): HTMLInputElement {
+ return document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "scrollPosition") as HTMLInputElement;
}
- doDblClick(event) {
+ doDblClick(event): void {
const row = event.currentTarget as HTMLTableRowElement;
const rowIndex = row.sectionRowIndex + this.getFirst();
if (this.dblClickActionId) {
@@ -560,7 +560,7 @@
return parseInt(this.getElement().dataset["tobagoFirst"]);
}
- isRowSelected(row: HTMLTableRowElement) {
+ isRowSelected(row: HTMLTableRowElement): boolean {
let rowIndex = +row.dataset["tobagoRowIndex"];
if (!rowIndex) {
rowIndex = row.sectionRowIndex + this.getFirst();
@@ -568,16 +568,16 @@
return this.isSelected(rowIndex);
}
- isSelected(rowIndex: number) {
+ isSelected(rowIndex: number): boolean {
const value = <number[]>JSON.parse(this.getHiddenSelected().value);
return value.indexOf(rowIndex) > -1;
}
- resetSelected() {
+ resetSelected():void {
this.getHiddenSelected().value = JSON.stringify([]);
}
- toggleSelection(row: HTMLTableRowElement, checkbox: HTMLInputElement) {
+ toggleSelection(row: HTMLTableRowElement, checkbox: HTMLInputElement): void {
this.getElement().dataset["tobagoLastClickedRowIndex"] = String(row.sectionRowIndex);
if (checkbox && !checkbox.disabled) {
const selected = this.getHiddenSelected();
@@ -590,24 +590,24 @@
}
}
- selectAll() {
+ selectAll(): void {
const rows = this.getRows();
this.selectRange(rows, 0, rows.length - 1, true, false);
}
- deselectAll() {
+ deselectAll(): void {
const rows = this.getRows();
this.selectRange(rows, 0, rows.length - 1, false, true);
}
- toggleAll() {
+ toggleAll(): void {
const rows = this.getRows();
this.selectRange(rows, 0, rows.length - 1, true, true);
}
selectRange(
rows: NodeListOf<HTMLTableRowElement>, first: number, last: number, selectDeselected: boolean,
- deselectSelected: boolean) {
+ deselectSelected: boolean): void {
const selected = this.getHiddenSelected();
const value = new Set<number>(JSON.parse(selected.value));
for (let i = first; i <= last; i++) {
@@ -640,13 +640,13 @@
* @param row tr-element: the row.
* @param checkbox input-element: selector in the row.
*/
- selectRow(selected: HTMLInputElement, rowIndex: number, row: HTMLTableRowElement, checkbox: HTMLInputElement) {
+ selectRow(selected: HTMLInputElement, rowIndex: number, row: HTMLTableRowElement, checkbox: HTMLInputElement): void {
const selectedSet = new Set<number>(JSON.parse(selected.value));
selected.value = JSON.stringify(Array.from(selectedSet.add(rowIndex)));
row.classList.add("tobago-sheet-row-markup-selected");
row.classList.add("table-info");
checkbox.checked = true;
- setTimeout(function () {
+ setTimeout(function ():void {
checkbox.checked = true;
}, 0);
}
@@ -657,7 +657,8 @@
* @param row tr-element: the row.
* @param checkbox input-element: selector in the row.
*/
- deselectRow(selected: HTMLInputElement, rowIndex: number, row: HTMLTableRowElement, checkbox: HTMLInputElement) {
+ deselectRow(
+ selected: HTMLInputElement, rowIndex: number, row: HTMLTableRowElement, checkbox: HTMLInputElement): void {
const selectedSet = new Set<number>(JSON.parse(selected.value));
selectedSet.delete(rowIndex);
selected.value = JSON.stringify(Array.from(selectedSet));
@@ -665,7 +666,7 @@
row.classList.remove("table-info");
checkbox.checked = false;
// XXX check if this is still needed... Async because of TOBAGO-1312
- setTimeout(function () {
+ setTimeout(function (): void {
checkbox.checked = false;
}, 0);
}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
index c3bc661..2da4fcf 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-split-layout.ts
@@ -57,7 +57,7 @@
this.setAttribute("orientation", orientation);
}
- start(event: MouseEvent) {
+ start(event: MouseEvent): void {
event.preventDefault();
const splitter = event.target as HTMLElement;
const previous = DomUtils.previousElementSibling(splitter);
@@ -121,11 +121,11 @@
return new SplitLayoutMousedown(data);
}
- static load() {
+ static load(): SplitLayoutMousedown {
return new SplitLayoutMousedown(Page.page().dataset["SplitLayoutMousedownData"]);
}
- static remove() {
+ static remove(): void {
Page.page().dataset["SplitLayoutMousedownData"] = null;
}
@@ -155,6 +155,6 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-split-layout', SplitLayout);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-split-layout", SplitLayout);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-stars.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-stars.ts
index 8d960d6..6b40bff 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-stars.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-stars.ts
@@ -23,7 +23,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
const hiddenInput = this.querySelector("input[type=hidden]") as HTMLInputElement;
const container = this.querySelector(".tobago-stars-container") as HTMLElement;
const tooltip = container.querySelector(".tobago-stars-tooltip") as HTMLElement;
@@ -61,23 +61,23 @@
if (!readonly && !disabled) {
/* preselectMode is a Workaround for IE11: fires change event instead of input event */
let preselectMode = false;
- slider.addEventListener('mousedown', function (event) {
+ slider.addEventListener("mousedown", function (event: Event): void {
preselectMode = true;
});
- slider.addEventListener('mouseup', function (event) {
+ slider.addEventListener("mouseup", function (event: Event): void {
preselectMode = false;
selectStars();
});
- slider.addEventListener('input', function (event) {
+ slider.addEventListener("input", function (event: Event): void {
preselectStars();
});
- slider.addEventListener('touchend', function (event) {
+ slider.addEventListener("touchend", function (event: Event): void {
/* Workaround for mobile devices. TODO: fire AJAX request for 'touchend' */
// slider.trigger("change");
slider.dispatchEvent(new Event("change"));
});
- slider.addEventListener('change', function (event) {
+ slider.addEventListener("change", function (event: Event): void {
if (preselectMode) {
preselectStars();
} else {
@@ -85,12 +85,12 @@
}
});
- slider.addEventListener('touchstart', touchstart);
- slider.addEventListener('touchmove', touchstart);
+ slider.addEventListener("touchstart", touchstart);
+ slider.addEventListener("touchmove", touchstart);
}
// XXX current issue: on ios-Safari select 5 stars and than click on 1 star doesn't work on labeled component.
- function touchstart(event: TouchEvent) {
+ function touchstart(event: TouchEvent): void {
/* Workaround for Safari browser on iPhone */
const target = event.currentTarget as HTMLInputElement;
const sliderValue = (parseInt(target.max) / target.offsetWidth)
@@ -105,7 +105,7 @@
preselectStars();
}
- function preselectStars() {
+ function preselectStars(): void {
tooltip.classList.add("show");
if (parseInt(slider.value) > 0) {
@@ -127,7 +127,7 @@
}
}
- function selectStars() {
+ function selectStars(): void {
tooltip.classList.remove("show");
preselected.classList.remove("show");
@@ -160,6 +160,6 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-stars', Stars);
+document.addEventListener("DOMContentLoaded", function (event:Event): void {
+ window.customElements.define("tobago-stars", Stars);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
index 586194c..b83efaf 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-suggest.ts
@@ -23,13 +23,13 @@
hiddenInput: HTMLInputElement;
- static loadFromServer = function (input: HTMLInputElement) {
+ static loadFromServer = function (input: HTMLInputElement): (query, syncResults, asyncResults) => void {
let timeout;
- return function findMatches(query, syncResults, asyncResults) {
+ return function findMatches(query, syncResults, asyncResults): void {
- const root = input.getRootNode() as ShadowRoot|Document;
+ const root = input.getRootNode() as ShadowRoot | Document;
let suggest = root.getElementById(input.dataset["tobagoSuggestFor"]) as Suggest;
// todo: suggest.hiddenInput.value should contain the last query value
@@ -41,7 +41,7 @@
const delay = suggest.delay;
- timeout = setTimeout(function () {
+ timeout = setTimeout(function (): void {
suggest.hiddenInput.value = query;
Suggest.asyncResults = asyncResults;
delete suggest.dataset["tobagoSuggestData"];
@@ -61,10 +61,10 @@
};
};
- static fromClient = function (data) {
- return function findMatches(query, syncResults) {
- var result = [];
- for (var i = 0; i < data.length; i++) {
+ static fromClient = function (data): (query, syncResults) => void {
+ return (query, syncResults): void => {
+ const result = [];
+ for (let i = 0; i < data.length; i++) {
if (data[i].indexOf(query) >= 0) {
result.push(data[i]);
}
@@ -153,8 +153,8 @@
}
}
- connectedCallback() {
- const root = this.getRootNode() as ShadowRoot|Document;
+ connectedCallback(): void {
+ const root = this.getRootNode() as ShadowRoot | Document;
const input = root.getElementById(this.for) as HTMLInputElement;
const $input = jQuery(input);
@@ -167,12 +167,11 @@
input.dataset["tobagoSuggestFor"] = this.id;
input.autocomplete = "off";
- var source;
+ let source;
if (this.update) {
source = Suggest.loadFromServer(input);
} else {
- var data2 = this.data;
- source = Suggest.fromClient(data2);
+ source = Suggest.fromClient(this.data);
}
let suggestPopup = root.getElementById(this.id + "::popup");
@@ -197,7 +196,7 @@
source: source
});
// old with jQuery:
- $input.on('typeahead:change', function (event: JQuery.Event) {
+ $input.on("typeahead:change", function (event: JQuery.Event): void {
const input = this;
input.dispatchEvent(new Event("change"));
});
@@ -208,7 +207,7 @@
// });
// old with jQuery:
- $input.on('typeahead:open', function (event: JQuery.Event) {
+ $input.on("typeahead:open", function (event: JQuery.Event): void {
const input = this;
const suggestPopup = root.getElementById(input.dataset["tobagoSuggestFor"] + "::popup");
suggestPopup.style.top = DomUtils.offset(input).top + input.offsetHeight + "px";
@@ -229,6 +228,6 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
window.customElements.define("tobago-suggest", Suggest);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tab.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tab.ts
index e99b522..0046888 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tab.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tab.ts
@@ -24,7 +24,7 @@
this.hiddenInput = this.querySelector(":scope > input[type=hidden]");
}
- connectedCallback() {
+ connectedCallback(): void {
}
get switchType(): string {
@@ -55,7 +55,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
let navLink = this.navLink;
if (!navLink.classList.contains("disabled")) {
navLink.addEventListener("click", this.select.bind(this));
@@ -74,7 +74,7 @@
return this.closest("tobago-tab-group") as TabGroup;
}
- select(event: MouseEvent) {
+ select(event: MouseEvent): void {
const tabGroup = this.tabGroup;
const old = tabGroup.getSelectedTab();
tabGroup.selected = this.index;
@@ -113,7 +113,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
}
get index(): number {
@@ -121,8 +121,8 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
- window.customElements.define('tobago-tab', Tab);
- window.customElements.define('tobago-tab-content', TabContent);
- window.customElements.define('tobago-tab-group', TabGroup);
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
+ window.customElements.define("tobago-tab", Tab);
+ window.customElements.define("tobago-tab-content", TabContent);
+ window.customElements.define("tobago-tab-group", TabGroup);
});
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
index 8d0e04a..4c7b458 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree-listbox.ts
@@ -22,7 +22,7 @@
id: string;
- static init = function (element) {
+ static init = function (element: HTMLElement): void {
for (const treeListbox of DomUtils.selfOrElementsByClassName(element, "tobago-treeListbox")) {
new TreeListbox(treeListbox);
}
@@ -48,7 +48,7 @@
}
}
- onChange(event: TextEvent) {
+ onChange(event: TextEvent): void {
let listbox = event.currentTarget as HTMLSelectElement;
for (const child of listbox.children) {
const option = child as HTMLOptionElement;
@@ -89,7 +89,7 @@
}
}
- setSelected(option: HTMLOptionElement) {
+ setSelected(option: HTMLOptionElement): void {
const hidden = document.getElementById(this.id + DomUtils.SUB_COMPONENT_SEP + "selected") as HTMLInputElement;
if (hidden) {
let value = <number[]>JSON.parse(hidden.value);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
index b5056f4..64b1c2f 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-tree.ts
@@ -23,7 +23,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
}
get isSheet(): boolean {
@@ -95,7 +95,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
if (this.isExpandable() && this.toggles !== null) {
this.toggles.forEach(element => element.addEventListener("click", this.toggleNode.bind(this)));
}
@@ -204,7 +204,7 @@
}
}
- showNodes(treeChildNodes: NodeListOf<TreeNode>) {
+ showNodes(treeChildNodes: NodeListOf<TreeNode>): void {
for (const treeChildNode of treeChildNodes) {
if (treeChildNode.tree.isSheet) {
@@ -224,7 +224,7 @@
super();
}
- connectedCallback() {
+ connectedCallback(): void {
this.input.addEventListener("change", this.select.bind(this));
if (this.tree.selectable === Selectable.multiCascade) {
@@ -276,7 +276,7 @@
}
}
-document.addEventListener("DOMContentLoaded", function (event) {
+document.addEventListener("DOMContentLoaded", function (event: Event): void {
window.customElements.define("tobago-tree-select", TreeSelect);
window.customElements.define("tobago-tree-node", TreeNode);
window.customElements.define("tobago-tree", Tree);
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
index d3dd795..30153a0 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-utils.ts
@@ -20,12 +20,12 @@
/**
* JSF's component separator constant
*/
- static readonly COMPONENT_SEP = ':';
+ static readonly COMPONENT_SEP = ":";
/**
- * Tobago's sub-coponent separator constant
+ * Tobago's sub-component separator constant
*/
- static readonly SUB_COMPONENT_SEP = '::';
+ static readonly SUB_COMPONENT_SEP = "::";
/**
* Find all elements (and also self) which have the class "className".
@@ -89,12 +89,12 @@
return null;
}
- static outerWidthWithMargin(element: HTMLElement) {
+ static outerWidthWithMargin(element: HTMLElement): number {
const style = window.getComputedStyle(element);
return element.offsetWidth + parseInt(style.marginLeft) + parseInt(style.marginRight);
}
- static outerHeightWithMargin(element: HTMLElement) {
+ static outerHeightWithMargin(element: HTMLElement): number {
const style = window.getComputedStyle(element);
return element.offsetHeight + parseInt(style.marginTop) + parseInt(style.marginBottom);
}
@@ -113,7 +113,7 @@
return {top: top, left: left};
}
- static isVisible(element: HTMLElement) {
+ static isVisible(element: HTMLElement): boolean {
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
}
@@ -123,24 +123,7 @@
* @return A string which can be used as a jQuery selector.
*/
static escapeClientId(id: string): string {
- return '#' + id.replace(/([:\.])/g, '\\$1');
- }
-
-}
-
-export class Tobago4Utils {
-
- /**
- * Helps to select either elements from the whole DOM or only find in sub trees
- * (in the case of AJAX partial rendering)
- * @param elements a jQuery object to initialize (ajax) or null for initializing the whole document (full load).
- * @param selector a jQuery selector.
- */
- static selectWithJQuery(elements, selector) {
- elements = elements.jQuery ? elements : jQuery(elements); // fixme jQuery -> ES5
- return elements == null
- ? jQuery(selector)
- : elements.find(selector).add(elements.filter(selector));
+ return "#" + id.replace(/([:\.])/g, "\\$1");
}
/**
@@ -151,27 +134,26 @@
* "a:b::sub-component" -> "a"
* "a::sub-component:b" -> "a::sub-component" // should currently not happen in Tobago
*
- * @param id The clientId of a component.
+ * @param clientId The clientId of a component.
* @return The clientId of the naming container.
*/
- static getNamingContainerId(id) {
- if (id == null) {
+ static getNamingContainerId(clientId: string): string {
+ if (clientId == null || clientId.lastIndexOf(DomUtils.COMPONENT_SEP) === -1) {
return null;
}
- if (id.lastIndexOf(":") == -1) {
- return null;
- }
+
+ let id = clientId;
while (true) {
- var sub = id.lastIndexOf("::");
+ const sub = id.lastIndexOf(DomUtils.SUB_COMPONENT_SEP);
if (sub == -1) {
break;
}
- if (sub + 1 == id.lastIndexOf(":")) {
+ if (sub + 1 == id.lastIndexOf(DomUtils.COMPONENT_SEP)) {
id = id.substring(0, sub);
} else {
break;
}
}
- return id.substring(0, id.lastIndexOf(":"));
+ return id.substring(0, id.lastIndexOf(DomUtils.COMPONENT_SEP));
}
-}
\ No newline at end of file
+}
diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/tslint.json b/tobago-theme/tobago-theme-standard/src/main/npm/tslint.json
index 49e3aa9..b644691 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/tslint.json
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/tslint.json
@@ -8,6 +8,12 @@
],
"max-line-length": {
"options": [120]
- }
+ },
+ "no-consecutive-blank-lines": true,
+ "no-var-keyword": true,
+ "no-parameter-reassignment": true,
+ "quotemark": [true, "double"],
+ "typedef": [true, "call-signature"],
+ "indent": [true, "spaces", 2]
}
}