browser_util.js 1.8 KB

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