From e8194e696584e3b679c0b704caff95c3c464ff47 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 26 Aug 2017 23:58:52 +0300 Subject: [PATCH] now focus handling/locking is global... Signed-off-by: Alex A. Naanou --- ui (gen4)/css/experimenting.css | 10 +++ ui (gen4)/features/collections.js | 1 + ui (gen4)/features/filesystem.js | 8 +- ui (gen4)/features/meta.js | 1 + ui (gen4)/features/ui-widgets.js | 3 +- ui (gen4)/features/ui.js | 135 ++++++++++++++++++++---------- ui (gen4)/package.json | 10 +-- 7 files changed, 111 insertions(+), 57 deletions(-) diff --git a/ui (gen4)/css/experimenting.css b/ui (gen4)/css/experimenting.css index 1c343c71..b723907c 100755 --- a/ui (gen4)/css/experimenting.css +++ b/ui (gen4)/css/experimenting.css @@ -133,6 +133,16 @@ body { box-shadow: none; } +.viewer .lock-clicks { + position: absolute; + display: block; + width: 100%; + height: 100%; + background: transparent; + cursor: auto; + z-index: 10000; +} + /*********************************************************************/ diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index 8b23d262..26ffa39b 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -74,6 +74,7 @@ var CollectionActions = actions.Actions({ set collection(value){ this.loadCollection(value) }, + // XXX should this check consistency??? get collection_order(){ if(this.collections == null){ return null diff --git a/ui (gen4)/features/filesystem.js b/ui (gen4)/features/filesystem.js index 269d63f1..5b2fcdf1 100755 --- a/ui (gen4)/features/filesystem.js +++ b/ui (gen4)/features/filesystem.js @@ -2152,7 +2152,7 @@ var FileSystemWriterUIActions = actions.Actions({ // XXX this needs feedback... // XXX should this return a promise??? - saveIndexHere: ['File/Save', + saveIndexHere: ['File/$Save', function(){ if(this.location.path){ this.saveIndex() @@ -2172,10 +2172,10 @@ var FileSystemWriterUIActions = actions.Actions({ .saveIndexHere()}], // XXX need to be able to make dirs... - browseExportIndex: ['File/Export/Export Index to...', + browseExportIndex: ['File/Export/Export Index...', makeBrowseProxy('exportIndex')], // XXX need to be able to make dirs... - browseExportDirs: ['File/Export/Export Images to...', + browseExportDirs: ['File/Export/Export Images...', makeBrowseProxy('exportDirs')], @@ -2351,7 +2351,7 @@ var FileSystemWriterUIActions = actions.Actions({ }, }, // XXX indicate export state: index, crop, image... - exportDialog: ['File/Export/Export optioons...', + exportDialog: ['File/Export/$Export...', widgets.makeUIDialog(function(){ var that = this diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index d81a2b98..d614be16 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -84,6 +84,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [ // features... 'ui-cursor', + 'ui-unfocused-lock', 'ui-single-image', diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index b42025e2..4e71dd2e 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -1736,8 +1736,7 @@ module.ContextActionMenu = core.ImageGridFeatures.Feature({ event.preventDefault() event.stopPropagation() - that.focused - && that.browseActions() + that.browseActions() }) }], ], diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index e12abf2e..168fad7e 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -10,6 +10,7 @@ * - ui-url-hash * handle .location.hash * - ui-cursor + - ui-unfocused-lock * - ui-control * touch/mouse control mechanics * @@ -154,10 +155,6 @@ module.ViewerActions = actions.Actions({ // transition. 'resize-done-timeout': 300, - // The timeout to wait after window focus before setting .focused - // to true. - 'window-focus-timeout': 200, - // Theme to set on startup... 'theme': null, @@ -232,14 +229,6 @@ module.ViewerActions = actions.Actions({ } }, - // Focus... - // - // This is true when window is focused and false when not + 200ms - // after focusing. - // This enables the used to ignore events that lead to window focus. - get focused(){ - return !!this.__focus_lock.state }, - // Scaling... // // NOTE: .screenwidth / .screenheight are measured in square image blocks... @@ -748,35 +737,6 @@ module.Viewer = core.ImageGridFeatures.Feature({ } }], - // focus-lock... - ['start', - function(){ - var that = this - var focus_lock = this.__focus_lock = this.__focus_lock || {} - var focused = focus_lock.state = focus_lock.state || document.hasFocus() - var unlock = focus_lock.unlock = focus_lock.unlock - || function(){ setTimeout( - function(){ focus_lock.state = true }, - that.config['window-focus-timeout'] || 0) } - var lock = focus_lock.lock = focus_lock.lock - || function(){ focus_lock.state = false } - - $(window) - .focus(unlock) - .blur(lock) - }], - ['stop', - function(){ - var focus_lock = this.__focus_lock = this.__focus_lock || {} - var unlock = focus_lock.unlock - var lock = focus_lock.lock - - unlock - && $(window).off('focus', unlock) - lock - && $(window).off('blur', lock) - }], - /*/ force browser to redraw images after resize... // NOTE: this fixes a bug where images are not always updated // when off-screen... @@ -1271,6 +1231,94 @@ module.Cursor = core.ImageGridFeatures.Feature({ +/*********************************************************************/ +// Lock mouse when unfocused... + +var LockUnfocusedActions = actions.Actions({ + config: { + 'lock-unfocused': 'on', + + // The timeout to wait after window focus before setting .focused + // to true. + 'window-focus-timeout': 200, + }, + + // Focus... + // + // This is true when window is focused and false when not + 200ms + // after focusing. + // This enables the used to ignore events that lead to window focus. + get focused(){ + return that.dom.find('.lock-clicks').length > 0 }, + + toggleUnfocusedLock: ['Interface/Lock unfocused viewer', + core.doc`Toggle unfocused viewer locking... + + NOTE: this defines the handlers on window.`, + core.makeConfigToggler('lock-unfocused', + ['off', 'on'], + function(state){ + var that = this + var handlers = this.__focus_lock_handlers = this.__focus_lock_handlers || {} + var unlock = handlers.unlock = handlers.unlock + || function(){ + setTimeout(function(){ + that.dom.find('.lock-clicks').remove() + }, that.config['window-focus-timeout'] || 0) } + var lock = handlers.lock = handlers.lock + || function(){ + that.dom.find('.lock-clicks').length == 0 + && that.dom + .append($('
') + .addClass('lock-clicks') + .on('click contextmenu',function(evt){ + evt.stopPropagation() + evt.preventDefault() + })) } + + // we reset the handlers to avoid multiple triggers... + $(window) + .off('focus', unlock) + .off('blur', lock) + + // setup... + if(state == 'on'){ + $(window) + .focus(unlock) + .blur(lock) + + // setup initial state... + document.hasFocus() ? unlock() : lock() + + // tare down... + } else { + unlock() + delete this.__focus_lock_handlers + } + })], +}) + +var LockUnfocused = +module.LockUnfocused = core.ImageGridFeatures.Feature({ + title: '', + doc: '', + + tag: 'ui-unfocused-lock', + depends: [ + 'ui' + ], + + actions: LockUnfocusedActions, + + handlers: [ + ['start', + function(){ + this.toggleUnfocusedLock('!') }], + ], +}) + + + /*********************************************************************/ // Touch/Control... // @@ -1514,11 +1562,6 @@ var ControlActions = actions.Actions({ var clicked_image = isImageClicked(event, img) - // ignore clicks when focusing window... - if(!that.focused){ - return - } - var inner = function(){ focus ? that[blockEvt] diff --git a/ui (gen4)/package.json b/ui (gen4)/package.json index 53d23c55..b0adc184 100755 --- a/ui (gen4)/package.json +++ b/ui (gen4)/package.json @@ -22,14 +22,14 @@ "fs-walk": "^0.0.1", "glob": "^4.0.6", "guarantee-events": "^1.0.0", - "ig-actions": "^3.5.4", - "ig-features": "^3.2.6", - "ig-object": "^1.0.1", + "ig-actions": "^3.5.5", + "ig-features": "^3.2.7", + "ig-object": "^1.0.2", "openseadragon": "^2.3.0", - "preact": "^8.2.1", + "preact": "^8.2.4", "react": "^15.6.1", "react-dom": "^15.6.1", - "requirejs": "^2.3.4", + "requirejs": "^2.3.5", "requirejs-plugins": "^1.0.2", "sharp": "^0.17.3", "wildglob": "^0.1.1"