annotation.js.orig 6.4 KB

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