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

267 lines
10 KiB

4 years ago
  1. // ******* SITEMAP TOOLBAR VIEWER ACTIONS ******** //
  2. $axure.internal(function ($ax) {
  3. var userTriggeredEventNames = ['onClick', 'onDoubleClick', 'onMouseOver', 'onMouseMove', 'onMouseOut', 'onMouseDown', 'onMouseUp',
  4. 'onKeyDown', 'onKeyUp', 'onFocus', 'onLostFocus', 'onTextChange', 'onSelectionChange', 'onSelectedChange', 'onSelect', 'onUnselect',
  5. 'onSwipeLeft', 'onSwipeRight', 'onSwipeUp', 'onSwipeDown', 'onDragStart', 'onDrag', 'onDragDrop', 'onScroll', 'onContextMenu', 'onMouseHover', 'onLongClick'];
  6. //var _toggleSelectWidgetNoteForRepeater = function (repeaterId, scriptId, select) {
  7. // var itemIds = $ax.getItemIdsForRepeater(repeaterId);
  8. // for(var i = 0; i < itemIds.length; i++) {
  9. // var itemId = itemIds[i];
  10. // var elementId = $ax.repeater.createElementId(scriptId, itemId);
  11. // if(select) $('#' + elementId).addClass('widgetNoteSelected');
  12. // else $('#' + elementId).removeClass('widgetNoteSelected');
  13. // }
  14. //}
  15. $ax.messageCenter.addMessageListener(function (message, data) {
  16. //If annotation toggle message received from sitemap, toggle footnotes
  17. if(message == 'toggleSelectWidgetNote') {
  18. if (!IOS) {
  19. $('.widgetNoteSelected').removeClass('widgetNoteSelected');
  20. }
  21. if(!data.value) return;
  22. //if(lastSelectedWidgetNote == data.id) {
  23. // lastSelectedWidgetNote = null;
  24. // return;
  25. //}
  26. $ax('*').each(function(obj, elementId) {
  27. if (obj.id == data.id) {
  28. if (!IOS) {
  29. $('#' + elementId).addClass('widgetNoteSelected');
  30. }
  31. _scrollToSelectedNote($('#' + elementId), data.view);
  32. }
  33. });
  34. }
  35. });
  36. var _scrollToSelectedNote = function ($elmt, view) {
  37. var isLandscape = IOS ? window.orientation != 0 && window.orientation != 180 : false;
  38. var winWidth = !IOS ? $(window).width() : (isLandscape ? window.screen.height : window.screen.width) - view.panelWidthOffset;
  39. var winHeight = !IOS ? $(window).height() : view.height;
  40. var docLeft = $('html').last().scrollLeft();
  41. var docTop = $('html').last().scrollTop();
  42. var docRight = docLeft + winWidth;
  43. var docBottom = docTop + winHeight;
  44. var scale = $('#base').css('transform');;
  45. scale = (scale == "none") ? 1 : Number(scale.substring(scale.indexOf('(') + 1, scale.indexOf(',')));
  46. var bodyLeft = ($('body').css('left') !== undefined && $('body').css('left') !== "auto") ? Number($('body').css('left').replace('px','')) : 0;
  47. var top = scale * Number($elmt.css('top').replace('px', ''));
  48. var bottom = top + scale * $elmt.height();
  49. var left = scale * Number($elmt.css('left').replace('px', '')) + bodyLeft;
  50. var right = left + scale * $elmt.width();
  51. var doHorizontalMove = left < docLeft || right > docRight;
  52. var doVerticalMove = top < docTop || bottom > docBottom;
  53. var padding = scale * 50;
  54. var newScrollLeft = 0
  55. if (left < docLeft) {
  56. newScrollLeft = left - padding;
  57. } else if (right > docRight) {
  58. newScrollLeft = right + padding - winWidth;
  59. }
  60. var newScrollTop = 0
  61. if (top < docTop) {
  62. newScrollTop = top - padding;
  63. } else if (bottom > docBottom) {
  64. newScrollTop = bottom + padding - winHeight;
  65. }
  66. // Device Frame or Scale to width or Scale to fit (situations where there is no horizontal scroll)
  67. if (view.h || view.scaleVal == 1 || view.scaleVal == 2) {
  68. doHorizontalMove = false;
  69. }
  70. // Has Device Frame or Scale to Width and widget with note is outside of viewable panel right bounds
  71. if ((view.scaleVal == 1 || view.h) && (left > docRight)) {
  72. doVerticalMove = false;
  73. }
  74. // TODO: need to do something for dynamic panel with scroll
  75. if (doHorizontalMove && doVerticalMove) {
  76. $("html, body").animate({ scrollLeft: newScrollLeft, scrollTop: newScrollTop }, 300);
  77. } else if (doHorizontalMove) {
  78. $("html, body").animate({ scrollLeft: newScrollLeft }, 300);
  79. } else if (doVerticalMove) {
  80. $("html, body").animate({ scrollTop: newScrollTop }, 300);
  81. }
  82. }
  83. var highlightEnabled = false;
  84. $ax.messageCenter.addMessageListener(function(message, data) {
  85. if(message == 'highlightInteractive') {
  86. highlightEnabled = data == true;
  87. _applyHighlight($ax('*'));
  88. }
  89. });
  90. var _applyHighlight = $ax.applyHighlight = function(query, ignoreUnset) {
  91. if(ignoreUnset && !highlightEnabled) return;
  92. var pulsateClassName = 'legacyPulsateBorder';
  93. //Determine if the widget has a defined userTriggeredEventName specified in the array above
  94. var _isInteractive = function(diagramObject) {
  95. if(diagramObject && diagramObject.interactionMap) {
  96. for(var index in userTriggeredEventNames) {
  97. if(diagramObject.interactionMap[userTriggeredEventNames[index]]) return true;
  98. }
  99. }
  100. return false;
  101. };
  102. //Traverse through parent layers (if any) of an element and see if any have a defined userTriggeredEventName
  103. var _findMatchInParent = function(id) {
  104. var parents = $ax('#' + id).getParents(true, ['layer'])[0];
  105. for(var i in parents) {
  106. var parentId = parents[i];
  107. var parentObj = $ax.getObjectFromScriptId(parentId);
  108. if(_isInteractive(parentObj)) return true;
  109. }
  110. return false;
  111. };
  112. //Find all widgets with a defined userTriggeredEventName specified in the array above
  113. var $matchingElements = query.filter(function (obj, id) {
  114. //This prevents the top left corner of the page from highlighting with everything else
  115. if($ax.public.fn.IsLayer(obj.type)) return false;
  116. if(_isInteractive(obj)) return true;
  117. else if($ax.public.fn.IsVector(obj.type) && obj.referencePageUrl) return true;
  118. //Last check on the object's parent layer(s), if a layer has a defined userTriggeredEventName
  119. //then we shall highlight each member of that layer TODO This is a design decision and is subject to change
  120. return _findMatchInParent(id);
  121. }).$();
  122. var isHighlighted = $matchingElements.is('.' + pulsateClassName);
  123. //Toggle the pulsate class on the matched elements
  124. if(highlightEnabled && !isHighlighted) {
  125. $matchingElements.addClass(pulsateClassName);
  126. } else if(!highlightEnabled && isHighlighted) {
  127. $matchingElements.removeClass(pulsateClassName);
  128. }
  129. };
  130. var getElementsFromPoint = function (x, y) {
  131. var elementsFromPointFn = document.elementsFromPoint || document.msElementsFromPoint;
  132. if (typeof elementsFromPointFn === "function") {
  133. return elementsFromPointFn.bind(document)(x, y);
  134. }
  135. return [];
  136. }
  137. $axure.getIdAndRectAtLoc = function (data) {
  138. var element = document.elementFromPoint(data.x, data.y);
  139. if (!element) return undefined;
  140. var jObj = _getElementIdFromTarget(element);
  141. if (jObj.length > 0) {
  142. var id = jObj.attr('id');
  143. var axObj = $ax('#' + id);
  144. var rect = axObj.pageBoundingRect();
  145. return { 'id': id, 'rect': rect };
  146. }
  147. return undefined;
  148. }
  149. $axure.getListOfIdAndRectAtLoc = function (data) {
  150. var domElements = getElementsFromPoint(data.x, data.y);
  151. if (!domElements || !domElements.length) return [];
  152. const elements = [];
  153. domElements.forEach(function (domElement) {
  154. var jObj = _getElementIdFromTarget(domElement);
  155. if (jObj.length > 0) {
  156. var id = jObj.attr('id');
  157. var axObj = $ax('#' + id);
  158. var rect = axObj.pageBoundingRect();
  159. if (elements.findIndex(function (x) { return x.id === id }) < 0) {
  160. elements.push( { 'id': id, 'rect': rect } );
  161. }
  162. }
  163. });
  164. return elements;
  165. }
  166. $axure.getIdRectAndStyleAtLoc = function(data) {
  167. var element = document.elementFromPoint(data.x, data.y);
  168. if (!element) return undefined;
  169. var jObj = _getElementIdFromTarget(element);
  170. if (jObj.length > 0) {
  171. var id = jObj.attr('id');
  172. return $axure.getRectAndStyleById(id);
  173. }
  174. return undefined;
  175. }
  176. $axure.getListOfIdRectAndStyleAtLoc = function(data) {
  177. var domElements = getElementsFromPoint(data.x, data.y);
  178. if (!domElements || !domElements.length) return [];
  179. const elements = [];
  180. domElements.forEach(function (domElement) {
  181. var jObj = _getElementIdFromTarget(domElement);
  182. if (jObj.length > 0) {
  183. var id = jObj.attr('id');
  184. if (elements.findIndex(function (x) { return x.id === id }) < 0) {
  185. elements.push($axure.getRectAndStyleById(id));
  186. }
  187. }
  188. });
  189. return elements;
  190. }
  191. $axure.getRectAndStyleById = function (id) {
  192. var axObj = $ax('#' + id);
  193. var rect = axObj.pageBoundingRect();
  194. var style = $ax.style.computeFullStyle(id, $ax.style.generateState(id), $ax.adaptive.currentViewId);
  195. style.text = axObj.text();
  196. return { 'id': id, 'rect': rect, 'style': style };
  197. }
  198. $axure.isIdVisible = function (id) {
  199. return id ? $ax.visibility.IsIdVisible(id) : false;
  200. }
  201. $axure.getParentElementById = function (elementId) {
  202. if (!elementId) return undefined;
  203. var parentId = $ax.getLayerParentFromElementId(elementId);
  204. if (!parentId) {
  205. return undefined;
  206. }
  207. return $axure.getRectAndStyleById(parentId);
  208. }
  209. var _getElementIdFromTarget = function (target) {
  210. var targetId = target.id;
  211. var jTarget = $(target);
  212. while((!targetId || targetId.indexOf('cache') > -1) && jTarget[0].tagName != 'HTML') {
  213. jTarget = jTarget.parent();
  214. targetId = jTarget.attr('id');
  215. }
  216. if(targetId && targetId != 'base') {
  217. var sections = targetId.split('_');
  218. return $('#' + sections[0]);
  219. }
  220. return '';
  221. }
  222. });