ajax.js 932 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true */
  9. 'use strict';
  10. module.exports = AjaxCollector;
  11. var collectEntropy_;
  12. function AjaxCollector(collectEntropyCallback) {
  13. collectEntropy_ = collectEntropyCallback;
  14. }
  15. AjaxCollector.prototype = {
  16. startCollector: function() {
  17. // if jQuery is included
  18. if (window.jQuery !== undefined) {
  19. $(window)
  20. .ajaxStart(function() {
  21. collectEntropy_((+new Date()), 1);
  22. })
  23. .ajaxComplete(function() {
  24. collectEntropy_((+new Date()), 1);
  25. });
  26. }
  27. },
  28. stopCollector: function() {
  29. // if jQuery is included
  30. if (window.jQuery !== undefined) {
  31. $(window).unbind('ajaxStart');
  32. $(window).unbind('ajaxComplete');
  33. }
  34. return true;
  35. }
  36. };