6363 |
29 Nov 13 |
nicklas |
/* $Id$ |
6363 |
29 Nov 13 |
nicklas |
2 |
------------------------------------------------------------------ |
6363 |
29 Nov 13 |
nicklas |
Copyright (C) 2012 Nicklas Nordborg |
6363 |
29 Nov 13 |
nicklas |
4 |
|
6363 |
29 Nov 13 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
6363 |
29 Nov 13 |
nicklas |
Available at http://base.thep.lu.se/ |
6363 |
29 Nov 13 |
nicklas |
7 |
|
6363 |
29 Nov 13 |
nicklas |
BASE is free software; you can redistribute it and/or |
6363 |
29 Nov 13 |
nicklas |
modify it under the terms of the GNU General Public License |
6363 |
29 Nov 13 |
nicklas |
as published by the Free Software Foundation; either version 3 |
6363 |
29 Nov 13 |
nicklas |
of the License, or (at your option) any later version. |
6363 |
29 Nov 13 |
nicklas |
12 |
|
6363 |
29 Nov 13 |
nicklas |
BASE is distributed in the hope that it will be useful, |
6363 |
29 Nov 13 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
6363 |
29 Nov 13 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
6363 |
29 Nov 13 |
nicklas |
GNU General Public License for more details. |
6363 |
29 Nov 13 |
nicklas |
17 |
|
6363 |
29 Nov 13 |
nicklas |
You should have received a copy of the GNU General Public License |
6363 |
29 Nov 13 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6363 |
29 Nov 13 |
nicklas |
20 |
------------------------------------------------------------------ |
6363 |
29 Nov 13 |
nicklas |
21 |
|
6363 |
29 Nov 13 |
nicklas |
JavaScript functions for the Joust2 tree outline. |
6363 |
29 Nov 13 |
nicklas |
23 |
|
6363 |
29 Nov 13 |
nicklas |
@author Nicklas |
6363 |
29 Nov 13 |
nicklas |
@since 3.3 |
6363 |
29 Nov 13 |
nicklas |
26 |
*/ |
7419 |
03 Nov 17 |
nicklas |
'use strict'; |
6363 |
29 Nov 13 |
nicklas |
28 |
|
6363 |
29 Nov 13 |
nicklas |
var Joust2 = function() |
6363 |
29 Nov 13 |
nicklas |
30 |
{ |
6363 |
29 Nov 13 |
nicklas |
var joust = {}; |
6363 |
29 Nov 13 |
nicklas |
var internal = {}; |
6363 |
29 Nov 13 |
nicklas |
33 |
|
6380 |
16 Dec 13 |
nicklas |
34 |
/** |
6380 |
16 Dec 13 |
nicklas |
Initialize and draw the Joust tree on |
6380 |
16 Dec 13 |
nicklas |
the given element. The tree definitions must |
6380 |
16 Dec 13 |
nicklas |
be stored as a JSON object in 'data-joust-tree' |
6380 |
16 Dec 13 |
nicklas |
attribute. |
6380 |
16 Dec 13 |
nicklas |
39 |
*/ |
6380 |
16 Dec 13 |
nicklas |
joust.draw = function(element) |
6380 |
16 Dec 13 |
nicklas |
41 |
{ |
6380 |
16 Dec 13 |
nicklas |
element = Doc.element(element); |
6380 |
16 Dec 13 |
nicklas |
43 |
|
6380 |
16 Dec 13 |
nicklas |
var tree = Data.json(element, 'joust-tree'); |
6380 |
16 Dec 13 |
nicklas |
if (!tree) return; |
6380 |
16 Dec 13 |
nicklas |
46 |
|
6380 |
16 Dec 13 |
nicklas |
var last = tree.length-1; |
6380 |
16 Dec 13 |
nicklas |
for (var itemNo = 0; itemNo < tree.length; itemNo++) |
6380 |
16 Dec 13 |
nicklas |
49 |
{ |
6380 |
16 Dec 13 |
nicklas |
var menuItem = tree[itemNo]; |
6380 |
16 Dec 13 |
nicklas |
51 |
|
6380 |
16 Dec 13 |
nicklas |
// Genereate <div> tag for each menuItem |
6382 |
17 Dec 13 |
nicklas |
var menuElement = internal.toElement(element, menuItem, '', itemNo==0, itemNo==last); |
6388 |
07 Jan 14 |
nicklas |
var appendElement = menuElement.parentNode == null; |
6388 |
07 Jan 14 |
nicklas |
if (appendElement) element.appendChild(menuElement); |
6382 |
17 Dec 13 |
nicklas |
56 |
|
6380 |
16 Dec 13 |
nicklas |
// Generate child elements with padding |
6380 |
16 Dec 13 |
nicklas |
if (menuItem.children) |
6380 |
16 Dec 13 |
nicklas |
59 |
{ |
6382 |
17 Dec 13 |
nicklas |
var pad = internal.padHtml(menuItem); |
6388 |
07 Jan 14 |
nicklas |
var childDiv = internal.addChildren(menuItem, pad); |
6388 |
07 Jan 14 |
nicklas |
if (appendElement) element.appendChild(childDiv); |
6380 |
16 Dec 13 |
nicklas |
63 |
} |
6380 |
16 Dec 13 |
nicklas |
64 |
} |
6380 |
16 Dec 13 |
nicklas |
65 |
} |
6380 |
16 Dec 13 |
nicklas |
66 |
|
6381 |
17 Dec 13 |
nicklas |
67 |
/** |
6382 |
17 Dec 13 |
nicklas |
Add child items to a menu element. It is assumed that |
6382 |
17 Dec 13 |
nicklas |
this method is called on a menu element that currently |
6382 |
17 Dec 13 |
nicklas |
has no children. |
6382 |
17 Dec 13 |
nicklas |
71 |
*/ |
6382 |
17 Dec 13 |
nicklas |
joust.addChildren = function(menuElement, children) |
6382 |
17 Dec 13 |
nicklas |
73 |
{ |
6382 |
17 Dec 13 |
nicklas |
menuElement = Doc.element(menuElement); |
6382 |
17 Dec 13 |
nicklas |
75 |
|
6382 |
17 Dec 13 |
nicklas |
var menuItem = menuElement.item; |
6382 |
17 Dec 13 |
nicklas |
menuItem.children = children; |
6382 |
17 Dec 13 |
nicklas |
menuItem.isLazy = false; |
6382 |
17 Dec 13 |
nicklas |
79 |
|
6382 |
17 Dec 13 |
nicklas |
var pad = internal.padHtml(menuItem); |
6382 |
17 Dec 13 |
nicklas |
var childContainer = internal.addChildren(menuItem, menuItem.pad+pad); |
6382 |
17 Dec 13 |
nicklas |
menuElement.parentNode.insertBefore(childContainer, menuElement.nextSibling); |
7983 |
22 Jun 21 |
nicklas |
return childContainer; |
6382 |
17 Dec 13 |
nicklas |
84 |
} |
6382 |
17 Dec 13 |
nicklas |
85 |
|
6382 |
17 Dec 13 |
nicklas |
86 |
/** |
6381 |
17 Dec 13 |
nicklas |
Toggle the open/closed status of the given menu |
6381 |
17 Dec 13 |
nicklas |
element. Sends a 'joust-expand' event to the |
6381 |
17 Dec 13 |
nicklas |
node unless noEvent option is set. |
6381 |
17 Dec 13 |
nicklas |
90 |
*/ |
6381 |
17 Dec 13 |
nicklas |
joust.toggle = function(menuElement, noEvent) |
6380 |
16 Dec 13 |
nicklas |
92 |
{ |
6380 |
16 Dec 13 |
nicklas |
menuElement = Doc.element(menuElement); |
6380 |
16 Dec 13 |
nicklas |
var menuItem = menuElement.item; |
6380 |
16 Dec 13 |
nicklas |
95 |
|
6382 |
17 Dec 13 |
nicklas |
if (!menuItem.isOpen && menuItem.isLazy) |
6380 |
16 Dec 13 |
nicklas |
97 |
{ |
6382 |
17 Dec 13 |
nicklas |
Events.sendCustomEvent(menuElement, 'joust-lazy-init', {}); |
6382 |
17 Dec 13 |
nicklas |
return; |
6380 |
16 Dec 13 |
nicklas |
100 |
} |
6380 |
16 Dec 13 |
nicklas |
101 |
|
6382 |
17 Dec 13 |
nicklas |
menuItem.isOpen = menuItem.isOpen ? 0 : 1; |
6388 |
07 Jan 14 |
nicklas |
var childContainer = Doc.element(menuItem.id+'-children'); |
6388 |
07 Jan 14 |
nicklas |
if (childContainer) |
6388 |
07 Jan 14 |
nicklas |
105 |
{ |
6388 |
07 Jan 14 |
nicklas |
Doc.addOrRemoveClass(childContainer, 'closed', !menuItem.isOpen); |
6388 |
07 Jan 14 |
nicklas |
107 |
} |
6382 |
17 Dec 13 |
nicklas |
joust.updateIconsAndText(menuElement); |
6380 |
16 Dec 13 |
nicklas |
109 |
|
6381 |
17 Dec 13 |
nicklas |
if (!noEvent) |
6381 |
17 Dec 13 |
nicklas |
111 |
{ |
6381 |
17 Dec 13 |
nicklas |
Events.sendCustomEvent(menuElement, 'joust-expand', {}); |
6381 |
17 Dec 13 |
nicklas |
113 |
} |
6380 |
16 Dec 13 |
nicklas |
114 |
} |
6380 |
16 Dec 13 |
nicklas |
115 |
|
6381 |
17 Dec 13 |
nicklas |
116 |
/** |
6381 |
17 Dec 13 |
nicklas |
Select the given menu element in the joust tree. |
6381 |
17 Dec 13 |
nicklas |
Sends a 'joust-select' event to the selected node |
6381 |
17 Dec 13 |
nicklas |
unless noEvent option is set. |
6381 |
17 Dec 13 |
nicklas |
120 |
*/ |
6381 |
17 Dec 13 |
nicklas |
joust.select = function(menuElement, noEvent) |
6380 |
16 Dec 13 |
nicklas |
122 |
{ |
6380 |
16 Dec 13 |
nicklas |
menuElement = Doc.element(menuElement); |
6380 |
16 Dec 13 |
nicklas |
var menuItem = menuElement.item; |
6380 |
16 Dec 13 |
nicklas |
var tree = menuItem.tree; |
6380 |
16 Dec 13 |
nicklas |
126 |
|
6382 |
17 Dec 13 |
nicklas |
// De-select the current selected item |
6380 |
16 Dec 13 |
nicklas |
if (tree.selectedItem) |
6380 |
16 Dec 13 |
nicklas |
129 |
{ |
6380 |
16 Dec 13 |
nicklas |
tree.selectedItem.isSelected = false; |
6380 |
16 Dec 13 |
nicklas |
joust.updateIconsAndText(tree.selectedItem.id); |
6380 |
16 Dec 13 |
nicklas |
132 |
} |
6380 |
16 Dec 13 |
nicklas |
133 |
|
6382 |
17 Dec 13 |
nicklas |
// Make the given item the selected item |
6380 |
16 Dec 13 |
nicklas |
tree.selectedItem = menuItem; |
6380 |
16 Dec 13 |
nicklas |
menuItem.isSelected = true; |
6380 |
16 Dec 13 |
nicklas |
joust.updateIconsAndText(menuElement); |
6380 |
16 Dec 13 |
nicklas |
138 |
|
6382 |
17 Dec 13 |
nicklas |
// Ensure parent path is open |
6382 |
17 Dec 13 |
nicklas |
var parentItem = menuItem.parent; |
6382 |
17 Dec 13 |
nicklas |
while (parentItem != null) |
6382 |
17 Dec 13 |
nicklas |
142 |
{ |
6382 |
17 Dec 13 |
nicklas |
if (!parentItem.isOpen) |
6382 |
17 Dec 13 |
nicklas |
144 |
{ |
6382 |
17 Dec 13 |
nicklas |
parentItem.isOpen = 1; |
6382 |
17 Dec 13 |
nicklas |
Doc.removeClass(parentItem.id+'-children', 'closed'); |
6382 |
17 Dec 13 |
nicklas |
joust.updateIconsAndText(parentItem.id); |
6382 |
17 Dec 13 |
nicklas |
148 |
} |
6382 |
17 Dec 13 |
nicklas |
parentItem = parentItem.parent; |
6382 |
17 Dec 13 |
nicklas |
150 |
} |
6382 |
17 Dec 13 |
nicklas |
151 |
|
6382 |
17 Dec 13 |
nicklas |
// Make sure the selected menu entry is visible, otherwise try to scroll the main <div> |
6382 |
17 Dec 13 |
nicklas |
if (menuElement.offsetTop > tree.scrollTop + tree.offsetHeight || menuElement.offsetTop < tree.scrollTop) |
6382 |
17 Dec 13 |
nicklas |
154 |
{ |
6382 |
17 Dec 13 |
nicklas |
tree.scrollTop = menuElement.offsetTop - 40; |
6382 |
17 Dec 13 |
nicklas |
156 |
} |
6382 |
17 Dec 13 |
nicklas |
157 |
|
6382 |
17 Dec 13 |
nicklas |
// Send 'joust-select' event |
6381 |
17 Dec 13 |
nicklas |
if (!noEvent) |
6381 |
17 Dec 13 |
nicklas |
160 |
{ |
6381 |
17 Dec 13 |
nicklas |
Events.sendCustomEvent(menuElement, 'joust-select', {}); |
6381 |
17 Dec 13 |
nicklas |
162 |
} |
6380 |
16 Dec 13 |
nicklas |
163 |
} |
6380 |
16 Dec 13 |
nicklas |
164 |
|
6380 |
16 Dec 13 |
nicklas |
165 |
/** |
6380 |
16 Dec 13 |
nicklas |
Re-draw icons based on the current state of the menu item |
6380 |
16 Dec 13 |
nicklas |
represented by the element. |
6380 |
16 Dec 13 |
nicklas |
168 |
*/ |
6380 |
16 Dec 13 |
nicklas |
joust.updateIconsAndText = function(menuElement) |
6380 |
16 Dec 13 |
nicklas |
170 |
{ |
6380 |
16 Dec 13 |
nicklas |
menuElement = Doc.element(menuElement); |
6380 |
16 Dec 13 |
nicklas |
var menuItem = menuElement.item; |
6380 |
16 Dec 13 |
nicklas |
173 |
|
6380 |
16 Dec 13 |
nicklas |
var outlineIcon = internal.outlineIcon(menuItem); |
6382 |
17 Dec 13 |
nicklas |
if (outlineIcon) |
6382 |
17 Dec 13 |
nicklas |
176 |
{ |
6382 |
17 Dec 13 |
nicklas |
Doc.element(menuItem.id+'-outline').src = outlineIcon.src; |
6382 |
17 Dec 13 |
nicklas |
178 |
} |
6380 |
16 Dec 13 |
nicklas |
179 |
|
6380 |
16 Dec 13 |
nicklas |
var docIcon = internal.docIcon(menuItem); |
6382 |
17 Dec 13 |
nicklas |
if (docIcon) |
6382 |
17 Dec 13 |
nicklas |
182 |
{ |
6382 |
17 Dec 13 |
nicklas |
Doc.element(menuItem.id+'-icon').src = docIcon.src; |
6382 |
17 Dec 13 |
nicklas |
184 |
} |
6382 |
17 Dec 13 |
nicklas |
185 |
|
6380 |
16 Dec 13 |
nicklas |
Doc.addOrRemoveClass(menuElement, 'selected', menuItem.isSelected); |
6380 |
16 Dec 13 |
nicklas |
187 |
} |
6380 |
16 Dec 13 |
nicklas |
188 |
|
6381 |
17 Dec 13 |
nicklas |
189 |
/** |
6381 |
17 Dec 13 |
nicklas |
Event handler for open/close of child items. |
6381 |
17 Dec 13 |
nicklas |
191 |
*/ |
6381 |
17 Dec 13 |
nicklas |
internal.toggle = function(event) |
6381 |
17 Dec 13 |
nicklas |
193 |
{ |
6381 |
17 Dec 13 |
nicklas |
event.cancelBubble = true; |
6381 |
17 Dec 13 |
nicklas |
joust.toggle(event.currentTarget.parentNode); |
6381 |
17 Dec 13 |
nicklas |
196 |
} |
6380 |
16 Dec 13 |
nicklas |
197 |
|
6381 |
17 Dec 13 |
nicklas |
198 |
/** |
6381 |
17 Dec 13 |
nicklas |
Event handler for clicking on a menu item. |
6381 |
17 Dec 13 |
nicklas |
200 |
*/ |
6380 |
16 Dec 13 |
nicklas |
internal.select = function(event) |
6380 |
16 Dec 13 |
nicklas |
202 |
{ |
6380 |
16 Dec 13 |
nicklas |
event.cancelBubble = true; |
6380 |
16 Dec 13 |
nicklas |
joust.select(event.currentTarget); |
6380 |
16 Dec 13 |
nicklas |
205 |
} |
6380 |
16 Dec 13 |
nicklas |
206 |
|
6382 |
17 Dec 13 |
nicklas |
internal.addChildren = function(menuItem, pad) |
6380 |
16 Dec 13 |
nicklas |
208 |
{ |
6380 |
16 Dec 13 |
nicklas |
// Create child <div> container |
6386 |
18 Dec 13 |
nicklas |
var childElements = internal.makeDiv(menuItem.id+'-children', 'children ' + (menuItem.isOpen ? 'open' : 'closed')); |
7347 |
28 Apr 17 |
nicklas |
if (menuItem.className) childElements.className += ' ' + menuItem.className; |
6382 |
17 Dec 13 |
nicklas |
212 |
|
6382 |
17 Dec 13 |
nicklas |
var tree = menuItem.tree; |
6380 |
16 Dec 13 |
nicklas |
var children = menuItem.children; |
6380 |
16 Dec 13 |
nicklas |
var last = children.length-1; |
6380 |
16 Dec 13 |
nicklas |
216 |
|
6380 |
16 Dec 13 |
nicklas |
for (var childNo = 0; childNo < children.length; childNo++) |
6380 |
16 Dec 13 |
nicklas |
218 |
{ |
6380 |
16 Dec 13 |
nicklas |
// Create each child element |
6380 |
16 Dec 13 |
nicklas |
var child = children[childNo]; |
6382 |
17 Dec 13 |
nicklas |
child.parent = menuItem; |
6388 |
07 Jan 14 |
nicklas |
var childElement = internal.toElement(tree, child, pad, false, childNo==last); |
6388 |
07 Jan 14 |
nicklas |
var appendElement = childElement.parentNode == null; |
6388 |
07 Jan 14 |
nicklas |
if (appendElement) childElements.appendChild(childElement); |
6380 |
16 Dec 13 |
nicklas |
225 |
|
6380 |
16 Dec 13 |
nicklas |
// Recursive call to create children of the child |
6380 |
16 Dec 13 |
nicklas |
if (child.children) |
6380 |
16 Dec 13 |
nicklas |
228 |
{ |
6382 |
17 Dec 13 |
nicklas |
var childPad = internal.padHtml(child); |
6388 |
07 Jan 14 |
nicklas |
var childDiv = internal.addChildren(child, pad+childPad); |
6388 |
07 Jan 14 |
nicklas |
if (appendElement) childElements.appendChild(childDiv); |
6380 |
16 Dec 13 |
nicklas |
232 |
} |
6380 |
16 Dec 13 |
nicklas |
233 |
} |
6380 |
16 Dec 13 |
nicklas |
return childElements; |
6380 |
16 Dec 13 |
nicklas |
235 |
} |
6380 |
16 Dec 13 |
nicklas |
236 |
|
6380 |
16 Dec 13 |
nicklas |
237 |
/** |
6380 |
16 Dec 13 |
nicklas |
Create a DOM element for the given menuItem definition. |
6380 |
16 Dec 13 |
nicklas |
239 |
*/ |
6382 |
17 Dec 13 |
nicklas |
internal.toElement = function(tree, menuItem, pad, first, last) |
6380 |
16 Dec 13 |
nicklas |
241 |
{ |
6380 |
16 Dec 13 |
nicklas |
// Remember some settings |
6382 |
17 Dec 13 |
nicklas |
menuItem.pad = pad; |
6380 |
16 Dec 13 |
nicklas |
menuItem.isFirst = first; |
6380 |
16 Dec 13 |
nicklas |
menuItem.isLast = last; |
6380 |
16 Dec 13 |
nicklas |
menuItem.tree = tree; |
6380 |
16 Dec 13 |
nicklas |
menuItem.isSelected = false; |
6380 |
16 Dec 13 |
nicklas |
248 |
|
6382 |
17 Dec 13 |
nicklas |
// Create main menu <div> container |
6613 |
21 Nov 14 |
nicklas |
var menuElement = internal.makeDiv(menuItem.id, 'joustitem', pad); |
6382 |
17 Dec 13 |
nicklas |
menuElement.item = menuItem; |
6385 |
18 Dec 13 |
nicklas |
if (menuItem.className) menuElement.className += ' ' + menuItem.className; |
6382 |
17 Dec 13 |
nicklas |
menuElement.addEventListener('click', internal.select, false); |
6382 |
17 Dec 13 |
nicklas |
254 |
|
6380 |
16 Dec 13 |
nicklas |
// Outline icon |
6380 |
16 Dec 13 |
nicklas |
var outlineIcon = internal.outlineIcon(menuItem); |
6382 |
17 Dec 13 |
nicklas |
if (outlineIcon) |
6382 |
17 Dec 13 |
nicklas |
258 |
{ |
6382 |
17 Dec 13 |
nicklas |
var outlineTag = outlineIcon.toHTML(menuItem.id+'-outline'); |
6382 |
17 Dec 13 |
nicklas |
var outline = internal.makeDiv(null, 'outline pad ' + (!last && !first ? 'line' : 'blank'), outlineTag); |
6382 |
17 Dec 13 |
nicklas |
outline.addEventListener('click', internal.toggle, false); |
6382 |
17 Dec 13 |
nicklas |
menuElement.appendChild(outline); |
6382 |
17 Dec 13 |
nicklas |
263 |
} |
6380 |
16 Dec 13 |
nicklas |
264 |
|
6380 |
16 Dec 13 |
nicklas |
// Document icon |
6380 |
16 Dec 13 |
nicklas |
var docIcon = internal.docIcon(menuItem); |
6382 |
17 Dec 13 |
nicklas |
if (docIcon) |
6382 |
17 Dec 13 |
nicklas |
268 |
{ |
6382 |
17 Dec 13 |
nicklas |
var iconTag = docIcon.toHTML(menuItem.id+'-icon'); |
6382 |
17 Dec 13 |
nicklas |
var icon = internal.makeDiv(null, 'icon', iconTag); |
6382 |
17 Dec 13 |
nicklas |
menuElement.appendChild(icon); |
6382 |
17 Dec 13 |
nicklas |
272 |
} |
6380 |
16 Dec 13 |
nicklas |
273 |
|
6380 |
16 Dec 13 |
nicklas |
// Menu text |
6613 |
21 Nov 14 |
nicklas |
var text = internal.makeDiv(menuItem.id+'-text', 'text interactable', menuItem.text); |
6382 |
17 Dec 13 |
nicklas |
if (menuItem.tooltip) text.title = menuItem.tooltip; |
6380 |
16 Dec 13 |
nicklas |
menuElement.appendChild(text); |
6380 |
16 Dec 13 |
nicklas |
return menuElement; |
6380 |
16 Dec 13 |
nicklas |
279 |
} |
6380 |
16 Dec 13 |
nicklas |
280 |
|
6380 |
16 Dec 13 |
nicklas |
281 |
/** |
6380 |
16 Dec 13 |
nicklas |
Get the outline icon that should be used for the menuItem |
6380 |
16 Dec 13 |
nicklas |
in it's current state (eg. open/closed). |
6380 |
16 Dec 13 |
nicklas |
284 |
*/ |
6380 |
16 Dec 13 |
nicklas |
internal.outlineIcon = function(menuItem) |
6380 |
16 Dec 13 |
nicklas |
286 |
{ |
6382 |
17 Dec 13 |
nicklas |
if (menuItem.noOutlineIcon == true) return null; |
6380 |
16 Dec 13 |
nicklas |
var name = ''; |
6382 |
17 Dec 13 |
nicklas |
if (menuItem.isLazy) |
6380 |
16 Dec 13 |
nicklas |
290 |
{ |
6380 |
16 Dec 13 |
nicklas |
name += 'Lazy'; |
6380 |
16 Dec 13 |
nicklas |
292 |
} |
6380 |
16 Dec 13 |
nicklas |
else if (menuItem.children && menuItem.children.length) |
6380 |
16 Dec 13 |
nicklas |
294 |
{ |
6380 |
16 Dec 13 |
nicklas |
name += menuItem.isOpen ? 'Minus' : 'Plus'; |
6380 |
16 Dec 13 |
nicklas |
296 |
} |
6380 |
16 Dec 13 |
nicklas |
else |
6380 |
16 Dec 13 |
nicklas |
298 |
{ |
6380 |
16 Dec 13 |
nicklas |
name += 'Join'; |
6380 |
16 Dec 13 |
nicklas |
300 |
} |
6380 |
16 Dec 13 |
nicklas |
301 |
|
6380 |
16 Dec 13 |
nicklas |
if (menuItem.isLast && !menuItem.isFirst) |
6380 |
16 Dec 13 |
nicklas |
303 |
{ |
6380 |
16 Dec 13 |
nicklas |
name += 'Bottom'; |
6380 |
16 Dec 13 |
nicklas |
305 |
} |
6380 |
16 Dec 13 |
nicklas |
if (menuItem.isFirst && !menuItem.isLast) |
6380 |
16 Dec 13 |
nicklas |
307 |
{ |
6380 |
16 Dec 13 |
nicklas |
name += 'Top'; |
6380 |
16 Dec 13 |
nicklas |
309 |
} |
6380 |
16 Dec 13 |
nicklas |
return IconStore.getIcon(name); |
6380 |
16 Dec 13 |
nicklas |
311 |
} |
6380 |
16 Dec 13 |
nicklas |
312 |
|
6380 |
16 Dec 13 |
nicklas |
internal.docIcon = function(menuItem) |
6380 |
16 Dec 13 |
nicklas |
314 |
{ |
6380 |
16 Dec 13 |
nicklas |
return IconStore.getIconFromSet(menuItem.icon, menuItem.isOpen, menuItem.isSelected); |
6380 |
16 Dec 13 |
nicklas |
316 |
} |
6380 |
16 Dec 13 |
nicklas |
317 |
|
6382 |
17 Dec 13 |
nicklas |
internal.padHtml = function(menuItem) |
6382 |
17 Dec 13 |
nicklas |
319 |
{ |
6382 |
17 Dec 13 |
nicklas |
if (menuItem.noOutlineIcon == true) return ''; |
6382 |
17 Dec 13 |
nicklas |
return '<div class="pad '+(menuItem.isLast ? 'blank' : 'line')+'"> </div>' |
6382 |
17 Dec 13 |
nicklas |
322 |
} |
6382 |
17 Dec 13 |
nicklas |
323 |
|
6380 |
16 Dec 13 |
nicklas |
internal.makeDiv = function(id, className, innerHTML) |
6380 |
16 Dec 13 |
nicklas |
325 |
{ |
6388 |
07 Jan 14 |
nicklas |
var div = null; |
6388 |
07 Jan 14 |
nicklas |
if (id) div = Doc.element(id); |
6388 |
07 Jan 14 |
nicklas |
if (!div) |
6388 |
07 Jan 14 |
nicklas |
329 |
{ |
6388 |
07 Jan 14 |
nicklas |
div = document.createElement('div'); |
6388 |
07 Jan 14 |
nicklas |
if (id) div.id = id; |
6388 |
07 Jan 14 |
nicklas |
if (className) div.className = className; |
6388 |
07 Jan 14 |
nicklas |
if (innerHTML) div.innerHTML = innerHTML; |
6388 |
07 Jan 14 |
nicklas |
334 |
} |
6388 |
07 Jan 14 |
nicklas |
else |
6388 |
07 Jan 14 |
nicklas |
336 |
{ |
6388 |
07 Jan 14 |
nicklas |
if (className) div.className += ' ' + className; |
6388 |
07 Jan 14 |
nicklas |
div.innerHTML = innerHTML ? innerHTML : ''; |
6388 |
07 Jan 14 |
nicklas |
339 |
} |
6380 |
16 Dec 13 |
nicklas |
return div; |
6380 |
16 Dec 13 |
nicklas |
341 |
} |
6380 |
16 Dec 13 |
nicklas |
342 |
|
6363 |
29 Nov 13 |
nicklas |
return joust; |
6363 |
29 Nov 13 |
nicklas |
344 |
}(); |
6363 |
29 Nov 13 |
nicklas |
345 |
|
6380 |
16 Dec 13 |
nicklas |
346 |
|
6380 |
16 Dec 13 |
nicklas |
347 |
|
6363 |
29 Nov 13 |
nicklas |
var IconStore = function() |
6363 |
29 Nov 13 |
nicklas |
349 |
{ |
6363 |
29 Nov 13 |
nicklas |
var iconStore = {}; |
6363 |
29 Nov 13 |
nicklas |
var iconSets = []; |
6363 |
29 Nov 13 |
nicklas |
var icons = []; |
6363 |
29 Nov 13 |
nicklas |
353 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addDefaultIcons = function() |
6363 |
29 Nov 13 |
nicklas |
355 |
{ |
6363 |
29 Nov 13 |
nicklas |
// Icons for the outline |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Plus', new Icon('plus.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('PlusTop', new Icon('plus-top.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('PlusBottom', new Icon('plus-bottom.png')); |
6363 |
29 Nov 13 |
nicklas |
360 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Minus', new Icon('minus.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('MinusTop', new Icon('minus-top.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('MinusBottom', new Icon('minus-bottom.png')); |
6363 |
29 Nov 13 |
nicklas |
364 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Lazy', new Icon('lazy.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('LazyTop', new Icon('lazy-top.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('LazyBottom', new Icon('lazy-bottom.png')); |
6363 |
29 Nov 13 |
nicklas |
368 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Join', new Icon('join.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('JoinTop', new Icon('join-top.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('JoinBottom', new Icon('join-bottom.png')); |
6363 |
29 Nov 13 |
nicklas |
372 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Line', new Icon('line.png')); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon('Blank', new Icon('blank.png')); |
6363 |
29 Nov 13 |
nicklas |
375 |
|
6363 |
29 Nov 13 |
nicklas |
// Icon sets for folder-like nodes |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet('Folder', 'folder-closed.png', 'folder-selected.png', 'folder-open.png', 'folder-selected.png'); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet('Root', 'root.png', 'root-selected.png'); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet('Home', 'home.png', 'home-selected.png'); |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet('UserHome', 'userhome.png', 'userhome-selected.png'); |
6363 |
29 Nov 13 |
nicklas |
381 |
|
6363 |
29 Nov 13 |
nicklas |
// Document nodes |
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet('Item', 'item.png', 'item-selected.png'); |
6363 |
29 Nov 13 |
nicklas |
384 |
} |
6363 |
29 Nov 13 |
nicklas |
385 |
|
6363 |
29 Nov 13 |
nicklas |
386 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIconSet = function(name, closed, closedSelected, open, openSelected, path) |
6363 |
29 Nov 13 |
nicklas |
388 |
{ |
6363 |
29 Nov 13 |
nicklas |
var set = {}; |
6363 |
29 Nov 13 |
nicklas |
set.closed = new Icon(closed, path); |
6363 |
29 Nov 13 |
nicklas |
set.closedSelected = new Icon(closedSelected || closed, path); |
6363 |
29 Nov 13 |
nicklas |
set.open = new Icon(open || closed, path); |
6363 |
29 Nov 13 |
nicklas |
set.openSelected = new Icon(openSelected || closedSelected || open || closed, path); |
6363 |
29 Nov 13 |
nicklas |
iconSets[name] = set; |
6363 |
29 Nov 13 |
nicklas |
return set; |
6363 |
29 Nov 13 |
nicklas |
396 |
} |
6363 |
29 Nov 13 |
nicklas |
397 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.getIconSet = function(name) |
6363 |
29 Nov 13 |
nicklas |
399 |
{ |
6363 |
29 Nov 13 |
nicklas |
return iconSets[name]; |
6363 |
29 Nov 13 |
nicklas |
401 |
} |
6363 |
29 Nov 13 |
nicklas |
402 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.getIconFromSet = function(name, open, selected) |
6363 |
29 Nov 13 |
nicklas |
404 |
{ |
6363 |
29 Nov 13 |
nicklas |
var set = iconSets[name]; |
6380 |
16 Dec 13 |
nicklas |
if (!set) return iconStore.nullIcon; |
6363 |
29 Nov 13 |
nicklas |
407 |
|
6363 |
29 Nov 13 |
nicklas |
var icon = null; |
6363 |
29 Nov 13 |
nicklas |
if (open && selected) |
6363 |
29 Nov 13 |
nicklas |
410 |
{ |
6363 |
29 Nov 13 |
nicklas |
icon = set.openSelected; |
6363 |
29 Nov 13 |
nicklas |
412 |
} |
6363 |
29 Nov 13 |
nicklas |
else if (open) |
6363 |
29 Nov 13 |
nicklas |
414 |
{ |
6363 |
29 Nov 13 |
nicklas |
icon = set.open; |
6363 |
29 Nov 13 |
nicklas |
416 |
} |
6363 |
29 Nov 13 |
nicklas |
else if (selected) |
6363 |
29 Nov 13 |
nicklas |
418 |
{ |
6363 |
29 Nov 13 |
nicklas |
icon = set.closedSelected; |
6363 |
29 Nov 13 |
nicklas |
420 |
} |
6363 |
29 Nov 13 |
nicklas |
else |
6363 |
29 Nov 13 |
nicklas |
422 |
{ |
6363 |
29 Nov 13 |
nicklas |
icon = set.closed; |
6363 |
29 Nov 13 |
nicklas |
424 |
} |
6380 |
16 Dec 13 |
nicklas |
return icon || iconStore.nullIcon; |
6363 |
29 Nov 13 |
nicklas |
426 |
} |
6363 |
29 Nov 13 |
nicklas |
427 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.addIcon = function(name, icon) |
6363 |
29 Nov 13 |
nicklas |
429 |
{ |
6363 |
29 Nov 13 |
nicklas |
icons[name] = icon; |
6363 |
29 Nov 13 |
nicklas |
431 |
} |
6363 |
29 Nov 13 |
nicklas |
432 |
|
6363 |
29 Nov 13 |
nicklas |
iconStore.getIcon = function(name) |
6363 |
29 Nov 13 |
nicklas |
434 |
{ |
6380 |
16 Dec 13 |
nicklas |
return icons[name] || iconStore.nullIcon; |
6363 |
29 Nov 13 |
nicklas |
436 |
} |
6363 |
29 Nov 13 |
nicklas |
437 |
|
6380 |
16 Dec 13 |
nicklas |
iconStore.nullIcon = {}; |
6363 |
29 Nov 13 |
nicklas |
439 |
|
6380 |
16 Dec 13 |
nicklas |
iconStore.nullIcon.toHTML = function() |
6380 |
16 Dec 13 |
nicklas |
441 |
{ |
6380 |
16 Dec 13 |
nicklas |
return ''; |
6380 |
16 Dec 13 |
nicklas |
443 |
} |
6380 |
16 Dec 13 |
nicklas |
444 |
|
6363 |
29 Nov 13 |
nicklas |
return iconStore; |
6363 |
29 Nov 13 |
nicklas |
446 |
}(); |
6363 |
29 Nov 13 |
nicklas |
447 |
|
6363 |
29 Nov 13 |
nicklas |
448 |
|
6363 |
29 Nov 13 |
nicklas |
function Icon(file, path) |
6363 |
29 Nov 13 |
nicklas |
450 |
{ |
6363 |
29 Nov 13 |
nicklas |
if (!path) path = App.getRoot() + 'images/joust/'; |
6363 |
29 Nov 13 |
nicklas |
this.src = path+file; |
6363 |
29 Nov 13 |
nicklas |
453 |
|
6363 |
29 Nov 13 |
nicklas |
// Preload the image |
6363 |
29 Nov 13 |
nicklas |
this.img = new Image(); |
6363 |
29 Nov 13 |
nicklas |
this.img.src = this.src; |
6363 |
29 Nov 13 |
nicklas |
457 |
} |
6363 |
29 Nov 13 |
nicklas |
458 |
|
6363 |
29 Nov 13 |
nicklas |
Icon.prototype.toHTML = function(id) |
6363 |
29 Nov 13 |
nicklas |
460 |
{ |
6363 |
29 Nov 13 |
nicklas |
var html = '<img'; |
6363 |
29 Nov 13 |
nicklas |
if (id) html += ' id="'+id+'"'; |
6363 |
29 Nov 13 |
nicklas |
html += ' src="' + this.src + '">'; |
6363 |
29 Nov 13 |
nicklas |
return html; |
6363 |
29 Nov 13 |
nicklas |
465 |
} |
6363 |
29 Nov 13 |
nicklas |
466 |
|
6363 |
29 Nov 13 |
nicklas |
467 |
|
6363 |
29 Nov 13 |
nicklas |
468 |
|