<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8' />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Jquery-idletimer : provides you a way to monitor user activity with a page." />
    <title>Jquery-idletimer</title>

    <!-- jQuery and idleTimer -->
    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="../src/idle-timer.js"></script>

    <!-- Bootstrap/respond (ie8) and moment -->
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js"></script>
    <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.5.1/moment.js"></script>

    <!-- Respond.js proxy on external server -->
    <link href="//netdna.bootstrapcdn.com/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
    <link href="respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
    <script src="respond.proxy.js"></script>
    <style>
        body {
            margin-top: 40px;
            margin-bottom: 40px;
        }

        .btn {
            padding: 5px 6px;
        }
    </style>
</head>
<body>
    <div class="navbar navbar-default navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="index.html">Jquery-idletimer</a>
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                    <li><a href="autologout.html">Auto Logout</a></li>
                    <li><a href="defaultbinding.html">Default Binding</a></li>
                    <li><a href="https://github.com/thorst/jquery-idletimer">Documentation</a></li>
                </ul>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="https://github.com/thorst/jquery-idletimer/zipball/master">Zip</a></li>
                    <li><a href="https://github.com/thorst/jquery-idletimer/tarball/master">Tar</a></li>
                    <li><a href="https://github.com/thorst/jquery-idletimer">Github</a></li>
                </ul>
            </div> <!--/.nav-collapse  -->
        </div>
    </div>
    <div class="container">
        <h2>Concept</h2>
        <p>The idle timer is built on <a href="http://jquery.com/">jQuery</a> and provides two events: <code>idle.idleTimer</code> and <code>active.idleTimer</code>, which fire when the user's idle state has changed.</p>
        <p>When you move your mouse over the page or start typing, you're considered "active".</p>
        <p>On this page we have two idle timers. One for the entire document. Another for the text area on the right (or bottom if your on mobile).</p>
        <p>I use explicit instantiation here</p>
        <div class="row">
            <div class="col-md-6">
                <h3>Document <small><span id="docTimeout"></span> second timeout</small></h3>
                <div class="btn-group">
                    <a href="#" id="btPause" class="btn btn-default btn-sm">Pause</a>
                    <a href="#" id="btResume" class="btn btn-default btn-sm">Resume</a>
                    <a href="#" id="btElapsed" class="btn btn-default btn-sm">Elapsed</a>
                    <a href="#" id="btInit" class="btn btn-default btn-sm">Init</a>
                    <a href="#" id="btDestroy" class="btn btn-default btn-sm">Destroy</a>
                </div>
                <textarea rows="10" cols="30" id="docStatus" class="form-control"></textarea><br />
            </div>
            <div class="col-md-6">
                <h3>Element <small><span id="elTimeout"></span> second timeout</small></h3>
                <div class="btn-group">
                    <a href="#" id="btReset" class="btn btn-default btn-sm">Reset</a>
                    <a href="#" id="btLastActive" class="btn btn-default btn-sm">Last Active</a>
                    <a href="#" id="btRemaining" class="btn btn-default btn-sm">Remaining</a>
                    <a href="#" id="btState" class="btn btn-default btn-sm">State</a>
                </div>
                <textarea rows="10" cols="30" id="elStatus" class="form-control"></textarea><br />
            </div>
        </div>
        <h3>Dialogs</h3>
        <!-- Button trigger modal -->
        <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            Launch modal
        </button>
        <button id="alert" class="btn btn-primary btn-lg">
            Launch alert
        </button>
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                    </div>
                    <div class="modal-body">
                        ...
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        /*
        scrollToBottom plugin, chainable
        */
        $.fn.scrollToBottom = function () {
            this.scrollTop(this[0].scrollHeight);
            return this;
        };
        /*
        click event for alert button
        */
        (function ($) {
            //Display alert
            $("#alert").click(function () { alert("Hello!"); return false; });
        })(jQuery);


    </script>
    <script type="text/javascript">
        /*
        Code for document idle timer
        */
        (function ($) {
            //Define default
            var
                docTimeout = 5000
            ;

            /*
            Handle raised idle/active events
            */
            $(document).on("idle.idleTimer", function (event, elem, obj) {
                $("#docStatus")
                    .val(function (i, v) {
                        return v + "Idle @ " + moment().format() + " \n";
                    })
                    .removeClass("alert-success")
                    .addClass("alert-warning")
                    .scrollToBottom();
            });
            $(document).on("active.idleTimer", function (event, elem, obj, e) {
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Active [" + e.type + "] [" + e.target.nodeName + "] @ " + moment().format() + " \n";
                    })
                    .addClass("alert-success")
                    .removeClass("alert-warning")
                    .scrollToBottom();
            });

            /*
            Handle button events
            */
            $("#btPause").click(function () {
                $(document).idleTimer("pause");
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Paused @ " + moment().format() + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            });
            $("#btResume").click(function () {
                $(document).idleTimer("resume");
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Resumed @ " + moment().format() + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            });
            $("#btElapsed").click(function () {
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Elapsed (since becoming active): " + $(document).idleTimer("getElapsedTime") + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            });
            $("#btDestroy").click(function () {
                $(document).idleTimer("destroy");
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Destroyed: @ " + moment().format() + " \n";
                    })
                    .removeClass("alert-success")
                    .removeClass("alert-warning")
                    .scrollToBottom();
                $(this).blur();
                return false;
            });
            $("#btInit").click(function () {
                // for demo purposes show init with just object
                $(document).idleTimer({ timeout: docTimeout });
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Init: @ " + moment().format() + " \n";
                    })
                    .scrollToBottom();

                //Apply classes for default state
                if ($(document).idleTimer("isIdle")) {
                    $('#docStatus')
                        .removeClass("alert-success")
                        .addClass("alert-warning");
                } else {
                    $('#docStatus')
                        .addClass("alert-success")
                        .removeClass("alert-warning");
                }
                $(this).blur();
                return false;
            });

            //Clear old statuses
            $('#docStatus').val('');

            //Start timeout, passing no options
            //Same as $.idleTimer(docTimeout, docOptions);
            $(document).idleTimer(docTimeout);

            //For demo purposes, style based on initial state
            if ($(document).idleTimer("isIdle")) {
                $("#docStatus")
                  .val(function (i, v) {
                      return v + "Initial Idle State @ " + moment().format() + " \n";
                  })
                  .removeClass("alert-success")
                  .addClass("alert-warning")
                  .scrollToBottom();
            } else {
                $('#docStatus')
                    .val(function (i, v) {
                        return v + "Initial Active State @ " + moment().format() + " \n";
                    })
                    .addClass("alert-success")
                    .removeClass("alert-warning")
                    .scrollToBottom();
            }


            //For demo purposes, display the actual timeout on the page
            $('#docTimeout').text(docTimeout / 1000);


        })(jQuery);

    </script>

    <script type="text/javascript">
        /*
        Code for element idle timer
        */
        (function ($) {
            //Define textarea settings
            var
                taTimeout = 3000
            ;

            /*
            Handle raised idle/active events
            */
            $('#elStatus').on("idle.idleTimer", function (event, elem, obj) {
                //If you dont stop propagation it will bubble up to document event handler
                event.stopPropagation();

                $('#elStatus')
                    .val(function (i, v) {
                        return v + "Idle @ " + moment().format() + " \n";
                    })
                    .removeClass("alert-success")
                    .addClass("alert-warning")
                    .scrollToBottom();

            });
            $('#elStatus').on("active.idleTimer", function (event) {
                //If you dont stop propagation it will bubble up to document event handler
                event.stopPropagation();

                $('#elStatus')
                    .val(function (i, v) {
                        return v + "Active @ " + moment().format() + " \n";
                    })
                    .addClass("alert-success")
                    .removeClass("alert-warning")
                    .scrollToBottom();
            });

            /*
            Handle button events
            */
            $("#btReset").click(function () {
                $('#elStatus')
                    .idleTimer("reset")
                    .val(function (i, v) {
                        return v + "Reset @ " + moment().format() + " \n";
                    })
                    .scrollToBottom();

                //Apply classes for default state
                if ($("#elStatus").idleTimer("isIdle")) {
                    $('#elStatus')
                        .removeClass("alert-success")
                        .addClass("alert-warning");
                } else {
                    $('#elStatus')
                        .addClass("alert-success")
                        .removeClass("alert-warning");
                }
                $(this).blur();
                return false;
            }); 
            $("#btRemaining").click(function () {
                $('#elStatus')
                    .val(function (i, v) {
                        return v + "Remaining: " + $("#elStatus").idleTimer("getRemainingTime") + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            });
            $("#btLastActive").click(function () {
                $('#elStatus')
                    .val(function (i, v) {
                        return v + "LastActive: " + $("#elStatus").idleTimer("getLastActiveTime") + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            }); 
            $("#btState").click(function () {
                $('#elStatus')
                    .val(function (i, v) {
                        return v + "State: " + ($("#elStatus").idleTimer("isIdle")? "idle":"active") + " \n";
                    })
                    .scrollToBottom();
                $(this).blur();
                return false;
            });

            //Clear value if there was one cached & start time
            $('#elStatus').val('').idleTimer(taTimeout);

            //For demo purposes, show initial state
            if ($("#elStatus").idleTimer("isIdle")) {
                $("#elStatus")
                  .val(function (i, v) {
                      return v + "Initial Idle @ " + moment().format() + " \n";
                  })
                  .removeClass("alert-success")
                  .addClass("alert-warning")
                  .scrollToBottom();
            } else {
                $('#elStatus')
                    .val(function (i, v) {
                        return v + "Initial Active @ " + moment().format() + " \n";
                    })
                    .addClass("alert-success")
                    .removeClass("alert-warning")
                    .scrollToBottom();
            }

            // Display the actual timeout on the page
            $('#elTimeout').text(taTimeout / 1000);

        })(jQuery);

    </script>
</body>
</html>
