minor fixes and refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-01-18 21:36:58 +03:00
parent 010f8dabf8
commit af6bc5a603
2 changed files with 44 additions and 6 deletions

View File

@ -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 ?

View File

@ -217,9 +217,6 @@ function(list, options){
//
// length_limit: <number>,
//
// // 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: <bool> | 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)