thorst / jquery-idletimer

provides you a way to monitor user activity with a page.
MIT License
721 stars 144 forks source link

Event mousemove triggered always #4

Closed psyafter closed 10 years ago

psyafter commented 13 years ago

Event mousemove triggered always on plugin change state if using modal window (jquery for example, with overlay) for displaying some popup on idle state. So if mouse is in document area (even if no mouse moving) so idle state finished without any activity.

I have a patch for this situation:

1) should remove event 'mousemove' in 'events' variable

2) after row //assign appropriate event handlers $(elem).bind($.trim((events + ' ').split(' ').join('.idleTimer ')), handleUserEvent);

we put this code:

    $(elem).mousemove(function (event) {
        if (event.pageX != obj.mX || event.pageY != obj.mY) {
            obj.mX = event.pageX;
            obj.mY = event.pageY;
            //handleUserEvent(elem); - not work for me, so I trigger another event 
            $(elem).trigger('keydown');
        }
    });
kaellis commented 12 years ago

Had the same issue myself, a better fix will be to change handleUserEvent method (since triggering 'keydown' might not work if not listening to keydown)

   handleUserEvent = function(event){
        var obj = $.data(this,'idleTimerObj');

        if (event.type !== 'mousemove' ||
                event.pageX != obj.pageX || 
                event.pageY != obj.pageY) {
            obj.pageX = event.pageX;
            obj.pageY = event.pageY;

            //clear any existing timeout
            clearTimeout(obj.tId);

            //if the idle timer is enabled
            if (obj.enabled) {
                //if it's idle, that means the user is no longer idle
                if (obj.idle){
                    toggleIdleState(this);
                }
                //set a new timeout
                obj.tId = setTimeout(toggleIdleState, obj.timeout);
            }
        }
     };
paulirish commented 12 years ago

@kaellis im not maintaining this library anymore but happy to add you as an admin to land your change

mikesherov commented 11 years ago

@kaellis, I'm maintaining this project now. If you'd to submit a pull request, I'd gladly review it :-)

akamensky commented 11 years ago

Is there anyone still maintaining this plugin?

thorst commented 10 years ago

I believe my branch implements this correctly. https://github.com/thorst/jquery-idletimer/blob/master/src/idle-timer.js

mikesherov commented 10 years ago

@thorst I'll review today. Thanks for the patch!

thorst commented 10 years ago

I was also hitting a mousemove bug in ios7. That fix along with this one are in 1.0.0