init.temp.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. window.shouldOutline = true;
  147. $(window.document).bind($ax.features.eventNames.mouseUpName, function() {
  148. window.shouldOutline = true;
  149. });
  150. var _lastFocusedClickableSelector = 'input, a';
  151. $ax.event.attachFocusAndBlur($(_lastFocusedClickableSelector));
  152. $(window.document).bind('keyup', function (e) {
  153. switch(e.which) {
  154. case 13:
  155. case 32:
  156. if(window.lastFocusedClickable) $(window.lastFocusedClickable).click();
  157. break;
  158. default: return; // exit this handler for other keys
  159. }
  160. });
  161. //if($ax.document.configuration.hideAddress) {
  162. // $(window).on('load', function() {
  163. // window.setTimeout(function() {
  164. // window.scrollTo(0, 0.9);
  165. // }, 0);
  166. // });
  167. //}
  168. //if($ax.document.configuration.preventScroll) {
  169. // $(window.document).bind('touchmove', function(e) {
  170. // var inScrollable = $ax.legacy.GetScrollable(e.target) != window.document.body;
  171. // if(!inScrollable) {
  172. // e.preventDefault();
  173. // }
  174. // });
  175. // $ax(function(diagramObject) {
  176. // return $ax.public.fn.IsDynamicPanel(diagramObject.type) && diagramObject.scrollbars != 'none';
  177. // }).$().children().bind('touchstart', function() {
  178. // var target = this;
  179. // var top = target.scrollTop;
  180. // if(top <= 0) target.scrollTop = 1;
  181. // if(top + target.offsetHeight >= target.scrollHeight) target.scrollTop = target.scrollHeight - target.offsetHeight - 1;
  182. // });
  183. //}
  184. if(OS_MAC && WEBKIT) {
  185. $ax(function(diagramObject) {
  186. return $ax.public.fn.IsComboBox(diagramObject.type);
  187. }).each(function(obj, id) {
  188. $jobj($ax.INPUT(id)).css('-webkit-appearance', 'menulist-button');
  189. });
  190. }
  191. if($ax.features.supports.mobile) {
  192. $('html').first().on('touchstart', _registerTouchCount);
  193. $('html').first().on('touchend', _clearTouchCount);
  194. // Stop pinch zoom (stopping all gestures for now)
  195. // Gesturestart is only supported in Safari
  196. if (SAFARI) {
  197. document.addEventListener("gesturestart", function (e) {
  198. e.preventDefault();
  199. });
  200. }
  201. }
  202. $ax.annotation.initialize();
  203. $ax.legacy.BringFixedToFront();
  204. $ax.event.initialize();
  205. $ax.style.initialize();
  206. $ax.visibility.initialize();
  207. $ax.repeater.initialize();
  208. $ax.dynamicPanelManager.initialize(); //needs to be called after visibility is initialized
  209. $ax.adaptive.initialize();
  210. $ax.loadDynamicPanelsAndMasters();
  211. $ax.adaptive.loadFinished();
  212. var start = (new Date()).getTime();
  213. $ax.repeater.initRefresh();
  214. var end = (new Date()).getTime();
  215. console.log('loadTime: ' + (end - start) / 1000);
  216. $ax.style.prefetch();
  217. $(window).resize();
  218. //var readyEnd = (new Date()).getTime();
  219. //window.alert('elapsed ' + (readyEnd - readyStart));
  220. };
  221. });
  222. /* extend canvas */
  223. var gv_hasCanvas = false;
  224. (function() {
  225. var _canvas = document.createElement('canvas'), proto, abbrev;
  226. if(gv_hasCanvas = !!(_canvas.getContext && _canvas.getContext('2d')) && typeof (CanvasGradient) !== 'undefined') {
  227. function chain(func) {
  228. return function() {
  229. return func.apply(this, arguments) || this;
  230. };
  231. }
  232. with(proto = CanvasRenderingContext2D.prototype) for(var func in abbrev = {
  233. a: arc,
  234. b: beginPath,
  235. n: clearRect,
  236. c: clip,
  237. p: closePath,
  238. g: createLinearGradient,
  239. f: fill,
  240. j: fillRect,
  241. z: function(s) { this.fillStyle = s; },
  242. l: lineTo,
  243. w: function(w) { this.lineWidth = w; },
  244. m: moveTo,
  245. q: quadraticCurveTo,
  246. h: rect,
  247. r: restore,
  248. o: rotate,
  249. s: save,
  250. x: scale,
  251. y: function(s) { this.strokeStyle = s; },
  252. u: setTransform,
  253. k: stroke,
  254. i: strokeRect,
  255. t: translate
  256. }) proto[func] = chain(abbrev[func]);
  257. CanvasGradient.prototype.a = chain(CanvasGradient.prototype.addColorStop);
  258. }
  259. })();