flyout.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. var value = active ? info.text : clearText ? '' : $jobj(inputId).val();
  194. $ax.style.SetWidgetPlaceholder(elementId, active, value, info.password);
  195. };
  196. _placeholderManager.updatePlaceholder = _updatePlaceholder;
  197. var _isActive = function(elementId) {
  198. var info = idToPlaceholderInfo[elementId];
  199. return Boolean(info && info.active);
  200. };
  201. _placeholderManager.isActive = _isActive;
  202. var _selectRange = function(elementId, start, end) {
  203. $jobj(elementId).each(function() {
  204. if(this.setSelectionRange) {
  205. var validTypes = ["text", "search", "url", "tel", "password"];
  206. if(this.tagName.toLowerCase() != "input" || validTypes.indexOf(this.type) > -1) {
  207. this.focus();
  208. this.setSelectionRange(start, end);
  209. }
  210. } else if(this.createTextRange) {
  211. var range = this.createTextRange();
  212. range.collapse(true);
  213. range.moveEnd('character', end);
  214. range.moveStart('character', start);
  215. range.select();
  216. }
  217. });
  218. };
  219. _placeholderManager.selectRange = _selectRange;
  220. var _moveCaret = function(id, index) {
  221. var inputIndex = id.indexOf('_input');
  222. if(inputIndex == -1) return;
  223. var inputId = id.substring(0, inputIndex);
  224. if(!_isActive(inputId)) return;
  225. _selectRange(id, index, index);
  226. };
  227. _placeholderManager.moveCaret = _moveCaret;
  228. });