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
Remove jQuery and replace it with pure JS fix some linting errors
Henriette Darge53ed1b236e95
diff --git a/frontend/src/app/shared/directives/a11y/keyboard-shortcut.service.ts b/frontend/src/app/shared/directives/a11y/keyboard-shortcut.service.tsindex 5b9d10432b0..ace1e6d0a19 100644--- a/frontend/src/app/shared/directives/a11y/keyboard-shortcut.service.ts+++ b/frontend/src/app/shared/directives/a11y/keyboard-shortcut.service.ts@@ -43,8 +43,7 @@ const accessKeys = {};// this could be extracted into a separate component if it grows-const accessibleListSelector = 'table.keyboard-accessible-list';-const accessibleRowSelector = 'table.keyboard-accessible-list tbody tr';+const accessibleListSelector = 'generic-table keyboard-accessible-list';@Injectable({providedIn: 'root',@@ -81,34 +80,35 @@ export class KeyboardShortcutService {/*** Register the keyboard shortcuts.*/- public register() {+ public register():void {_.each(this.shortcuts, (action:() => void, key:string) => Mousetrap.bind(key, action));}- public accessKey(keyName:'preview'|'newWorkPackage'|'edit'|'quickSearch'|'projectSearch'|'help'|'moreMenu'|'details') {+ public accessKey(keyName:'preview'|'newWorkPackage'|'edit'|'quickSearch'|'projectSearch'|'help'|'moreMenu'|'details'):() => void {const key = accessKeys[keyName];return () => {- const elem = jQuery(`[accesskey=${key}]:first`);- if (elem.is('input') || elem.attr('id') === 'global-search-input') {+ // eslint-disable-next-line no-useless-concat+ const elem:HTMLElement = document.querySelectorAll("[accesskey='" + `${key}` + "']")[0] as HTMLElement;+ if (elem instanceof HTMLInputElement || elem.id === 'global-search-input') {// timeout with delay so that the key is not// triggered on the input- setTimeout(() => this.FocusHelper.focus(elem), 200);- } else if (elem.is('[href]')) {- this.clickLink(elem[0]);+ setTimeout(() => this.FocusHelper.focus(jQuery(elem)), 200);+ } else if (elem.getAttribute('href')) {+ this.clickLink(elem);} else {- elem[0].click();+ elem.click();}};}- public globalAction(action:keyof PathHelperService) {+ public globalAction(action:keyof PathHelperService):() => void {return () => {const url = (this.PathHelper[action] as any)();window.location.href = url;};}- public projectScoped(action:keyof PathHelperService) {+ public projectScoped(action:keyof PathHelperService):() => void {return () => {const projectIdentifier = this.currentProject.identifier;if (projectIdentifier) {@@ -118,7 +118,12 @@ export class KeyboardShortcutService {};}- clickLink(link:any) {+ // eslint-disable-next-line class-methods-use-this+ clickLink(link:HTMLElement):void {+ if (!link.getAttribute('href')) {+ return;+ }+const event = new MouseEvent('click', {view: window,bubbles: true,@@ -127,47 +132,35 @@ export class KeyboardShortcutService {const cancelled = !link.dispatchEvent(event);if (!cancelled) {- window.location.href = link.href;+ window.location.href = link.getAttribute('href') as string;}}- showHelpModal() {+ showHelpModal():void {window.open(this.PathHelper.keyboardShortcutsHelpPath());}- findListInPage() {- const domLists = jQuery(accessibleListSelector);- const focusElements:any = [];- domLists.find('tbody tr').each((index, tr) => {- const firstLink = jQuery(tr).find(':visible:tabbable')[0];- if (firstLink !== undefined) {- focusElements.push(firstLink);- }- });- return focusElements;- }-- focusItemOffset(offset:number) {- const list = this.findListInPage();+ // eslint-disable-next-line class-methods-use-this+ focusItemOffset(offset:number):void {+ const list = document.getElementsByClassName(accessibleListSelector)[0];if (list === null) {return;}- const index:number = list.indexOf(- jQuery(document.activeElement!)- .closest(accessibleRowSelector)- .find(':visible:tabbable')[0],- );-- const target = jQuery(list[(index + offset + list.length) % list.length]);- target.focus();+ const rows:Element[] = Array.from(list.querySelectorAll('tbody > tr'));+ let index:number;+ if (document.activeElement) {+ index = rows.indexOf(document.activeElement);+ const target = rows[index + offset] as HTMLElement;+ target.focus();+ }}- focusNextItem() {+ focusNextItem():void {this.focusItemOffset(1);}- focusPrevItem() {+ focusPrevItem():void {this.focusItemOffset(-1);}}diff --git a/spec/features/accessibility/work_packages/work_package_query_spec.rb b/spec/features/accessibility/work_packages/work_package_query_spec.rbindex f534b915cc5..6369e15ab89 100644--- a/spec/features/accessibility/work_packages/work_package_query_spec.rb+++ b/spec/features/accessibility/work_packages/work_package_query_spec.rb@@ -163,11 +163,11 @@ describe 'Work package index accessibility', type: :feature, selenium: true doendcontext 'focus' do- let(:first_link_selector) do- ".wp-row-#{work_package.id} .inline-edit--display-field.id a"+ let(:first_row_selector) do+ ".wp-row-#{work_package.id}"end- let(:second_link_selector) do- ".wp-row-#{another_work_package.id} .inline-edit--display-field.id a"+ let(:second_row_selector) do+ ".wp-row-#{another_work_package.id}"endit 'navigates with J and K' do@@ -175,14 +175,14 @@ describe 'Work package index accessibility', type: :feature, selenium: true doexpect(page).to have_selector(".wp-row-#{another_work_package.id}")find('body').native.send_keys('j')- expect(page).to have_focus_on(first_link_selector)+ expect(page).to have_focus_on(first_row_selector)# Avoid sending keys on body since that resets focuspage.driver.browser.switch_to.active_element.send_keys('j')- expect(page).to have_focus_on(second_link_selector)+ expect(page).to have_focus_on(second_row_selector)page.driver.browser.switch_to.active_element.send_keys('k')- expect(page).to have_focus_on(first_link_selector)+ expect(page).to have_focus_on(first_row_selector)endend