OSHelper.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. 
  2. var OSHelper = {
  3. isPC: undefined,
  4. touchStart: undefined,
  5. touchMove: undefined,
  6. touchEnd: undefined,
  7. orbitCtlDistanceMultiple: undefined,
  8. windowWidthDefault: undefined,
  9. init: function () {
  10. this.isPC = this.isPCOS();
  11. this.touchStart = this.isPC ? 'mousedown' : 'touchstart';
  12. this.touchMove = this.isPC ? 'mousemove' : 'touchmove';
  13. this.touchEnd = this.isPC ? 'mouseup' : 'touchend';
  14. this.orbitCtlDistanceMultiple = this.isPC ? 3 : 2;
  15. this.windowWidthDefault = this.isPC ? 1100 : 600;
  16. },
  17. isPCOS: function () {
  18. var userAgentInfo = navigator.userAgent;
  19. var Agents = ["Android", "iPhone",
  20. "SymbianOS", "Windows Phone",
  21. "iPad", "iPod"];
  22. var result = true;
  23. for (var v = 0; v < Agents.length; v++) {
  24. if (userAgentInfo.indexOf(Agents[v]) > 0) {
  25. result = false;
  26. break;
  27. }
  28. }
  29. return result;
  30. },
  31. clientX: function (event) {
  32. return this.isPC ? event.clientX : event.targetTouches[0].clientX;
  33. },
  34. clientY: function (event) {
  35. return this.isPC ? event.clientY : event.targetTouches[0].clientY;
  36. },
  37. convertCefParameter: function (inputData) {
  38. return this.isPC ? inputData : JSON.stringify(inputData);
  39. }
  40. };