-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolStrip.js
More file actions
118 lines (102 loc) · 3.78 KB
/
Copy pathToolStrip.js
File metadata and controls
118 lines (102 loc) · 3.78 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
/// <reference path="../Scripts/jspack-vsdoc.js" />
var common = MindFusion.Common;
var ui = MindFusion.Common.UI;
var d = MindFusion.Drawing;
// Create a new ToolStrip control.
var strip = new ui.ToolStrip();
strip.theme = "business";
strip.scrollable = false;
// Create an item, displaying text.
var item = new ui.ToolStripItem(ui.ToolStripItemType.Label, "Theme");
strip.items.add(item);
// Create an item, displaying an icon.
item = new ui.ToolStripItem(ui.ToolStripItemType.Icon);
item.imageSrc = "images/icon_home.png";
item.size = common.Unit.pixel(36);
strip.items.add(item);
// create an item, displaying text and an icon.
item = new ui.ToolStripItem(ui.ToolStripItemType.Label, "Armillaria Ponderosa");
item.imageSrc = "images/h1.png";
strip.items.add(item);
// Create a separator item.
item = new ui.ToolStripItem(ui.ToolStripItemType.Separator);
strip.items.add(item);
// Create an item with HTML template
item = new ui.ToolStripItem(ui.ToolStripItemType.Default);
item.template = "<input type='text' id='node_title'></input><input type='button' value='🔍'/>";
strip.items.add(item);
// Draw the control and append it to the page DOM.
document.getElementById("content").appendChild(strip.draw());
// Prepare the control for user interaction.
strip.attach();
// Add event handlers.
strip.itemDragStart.addEventListener(itemDragStart);
strip.itemMouseEnter.addEventListener(itemMouseEnter);
strip.itemMouseDown.addEventListener(itemMouseDown);
// Create a tooltip for the search field.
// When the search field is focused the tooltip will appear below it with the specified offset.
var tooltip = new ui.Tooltip(document.getElementById("node_title"), "This is a search field.");
tooltip.theme = "business";
tooltip.offset = new d.Point(0, 10);
tooltip.position = ui.TooltipPosition.Bottom;
tooltip.trigger = ui.TooltipTrigger.Focus;
tooltip.render();
// Create a new Menu control.
// It will be used as a popup menu for the "Theme" toolstrip item.
var menu = new ui.Menu();
menu.cssClass = "popmenu";
menu.items.add(new ui.MenuItem("earth"));
menu.items.add(new ui.MenuItem("peach"));
menu.items.add(new ui.MenuItem("business"));
// Add event handler to menu's itemClick event.
// When an item is clicked the toolstrip's theme will be changed
// and then the menu will removed from the page DOM.
menu.itemClick.addEventListener(function (sender, args)
{
strip.theme = args.item.title;
sender.dispose();
})
// This is the handler function of the toolstrip.itemDragStart event.
// Drag operations will be cancelled if the item to be dragged is the templated item
// or if the menu is currently visible.
function itemDragStart(sender, args)
{
if (sender.type == ui.ToolStripItemType.Default)
args.cancel = true;
if (menu.loaded)
args.cancel = true;
}
// This is the handler function of the toolstrip.itemMouseEnter event.
// If the menu is currently visible it will be removed.
// Otherwise, the menu will be created right below the hovered item.
function itemMouseEnter(sender, args)
{
if (menu.loaded)
{
menu.dispose();
}
else if (args.item.title == "Theme")
{
menu.theme = sender.theme;
menu.left = common.Unit.pixel(sender.bounds.x + args.item.bounds.x);
menu.top = common.Unit.pixel(sender.bounds.y + args.item.bounds.height);
document.body.appendChild(menu.draw());
menu.attach();
}
}
// This is the handler function of the toolstrip.itemMouseDown event.
// Simulate a search.
// An information dialog will be shown when the search button is pressed.
function itemMouseDown(sender, args)
{
var input = args.item.element.querySelector("#node_title");
if (args.rawEventArgs.target.type == "button")
{
ui.Dialogs.showInfoDialog("Search", "Searching for '" + input.value + "'.\n No results found.",
null, document.getElementById("content"), sender.theme);
}
else
{
if (input) input.focus();
}
}