产品原型
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.6 KiB

4 years ago
  1. $axure.internal(function ($ax) {
  2. if ((IOS && SAFARI) || SHARE_APP) {
  3. var outerHtml = document.documentElement;
  4. outerHtml.id = 'ios-safari';
  5. var html = document.createElement('html');
  6. html.id = 'ios-safari-html';
  7. outerHtml.appendChild(html);
  8. var body = document.body;
  9. html.appendChild(body);
  10. Object.defineProperty(document, 'body', {
  11. get: function () {
  12. return body;
  13. }
  14. });
  15. var fixedBody = document.createElement('body');
  16. fixedBody.id = 'ios-safari-fixed';
  17. outerHtml.appendChild(fixedBody);
  18. var fixedBase = document.createElement('div');
  19. fixedBase.id = 'base-fixed';
  20. fixedBody.appendChild(fixedBase);
  21. var isDevice = false;
  22. var deviceWidth = 0;
  23. var updateHtmlWidth = function (panelWidthOffset, scale, height, scaleN) {
  24. var iosSafHtml = $('#ios-safari-html');
  25. iosSafHtml.css('overflow', '');
  26. iosSafHtml.css('overflow-x', '');
  27. iosSafHtml.css('height', '');
  28. if (isDevice) {
  29. iosSafHtml.width(deviceWidth / scaleN);
  30. iosSafHtml.css('overflow-x', 'hidden');
  31. } else {
  32. var isLandscape = window.orientation != 0 && window.orientation != 180;
  33. var mobileWidth = isLandscape ? window.screen.height : window.screen.width
  34. iosSafHtml.width((mobileWidth - panelWidthOffset) / scaleN);
  35. }
  36. if (scale == 1) {
  37. iosSafHtml.css('overflow-x', 'hidden');
  38. iosSafHtml.css('height', (height / scaleN) + 'px');
  39. } else if (scale == 2) iosSafHtml.css('overflow', 'hidden');
  40. };
  41. updateHtmlWidth(0);
  42. $axure('*').each(function (obj, element) {
  43. if (obj && obj.fixedVertical && obj.fixedKeepInFront) {
  44. var parent = $axure('#' + element).getParents(false, ['item', 'state'])[0];
  45. if (!parent) {
  46. $('#base-fixed').append($('#' + element));
  47. }
  48. }
  49. });
  50. $axure.messageCenter.addMessageListener(function (message, data) {
  51. if (message == "setContentScale") {
  52. updateHtmlWidth(data.panelWidthOffset, data.scale, data.viewportHeight, data.scaleN);
  53. } else if (message == "setDeviceMode") {
  54. isDevice = data.device && !data.scaleToWidth;
  55. if (isDevice) deviceWidth = data.width;
  56. updateHtmlWidth(0);
  57. }
  58. });
  59. $('#ios-safari-html').scroll(function () {
  60. $axure.updateWindowInfo();
  61. });
  62. var scrollStartY;
  63. var maxScrollY
  64. var touchStart;
  65. $axure('*').each(function (obj, element) {
  66. if (obj && obj.scrollbars && obj.scrollbars.toLowerCase() != 'none') {
  67. if (obj.scrollbars == 'horizontalAsNeeded') return;
  68. $('#' + element).on('touchstart', function (e) {
  69. touchStart = e.pageY;
  70. var stateId = $ax.visibility.GetPanelState($('#' + element).attr('id'));
  71. scrollStartY = $('#' + stateId).scrollTop();
  72. maxScrollY = $('#' + stateId)[0].scrollHeight - $('#' + stateId).height();
  73. });
  74. $('#' + element).on('touchmove', function (e) {
  75. if (maxScrollY <= 0) return false;
  76. if (scrollStartY == 0 && e.pageY > touchStart) e.preventDefault();
  77. if (scrollStartY == maxScrollY && e.pageY < touchStart) e.preventDefault();
  78. });
  79. }
  80. });
  81. }
  82. });