init.temp.js 6.6 KB

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