Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On startup mousemove is ignored #23

Closed
thorst opened this issue Feb 27, 2014 · 3 comments
Closed

On startup mousemove is ignored #23

thorst opened this issue Feb 27, 2014 · 3 comments

Comments

@thorst
Copy link
Owner

thorst commented Feb 27, 2014

I'm still experiencing the issue I described in #16 (comment). However now I have had time to investigate what I was experiencing.

Tested on 2/27/2014 with Chrome Version 33.0.1750.117 m && Firefox 27.0.1.

Im testing https://raw.github.com/mikesherov/jquery-idletimer/master/dist/idle-timer.js

Here's how reproduce it.

  1. Refresh the demo page
  2. Immediately begin moving mouse on document, but not textarea. It will pause for what seems to be 3 seconds, then show as an inactive state in #status.
  3. Continue moving the mouse on document but not textarea, without pause, until your arm is tired. It will show as an inactive state in #status.
  4. Stop moving the mouse for at least the timeout time (5 seconds). It will show as an inactive state in #status.
  5. Now move the mouse again, and it shows as active in #status.

Details

The mouse move event is triggered (line 97). obj.idle (line 106) is false, so it never triggers the toggle until the timeout expires once.

I havent tracked it down, but it seems like the textareas timer is triggering for the document timer, and thats why #status shows as idle (step number 2 above)

Issue

This isn't an issue when the timeout is 5 seconds, because it will go in and out of idle state frequently.

But my timeout is high (13 minutes) so for it to perform this cycle, its too late and my server side's session has expired.

Side Note

I thought just setting idle to true or startImmediately to false (or both) would be enough. But the result is the same, after the timeout the banner shows idle even though I'm moving my mouse.

Looking at #1 I believe a fix for that would solve my issue. However, i still need to support ie8, so the proposed fix (pagevisibility) wouldn't work.

Summary

I beleive there are 2 issues:

  1. Textarea timer may be triggering idle on document
  2. Initial activity is ignored until it becomes idle at least 1 time
@thorst
Copy link
Owner Author

thorst commented Feb 27, 2014

Issue number 1 from my summary is fixed with the following

$('textarea').bind("idle.idleTimer", function (event) {
  event.stopPropagation();
  $('textarea').val(function (i, v) {
    return v + "textarea has been idle for " + stimeout / 1000 + ' seconds\n';
  }).css("backgroundColor", "silver");
 });

 $('textarea').bind("active.idleTimer", function (event) {
  event.stopPropagation();
  $('textarea').val(function (i, v) {
    return v + "User is active, again! :D\n";
  }).css("backgroundColor", "yellow");
 });

Although it was just me not thinking, may want to add that to the demo. I don't know?

@thorst
Copy link
Owner Author

thorst commented Feb 27, 2014

I've achieved the expected behavior for issue number 2 from my summary with the following changes

  1. Initialize the plugin for document monitoring as idle by default. (on demo.html). This is the behavior i think makes most sense. But leaving it the default is perfectly fine.
$(document).idleTimer(timeout, {
  idle:true
});
  1. Modify line 140 (on idle-time.js). This way when it gets flipped on line 37, it will trigger the idle function, if the timer hasn't been reset by that point.
obj.tId = setTimeout(function () { $(elem).data("idleTimerObj").idle = false; toggleIdleState(elem); }, obj.timeout);

Please consider these changes for the main branch.

@thorst
Copy link
Owner Author

thorst commented Mar 4, 2014

These fixes and more are in my fork

https://github.com/thorst/jquery-idletimer/blob/master/src/idle-timer.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant