From af6bc5a603350b52b3826bc7cf5e50016120501f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 18 Jan 2017 21:36:58 +0300 Subject: [PATCH] minor fixes and refactoring... Signed-off-by: Alex A. Naanou --- ui (gen4)/lib/keyboard.js | 25 +++++++++++++++++++++++++ ui (gen4)/lib/widget/browse.js | 25 +++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index ec038e5b..4e6ccfe0 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -103,6 +103,28 @@ for(var k in SPECIAL_KEYS){ } +// This is used to identify and correct key notation... +// NOTE: the keys here are intentionally lowercase... +var SPECIAL_KEY_ALTERNATIVE_TITLES = { + 1: '#1', 2: '#2', 3: '#3', 4: '#4', 5: '#5', + 6: '#6', 7: '#7', 8: '#8', 9: '#9', 0: '#0', + + ctl: 'Ctrl', control: 'Ctrl', + + 'capslock': 'Caps Lock', + + 'page up': 'PgUp', 'pageup': 'PgUp', + + 'page down': 'PgDown', 'pagedown': 'PgDown', + + insert: 'Ins', + + delete: 'Del', + + 'bkspace' : 'Backspace', 'back space' : 'Backspace', + + windows: 'Win', +} var SPECIAL_KEYS_DICT = {} for(var k in SPECIAL_KEYS){ SPECIAL_KEYS_DICT[SPECIAL_KEYS[k].toLowerCase()] = SPECIAL_KEYS[k] @@ -255,6 +277,7 @@ function splitKey(key){ .concat(sep.indexOf(key.slice(-1)) >= 0 ? key.slice(-1) : []) .filter(function(c){ return c != '' }) } + var joinKey = module.joinKey = function joinKey(key){ @@ -262,6 +285,7 @@ function joinKey(key){ key.join(KEY_SEPARATORS[0] || '+') : key } + // Normalize key string/array... // // NOTE: this will not check if a key is a key use isKey(..) for that. @@ -294,6 +318,7 @@ function normalizeKey(key){ } // get the propper name... + k = SPECIAL_KEY_ALTERNATIVE_TITLES[k.toLowerCase()] || k k = SPECIAL_KEYS_DICT[k.toLowerCase()] || k k = modifiers.indexOf(k.toLowerCase()) >= 0 ? diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index a1ad026f..3b0eb7f1 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -217,9 +217,6 @@ function(list, options){ // // length_limit: , // -// // list of items to mark for removal... -// to_remove: [ ... ], -// // // called when an item is opend... // // // // NOTE: this is simpler that binding to the global open event @@ -229,11 +226,19 @@ function(list, options){ // // check input value... // check: function(value){ ... }, // +// // normalize new input value... +// // +// // NOTE: this will replace the input with normalized value. // normalize: function(value){ ... }, // // // if true only unique values will be stored... +// // // // if a function this will be used to normalize the values before // // uniqueness check is performed... +// // +// // NOTE: this (if a function) is different from normalize above +// // in that this will not store the normalized value, rather +// // just use it for uniqueness testing... // unique: | function(value){ ... }, // // // if true sort values... @@ -277,7 +282,7 @@ function(list, options){ || lst } - var to_remove = options.to_remove = options.to_remove || [] + var to_remove = dialog.__to_remove = dialog.__to_remove || [] // make a copy of options, to keep it safe from changes we are going // to make... @@ -297,6 +302,8 @@ function(list, options){ // or discrete and not done as they come in... lst = !editable ? Object.keys(lst) : lst.slice() + dialog.__list = lst + // add the 'x' button if not disabled... var buttons = options.buttons = (options.buttons || []).slice() !options.no_delete_button @@ -309,7 +316,7 @@ function(list, options){ // mark items for removal -- if a list is given by user... to_remove.forEach(function(e){ dialog.filter('"'+ e +'"') - .toggleClass('strike-out') + .addClass('strike-out') }) options.itemopen @@ -340,6 +347,8 @@ function(list, options){ return } + lst = dialog.__list + // list length limit if(options.length_limit && (lst.length >= options.length_limit)){ @@ -377,6 +386,8 @@ function(list, options){ lst = write(list, lst) + dialog.__list = lst + // update list and select new value... dialog.update() .done(function(){ @@ -394,7 +405,7 @@ function(list, options){ .on('update', function(){ to_remove.forEach(function(e){ dialog.filter('"'+ e +'"') - .toggleClass('strike-out') + .addClass('strike-out') }) }) // clear the to_remove items + save list... @@ -404,6 +415,8 @@ function(list, options){ return } + lst = dialog.__list + // remove items... to_remove.forEach(function(e){ lst.splice(lst.indexOf(e), 1)