From 86c2ff00df2964b709b86b9b517bce16fef3a51a Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 6 May 2020 03:19:57 +0000 Subject: [PATCH] Allow a snippet to be auto-generated after a simple note has been edited. --- vasl_templates/webapp/static/simple_notes.js | 10 ++++++++-- vasl_templates/webapp/static/utils.js | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/vasl_templates/webapp/static/simple_notes.js b/vasl_templates/webapp/static/simple_notes.js index 2cdc625..c168638 100644 --- a/vasl_templates/webapp/static/simple_notes.js +++ b/vasl_templates/webapp/static/simple_notes.js @@ -95,9 +95,15 @@ function _do_edit_simple_note( $sortable2, $entry, default_width ) } ) ; data.id = auto_assign_id( usedIds, "id" ) ; } - _do_add_simple_note( $sortable2, data ) ; + $entry = _do_add_simple_note( $sortable2, data ) ; } } + // check if we should automatically generate a snippet + if ( isKeyDown( "Shift" ) ) { + var $elem = $entry.find( "img.snippet" ) ; + if ( $elem.length !== 0 ) + $elem.click() ; + } $(this).dialog( "close" ) ; }, Cancel: function() { $(this).dialog( "close" ) ; }, @@ -111,7 +117,7 @@ function _do_add_simple_note( $sortable2, data ) { // add a new sortable2 entry var note_type = _get_note_type_for_sortable( $sortable2 ) ; - $sortable2.sortable2( "add", { + return $sortable2.sortable2( "add", { content: _make_simple_note( note_type, data.caption ), data: data, } ) ; diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 900151c..f52d14b 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -445,6 +445,13 @@ function isIE() return false ; } +isKeyDown = ( function( key ) { + var keyState = {} ; + window.addEventListener( "keyup", function(e) { keyState[e.key] = false ; } ) ; + window.addEventListener( "keydown", function(e) { keyState[e.key] = true ; } ) ; + return function( key ) { return keyState.hasOwnProperty(key) && keyState[key] || false ; } ; +} )() ; + // -------------------------------------------------------------------- ( function( scope ) {