bs-common.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var startPoint = new Date();
  2. var loadStartPoint = new Date();
  3. var loadingShowed = false;
  4. //防止页面后退
  5. history.pushState(null, null, document.URL);
  6. window.addEventListener('popstate', back_common);
  7. function back_common() {
  8. history.pushState(null, null, document.URL);
  9. }
  10. document.addEventListener('contextmenu', function (e) {
  11. e.preventDefault();
  12. return false;
  13. });
  14. document.addEventListener("touchstart", function (e) {
  15. e.preventDefault();
  16. e.stopPropagation();
  17. return false;
  18. }, false);
  19. $(function () {
  20. $(document).click(function () {
  21. resetTime();
  22. });
  23. jQuery.support.cors = true;
  24. var commonTimeOut = 10000;
  25. var longTimeOut = 60000;
  26. var loadingTimeout = 60000;
  27. if ($("#loading") != null) {
  28. window.setInterval(function () {
  29. if ($("#loading").is(":visible") && !loadingShowed) {
  30. loadingShowed = true;
  31. loadStartPoint = new Date;
  32. }
  33. if ($("#loading").is(":hidden") && loadingShowed) {
  34. loadingShowed = false;
  35. }
  36. }, 100);
  37. }
  38. if (location.href.indexOf("/Home/screensaver") < 0 || location.href.indexOf("/Home/screensaverTwo") >= 0) {
  39. var interRet = window.setInterval(function () {
  40. var isNotLoading = $("#loading").is(":hidden");
  41. if ($("#loading").length > 0 && !isNotLoading) {
  42. resetTime();
  43. }
  44. var curTime = new Date();
  45. var timeOutVal = commonTimeOut;
  46. if (location.href.indexOf("/Home/screensaverTwo") >= 0
  47. || location.href.indexOf("/Home/Preview") >= 0) {
  48. timeOutVal = longTimeOut;
  49. }
  50. if (parseInt(curTime - startPoint) >= timeOutVal) {
  51. $.post(rootPath + "/Home/StopCheck", null, function (res) {
  52. });
  53. window.clearInterval(interRet);
  54. location.href = rootPath + "/Home/screensaver";
  55. }
  56. //设置读取超时
  57. if (parseInt(curTime - loadStartPoint) >= loadingTimeout && loadingShowed) {
  58. $.post(rootPath + "/Home/StopCheck", null, function (res) {
  59. });
  60. window.clearInterval(interRet);
  61. location.href = rootPath + "/Home/screensaver";
  62. }
  63. }, 1000);
  64. }
  65. });
  66. function getUrlParam(name) {
  67. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  68. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  69. if (r != null)
  70. return unescape(r[2]);
  71. return null; //返回参数值
  72. }
  73. function resetTime() {
  74. startPoint = new Date();
  75. }