annotation.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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(textId) {
  6. var diagramObject = $ax.getObjectFromElementId(textId);
  7. var rotation = (diagramObject && diagramObject.style.rotation);
  8. var shapeId = $ax.style.GetShapeIdFromText(textId);
  9. //we have to do this because webkit reports the post-transform position but when you set
  10. //positions it's pre-transform
  11. if(WEBKIT && rotation) {
  12. //we can dynamiclly rotate a widget now, show need to remember the transform rather than just remove it
  13. //here jquery.css will return 'none' if element is display none
  14. var oldShapeTransform = document.getElementById(shapeId).style['-webkit-transform'];
  15. var oldTextTransform = document.getElementById(textId).style['-webkit-transform'];
  16. $('#' + shapeId).css('-webkit-transform', 'scale(1)');
  17. $('#' + textId).css('-webkit-transform', 'scale(1)');
  18. }
  19. $('#' + textId).find('span[id$="_ann"]').each(function(index, value) {
  20. var elementId = value.id.replace('_ann', '');
  21. var annPos = $(value).position();
  22. var left = annPos.left - NOTE_SIZE;
  23. var top = annPos.top;
  24. $('#' + elementId + 'Note').css('left', left).css('top', top);
  25. });
  26. //undo the transform reset
  27. if(WEBKIT && rotation) {
  28. $('#' + shapeId).css('-webkit-transform', oldShapeTransform || '');
  29. $('#' + textId).css('-webkit-transform', oldTextTransform || '');
  30. }
  31. };
  32. var dialogs = {};
  33. $ax.annotation.ToggleWorkflow = function(event, id, width, height) {
  34. if(dialogs[id]) {
  35. var $dialog = dialogs[id];
  36. // reset the dialog
  37. dialogs[id] = undefined;
  38. if($dialog.dialog("isOpen")) {
  39. $dialog.dialog("close");
  40. return;
  41. }
  42. }
  43. // we'll need to save the scroll position just for stupid IE which will skip otherwise
  44. var win = $(window);
  45. var scrollY = win.scrollTop();
  46. var scrollX = win.scrollLeft();
  47. var bufferH = 10;
  48. var bufferV = 10;
  49. var blnLeft = false;
  50. var blnAbove = false;
  51. var sourceTop = event.pageY - scrollY;
  52. var sourceLeft = event.pageX - scrollX;
  53. if(sourceLeft > width + bufferH) {
  54. blnLeft = true;
  55. }
  56. if(sourceTop > height + bufferV) {
  57. blnAbove = true;
  58. }
  59. var top = 0;
  60. var left = 0;
  61. if(blnAbove) top = sourceTop - height - 20;
  62. else top = sourceTop + 10;
  63. if(blnLeft) left = sourceLeft - width - 4;
  64. else left = sourceLeft - 6;
  65. $ax.globals.MaxZIndex = $ax.globals.MaxZIndex + 1;
  66. if(IE_10_AND_BELOW) height += 50;
  67. var dObj = $ax.getObjectFromElementId(id);
  68. var ann = dObj.annotation;
  69. var $dialog = $('<div></div>')
  70. .appendTo('body')
  71. .html($ax.legacy.GetAnnotationHtml(ann))
  72. .dialog({
  73. title: dObj.label,
  74. width: width,
  75. height: height,
  76. minHeight: 150,
  77. zIndex: $ax.globals.MaxZIndex,
  78. position: [left, top],
  79. dialogClass: 'dialogFix',
  80. autoOpen: false
  81. });
  82. $dialog.parent().appendTo('#base');
  83. $dialog.dialog('open');
  84. dialogs[id] = $dialog;
  85. // scroll ... just for IE
  86. window.scrollTo(scrollX, scrollY);
  87. };
  88. $ax.annotation.InitializeAnnotations = function (query) {
  89. if(!$ax.document.configuration.showAnnotations) return;
  90. query.each(function(dObj, elementId) {
  91. if(!dObj.annotation) return;
  92. if(dObj.type == 'hyperlink') {
  93. var textId = $ax.style.GetTextIdFromLink(elementId);
  94. var elementIdQuery = $('#' + elementId);
  95. elementIdQuery.after("<span id='" + elementId + "_ann'>&#8203;</span>");
  96. if($ax.document.configuration.useLabels) {
  97. var label = $('#' + elementId).attr("data-label");
  98. if(!label || label == "") label = "?";
  99. $('#' + textId).append("<div id='" + elementId + "Note' class='annnotelabel' >" + label + "</div>");
  100. } else {
  101. $('#' + textId).append("<div id='" + elementId + "Note' class='annnoteimage' ></div>");
  102. }
  103. $('#' + elementId + 'Note').click(function(e) {
  104. $ax.annotation.ToggleWorkflow(e, elementId, 300, 200, false);
  105. return false;
  106. });
  107. _updateLinkLocations(textId);
  108. } else {
  109. if($ax.document.configuration.useLabels) {
  110. var label = $('#' + elementId).attr("data-label");
  111. if(!label || label == "") label = "?";
  112. $('#' + elementId + "_ann").append("<div id='" + elementId + "Note' class='annnotelabel'>" + label + "</div>");
  113. } else {
  114. $('#' + elementId + "_ann").append("<div id='" + elementId + "Note' class='annnoteimage'></div>");
  115. }
  116. $('#' + elementId + 'Note').click(function(e) {
  117. $ax.annotation.ToggleWorkflow(e, elementId, 300, 200, false);
  118. return false;
  119. });
  120. }
  121. $('#' + elementId + 'Note.annnoteimage').append("<div class='annnoteline'></div><div class='annnoteline'></div><div class='annnoteline'></div>");
  122. });
  123. };
  124. $ax.annotation.jQueryAnn = function(query) {
  125. var elementIds = [];
  126. query.each(function(diagramObject, elementId) {
  127. if(diagramObject.annotation) elementIds[elementIds.length] = elementId;
  128. });
  129. var elementIdSelectors = jQuery.map(elementIds, function(elementId) { return '#' + elementId + '_ann'; });
  130. var jQuerySelectorText = (elementIdSelectors.length > 0) ? elementIdSelectors.join(', ') : '';
  131. return $(jQuerySelectorText);
  132. };
  133. $(window.document).ready(function() {
  134. $ax.annotation.InitializeAnnotations($ax(function(dObj) { return dObj.annotation; }));
  135. $ax.messageCenter.addMessageListener(function(message, data) {
  136. //If the annotations are being hidden via the Sitemap toggle button, hide any open dialogs
  137. if(message == 'annotationToggle') {
  138. if(data == false) {
  139. for(var index in dialogs) {
  140. var $dialog = dialogs[index];
  141. if($dialog.dialog("isOpen")) {
  142. $dialog.dialog("close");
  143. }
  144. }
  145. }
  146. }
  147. });
  148. });
  149. });