tree.js
8.02 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
177
178
179
180
181
182
183
184
185
186
// This is actually for BOTH trees and menus
$axure.internal(function($ax) {
var _tree = $ax.tree = {};
var _menu = $ax.menu = {};
$ax.menu.InitializeSubmenu = function(subMenuId, cellId) {
var $submenudiv = $('#' + subMenuId);
//mouseenter and leave for parent table cell
$('#' + cellId).mouseenter(function(e) {
//show current submenu
// var submenuElement = document.getElementById(subMenuId);
// if($ax.visibility.IsVisible(submenuElement) && submenuElement.style.display !== 'none') return;
$ax.visibility.SetIdVisible(subMenuId, true);
$ax.legacy.BringToFront(subMenuId);
_fireEventForSubmenu(subMenuId, "onShow");
}).mouseleave(function (e) {
var offset = $submenudiv.offset();
var subcontwidth = $submenudiv.width();
var subcontheight = $submenudiv.height();
//If mouse is not within the submenu (added 3 pixel margin to top and left calculations), then close the submenu...
if(e.pageX + 3 < offset.left || e.pageX > offset.left + subcontwidth || e.pageY + 3 < offset.top || e.pageY > offset.top + subcontheight) {
$submenudiv.find('.sub_menu').andSelf().each(function () {
// if(!$ax.visibility.IsVisible(this)) return;
$ax.visibility.SetVisible(this, false);
_fireEventForSubmenu(subMenuId, "onHide");
});
$ax.style.SetWidgetHover(cellId, false);
}
});
$submenudiv.css('display', 'none');
//mouseleave for submenu
$submenudiv.mouseleave(function(e) {
//close this menu and all menus below it
$(this).find('.sub_menu').andSelf().css({ 'visibility': 'hidden', 'display': 'none' }).each(function () {
// if(!$ax.visibility.IsVisible(this)) return;
_fireEventForSubmenu(this.id, "onHide");
});
$ax.style.SetWidgetHover(cellId, false);
});
};
var _fireEventForSubmenu = function(targetId, eventName) {
var diagramObject = $ax.getObjectFromElementId(targetId);
var event = diagramObject.interactionMap && diagramObject.interactionMap[eventName];
if(event) {
var eventInfo = $ax.getEventInfoFromEvent($ax.getjBrowserEvent(), false, targetId);
$ax.event.handleEvent(targetId, eventInfo, event, false, true);
}
}
function IsNodeVisible(nodeId) {
var current = window.document.getElementById(nodeId);
var parent = current.parentNode;
//move all the parent's children that are below the node and their annotations
while(!$(current).hasClass("treeroot")) {
if(!$ax.visibility.IsVisible(parent)) return false;
current = parent;
parent = parent.parentNode;
}
return true;
}
$ax.tree.ExpandNode = function(nodeId, childContainerId, plusMinusId) {
var container = window.document.getElementById(childContainerId);
if(!container || $ax.visibility.IsVisible(container)) return;
$ax.visibility.SetVisible(container, true);
if(plusMinusId != '') $ax.style.SetWidgetSelected(plusMinusId, true);
var delta = _getExpandCollapseDelta(nodeId, childContainerId);
var isVisible = IsNodeVisible(nodeId);
var current = window.document.getElementById(nodeId);
var parent = current.parentNode;
//move all the parent's children that are below the node and their annotations
while(!$(current).hasClass("treeroot")) {
var after = false;
var i = 0;
for(i = 0; i < parent.childNodes.length; i++) {
var child = parent.childNodes[i];
if(after && child.id && $(child).hasClass("treenode")) {
var elementId = child.id;
child.style.top = Number($(child).css('top').replace("px", "")) + delta + 'px';
var ann = window.document.getElementById(elementId + "_ann");
if(ann) ann.style.top = Number($(ann).css('top').replace("px", "")) + delta + 'px';
}
if(child == current) after = true;
}
current = parent;
parent = parent.parentNode;
if(!isVisible && $ax.visibility.IsVisible(parent)) break;
}
};
$ax.tree.CollapseNode = function(nodeId, childContainerId, plusMinusId) {
var container = window.document.getElementById(childContainerId);
if(!container || !$ax.visibility.IsVisible(container)) return;
if(plusMinusId != '') $ax.style.SetWidgetSelected(plusMinusId, false);
var delta = _getExpandCollapseDelta(nodeId, childContainerId);
//hide it after getting the delta, otherwise the delta can't be calculated (offsetParent is null)
$ax.visibility.SetVisible(container, false);
var isVisible = IsNodeVisible(nodeId);
var current = window.document.getElementById(nodeId);
var parent = current.parentNode;
//move all the parent's children that are below the node and their annotations
while(!$(current).hasClass("treeroot")) {
var after = false;
var i = 0;
for(i = 0; i < parent.childNodes.length; i++) {
var child = parent.childNodes[i];
if(after && child.id && $(child).hasClass("treenode")) {
var elementId = child.id;
child.style.top = Number($(child).css('top').replace("px", "")) - delta + 'px';
var ann = window.document.getElementById(elementId + "_ann");
if(ann) ann.style.top = Number($(ann).css('top').replace("px", "")) - delta + 'px';
}
if(child == current) after = true;
}
current = parent;
parent = current.parentNode;
if(!isVisible && $ax.visibility.IsVisible(parent)) break;
}
};
var _getExpandCollapseDelta = function(nodeId, childContainerId) {
return _getChildContainerHeightHelper(childContainerId);
};
var _getChildContainerHeightHelper = function(childContainerId) {
var height = 0;
$('#' + childContainerId).children().each(function() {
if($(this).hasClass("treenode")) {
height += $(this).height();
var subContainer = window.document.getElementById(this.id + '_children');
if(subContainer && $ax.visibility.IsVisible(subContainer)) {
height += _getChildContainerHeightHelper(subContainer.id);
}
}
});
return height;
};
$ax.tree.InitializeTreeNode = function(nodeId, plusminusid, childContainerId, selectText) {
var childContainer = window.document.getElementById(childContainerId);
if(childContainer) {
//relying on the html generator to put this inline so we know to collapse by default
var isCollapsed = childContainer.style.visibility == "hidden";
if(isCollapsed) $ax.visibility.SetVisible(childContainer, false);
if(!isCollapsed && plusminusid != '') $ax.style.SetWidgetSelected(plusminusid, true);
}
if(plusminusid != '') {
$jobj(plusminusid).click(function() {
var visibleSet = $ax.visibility.IsIdVisible(childContainerId);
if(visibleSet) $ax.tree.CollapseNode(nodeId, childContainerId, plusminusid);
else $ax.tree.ExpandNode(nodeId, childContainerId, plusminusid);
$ax.tree.SelectTreeNode(nodeId, true);
return false;
}).css('cursor', 'default');
}
};
var _getButtonShapeId = function(id) {
var obj = $obj(id);
return $ax.public.fn.IsTreeNodeObject(obj.type) ? $ax.getElementIdFromPath([obj.buttonShapeId], { relativeTo: id }) : id;
};
$ax.tree.SelectTreeNode = function(id, selected) {
$ax.style.SetWidgetSelected(_getButtonShapeId(id), selected);
};
});