browser_util.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.mapsForIE = void 0;
  4. exports.detectIE = detectIE;
  5. exports.detectEdge = detectEdge;
  6. const system_external_js_1 = require("./system_external.js");
  7. const xpath_util_js_1 = require("./xpath_util.js");
  8. function detectIE() {
  9. const isIE = typeof window !== 'undefined' &&
  10. 'ActiveXObject' in window &&
  11. 'clipboardData' in window;
  12. if (!isIE) {
  13. return false;
  14. }
  15. loadMapsForIE();
  16. loadWGXpath();
  17. return true;
  18. }
  19. function detectEdge() {
  20. var _a;
  21. const isEdge = typeof window !== 'undefined' &&
  22. 'MSGestureEvent' in window &&
  23. ((_a = window.chrome) === null || _a === void 0 ? void 0 : _a.loadTimes) === null;
  24. if (!isEdge) {
  25. return false;
  26. }
  27. document.evaluate = null;
  28. loadWGXpath(true);
  29. return true;
  30. }
  31. exports.mapsForIE = null;
  32. function loadWGXpath(opt_isEdge) {
  33. loadScript(system_external_js_1.SystemExternal.WGXpath);
  34. installWGXpath(opt_isEdge);
  35. }
  36. function installWGXpath(opt_isEdge, opt_count) {
  37. let count = opt_count || 1;
  38. if (typeof wgxpath === 'undefined' && count < 10) {
  39. setTimeout(function () {
  40. installWGXpath(opt_isEdge, count++);
  41. }, 200);
  42. return;
  43. }
  44. if (count >= 10) {
  45. return;
  46. }
  47. system_external_js_1.SystemExternal.wgxpath = wgxpath;
  48. opt_isEdge
  49. ? system_external_js_1.SystemExternal.wgxpath.install({ document: document })
  50. : system_external_js_1.SystemExternal.wgxpath.install();
  51. xpath_util_js_1.xpath.evaluate = document.evaluate;
  52. xpath_util_js_1.xpath.result = XPathResult;
  53. xpath_util_js_1.xpath.createNSResolver = document.createNSResolver;
  54. }
  55. function loadMapsForIE() {
  56. loadScript(system_external_js_1.SystemExternal.mathmapsIePath);
  57. }
  58. function loadScript(src) {
  59. const scr = system_external_js_1.SystemExternal.document.createElement('script');
  60. scr.type = 'text/javascript';
  61. scr.src = src;
  62. system_external_js_1.SystemExternal.document.head
  63. ? system_external_js_1.SystemExternal.document.head.appendChild(scr)
  64. : system_external_js_1.SystemExternal.document.body.appendChild(scr);
  65. }