From 35a6fb99b85b8d68d7d8d60a66f27228d52380e4 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Sat, 14 Sep 2019 16:33:21 +1000 Subject: [PATCH] Add keyboard support to list items --- modules/system/assets/ui/js/list.rowlink.js | 15 ++++++++++++++- modules/system/assets/ui/storm-min.js | 10 +++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/system/assets/ui/js/list.rowlink.js b/modules/system/assets/ui/js/list.rowlink.js index de8add4c3..4e395912a 100644 --- a/modules/system/assets/ui/js/list.rowlink.js +++ b/modules/system/assets/ui/js/list.rowlink.js @@ -40,7 +40,7 @@ popup = link.is('[data-control=popup]'), request = link.is('[data-request]') - $(this).find('td').not('.' + options.excludeClass).click(function(e) { + function handleClick(e) { if ($(document.body).hasClass('drag')) { return } @@ -60,12 +60,25 @@ else { window.location = href } + } + + $(this).find('td').not('.' + options.excludeClass).click(function(e) { + handleClick(e) + }) + + $(this).on('keypress', function(e) { + if (e.key === '(Space character)' || e.key === 'Spacebar' || e.key === ' ') { + handleClick(e) + return false + } }) $(this).addClass(options.linkedClass) link.hide().after(link.html()) }) + // Add Keyboard Navigation to list rows + $('tr.rowlink').attr('tabindex', 0) } RowLink.DEFAULTS = { diff --git a/modules/system/assets/ui/storm-min.js b/modules/system/assets/ui/storm-min.js index 3183ccd0e..7406fe89c 100644 --- a/modules/system/assets/ui/storm-min.js +++ b/modules/system/assets/ui/storm-min.js @@ -4038,14 +4038,18 @@ var tr=this.$el.prop('tagName')=='TR'?this.$el:this.$el.find('tr:has(td)') tr.each(function(){var link=$(this).find(options.target).filter(function(){return!$(this).closest('td').hasClass(options.excludeClass)&&!$(this).hasClass(options.excludeClass)}).first() if(!link.length)return var href=link.attr('href'),onclick=(typeof link.get(0).onclick=="function")?link.get(0).onclick:null,popup=link.is('[data-control=popup]'),request=link.is('[data-request]') -$(this).find('td').not('.'+options.excludeClass).click(function(e){if($(document.body).hasClass('drag')){return} +function handleClick(e){if($(document.body).hasClass('drag')){return} if(onclick){onclick.apply(link.get(0))} else if(request){link.request()} else if(popup){link.popup()} else if(e.ctrlKey||e.metaKey){window.open(href)} -else{window.location=href}}) +else{window.location=href}} +$(this).find('td').not('.'+options.excludeClass).click(function(e){handleClick(e)}) +$(this).on('keypress',function(e){if(e.key==='(Space character)'||e.key==='Spacebar'||e.key===' '){handleClick(e) +return false}}) $(this).addClass(options.linkedClass) -link.hide().after(link.html())})} +link.hide().after(link.html())}) +$('tr.rowlink').attr('tabindex',0)} RowLink.DEFAULTS={target:'a',excludeClass:'nolink',linkedClass:'rowlink'} var old=$.fn.rowLink $.fn.rowLink=function(option){var args=Array.prototype.slice.call(arguments,1)