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.

160 lines
7.1 KiB

3 years ago
  1. // ******* Annotation MANAGER ******** //
  2. $axure.internal(function($ax) {
  3. var NOTE_SIZE = 10;
  4. var _annotationManager = $ax.annotation = {};
  5. var _updateLinkLocations = $ax.annotation.updateLinkLocations = function(elementId) {
  6. var textId = $ax.GetTextPanelId(elementId);
  7. if(!textId) return;
  8. var rotation = $ax.getObjectFromElementId(elementId).style.rotation;
  9. //we have to do this because webkit reports the post-transform position but when you set positions it's pre-transform
  10. if(WEBKIT && rotation) {
  11. //we can dynamiclly rotate a widget now, show need to remember the transform rather than just remove it
  12. //here jquery.css will return 'none' if element is display none
  13. var oldShapeTransform = document.getElementById(elementId).style['-webkit-transform'];
  14. var oldTextTransform = document.getElementById(textId).style['-webkit-transform'];
  15. $('#' + elementId).css('-webkit-transform', 'scale(1)');
  16. $('#' + textId).css('-webkit-transform', 'scale(1)');
  17. }
  18. $('#' + textId).find('div[id$="_ann"]').each(function(index, value) {
  19. var elementId = value.id.replace('_ann', '');
  20. var $link = $('#' + elementId);
  21. var annPos = $link.position();
  22. annPos.left += $link.width();
  23. //var annPos = $(value).position();
  24. var left = annPos.left;// - NOTE_SIZE;
  25. var top = annPos.top - 5;
  26. $(value).css('left', left).css('top', top);
  27. });
  28. //undo the transform reset
  29. if(WEBKIT && rotation) {
  30. $('#' + elementId).css('-webkit-transform', oldShapeTransform || '');
  31. $('#' + textId).css('-webkit-transform', oldTextTransform || '');
  32. }
  33. };
  34. var _toggleAnnotationDialog = function (elementId, event) {
  35. var win = $(window);
  36. var scrollY = win.scrollTop();
  37. var scrollX = win.scrollLeft();
  38. var messageData = { id: elementId, x: event.pageX - scrollX, y: event.pageY - scrollY }
  39. if (!$axure.utils.isInPlayer()) messageData.page = $ax.pageData.notesData;
  40. $ax.messageCenter.postMessage('toggleAnnDialog', messageData);
  41. }
  42. $ax.annotation.initialize = function () {
  43. _createFootnotes($ax('*'), true);
  44. }
  45. var _createFootnotes = $ax.annotation.createFootnotes = function(query, create) {
  46. if(!$ax.document.configuration.showAnnotations) return;
  47. var widgetNotes = $ax.pageData.notesData.widgetNotes;
  48. if (widgetNotes) {
  49. var ownerToFns = $ax.pageData.notesData.ownerToFns;
  50. if(!$.isEmptyObject(ownerToFns)) {
  51. query.each(function(dObj, elementId) {
  52. var fns = ownerToFns[dObj.id];
  53. if (fns !== undefined) {
  54. var elementIdQuery = $('#' + elementId);
  55. if (dObj.type == 'hyperlink') {
  56. var parentId = $ax.GetParentIdFromLink(elementId);
  57. if (create) {
  58. elementIdQuery.after("<div id='" + elementId + "_ann' class='annnote'>&#8203;</div>");
  59. appendFns($('#' + elementId + "_ann"), fns);
  60. }
  61. _updateLinkLocations(parentId);
  62. } else {
  63. if (create) {
  64. elementIdQuery.after("<div id='" + elementId + "_ann' class='annnote'>&#8203;</div>");
  65. appendFns($('#' + elementId + "_ann"), fns);
  66. }
  67. _adjustIconLocation(elementId, dObj);
  68. }
  69. if (create) {
  70. $('#' + elementId + "_ann").click(function (e) {
  71. _toggleAnnotationDialog(dObj.id, e);
  72. return false;
  73. });
  74. var isVisible = true;
  75. var isMaster = $ax.public.fn.IsReferenceDiagramObject(dObj.type);
  76. if (isMaster) isVisible = dObj.visible;
  77. else isVisible = $ax.visibility.IsIdVisible(elementId);
  78. if (!isVisible) {
  79. var ann = document.getElementById(elementId + "_ann");
  80. if (ann) $ax.visibility.SetVisible(ann, false);
  81. }
  82. }
  83. }
  84. });
  85. }
  86. }
  87. function appendFns($parent, fns) {
  88. for (var index = 0; index < fns.length; index++) {
  89. $parent.append("<div class='annnotelabel' >" + fns[index] + "</div>");
  90. }
  91. }
  92. };
  93. $ax.annotation.updateAllFootnotes = function () {
  94. _createFootnotes($ax('*'), false);
  95. }
  96. $ax.annotation.jQueryAnn = function(query) {
  97. var elementIds = [];
  98. query.each(function(diagramObject, elementId) {
  99. if(diagramObject.annotation) elementIds[elementIds.length] = elementId;
  100. });
  101. var elementIdSelectors = jQuery.map(elementIds, function(elementId) { return '#' + elementId + '_ann'; });
  102. var jQuerySelectorText = (elementIdSelectors.length > 0) ? elementIdSelectors.join(', ') : '';
  103. return $(jQuerySelectorText);
  104. };
  105. $(window.document).ready(function() {
  106. //$ax.annotation.InitializeAnnotations($ax(function(dObj) { return dObj.annotation; }));
  107. $ax.messageCenter.addMessageListener(function(message, data) {
  108. //If the annotations are being hidden via the Sitemap toggle button, hide any open dialogs
  109. if(message == 'annotationToggle') {
  110. if (data == true) {
  111. $('div.annnote').show();
  112. } else {
  113. $('div.annnote').hide();
  114. }
  115. }
  116. });
  117. });
  118. //adjust annotation location to a element's top right corner
  119. var _adjustIconLocation = $ax.annotation.adjustIconLocation = function(id, dObj) {
  120. var ann = document.getElementById(id + "_ann");
  121. if(ann) {
  122. var corners = $ax.public.fn.getCornersFromComponent(id);
  123. var width = $(ann).width();
  124. var newTopRight = $ax.public.fn.vectorPlus(corners.relativeTopRight, corners.centerPoint);
  125. //note size is 14x8, this is how rp calculated it as well
  126. ann.style.left = (newTopRight.x - width) + "px";
  127. var elementType = dObj ? dObj.type : $ax.getTypeFromElementId(id);
  128. var yOffset = $ax.public.fn.IsTableCell(elementType) ? 0 : -8;
  129. ann.style.top = (newTopRight.y + yOffset) + "px";
  130. }
  131. var ref = document.getElementById(id + "_ref");
  132. if(ref) {
  133. if(!corners) corners = $ax.public.fn.getCornersFromComponent(id);
  134. var newBottomRight = $ax.public.fn.vectorPlus(corners.relativeBottomRight, corners.centerPoint);
  135. ref.style.left = (newBottomRight.x - 8) + 'px';
  136. ref.style.top = (newBottomRight.y - 10) + 'px';
  137. }
  138. }
  139. });