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