legacy.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. //stored on each browser event
  2. var windowEvent;
  3. $axure.internal(function($ax) {
  4. var _legacy = {};
  5. $ax.legacy = _legacy;
  6. // ************************** GLOBAL VARS *********************************//
  7. // ************************************************************************//
  8. //Check if IE
  9. //var bIE = false;
  10. //if ((index = navigator.userAgent.indexOf("MSIE")) >= 0) {
  11. // bIE = true;
  12. //}
  13. var Forms = window.document.getElementsByTagName("FORM");
  14. for(var i = 0; i < Forms.length; i++) {
  15. var Form = Forms[i];
  16. Form.onclick = $ax.legacy.SuppressBubble;
  17. }
  18. $ax.legacy.SuppressBubble = function(event) {
  19. if(IE_10_AND_BELOW) {
  20. window.event.cancelBubble = true;
  21. window.event.returnValue = false;
  22. } else {
  23. if(event) {
  24. event.stopPropagation();
  25. }
  26. }
  27. };
  28. // function InsertAfterBegin(dom, html) {
  29. // if(!IE) {
  30. // var phtml;
  31. // var range = dom.ownerDocument.createRange();
  32. // range.selectNodeContents(dom);
  33. // range.collapse(true);
  34. // phtml = range.createContextualFragment(html);
  35. // dom.insertBefore(phtml, dom.firstChild);
  36. // } else {
  37. // dom.insertAdjacentHTML("afterBegin", html);
  38. // }
  39. // }
  40. // function InsertBeforeEnd(dom, html) {
  41. // if(!IE) {
  42. // var phtml;
  43. // var range = dom.ownerDocument.createRange();
  44. // range.selectNodeContents(dom);
  45. // range.collapse(dom);
  46. // phtml = range.createContextualFragment(html);
  47. // dom.appendChild(phtml);
  48. // } else {
  49. // dom.insertAdjacentHTML("beforeEnd", html);
  50. // }
  51. // }
  52. //Get the id of the Workflow Dialog belonging to element with id = id
  53. // function Workflow(id) {
  54. // return id + 'WF';
  55. // }
  56. $ax.legacy.BringToFront = function(id, skipFixed) {
  57. _bringToFrontHelper(id);
  58. if(!skipFixed) $ax.legacy.BringFixedToFront();
  59. };
  60. var _bringToFrontHelper = function(id) {
  61. var target = window.document.getElementById(id);
  62. if(target == null) return;
  63. $ax.globals.MaxZIndex = $ax.globals.MaxZIndex + 1;
  64. target.style.zIndex = $ax.globals.MaxZIndex;
  65. };
  66. $ax.legacy.BringFixedToFront = function() {
  67. $ax(function(diagramObject) { return diagramObject.fixedKeepInFront; }).each(function(diagramObject, scriptId) {
  68. _bringToFrontHelper(scriptId);
  69. });
  70. };
  71. $ax.legacy.SendToBack = function(id) {
  72. var target = window.document.getElementById(id);
  73. if(target == null) return;
  74. target.style.zIndex = $ax.globals.MinZIndex = $ax.globals.MinZIndex - 1;
  75. };
  76. $ax.legacy.RefreshScreen = function() {
  77. var oldColor = window.document.body.style.backgroundColor;
  78. var setColor = (oldColor == "rgb(0,0,0)") ? "#FFFFFF" : "#000000";
  79. window.document.body.style.backgroundColor = setColor;
  80. window.document.body.style.backgroundColor = oldColor;
  81. };
  82. $ax.legacy.getAbsoluteLeft = function(currentNode, elementId) {
  83. var oldDisplay = currentNode.css('display');
  84. var displaySet = false;
  85. if(oldDisplay == 'none') {
  86. currentNode.css('display', '');
  87. displaySet = true;
  88. }
  89. var left = currentNode.offset().left;
  90. // Special Layer code
  91. if($ax.getTypeFromElementId(elementId) == 'layer') {
  92. var first = true;
  93. var children = currentNode.children();
  94. for(var i = 0; i < children.length; i++) {
  95. var child = $(children[i]);
  96. var subDisplaySet = false;
  97. if(child.css('display') == 'none') {
  98. child.css('display', '');
  99. subDisplaySet = true;
  100. }
  101. if(first) left = child.offset().left;
  102. else left = Math.min(child.offset().left, left);
  103. first = false;
  104. if(subDisplaySet) child.css('display', 'none');
  105. }
  106. }
  107. if (displaySet) currentNode.css('display', oldDisplay);
  108. return $axure.fn.bodyToWorld(left, true);
  109. };
  110. $ax.legacy.getAbsoluteTop = function(currentNode, elementId) {
  111. var oldDisplay = currentNode.css('display');
  112. var displaySet = false;
  113. if(oldDisplay == 'none') {
  114. currentNode.css('display', '');
  115. displaySet = true;
  116. }
  117. var top = currentNode.offset().top;
  118. // Special Layer code
  119. if ($ax.getTypeFromElementId(elementId) == 'layer') {
  120. var first = true;
  121. var children = currentNode.children();
  122. for (var i = 0; i < children.length; i++) {
  123. var child = $(children[i]);
  124. var subDisplaySet = false;
  125. if (child.css('display') == 'none') {
  126. child.css('display', '');
  127. subDisplaySet = true;
  128. }
  129. if (first) top = child.offset().top;
  130. else top = Math.min(child.offset().top, top);
  131. first = false;
  132. if (subDisplaySet) child.css('display', 'none');
  133. }
  134. }
  135. if(displaySet) currentNode.css('display', oldDisplay);
  136. return top;
  137. };
  138. // ****************** Annotation and Link Functions ****************** //
  139. $ax.legacy.GetAnnotationHtml = function(annJson) {
  140. var retVal = "";
  141. for(var noteName in annJson) {
  142. if(noteName != "label" && noteName != "id") {
  143. retVal += "<div class='annotationName'>" + noteName + "</div>";
  144. retVal += "<div class='annotationValue'>" + linkify(annJson[noteName]) + "</div>";
  145. }
  146. }
  147. return retVal;
  148. function linkify(text) {
  149. var urlRegex = /(\b(((https?|ftp|file):\/\/)|(www\.))[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
  150. return text.replace(urlRegex, function (url, b, c) {
  151. var url2 = (c == 'www.') ? 'http://' + url : url;
  152. return '<a href="' + url2 + '" target="_blank" class="noteLink">' + url + '</a>';
  153. });
  154. }
  155. };
  156. $ax.legacy.GetScrollable = function(target) {
  157. var $target = $(target);
  158. var last = $target;
  159. // Start past inital target. Can't scroll to target in itself, must be some ancestor.
  160. var current = last.parent();
  161. while(!current.is('body') && !current.is('html')) {
  162. var elementId = current.attr('id');
  163. var diagramObject = elementId && $ax.getObjectFromElementId(elementId);
  164. if (diagramObject && $ax.public.fn.IsDynamicPanel(diagramObject.type) && diagramObject.scrollbars != 'none') {
  165. //returns the panel diagram div which handles scrolling
  166. return window.document.getElementById(last.attr('id'));
  167. }
  168. last = current;
  169. current = current.parent();
  170. }
  171. // Need to do this because of ie
  172. if(IE_10_AND_BELOW) return window.document.documentElement;
  173. else return window.document.body;
  174. };
  175. });