PageSourceSearch

https://www.valleyforgeflag.com/VLInclude/jquery.idle/jquery.idle.js

js valleyforgeflag.com collected 2026-09-26 13:32:01 UTC 3,865 bytes, 102 lines download raw bytes

vendor: 3,865 bytes, lines 1-102
1/**
2 *  File: jquery.idle.js
3 *  Title:  JQuery Idle.
4 *  A dead simple jQuery plugin that executes a callback function if the user is idle.
5 *  About: Author
6 *  Henrique Boaventura ([email protected]).
7 *  About: Version
8 *  1.2.6
9 *  About: License
10 *  Copyright (C) 2013, Henrique Boaventura ([email protected]).
11 *  MIT License:
12 *  Permission is hereby granted, free of charge, to any person obtaining a copy
13 *  of this software and associated documentation files (the "Software"), to deal
14 *  in the Software without restriction, including without limitation the rights
15 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 *  copies of the Software, and to permit persons to whom the Software is
17 *  furnished to do so, subject to the following conditions:
18 *  - The above copyright notice and this permission notice shall be included in all
19 *    copies or substantial portions of the Software.
20 *  - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 *    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 *    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 *    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 *    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 *    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 *    SOFTWARE.
27 **/
28/*jslint browser: true */
29/*global jQuery: false */
30(function ($) {
31  'use strict';
32
33  $.fn.idle = function (options) {
34    var defaults = {
35        idle: 60000, //idle time in ms
36        events: 'mousemove keydown mousedown touchstart', //events that will trigger the idle resetter
37        onIdle: function () {}, //callback function to be executed after idle time
38        onActive: function () {}, //callback function to be executed after back from idleness
39        onHide: function () {}, //callback function to be executed when window is hidden
40        onShow: function () {}, //callback function to be executed when window is visible
41        keepTracking: true, //set it to false if you want to track only the first time
42        startAtIdle: false,
43        recurIdleCall: false
44      },
45      idle = options.startAtIdle || false,
46      visible = !options.startAtIdle || true,
47      settings = $.extend({}, defaults, options),
48      lastId = null,
49      resetTimeout,
50      timeout;
51
52    //event to clear all idle events
53    $(this).on( "idle:stop", {}, function( event) {
54      $(this).off(settings.events);
55      settings.keepTracking = false;
56      resetTimeout(lastId, settings);
57    });
58
59    resetTimeout = function (id, settings) {
60      if (idle) {
61        settings.onActive.call();
62        idle = false;
63      }
64      clearTimeout(id);
65      if(settings.keepTracking) {
66        return timeout(settings);
67      }
68    };
69
70    timeout = function (settings) {
71      var timer = (settings.recurIdleCall ? setInterval : setTimeout), id;
72      id = timer(function () {
73        idle = true;
74        settings.onIdle.call();
75      }, settings.idle);
76      return id;
77    };
78
79    return this.each(function () {
80      lastId = timeout(settings);
81      $(this).on(settings.events, function (e) {
82        lastId = resetTimeout(lastId, settings);
83      });
84      if (settings.onShow || settings.onHide) {
85        $(document).on("visibilitychange webkitvisibilitychange mozvisibilitychange msvisibilitychange", function () {
86          if (document.hidden || document.webkitHidden || document.mozHidden || document.msHidden) {
87            if (visible) {
88              visible = false;
89              settings.onHide.call();
90            }
91          } else {
92            if (!visible) {
93              visible = true;
94              settings.onShow.call();
95            }
96          }
97        });
98      }
99    });
100
101  };
102}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.