From edd0fba14142ab46d633572c3f427f1d65492cbc Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 7 Jun 2016 04:28:56 +0300 Subject: [PATCH] cleanup + added 'activate' option to .makeEditable(..)... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/ui-status.js | 46 ++++++++------------------------ ui (gen4)/features/ui-widgets.js | 2 ++ ui (gen4)/lib/util.js | 18 +++++++++---- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/ui (gen4)/features/ui-status.js b/ui (gen4)/features/ui-status.js index 4942f8bd..2c63a50a 100755 --- a/ui (gen4)/features/ui-status.js +++ b/ui (gen4)/features/ui-status.js @@ -87,7 +87,6 @@ var StatusBarActions = actions.Actions({ }, __statusbar_elements__: { - // XXX use .makeEditable(..) index: function(item, gid, img){ var that = this gid = gid || this.current @@ -111,36 +110,15 @@ var StatusBarActions = actions.Actions({ : $('') .addClass('position editable') .attr('info', 'Image position (click to edit)') - .prop('contenteditable', true) - .keydown(function(){ - // keep this from affecting the viewer... - event.stopPropagation() - - var n = keyboard.toKeyName(event.keyCode) - - var i = parseInt($(this).text()) + .makeEditable({ clear_on_edit: false }) + // select image when done... + .on('edit-done', function(_, text){ + var i = parseInt(text) i = i >= 1 ? i-1 : i == null ? 'current' : i - - // lose focus and exit... - if(n == 'Esc' || n == 'Enter'){ - event.preventDefault() - - // get image on enter... - if(n == 'Enter'){ - that.focusImage(i, - item.hasClass('global') ? 'global' : undefined) - } - - // clear selection.... - window.getSelection().removeAllRanges() - $(this).blur() - - that.updateStatusBar() - - return false - } + that.focusImage(i, + item.hasClass('global') ? 'global' : undefined) }) // update image position... // XXX this appears to be run in the node context... @@ -210,14 +188,12 @@ var StatusBarActions = actions.Actions({ item = $('') .addClass('ribbon-number') .attr('info', 'Current ribbon (click to edit)') + .makeEditable({ clear_on_edit: false }) + .on('edit-done', function(_, text){ + that.focusRibbon(text == '*' ? that.base : parseInt(text)) + }) .click(function(){ - $(this) - .makeEditable({ - clear_on_edit: false - }) - .on('edit-done', function(_, text){ - that.focusRibbon(text == '*' ? that.base : parseInt(text)) - }) + $(this).selectText() }) .blur(function(){ that.updateStatusBar() diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index ce44adeb..7e184044 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -38,6 +38,7 @@ module.makeEditableItem = function(list, item, elem, callback, options){ return elem .makeEditable({ + activate: true, clear_on_edit: false, }) .on('edit-done', callback || function(){}) @@ -93,6 +94,7 @@ function(actions, list_key, options){ var _makeEditable = function(elem){ return $(elem).find('.text') .makeEditable({ + activate: true, blur_on_abort: false, blur_on_commit: false, }) diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index 32cae8af..fa38644e 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -367,21 +367,29 @@ if(typeof(jQuery) != typeof(undefined)){ // // Options format: // { + // // activate (focus) element when done... + // activate: false, + // + // // set multi line edit mode... // multiline: false, // + // // reset value on abort... // reset_on_abort: true, // + // // blur element on abort/commit... // blur_on_abort: false, // blur_on_commit: false, // + // // clear selection on abort/commit... // clear_selection_on_abort: true, // clear_selection_on_commit: true, // + // // clear element value on edit... // clear_on_edit: true, // + // // Keys that will abort the edit... // abort_keys: [ // 'Esc', - // ... // ], // } // @@ -415,10 +423,10 @@ if(typeof(jQuery) != typeof(undefined)){ this.text('') } - this - .prop('contenteditable', true) - // NOTE: this will also focus the element... - .selectText() + this.prop('contenteditable', true) + + // NOTE: this will also focus the element... + options.activate && this.selectText() // do not setup handlers more than once... if(!this.hasClass('editable-field')){