mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
added cursor autohide threshold + some cleanup...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
02638893db
commit
11a6753c52
@ -1061,6 +1061,7 @@ module.Clickable = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
// XXX might be a good idea to add a threshold to show the cursor...
|
||||||
var AutoHideCursor =
|
var AutoHideCursor =
|
||||||
module.AutoHideCursor = core.ImageGridFeatures.Feature({
|
module.AutoHideCursor = core.ImageGridFeatures.Feature({
|
||||||
title: '',
|
title: '',
|
||||||
@ -1070,7 +1071,8 @@ module.AutoHideCursor = core.ImageGridFeatures.Feature({
|
|||||||
depends: ['ui'],
|
depends: ['ui'],
|
||||||
|
|
||||||
config: {
|
config: {
|
||||||
'cursor-hide-timeout': 1000,
|
'cursor-autohide-timeout': 1000,
|
||||||
|
'cursor-autohide-threshold': 10,
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: actions.Actions({
|
actions: actions.Actions({
|
||||||
@ -1084,27 +1086,44 @@ module.AutoHideCursor = core.ImageGridFeatures.Feature({
|
|||||||
|
|
||||||
// setup...
|
// setup...
|
||||||
if(state == 'on'){
|
if(state == 'on'){
|
||||||
|
var x, y
|
||||||
var timer
|
var timer
|
||||||
var timeout = this.config['cursor-hide-timeout']
|
var timeout = this.config['cursor-autohide-timeout'] || 1000
|
||||||
var handler
|
var handler
|
||||||
= this.__cursor_autohide_handler
|
= this.__cursor_autohide_handler
|
||||||
= (this.__cursor_autohide_handler
|
= (this.__cursor_autohide_handler
|
||||||
|| function(){
|
|| function(){
|
||||||
timer && clearTimeout(timer)
|
timer && clearTimeout(timer)
|
||||||
|
|
||||||
that.ribbons.viewer
|
var threshold = that.config['cursor-autohide-threshold'] || 0
|
||||||
.removeClass('cursor-hidden')
|
x = x || event.clientX
|
||||||
|
y = y || event.clientY
|
||||||
|
|
||||||
if(!viewer.prop('cursor-auto-hide')){
|
// show only if cursor moved outside of threshold...
|
||||||
|
if(threshold > 0){
|
||||||
|
if(Math.max(Math.abs(x - event.clientX),
|
||||||
|
Math.abs(y - event.clientY)) > threshold){
|
||||||
|
x = y = null
|
||||||
|
that.ribbons.viewer
|
||||||
|
.removeClass('cursor-hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
// show right away...
|
||||||
|
} else {
|
||||||
|
that.ribbons.viewer
|
||||||
|
.removeClass('cursor-hidden')
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!viewer.prop('cursor-autohide')){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var timeout = that.config['cursor-hide-timeout']
|
var timeout = that.config['cursor-autohide-timeout'] || 1000
|
||||||
if(timeout && timeout > 0){
|
if(timeout && timeout > 0){
|
||||||
timer = setTimeout(function(){
|
timer = setTimeout(function(){
|
||||||
var viewer = that.ribbons.viewer
|
var viewer = that.ribbons.viewer
|
||||||
|
|
||||||
if(!viewer.prop('cursor-auto-hide')){
|
if(!viewer.prop('cursor-autohide')){
|
||||||
viewer.removeClass('cursor-hidden')
|
viewer.removeClass('cursor-hidden')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -1114,16 +1133,16 @@ module.AutoHideCursor = core.ImageGridFeatures.Feature({
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
!viewer.prop('cursor-auto-hide')
|
!viewer.prop('cursor-autohide')
|
||||||
&& viewer
|
&& viewer
|
||||||
.prop('cursor-auto-hide', true)
|
.prop('cursor-autohide', true)
|
||||||
.mousemove(handler)
|
.mousemove(handler)
|
||||||
|
|
||||||
// teardown...
|
// teardown...
|
||||||
} else {
|
} else {
|
||||||
viewer
|
viewer
|
||||||
.off('mousemove', this.__cursor_autohide_handler)
|
.off('mousemove', this.__cursor_autohide_handler)
|
||||||
.prop('cursor-auto-hide', false)
|
.prop('cursor-autohide', false)
|
||||||
.removeClass('cursor-hidden')
|
.removeClass('cursor-hidden')
|
||||||
delete this.__cursor_autohide_handler
|
delete this.__cursor_autohide_handler
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user