Skip to content

Commit

Permalink
js-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
cuioss committed Jul 24, 2024
1 parent 37abbe0 commit 249bdf8
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import de.cuioss.jsf.api.components.partial.ModelProvider;
import de.cuioss.jsf.api.components.util.CuiState;
import de.cuioss.jsf.bootstrap.BootstrapFamily;

import jakarta.faces.application.ResourceDependency;
import jakarta.faces.component.FacesComponent;

import java.io.Serializable;
import java.util.List;

Expand All @@ -49,6 +50,7 @@
* @author Sven Haag
*/
@FacesComponent(BootstrapFamily.NAVIGATION_MENU_COMPONENT)
@ResourceDependency(library = "javascript.enabler", name = "enabler.sub_menu.js", target = "head")
public class NavigationMenuComponent extends AbstractBaseCuiComponent {

private static final String MODEL_ITEMS_KEY = "modelItems";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Used for initializing GuardedInput components.
* The implementation assumes JQuery, faces.js and cui.jsf being present.
*/
let intitializeHelpTexts = function () {
let initializeHelpTexts = function () {
jQuery('[data-help-input-button]').each(function () {
let helpButton = jQuery(this);
helpButton.prop('onclick', null); // Fix for IE 11
Expand All @@ -22,5 +22,5 @@ let intitializeHelpTexts = function () {

// Should be loaded at document-ready
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(intitializeHelpTexts);
Cui.Core.registerComponentEnabler(initializeHelpTexts);
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Used for initializing GuardedInput components.
* The implementation assumes JQuery, faces.js and cui.jsf being present.
*/
let intitializeInputGuards = function () {
let initializeInputGuards = function () {
jQuery('[data-input-guard-button]').each(function () {
let guardButton = jQuery(this);
guardButton.prop('onclick', null); // Fix for IE 11
Expand Down Expand Up @@ -33,5 +33,5 @@ let intitializeInputGuards = function () {

// Should be loaded at document-ready
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(intitializeInputGuards);
Cui.Core.registerComponentEnabler(initializeInputGuards);
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ jQuery(document).ready(function () {
if (updateString === "@none") {
return;
}
F
// split by "+" (urlencoded space)
let updateStringSplit = updateString.split("+");
for (const element of updateStringSplit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/**
* Used for initializing modal-control components. The implementations assumes
* JQuery being present, If present the initial handler, e.g. onclick will be removed.
* Used for initializing modal-control components. The implementations assume
* JQuery being present, If present the initial handler, e.g., onclick will be removed.
*/
let intitializeModalControl = function() {
jQuery('[data-modal-for]').each(function(i, filtered) {
let initializeModalControl = function () {
jQuery('[data-modal-for]').each(function (i, filtered) {
let element = jQuery(filtered);
let forid = element.data("modal-for");
let forId = element.data("modal-for");
let action = element.data("modal-action");
let event = element.data("modal-event");
// Remove existing handler
element.prop("on" + event, null);
element.on(event, function(e) {
let modal = jQuery('[data-modal-dialog-id=' + forid + ']');
element.on(event, function (e) {
let modal = jQuery('[data-modal-dialog-id=' + forId + ']');
if (modal.length === 0) {
console.error("Invalid forId: " + forid + ", not existing element");
console.error("Invalid forId: " + forId + ", not existing element");
} else {
modal.modal(action);
e.stopPropagation();
Expand All @@ -25,6 +25,6 @@ let intitializeModalControl = function() {
};

// Should be loaded at document-ready
jQuery(document).ready(function() {
Cui.Core.registerComponentEnabler(intitializeModalControl);
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(initializeModalControl);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* assumes JQuery and faces.js being present
*/

let intitializeNotificationbox = function () {
let initializeNotificationbox = function () {
jQuery('.alert-dismissible > [data-dismiss="alert"][data-dismiss-listener="true"]').each(function () {
$(this).parent().one('close.bs.alert', function () {
faces.ajax.request($(this).attr('id'), null, {execute: '@this'});
Expand All @@ -13,5 +13,5 @@ let intitializeNotificationbox = function () {

// Should be loaded at document-ready
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(intitializeNotificationbox);
Cui.Core.registerComponentEnabler(initializeNotificationbox);
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ let cuiUpdateCollapsiblePanelServerState = function (panelId, isExpanded, event)
* Update component state
* @param {string} panelId - panel ID
* @param {boolean} isExpanded - state after transition
* @param {boolean} isAsyncUpdate - update server side state
*/
let cuiUpdateCollapsiblePanelState = function (panelId, isExpanded, event) {
let panelStateHolder = jQuery(Cui.Utilities.escapeClientId(panelId) + "_isexpanded");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
/**
* Used to initialize bootstraps popover components.
* Used to initialize bootstrap's popover components.
*/
let intitializePopovers = function() {
let initializePopovers = function() {
jQuery('[data-toggle="popover"]').each(function(i, filtered) {
let element = jQuery(filtered);
let isHtmlContent = element.data("html") + "" === "true";
let content = element.data("content");
let contentwrapper = element.data("contentwrapper");
let contentWrapper = element.data("contentwrapper");
let placement = element.data("placement");
let selector = element.data("selector");
let title = element.data("title");
let trigger = element.data("trigger");
let viewport = element.data("viewport");

if (contentwrapper) {
content = jQuery(Cui.Utilities.escapeClientId(contentwrapper)).html();
if (contentWrapper) {
content = jQuery(Cui.Utilities.escapeClientId(contentWrapper)).html();
}

if (selector) {
selector = Cui.Utilities.escapeClientId(selector);
}

if (viewport) {
viewport = Cui.Utilities.escapeClientId(viewport);
}
Expand All @@ -39,5 +37,5 @@ let intitializePopovers = function() {

// Should be loaded at document-ready
jQuery(document).ready(function() {
Cui.Core.registerComponentEnabler(intitializePopovers);
Cui.Core.registerComponentEnabler(initializePopovers);
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** Selectize.js init for the cui:tagInput Component */
let initSelectize = function() {
jQuery("[data-selectize='true']").each(function() {
let initializeSelectize = function () {
jQuery("[data-selectize='true']").each(function () {
let component = jQuery(this);

if (component[0].selectize !== undefined) {
Expand All @@ -11,7 +11,7 @@ let initSelectize = function() {
options["valueField"] = "value";
options["labelField"] = "label";
options["searchField"] = "label";
options["sortField"] = [{ field: 'label', direction: 'asc' }];
options["sortField"] = [{field: 'label', direction: 'asc'}];

options["maxItems"] = component.data("maxitems");
options["wrapperClass"] = component.data("wrapperclass");
Expand All @@ -20,8 +20,8 @@ let initSelectize = function() {
options["options"] = component.data("options");

if (component.data("cancreate")) {
options["create"] = function(input) {
return { value: '_client_created_' + input, label: input }
options["create"] = function (input) {
return {value: '_client_created_' + input, label: input}
};
}

Expand All @@ -39,6 +39,6 @@ let initSelectize = function() {
/**
* Registering this script to all AJAX requests/responses and page load.
*/
jQuery(document).ready(function() {
Cui.Core.registerComponentEnabler(initSelectize);
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(initializeSelectize);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Bootstrap 3 Triple Nested Sub-Menus
* This script will activate Triple level multi drop-down menus in Bootstrap 3.
*/

let initializeSubMenus = function () {

jQuery('ul.dropdown-menu [data-toggle=dropdown]').on('click', function (event) {
// Avoid following the href location when clicking
event.preventDefault();
// Avoid having the menu to close when clicking
event.stopPropagation();
// Re-add .open to parent sub-menu item
jQuery(this).parent().addClass('open');
jQuery(this).parent().find("ul").parent().find("li.dropdown").addClass('open');
});
};

// Should be loaded at document-ready
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(initializeSubMenus);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
* <span class="switch-text" data-item-active="false">offText</span>
* </div>
*/
let initSwitch = function () {
let initializeSwitch = function () {
let classHidden = "hidden";
jQuery(".switch-placing").each(function () {
let input = jQuery(this).find(".switch input");
let onText = jQuery(this).find(".switch-text[data-item-active='true']");
let offText = jQuery(this).find(".switch-text[data-item-active='false']");

jQuery(input).change(function () {
if(jQuery(this)[0].checked){
if (jQuery(this)[0].checked) {
onText.removeClass(classHidden);
offText.addClass(classHidden);
}
else {
} else {
onText.addClass(classHidden);
offText.removeClass(classHidden);
}
Expand All @@ -33,5 +32,5 @@ let initSwitch = function () {
* Registering this script to all AJAX requests/responses and page load.
*/
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(initSwitch);
Cui.Core.registerComponentEnabler(initializeSwitch);
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* assumes JQuery and faces.js being present
*/

let intitializeTooltips = function () {
let initializeTooltips = function () {
jQuery('[data-toggle="tooltip"]').tooltip();
};

// Should be loaded at document-ready
jQuery(document).ready(function () {
Cui.Core.registerComponentEnabler(intitializeTooltips);
Cui.Core.registerComponentEnabler(initializeTooltips);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,6 @@ namespace Cui {
});
}

public static enableSubMenu(): void {
jQuery(() => {
/**
* NAME: Bootstrap 3 Triple Nested Sub-Menus
* This script will active Triple level multi drop-down menus in Bootstrap 3.*
*/
jQuery('ul.dropdown-menu [data-toggle=dropdown]').on('click', function (event: {
preventDefault: () => void;
stopPropagation: () => void;
}) {
// Avoid following the href location when clicking
event.preventDefault();
// Avoid having the menu to close when clicking
event.stopPropagation();
// Re-add .open to parent sub-menu item
jQuery(this).parent().addClass('open');
jQuery(this).parent().find("ul").parent().find("li.dropdown").addClass('open');
});
});
}

private static getKeyCodeByName(key: number): string {
switch (key) {
case 27:
Expand Down Expand Up @@ -78,7 +57,7 @@ namespace Cui {
// Access the tag object
const tag: JQuery = jQuery(Cui.Utilities.escapeClientId(target));

// Hidden field for dispose state
// Hidden field for disposed state
const disposeInfo: JQuery = jQuery(Cui.Utilities.escapeClientId(target) + "_disposed-info");
disposeInfo.val("true");

Expand Down

0 comments on commit 249bdf8

Please sign in to comment.