From 33f3db6d81ad62d2ac125487b8e319324d4b1744 Mon Sep 17 00:00:00 2001 From: Ere Maijala Date: Fri, 13 Oct 2017 14:07:21 +0300 Subject: [PATCH] Bug 21362: Advanced editor: Fix tab navigation in fixed fields Also minor tweaks to how the fields look. Test plan: 1. Try moving from field to field and inside control fields with tab/shift-tab. 2. Make sure focus doesn't get stuck in any position. Signed-off-by: Michal Denar --- .../intranet-tmpl/lib/koha/cateditor/widget.js | 33 +++++++++++++++------- koha-tmpl/intranet-tmpl/prog/css/cateditor.css | 5 +++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js index 7ea3fc8..c36914d 100644 --- a/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js +++ b/koha-tmpl/intranet-tmpl/lib/koha/cateditor/widget.js @@ -61,10 +61,11 @@ define( [ 'resources' ], function( Resources ) { // Fixed field utils bindFixed: function( sel, start, end ) { var $node = $( this.node ).find( sel ); - $node.val( this.getFixed( start, end ) ); + var val = this.getFixed( start, end ); + $node.val( val ); var widget = this; - var $collapsed = $( '' + $node.val() + '' ).insertAfter( $node ); + var $collapsed = $( '' + val + '' ).insertAfter( $node ); function show() { $collapsed.hide(); @@ -75,7 +76,8 @@ define( [ 'resources' ], function( Resources ) { function hide() { $node.hide(); - $collapsed.text( Widget.PadStringRight( $node.val(), end - start ) ).show(); + var val = $node.val(); + $collapsed.text( Widget.PadStringRight( val === null ? '' : val, end - start ) ).show(); } $node.on( 'change keyup', function() { @@ -92,6 +94,9 @@ define( [ 'resources' ], function( Resources ) { }, setFixed: function( start, end, value, source ) { + if ( null === value ) { + value = ''; + } this.setText( this.text.substring( 0, start ) + Widget.PadStringRight( value.toString().substr( 0, end - start ), end - start ) + this.text.substring( end ), source ); }, @@ -118,6 +123,7 @@ define( [ 'resources' ], function( Resources ) { $matSelect.change( function() { widget.loadXMLMaterial( materialInfo[ $matSelect.val() ] ); + widget.nodeChanged(); } ).change(); } ); }, @@ -169,11 +175,8 @@ define( [ 'resources' ], function( Resources ) { $inputs.each( function( i ) { $(this).on( 'keydown.marc-tab', function( e ) { - // Cheap hack to disable backspace and special keys - if ( ( this.nodeName.toLowerCase() == 'select' && e.which == 9 ) || e.ctrlKey ) { - e.preventDefault(); - return; - } else if ( e.which != 9 ) { // Tab + // Handle tab/shift-tab + if ( e.which != 9 ) { // Tab return; } @@ -182,7 +185,12 @@ define( [ 'resources' ], function( Resources ) { if ( e.shiftKey ) { if ( i > 0 ) { - $inputs.eq(i - 1).trigger( 'focus' ); + var $input = $inputs.eq( i - 1 ); + if ( $input.is( ':visible' ) ) { + $input.focus(); + } else { + $input.next('span').click(); + } } else { editor.cm.setCursor( span.from ); // FIXME: ugly hack @@ -191,7 +199,12 @@ define( [ 'resources' ], function( Resources ) { } } else { if ( i < $inputs.length - 1 ) { - $inputs.eq(i + 1).trigger( 'focus' ); + var $input = $inputs.eq( i + 1 ); + if ( $input.is( ':visible' ) ) { + $input.focus(); + } else { + $input.next('span').click(); + } } else { editor.cm.setCursor( span.to ); editor.focus(); diff --git a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css b/koha-tmpl/intranet-tmpl/prog/css/cateditor.css index 6840d0c..a691390 100644 --- a/koha-tmpl/intranet-tmpl/prog/css/cateditor.css +++ b/koha-tmpl/intranet-tmpl/prog/css/cateditor.css @@ -125,7 +125,7 @@ body { font-family: inherit; line-height: 2.75; margin: 3px 0; - padding: 4px; + padding: 2px; } #editor .subfield-widget select, #editor .subfield-widget input { @@ -139,6 +139,9 @@ body { #editor .fixed-widget input { width: 4em; + padding: 0; + border-radius: 2px; + border-width: 1px; } #editor .fixed-widget select { -- 2.1.4