产品原型
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.

285 lines
10 KiB

4 years ago
  1. // ******* Flyout MANAGER ******** //
  2. $axure.internal(function($ax) {
  3. var _flyoutManager = $ax.flyoutManager = {};
  4. var getFlyoutLabel = function(panelId) {
  5. return panelId + '_flyout';
  6. };
  7. var _unregisterPanel = function(panelId, keepShown) {
  8. $ax.geometry.unregister(getFlyoutLabel(panelId));
  9. if(panelToSrc[panelId]) {
  10. $ax.style.RemoveRolloverOverride(panelToSrc[panelId]);
  11. delete panelToSrc[panelId];
  12. }
  13. if(!keepShown) {
  14. $ax.action.addAnimation(panelId, $ax.action.queueTypes.fade, function() {
  15. $ax('#' + panelId).hide();
  16. });
  17. }
  18. };
  19. _flyoutManager.unregisterPanel = _unregisterPanel;
  20. var genPoint = $ax.geometry.genPoint;
  21. var _updateFlyout = function(panelId) {
  22. var label = getFlyoutLabel(panelId);
  23. if(!$ax.geometry.polygonRegistered(label)) return;
  24. var info = $ax.geometry.getPolygonInfo(label);
  25. var rects = info && info.rects;
  26. var targetWidget = $ax.getWidgetInfo(panelId);
  27. rects.target = $ax.geometry.genRect(targetWidget);
  28. // Src will stay the same, just updating
  29. $ax.flyoutManager.registerFlyout(rects, panelId, panelToSrc[panelId]);
  30. if(!$ax.geometry.checkInsideRegion(label)) _unregisterPanel(panelId);
  31. };
  32. _flyoutManager.updateFlyout = _updateFlyout;
  33. var panelToSrc = {};
  34. var _registerFlyout = function(rects, panelId, srcId) {
  35. var label = _getFlyoutLabel(panelId);
  36. var callback = function(info) {
  37. // If leaving object or already outside it, then unregister, otherwise just return
  38. if(!info.exiting && !info.outside) return;
  39. _unregisterPanel(panelId);
  40. };
  41. var points = [];
  42. var lastSrcId = panelToSrc[panelId];
  43. if(lastSrcId != srcId) {
  44. if(lastSrcId) $ax.style.RemoveRolloverOverride(lastSrcId);
  45. if(srcId) {
  46. $ax.style.AddRolloverOverride(srcId);
  47. panelToSrc[panelId] = srcId;
  48. } else delete panelToSrc[panelId];
  49. }
  50. // rects should be one or two rectangles
  51. if(!rects.src) {
  52. var rect = rects.target;
  53. points.push(genPoint(rect.Left(), rect.Top()));
  54. points.push(genPoint(rect.Right(), rect.Top()));
  55. points.push(genPoint(rect.Right(), rect.Bottom()));
  56. points.push(genPoint(rect.Left(), rect.Bottom()));
  57. } else {
  58. var r0 = rects.src;
  59. var r1 = rects.target;
  60. // Right left of right, left right of left, top below top, bottom above bottom
  61. var rlr = r0.Right() <= r1.Right();
  62. var lrl = r0.Left() >= r1.Left();
  63. var tbt = r0.Top() >= r1.Top();
  64. var bab = r0.Bottom() <= r1.Bottom();
  65. var info = { rlr: rlr, lrl: lrl, tbt: tbt, bab: bab };
  66. if((rlr && lrl) || (tbt && bab)) {
  67. points = getSmallPolygon(r0, r1, info);
  68. } else {
  69. points = getLargePolygon(r0, r1, info);
  70. }
  71. }
  72. $ax.geometry.registerPolygon(label, points, callback, { rects: rects });
  73. };
  74. _flyoutManager.registerFlyout = _registerFlyout;
  75. var _getFlyoutLabel = function(panelId) {
  76. return panelId + '_flyout';
  77. };
  78. var _reregisterAllFlyouts = function() {
  79. for(var panelId in panelToSrc) _reregisterFlyout(panelId);
  80. };
  81. _flyoutManager.reregisterAllFlyouts = _reregisterAllFlyouts;
  82. var _reregisterFlyout = function(panelId) {
  83. var rects = $ax.geometry.getPolygonInfo(getFlyoutLabel(panelId)).rects;
  84. _registerFlyout(rects, panelId, panelToSrc[panelId]);
  85. };
  86. // This is the reduced size polygon connecting r0 to r1 by means of horizontal or vertical lines.
  87. var getSmallPolygon = function(r0, r1, info) {
  88. var points = [];
  89. // NOTE: currently I make the assumption that if horizontal/vertical connecting lines from the src hit the target
  90. // Meaning if horizontal, rlr and lrl are true, and if vertical, tbt and bab are true.
  91. var r0Left = r0.Left();
  92. var r0Right = r0.Right();
  93. var r0Top = r0.Top();
  94. var r0Bottom = r0.Bottom();
  95. var r1Left = r1.Left();
  96. var r1Right = r1.Right();
  97. var r1Top = r1.Top();
  98. var r1Bottom = r1.Bottom();
  99. points.push(genPoint(r1Left, r1Top));
  100. if(!info.tbt) {
  101. points.push(genPoint(r0Left, r1Top));
  102. points.push(genPoint(r0Left, r0Top));
  103. points.push(genPoint(r0Right, r0Top));
  104. points.push(genPoint(r0Right, r1Top));
  105. }
  106. points.push(genPoint(r1Right, r1Top));
  107. if(!info.rlr) {
  108. points.push(genPoint(r1Right, r0Top));
  109. points.push(genPoint(r0Right, r0Top));
  110. points.push(genPoint(r0Right, r0Bottom));
  111. points.push(genPoint(r1Right, r0Bottom));
  112. }
  113. points.push(genPoint(r1Right, r1Bottom));
  114. if(!info.bab) {
  115. points.push(genPoint(r0Right, r1Bottom));
  116. points.push(genPoint(r0Right, r0Bottom));
  117. points.push(genPoint(r0Left, r0Bottom));
  118. points.push(genPoint(r0Left, r1Bottom));
  119. }
  120. points.push(genPoint(r1Left, r1Bottom));
  121. if(!info.lrl) {
  122. points.push(genPoint(r1Left, r0Bottom));
  123. points.push(genPoint(r0Left, r0Bottom));
  124. points.push(genPoint(r0Left, r0Top));
  125. points.push(genPoint(r1Left, r0Top));
  126. }
  127. return points;
  128. };
  129. // This is the original algorithm that connects the most extream corners to make polygon
  130. var getLargePolygon = function(r0, r1, info) {
  131. var points = [];
  132. var r0Left = r0.Left();
  133. var r0Right = r0.Right();
  134. var r0Top = r0.Top();
  135. var r0Bottom = r0.Bottom();
  136. var r1Left = r1.Left();
  137. var r1Right = r1.Right();
  138. var r1Top = r1.Top();
  139. var r1Bottom = r1.Bottom();
  140. // Top lefts
  141. if(info.tbt) {
  142. if(!info.lrl) points.push(genPoint(r0Left, r0Top));
  143. points.push(genPoint(r1Left, r1Top));
  144. } else {
  145. if(info.lrl) points.push(genPoint(r1Left, r1Top));
  146. points.push(genPoint(r0Left, r0Top));
  147. }
  148. // Top rights
  149. if(info.tbt) {
  150. points.push(genPoint(r1Right, r1Top));
  151. if(!info.rlr) points.push(genPoint(r0Right, r0Top));
  152. } else {
  153. points.push(genPoint(r0Right, r0Top));
  154. if(info.rlr) points.push(genPoint(r1Right, r1Top));
  155. }
  156. // Bottom rights
  157. if(info.bab) {
  158. if(!info.rlr) points.push(genPoint(r0Right, r0Bottom));
  159. points.push(genPoint(r1Right, r1Bottom));
  160. } else {
  161. if(info.rlr) points.push(genPoint(r1Right, r1Bottom));
  162. points.push(genPoint(r0Right, r0Bottom));
  163. }
  164. // Bottom Lefts
  165. if(info.bab) {
  166. points.push(genPoint(r1Left, r1Bottom));
  167. if(!info.lrl) points.push(genPoint(r0Left, r0Bottom));
  168. } else {
  169. points.push(genPoint(r0Left, r0Bottom));
  170. if(info.lrl) points.push(genPoint(r1Left, r1Bottom));
  171. }
  172. return points;
  173. };
  174. });
  175. // ******* Placeholder Manager ********* //
  176. $axure.internal(function($ax) {
  177. var _placeholderManager = $ax.placeholderManager = {};
  178. var idToPlaceholderInfo = {};
  179. var _registerPlaceholder = function(elementId, text, password) {
  180. idToPlaceholderInfo[elementId] = { text: text, password: password, active: false };
  181. };
  182. _placeholderManager.registerPlaceholder = _registerPlaceholder;
  183. _placeholderManager.refreshPlaceholder = function (elementId) {
  184. var info = idToPlaceholderInfo[elementId];
  185. if (!info || !info.active) return;
  186. $ax.style.SetWidgetPlaceholder(elementId, true, info.text, info.password);
  187. }
  188. var _updatePlaceholder = function(elementId, active, clearText) {
  189. var inputId = $ax.repeater.applySuffixToElementId(elementId, '_input');
  190. var info = idToPlaceholderInfo[elementId];
  191. if(!info || info.active == active) return;
  192. info.active = active;
  193. if(active) var text = info.text;
  194. else if(!ANDROID) text = clearText ? '' : document.getElementById(inputId).value;
  195. else {
  196. var currentText = document.getElementById(inputId).value;
  197. if(!clearText) text = currentText;
  198. else if(currentText == info.text) text = "";
  199. else {
  200. var lastIndex = currentText.lastIndexOf(info.text);
  201. //here i am assuming the text is always inserted in front
  202. text = currentText.substring(0, lastIndex);
  203. }
  204. }
  205. $ax.style.SetWidgetPlaceholder(elementId, active, text, info.password);
  206. };
  207. _placeholderManager.updatePlaceholder = _updatePlaceholder;
  208. var _isActive = function(elementId) {
  209. var info = idToPlaceholderInfo[elementId];
  210. return Boolean(info && info.active);
  211. };
  212. _placeholderManager.isActive = _isActive;
  213. var _selectRange = function(elementId, start, end) {
  214. $jobj(elementId).each(function() {
  215. if(this.setSelectionRange) {
  216. var validTypes = ["text", "search", "url", "tel", "password"];
  217. if(this.tagName.toLowerCase() != "input" || validTypes.indexOf(this.type) > -1) {
  218. this.focus();
  219. this.setSelectionRange(start, end);
  220. }
  221. } else if(this.createTextRange) {
  222. var range = this.createTextRange();
  223. range.collapse(true);
  224. range.moveEnd('character', end);
  225. range.moveStart('character', start);
  226. range.select();
  227. }
  228. });
  229. };
  230. _placeholderManager.selectRange = _selectRange;
  231. var _moveCaret = function(id, index) {
  232. var inputIndex = id.indexOf('_input');
  233. if(inputIndex == -1) return;
  234. var inputId = id.substring(0, inputIndex);
  235. if(!_isActive(inputId)) return;
  236. _selectRange(id, index, index);
  237. };
  238. _placeholderManager.moveCaret = _moveCaret;
  239. });