From 6385660b09a0233b8e77af0574e054d2b200ce8a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 21 Jun 2016 02:45:45 +0300 Subject: [PATCH] minor refactoring + docs... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/keyboard.js | 13 +++++++---- ui (gen4)/features/ui-single-image.js | 31 +++++++++++++++++++++------ ui (gen4)/lib/keyboard.js | 2 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/ui (gen4)/features/keyboard.js b/ui (gen4)/features/keyboard.js index c198e4cd..dadcedf8 100755 --- a/ui (gen4)/features/keyboard.js +++ b/ui (gen4)/features/keyboard.js @@ -28,8 +28,9 @@ var drawer = require('lib/widget/drawer') // helper... function customScale(n){ return { - default: 'fitCustom: '+n, - 'ctrl+shift': 'setCustomSize: '+n, + default: 'fitCustom: '+n+' -- Set cutom image size', + 'alt': 'setCustomSize: '+n+' -- Set current image size as custom', + 'ctrl+shift': 'setCustomSize: '+n+' null -- Clear custom image size', } } @@ -80,14 +81,18 @@ module.GLOBAL_KEYBOARD = { '#0', '#1', '#2', '#3', '#4', '#5', '#6', '#7', '#8', '#9', ], + + // zooming... '#1': 'fitScreen', '#2': { default: 'fitNormal', - 'ctrl+shift': 'setNormalScale', + 'alt': 'setNormalScale', + 'ctrl+shift': 'setNormalScale: null -- Reset normal size to default', }, '#3': { default: 'fitSmall', - 'ctrl+shift': 'setSmallScale', + 'alt': 'setSmallScale', + 'ctrl+shift': 'setSmallScale: null -- Reset small size to default', }, '#4': customScale(4), '#5': customScale(5), diff --git a/ui (gen4)/features/ui-single-image.js b/ui (gen4)/features/ui-single-image.js index 6e5b03d8..def631bd 100755 --- a/ui (gen4)/features/ui-single-image.js +++ b/ui (gen4)/features/ui-single-image.js @@ -253,12 +253,16 @@ var SingleImageActions = actions.Actions({ // basic single image view sizing... fitSmall: ['Zoom/Show small image', function(){ this.screenfit = this.config['fit-small-scale'] || 4 }], + setSmallScale: ['Zoom/Set small size to current', + function(value){ + this.config['fit-small-scale'] + = value === null ? 4 : (value || this.screenfit) }], fitNormal: ['Zoom/Show normal image', function(){ this.screenfit = this.config['fit-normal-scale'] || 1.2 }], - setSmallScale: ['Zoom/Set small size to current', - function(){ this.config['fit-small-scale'] = this.screenfit }], setNormalScale: ['Zoom/Set normal size to current', - function(){ this.config['fit-normal-scale'] = this.screenfit }], + function(value){ + this.config['fit-normal-scale'] + = value === null ? 1.2 : (value || this.screenfit) }], fitCustom: ['- Zoom/Show cusotm size image', function(n){ @@ -275,16 +279,29 @@ var SingleImageActions = actions.Actions({ this.screenfit = s }], setCustomSize: ['- Zoom/Set image cusotm size', - function(n){ + function(n, value){ if(n == null){ return } - var sizes = this.config['fit-custom-scale'] || {} - sizes[n] = this.screenfit + var sizes = this.config['fit-custom-scale'] + + // reset... + if(value === null){ + if(sizes && n in sizes){ + delete sizes[n] + } + + // set... + } else { + sizes = sizes && JSON.parse(JSON.stringify(sizes)) || {} + sizes[n] = value || this.screenfit + } // NOTE: we are resetting this for it to be stored correctly... - this.config['fit-custom-scale'] = sizes + if(sizes){ + this.config['fit-custom-scale'] = sizes + } }], }) diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index da1763e8..600ec9ab 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -249,7 +249,7 @@ function parseActionCall(txt){ // parse arguments... var args = JSON.parse('['+( ((c[1] || '') - .match(/"[^"]*"|'[^']*'|\{[^\}]*\}|\[[^\]]*\]|\d+|\d+\.\d*/gm) + .match(/"[^"]*"|'[^']*'|\{[^\}]*\}|\[[^\]]*\]|\d+|\d+\.\d*|null/gm) || []) .join(','))+']')