OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Setup listeners so that they run on turbo:load
Oliver Günther7045e836b01b
diff --git a/frontend/src/app/core/setup/globals/global-listeners.ts b/frontend/src/app/core/setup/globals/global-listeners.tsindex cf37cfab8b7..3cc5cd99747 100644--- a/frontend/src/app/core/setup/globals/global-listeners.ts+++ b/frontend/src/app/core/setup/globals/global-listeners.ts@@ -26,18 +26,8 @@// See COPYRIGHT and LICENSE files for more details.//++-import { registerRequestForConfirmation } from 'core-app/core/setup/globals/global-listeners/request-for-confirmation';-import { DeviceService } from 'core-app/core/browser/device.service';-import { scrollHeaderOnMobile } from 'core-app/core/setup/globals/global-listeners/top-menu-scroll';-import { setupToggableFieldsets } from 'core-app/core/setup/globals/global-listeners/toggable-fieldset';-import { installMenuLogic } from 'core-app/core/setup/globals/global-listeners/action-menu';-import { makeColorPreviews } from 'core-app/core/setup/globals/global-listeners/color-preview';-import { dangerZoneValidation } from 'core-app/core/setup/globals/global-listeners/danger-zone-validation';import { setupServerResponse } from 'core-app/core/setup/globals/global-listeners/setup-server-response';-import { listenToSettingChanges } from 'core-app/core/setup/globals/global-listeners/settings';-import { detectOnboardingTour } from 'core-app/core/setup/globals/onboarding/onboarding_tour_trigger';import { openExternalLinksInNewTab, performAnchorHijacking } from './global-listeners/link-hijacking';-import { fixFragmentAnchors } from 'core-app/core/setup/globals/global-listeners/fix-fragment-anchors';/*** A set of listeners that are relevant on every page to set sensible defaults@@ -104,14 +94,6 @@ export function initializeGlobalListeners():void {window.OpenProject.pageIsSubmitted = true;});- // Add to content if warnings displayed- if (document.querySelector('.warning-bar--item')) {- const content = document.querySelector('#content') as HTMLElement;- if (content) {- content.style.marginBottom = '100px';- }- }-// Global beforeunload hookjQuery(window).on('beforeunload', (e:JQuery.TriggeredEvent) => {const event = e.originalEvent as BeforeUnloadEvent;@@ -125,49 +107,11 @@ export function initializeGlobalListeners():void {// Disable global drag & drop handling, which results in the browser loading the image and losing the pagejQuery(document.documentElement)- .on('dragover drop', (evt:any) => {+ .on('dragover drop', (evt:Event) => {evt.preventDefault();return false;});- // Allow forms with [request-for-confirmation]- // to show the password confirmation dialog- registerRequestForConfirmation(jQuery);-- const deviceService:DeviceService = new DeviceService();- // Register scroll handler on mobile header- if (deviceService.isMobile) {- scrollHeaderOnMobile();- }-- // Detect and trigger the onboarding tour- // through a lazy loaded script- detectOnboardingTour();-- //- // Legacy scripts from app/assets that are not yet component based- //-- // Toggable fieldsets- setupToggableFieldsets();-- // Action menu logic- jQuery('.toolbar-items').each((idx:number, menu:HTMLElement) => {- installMenuLogic(jQuery(menu));- });-- // Legacy settings listener- listenToSettingChanges();-- // Color patches preview the color- makeColorPreviews();-- // Danger zone input validation- dangerZoneValidation();-// Bootstrap legacy app codesetupServerResponse();-- // Replace fragment- fixFragmentAnchors();}diff --git a/frontend/src/app/core/setup/globals/global-listeners/setup-server-response.ts b/frontend/src/app/core/setup/globals/global-listeners/setup-server-response.tsindex 6f07838b76b..fd0e40cba3f 100644--- a/frontend/src/app/core/setup/globals/global-listeners/setup-server-response.ts+++ b/frontend/src/app/core/setup/globals/global-listeners/setup-server-response.ts@@ -1,11 +1,6 @@// Legacy code ported from app/assets/javascripts/application.js.erb// Do not add stuff here, but ideally remove into components whenever changes are necessaryexport function setupServerResponse() {- initMainMenuExpandStatus();- focusFirstErroneousField();- activateFlashNotice();- activateFlashError();-jQuery(document).ajaxComplete(activateFlashNotice);jQuery(document).ajaxComplete(activateFlashError);@@ -103,7 +98,7 @@ function addClickEventToAllErrorMessages() {});}-function initMainMenuExpandStatus() {+export function initMainMenuExpandStatus() {const wrapper = jQuery('#wrapper');const upToggle = jQuery('ul.menu_root.closed li.open a.arrow-left-to-project');@@ -121,15 +116,15 @@ function activateFlash(selector:any) {});}-function activateFlashNotice() {+export function activateFlashNotice() {activateFlash('.op-toast[role="alert"]');}-function activateFlashError() {+export function activateFlashError() {activateFlash('.errorExplanation[role="alert"]');}-function focusFirstErroneousField() {+export function focusFirstErroneousField() {const firstErrorSpan = jQuery('span.errorSpan').first();const erroneousInput = firstErrorSpan.find('*').filter(':input');diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.tsindex 8d3f17b5053..0a32ec07b8a 100644--- a/frontend/src/turbo/setup.ts+++ b/frontend/src/turbo/setup.ts@@ -4,6 +4,7 @@ import TurboPower from 'turbo_power';import { registerDialogStreamAction } from './dialog-stream-action';import { addTurboEventListeners } from './turbo-event-listeners';import { registerFlashStreamAction } from './flash-stream-action';+import { addTurboGlobalListeners } from './turbo-global-listeners';import { applyTurboNavigationPatch } from './turbo-navigation-patch';import { debugLog, whenDebugging } from 'core-app/shared/helpers/debug_output';import { TURBO_EVENTS } from './constants';@@ -25,6 +26,7 @@ whenDebugging(() => {// Register our own actionsaddTurboEventListeners();+addTurboGlobalListeners();registerDialogStreamAction();registerFlashStreamAction();diff --git a/frontend/src/turbo/turbo-global-listeners.ts b/frontend/src/turbo/turbo-global-listeners.tsnew file mode 100644index 00000000000..eaae07ebb2c--- /dev/null+++ b/frontend/src/turbo/turbo-global-listeners.ts@@ -0,0 +1,72 @@+import { registerRequestForConfirmation } from 'core-app/core/setup/globals/global-listeners/request-for-confirmation';+import { DeviceService } from 'core-app/core/browser/device.service';+import { scrollHeaderOnMobile } from 'core-app/core/setup/globals/global-listeners/top-menu-scroll';+import { detectOnboardingTour } from 'core-app/core/setup/globals/onboarding/onboarding_tour_trigger';+import { setupToggableFieldsets } from 'core-app/core/setup/globals/global-listeners/toggable-fieldset';+import { installMenuLogic } from 'core-app/core/setup/globals/global-listeners/action-menu';+import { listenToSettingChanges } from 'core-app/core/setup/globals/global-listeners/settings';+import { makeColorPreviews } from 'core-app/core/setup/globals/global-listeners/color-preview';+import { dangerZoneValidation } from 'core-app/core/setup/globals/global-listeners/danger-zone-validation';+import { fixFragmentAnchors } from 'core-app/core/setup/globals/global-listeners/fix-fragment-anchors';+import {+ activateFlashError,+ activateFlashNotice,+ focusFirstErroneousField,+ initMainMenuExpandStatus,+} from 'core-app/core/setup/globals/global-listeners/setup-server-response';++export function addTurboGlobalListeners() {+ document.addEventListener('turbo:load', (event) => {+ // Add to content if warnings displayed+ if (document.querySelector('.warning-bar--item')) {+ const content = document.querySelector('#content') as HTMLElement;+ if (content) {+ content.style.marginBottom = '100px';+ }+ }++ // Allow forms with [request-for-confirmation]+ // to show the password confirmation dialog+ registerRequestForConfirmation(jQuery);++ const deviceService:DeviceService = new DeviceService();+ // Register scroll handler on mobile header+ if (deviceService.isMobile) {+ scrollHeaderOnMobile();+ }++ // Detect and trigger the onboarding tour+ // through a lazy loaded script+ detectOnboardingTour();++ //+ // Legacy scripts from app/assets that are not yet component based+ //++ // Toggable fieldsets+ setupToggableFieldsets();++ // Action menu logic+ jQuery('.toolbar-items').each((idx:number, menu:HTMLElement) => {+ installMenuLogic(jQuery(menu));+ });++ // Legacy settings listener+ listenToSettingChanges();++ // Color patches preview the color+ makeColorPreviews();++ // Danger zone input validation+ dangerZoneValidation();++ // Replace fragment+ fixFragmentAnchors();++ // Legacy server response setup+ initMainMenuExpandStatus();+ focusFirstErroneousField();+ activateFlashNotice();+ activateFlashError();+ });+}