init.temp.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. };
  12. var anns = [];
  13. $ax('*').each(function (dObj, elementId) {
  14. pushAnnotation(dObj, elementId);
  15. });
  16. function pushAnnotation(dObj, elementId) {
  17. var ann = dObj.annotation;
  18. if(ann) {
  19. ann["id"] = elementId;
  20. ann["label"] = dObj.label + " (" + dObj.friendlyType + ")";
  21. anns.push(ann);
  22. }
  23. if(dObj.type == 'repeater') {
  24. if(dObj.objects) {
  25. for(var i = 0, len = dObj.objects.length; i < len; i++) {
  26. pushAnnotation(dObj.objects[i]);
  27. }
  28. }
  29. }
  30. }
  31. pageData.widgetNotes = anns;
  32. //only trigger the page.data setting if the window is on the mainframe
  33. var isMainFrame = false;
  34. try {
  35. if(window.name == 'mainFrame' ||
  36. (!CHROME_5_LOCAL && window.parent.$ && window.parent.$('#mainFrame').length > 0)) {
  37. isMainFrame = true;
  38. $ax.messageCenter.addMessageListener(function(message, data) {
  39. if(message == 'finishInit') {
  40. _processTempInit();
  41. }
  42. });
  43. $axure.messageCenter.setState('page.data', pageData);
  44. window.focus();
  45. }
  46. } catch(e) { }
  47. //attach here for chrome local
  48. $(window).load(function() {
  49. $ax.style.initializeObjectTextAlignment($ax('*'));
  50. });
  51. if(!isMainFrame) _processTempInit();
  52. });
  53. var _processTempInit = function() {
  54. //var start = (new Date()).getTime();
  55. //var end = (new Date()).getTime();
  56. //window.alert('elapsed ' + (end - start));
  57. $('iframe').each(function() {
  58. var origSrc = $(this).attr('basesrc');
  59. var $this = $(this);
  60. if(origSrc) {
  61. var newSrcUrl = origSrc.toLowerCase().indexOf('http://') == -1 ? $ax.globalVariableProvider.getLinkUrl(origSrc) : origSrc;
  62. $this.attr('src', newSrcUrl);
  63. }
  64. if(IOS) {
  65. $this.parent().css('overflow', 'auto').css('-webkit-overflow-scrolling', 'touch').css('-ms-overflow-x', 'hidden').css('overflow-x', 'hidden');
  66. }
  67. });
  68. $axure.messageCenter.addMessageListener(function(message, data) {
  69. if(message == 'setGlobalVar') {
  70. $ax.globalVariableProvider.setVariableValue(data.globalVarName, data.globalVarValue, true);
  71. }
  72. });
  73. window.lastFocusedClickable = null;
  74. var _lastFocusedClickableSelector = 'div[tabIndex=0], img[tabIndex=0], input, a';
  75. var shouldOutline = true;
  76. $ax(function (dObj) { return dObj.tabbable; }).each(function (dObj, elementId) {
  77. if ($ax.public.fn.IsLayer(dObj.type)) $ax.event.layerMapFocus(dObj, elementId);
  78. var focusableId = $ax.event.getFocusableWidgetOrChildId(elementId);
  79. $('#' + focusableId).attr("tabIndex", 0);
  80. });
  81. $('div[tabIndex=0], img[tabIndex=0]').bind($ax.features.eventNames.mouseDownName, function() {
  82. shouldOutline = false;
  83. });
  84. $(window.document).bind($ax.features.eventNames.mouseUpName, function() {
  85. shouldOutline = true;
  86. });
  87. $(_lastFocusedClickableSelector).focus(function () {
  88. if(shouldOutline) {
  89. $(this).css('outline', '');
  90. } else {
  91. $(this).css('outline', 'none');
  92. }
  93. window.lastFocusedClickable = this;
  94. });
  95. $(_lastFocusedClickableSelector).blur(function () {
  96. if(window.lastFocusedClickable == this) window.lastFocusedClickable = null;
  97. });
  98. $(window.document).bind('keyup', function(e) {
  99. if(e.keyCode == '13' || e.keyCode == '32') {
  100. if(window.lastFocusedClickable) $(window.lastFocusedClickable).click();
  101. }
  102. });
  103. if($ax.document.configuration.hideAddress) {
  104. $(window).load(function() {
  105. window.setTimeout(function() {
  106. window.scrollTo(0, 0.9);
  107. }, 0);
  108. });
  109. }
  110. if($ax.document.configuration.preventScroll) {
  111. $(window.document).bind('touchmove', function(e) {
  112. var inScrollable = $ax.legacy.GetScrollable(e.target) != window.document.body;
  113. if(!inScrollable) {
  114. e.preventDefault();
  115. }
  116. });
  117. $ax(function(diagramObject) {
  118. return $ax.public.fn.IsDynamicPanel(diagramObject.type) && diagramObject.scrollbars != 'none';
  119. }).$().children().bind('touchstart', function() {
  120. var target = this;
  121. var top = target.scrollTop;
  122. if(top <= 0) target.scrollTop = 1;
  123. if(top + target.offsetHeight >= target.scrollHeight) target.scrollTop = target.scrollHeight - target.offsetHeight - 1;
  124. });
  125. }
  126. if(OS_MAC && WEBKIT) {
  127. $ax(function(diagramObject) {
  128. return $ax.public.fn.IsComboBox(diagramObject.type);
  129. }).each(function(obj, id) {
  130. $jobj($ax.INPUT(id)).css('-webkit-appearance', 'menulist-button').css('border-color', '#999999');
  131. });
  132. }
  133. $ax.legacy.BringFixedToFront();
  134. $ax.event.initialize();
  135. $ax.style.initialize();
  136. $ax.visibility.initialize();
  137. $ax.repeater.initialize();
  138. $ax.dynamicPanelManager.initialize(); //needs to be called after visibility is initialized
  139. $ax.adaptive.initialize();
  140. $ax.loadDynamicPanelsAndMasters();
  141. $ax.adaptive.loadFinished();
  142. var start = (new Date()).getTime();
  143. $ax.repeater.initRefresh();
  144. var end = (new Date()).getTime();
  145. console.log('loadTime: ' + (end - start) / 1000);
  146. $ax.style.prefetch();
  147. $(window).resize();
  148. //var readyEnd = (new Date()).getTime();
  149. //window.alert('elapsed ' + (readyEnd - readyStart));
  150. };
  151. });
  152. /* extend canvas */
  153. var gv_hasCanvas = false;
  154. (function() {
  155. var _canvas = document.createElement('canvas'), proto, abbrev;
  156. if(gv_hasCanvas = !!(_canvas.getContext && _canvas.getContext('2d')) && typeof (CanvasGradient) !== 'undefined') {
  157. function chain(func) {
  158. return function() {
  159. return func.apply(this, arguments) || this;
  160. };
  161. }
  162. with(proto = CanvasRenderingContext2D.prototype) for(var func in abbrev = {
  163. a: arc,
  164. b: beginPath,
  165. n: clearRect,
  166. c: clip,
  167. p: closePath,
  168. g: createLinearGradient,
  169. f: fill,
  170. j: fillRect,
  171. z: function(s) { this.fillStyle = s; },
  172. l: lineTo,
  173. w: function(w) { this.lineWidth = w; },
  174. m: moveTo,
  175. q: quadraticCurveTo,
  176. h: rect,
  177. r: restore,
  178. o: rotate,
  179. s: save,
  180. x: scale,
  181. y: function(s) { this.strokeStyle = s; },
  182. u: setTransform,
  183. k: stroke,
  184. i: strokeRect,
  185. t: translate
  186. }) proto[func] = chain(abbrev[func]);
  187. CanvasGradient.prototype.a = chain(CanvasGradient.prototype.addColorStop);
  188. }
  189. })();