Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Timer

I am using the following script to time out a user. It works great but once I added it other parts of the system such as validation scripts and other things stopped working. Perhaps because the script is applied to 'document' ?
Is there an alternative I can try ?  this is my code as it is currently:

<script src="../includes/js/plugins/toastr/toastr.min.js"></script>
<script>
var timer;
$(document).ready(function () {
  // Set idle time
  $(document).idleTimer(5000);
});

$(document).on('idle.idleTimer', function(event, elem, obj){
  toastr.options = {
    "positionClass": "toast-top-right",
    "timeOut": 300000
  }

  toastr.warning('You have been idle for too long, to stayed logged in please move your mouse.','Idle for too long');
  $('.custom-alert').fadeIn();
  $('.custom-alert-active').fadeOut();
  timer = setTimeout(function() {
    window.location = '../Signout.asp';
  }, 300000);
});

$(document).on("active.idleTimer", function(event, elem, obj, triggerevent){
	toastr.options = {
    "timeOut": 3000
  }
  // function you want to fire when the user becomes active again
  clearTimeout(timer);
  toastr.clear();
  $('.custom-alert').fadeOut();
  toastr.success('Great to see you back!','You are back. ');
});
</script>

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

We would need to see this in the context of the page that is not working.

Are there errors in the console?
Avatar of Aleks

ASKER

Yes there is one. when I load the page it displays the error attached.  If I add the toast scipt here, or anywhere for that matter then I get this error and it some of the scripts in the include file like the validation scripts.

 I put the script inside an include file with the rest of the scripts below:

And the include file is right before the </body>  tag.

<!-- Mainly scripts -->
<script src="../includes/js/jquery-2.1.1.js"></script>
<script src="../includes/js/bootstrap.min.js"></script>
<script src="../includes/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="../includes/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
    
<!-- Custom and plugin javascript -->
<script src="../includes/js/inspinia.js"></script>
<script src="../includes/js/plugins/pace/pace.min.js"></script>

<!-- iCheck -->
<script src="../includes/js/plugins/iCheck/icheck.min.js"></script>
 <script>
            $(document).ready(function () {
                $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
                });
            });
</script>

<!-- Forms validation scripts -->
<script src="../includes/formvalidation/dist/js/formValidation.min.js"></script>
<script src="../includes/formvalidation/dist/js/framework/bootstrap.min.js"></script>

<!-- Date picker validation scripts -->
<script src="../includes/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="../includes/js/plugins/clockpicker/clockpicker.js"></script>  

<!-- Toastr script -->

<script src="../includes/js/plugins/toastr/toastr.min.js"></script>
<script>
var timer;
$(document).ready(function () {
  // Set idle time
  $(document).idleTimer(5000);
});

$(document).on('idle.idleTimer', function(event, elem, obj){
  toastr.options = {
    "positionClass": "toast-top-right",
    "timeOut": 300000
  }

  toastr.warning('You have been idle for too long, to stayed logged in please move your mouse.','Idle for too long');
  $('.custom-alert').fadeIn();
  $('.custom-alert-active').fadeOut();
  timer = setTimeout(function() {
    window.location = '../Signout.asp';
  }, 300000);
});

$(document).on("active.idleTimer", function(event, elem, obj, triggerevent){
	toastr.options = {
    "timeOut": 3000
  }
  // function you want to fire when the user becomes active again
  clearTimeout(timer);
  toastr.clear();
  $('.custom-alert').fadeOut();
  toastr.success('Great to see you back!','You are back. ');
});
</script>

Open in new window

error.PNG
Avatar of sajayj2009
sajayj2009

Which is plugin for idleTimer in above code?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

That was the issue. I found the library and now the issue is fixed !  Thanks so much !
You are welcome.