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.

326 lines
12 KiB

3 years ago
  1. $axure.internal(function($ax) {
  2. $(window.document).ready(function () {
  3. //var readyStart = (new Date()).getTime();
  4. //this is because the page id is not formatted as a guid
  5. var pageId = $ax.pageData.page.packageId;
  6. var pageData = {
  7. id: pageId,
  8. pageName: $ax.pageData.page.name,
  9. location: window.location.toString(),
  10. notes: $ax.pageData.page.notes,
  11. widgetNotes: $ax.pageData.page.annotations,
  12. //clipToView: $ax.pageData.clipToView,
  13. defaultAdaptiveView: $ax.pageData.defaultAdaptiveView,
  14. adaptiveViews: $ax.pageData.adaptiveViews,
  15. masterNotes: []
  16. };
  17. var fnPrefix = '';
  18. function pushNextPrefix() {
  19. if (fnPrefix.length == 0) fnPrefix = 'A';
  20. else fnPrefix = fnPrefix[0] == 'Z' ? 'A'.repeat(fnPrefix.length + 1) : String.fromCharCode(fnPrefix.charCodeAt(0) + 1).repeat(fnPrefix.length);
  21. }
  22. function populateNotes(pageForNotes) {
  23. for (var master in pageForNotes.masters) {
  24. //var master = pageForNotes.masters[i];
  25. var masterData = pageForNotes.masters[master];
  26. var hasWidgetNotes = masterData.annotations && masterData.annotations.length > 0;
  27. if ((master.notes && !$.isEmptyObject(masterData.notes)) || hasWidgetNotes) {
  28. if(hasWidgetNotes) pushNextPrefix();
  29. var m = {};
  30. m.pageName = masterData.name;
  31. m.notes = masterData.notes;
  32. m.widgetNotes = masterData.annotations;
  33. pageData.masterNotes.push(m);
  34. if(hasWidgetNotes) populateOwnerToFn(m.widgetNotes);
  35. }
  36. populateNotes(master);
  37. }
  38. }
  39. var ownerToFns = {};
  40. function populateOwnerToFn(widgetNotes) {
  41. if(typeof widgetNotes == 'undefined') return false;
  42. for (var i = 0; i < widgetNotes.length; i++) {
  43. var widgetNote = widgetNotes[i];
  44. widgetNote['fn'] = fnPrefix + widgetNote['fn'];
  45. var fn = widgetNote['fn'];
  46. var ownerId = widgetNote['ownerId'];
  47. if (ownerId !== undefined && ownerId.length > 0) {
  48. var ownerLabels = ownerToFns[ownerId];
  49. if (ownerLabels == undefined) ownerLabels = [];
  50. ownerLabels.push(fn);
  51. ownerToFns[ownerId] = ownerLabels;
  52. }
  53. }
  54. }
  55. populateOwnerToFn(pageData.widgetNotes);
  56. populateNotes($ax.pageData);
  57. pageData.ownerToFns = ownerToFns;
  58. $ax.pageData.notesData = pageData;
  59. //var anns = [];
  60. //$ax('*').each(function (dObj, elementId) {
  61. // pushAnnotation(dObj, elementId);
  62. //});
  63. //function pushAnnotation(dObj, elementId) {
  64. // var ann = dObj.annotation;
  65. // if(ann) {
  66. // ann = $ax.deepCopy(ann);
  67. // ann["id"] = elementId;
  68. // ann["label"] = dObj.label + " (" + dObj.friendlyType + ")";
  69. // anns.push(ann);
  70. // }
  71. // if(dObj.type === 'repeater' && dObj.objects) {
  72. // //if it's repeater, save the id as repeaterId@scriptId
  73. // for(var i = 0, len = dObj.objects.length; i < len; i++) {
  74. // var child = dObj.objects[i];
  75. // var scriptId = $ax.getScriptIdFromPath([child.id], elementId);
  76. // pushAnnotation(child, elementId + '@' + scriptId);
  77. // }
  78. // }
  79. //}
  80. //pageData.widgetNotes = anns;
  81. //only trigger the page.data setting if the window is on the mainframe
  82. var isMainFrame = false;
  83. try {
  84. if(window.name == 'mainFrame' ||
  85. (!CHROME_5_LOCAL && window.parent.$ && window.parent.$('#mainFrame').length > 0)) {
  86. isMainFrame = true;
  87. $ax.messageCenter.addMessageListener(function(message, data) {
  88. if(message == 'finishInit') {
  89. _processTempInit();
  90. }
  91. });
  92. $axure.messageCenter.setState('page.data', pageData);
  93. window.focus();
  94. }
  95. } catch(e) { }
  96. //attach here for chrome local
  97. //$(window).on('load', function() {
  98. // $ax.style.initializeObjectTextAlignment($ax('*'));
  99. //});
  100. if(!isMainFrame) _processTempInit();
  101. });
  102. var touchCount = 0;
  103. var lastTouch = Date.now();
  104. var _registerTouchCount = $ax.registerTouchCount = function (e) {
  105. var now = Date.now();
  106. if (now - lastTouch < 375) {
  107. if (++touchCount === 3) {
  108. $(':input').blur();
  109. $ax.messageCenter.postMessage('tripleClick', true);
  110. e.preventDefault();
  111. };
  112. } else {
  113. touchCount = 1;
  114. }
  115. lastTouch = now;
  116. };
  117. // Block IOS stalling second tap.
  118. // Stop third click from also clicking mobile card
  119. var _clearTouchCount = $ax.clearTouchCount = function (e) {
  120. if (touchCount === 3) {
  121. touchCount = 0;
  122. e.preventDefault();
  123. }
  124. };
  125. var _processTempInit = function() {
  126. //var start = (new Date()).getTime();
  127. //var end = (new Date()).getTime();
  128. //window.alert('elapsed ' + (end - start));
  129. $('iframe').each(function() {
  130. var origSrc = $(this).attr('basesrc');
  131. var $this = $(this);
  132. if(origSrc) {
  133. var newSrcUrl = origSrc.toLowerCase().indexOf('http://') == -1 ? $ax.globalVariableProvider.getLinkUrl(origSrc) : origSrc;
  134. $this.attr('src', newSrcUrl);
  135. }
  136. if(IOS) {
  137. $this.parent().css('overflow', 'auto').css('-webkit-overflow-scrolling', 'touch').css('-ms-overflow-x', 'hidden').css('overflow-x', 'hidden');
  138. }
  139. });
  140. $axure.messageCenter.addMessageListener(function(message, data) {
  141. if(message == 'setGlobalVar') {
  142. $ax.globalVariableProvider.setVariableValue(data.globalVarName, data.globalVarValue, true);
  143. }
  144. });
  145. window.lastFocusedClickable = null;
  146. var _lastFocusedClickableSelector = 'input, a';
  147. var shouldOutline = true;
  148. $ax(function (dObj) { return dObj.tabbable; }).each(function (dObj, elementId) {
  149. if ($ax.public.fn.IsLayer(dObj.type)) $ax.event.layerMapFocus(dObj, elementId);
  150. var focusableId = $ax.event.getFocusableWidgetOrChildId(elementId);
  151. var $focusable = $('#' + focusableId);
  152. $focusable.attr("tabIndex", 0);
  153. if($focusable.is('div') || $focusable.is('img')) {
  154. $focusable.bind($ax.features.eventNames.mouseDownName, function() {
  155. shouldOutline = false;
  156. });
  157. attachFocusAndBlur($focusable);
  158. }
  159. });
  160. $(window.document).bind($ax.features.eventNames.mouseUpName, function() {
  161. shouldOutline = true;
  162. });
  163. attachFocusAndBlur($(_lastFocusedClickableSelector));
  164. function attachFocusAndBlur($query) {
  165. $query.focus(function () {
  166. if(shouldOutline) {
  167. $(this).css('outline', '');
  168. } else {
  169. $(this).css('outline', 'none');
  170. }
  171. window.lastFocusedClickable = this;
  172. }).blur(function () {
  173. if(window.lastFocusedClickable == this) window.lastFocusedClickable = null;
  174. });
  175. }
  176. $(window.document).bind('keyup', function (e) {
  177. switch(e.which) {
  178. case 13:
  179. case 32:
  180. if(window.lastFocusedClickable) $(window.lastFocusedClickable).click();
  181. break;
  182. default: return; // exit this handler for other keys
  183. }
  184. });
  185. //if($ax.document.configuration.hideAddress) {
  186. // $(window).on('load', function() {
  187. // window.setTimeout(function() {
  188. // window.scrollTo(0, 0.9);
  189. // }, 0);
  190. // });
  191. //}
  192. //if($ax.document.configuration.preventScroll) {
  193. // $(window.document).bind('touchmove', function(e) {
  194. // var inScrollable = $ax.legacy.GetScrollable(e.target) != window.document.body;
  195. // if(!inScrollable) {
  196. // e.preventDefault();
  197. // }
  198. // });
  199. // $ax(function(diagramObject) {
  200. // return $ax.public.fn.IsDynamicPanel(diagramObject.type) && diagramObject.scrollbars != 'none';
  201. // }).$().children().bind('touchstart', function() {
  202. // var target = this;
  203. // var top = target.scrollTop;
  204. // if(top <= 0) target.scrollTop = 1;
  205. // if(top + target.offsetHeight >= target.scrollHeight) target.scrollTop = target.scrollHeight - target.offsetHeight - 1;
  206. // });
  207. //}
  208. if(OS_MAC && WEBKIT) {
  209. $ax(function(diagramObject) {
  210. return $ax.public.fn.IsComboBox(diagramObject.type);
  211. }).each(function(obj, id) {
  212. $jobj($ax.INPUT(id)).css('-webkit-appearance', 'menulist-button');
  213. });
  214. }
  215. if($ax.features.supports.mobile) {
  216. $('html').first().on('touchstart', _registerTouchCount);
  217. $('html').first().on('touchend', _clearTouchCount);
  218. // Stop pinch zoom (stopping all gestures for now)
  219. // Gesturestart is only supported in Safari
  220. if (SAFARI) {
  221. document.addEventListener("gesturestart", function (e) {
  222. e.preventDefault();
  223. });
  224. }
  225. }
  226. $ax.annotation.initialize();
  227. $ax.legacy.BringFixedToFront();
  228. $ax.event.initialize();
  229. $ax.style.initialize();
  230. $ax.visibility.initialize();
  231. $ax.repeater.initialize();
  232. $ax.dynamicPanelManager.initialize(); //needs to be called after visibility is initialized
  233. $ax.adaptive.initialize();
  234. $ax.loadDynamicPanelsAndMasters();
  235. $ax.adaptive.loadFinished();
  236. var start = (new Date()).getTime();
  237. $ax.repeater.initRefresh();
  238. var end = (new Date()).getTime();
  239. console.log('loadTime: ' + (end - start) / 1000);
  240. $ax.style.prefetch();
  241. $(window).resize();
  242. //var readyEnd = (new Date()).getTime();
  243. //window.alert('elapsed ' + (readyEnd - readyStart));
  244. };
  245. });
  246. /* extend canvas */
  247. var gv_hasCanvas = false;
  248. (function() {
  249. var _canvas = document.createElement('canvas'), proto, abbrev;
  250. if(gv_hasCanvas = !!(_canvas.getContext && _canvas.getContext('2d')) && typeof (CanvasGradient) !== 'undefined') {
  251. function chain(func) {
  252. return function() {
  253. return func.apply(this, arguments) || this;
  254. };
  255. }
  256. with(proto = CanvasRenderingContext2D.prototype) for(var func in abbrev = {
  257. a: arc,
  258. b: beginPath,
  259. n: clearRect,
  260. c: clip,
  261. p: closePath,
  262. g: createLinearGradient,
  263. f: fill,
  264. j: fillRect,
  265. z: function(s) { this.fillStyle = s; },
  266. l: lineTo,
  267. w: function(w) { this.lineWidth = w; },
  268. m: moveTo,
  269. q: quadraticCurveTo,
  270. h: rect,
  271. r: restore,
  272. o: rotate,
  273. s: save,
  274. x: scale,
  275. y: function(s) { this.strokeStyle = s; },
  276. u: setTransform,
  277. k: stroke,
  278. i: strokeRect,
  279. t: translate
  280. }) proto[func] = chain(abbrev[func]);
  281. CanvasGradient.prototype.a = chain(CanvasGradient.prototype.addColorStop);
  282. }
  283. })();