1 |
/*
|
1 |
/*
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
2 |
Copyright (c) 2004-2006, The Dojo Foundation
|
3 |
All Rights Reserved.
|
3 |
All Rights Reserved.
|
4 |
|
4 |
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
5 |
Licensed under the Academic Free License version 2.1 or above OR the
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
6 |
modified BSD license. For more information on Dojo licensing, see:
|
7 |
|
7 |
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
8 |
http://dojotoolkit.org/community/licensing.shtml
|
9 |
*/
|
9 |
*/
|
- |
|
10 |
|
- |
|
11 |
|
10 |
|
12 |
|
11 |
dojo.provide("dojo.widget.Editor2Plugin.ContextMenu");
|
13 |
dojo.provide("dojo.widget.Editor2Plugin.ContextMenu");
|
12 |
dojo.require("dojo.widget.Menu2");
|
14 |
dojo.require("dojo.widget.Menu2");
|
13 |
dojo.event.topic.subscribe("dojo.widget.Editor2::onLoad", function (editor) {
|
15 |
dojo.event.topic.subscribe("dojo.widget.Editor2::onLoad", function (editor) {
|
14 |
dojo.widget.Editor2Plugin.ContextMenuManager.getContextMenu(editor);
|
16 |
dojo.widget.Editor2Plugin.ContextMenuManager.getContextMenu(editor);
|
15 |
});
|
17 |
});
|
16 |
dojo.widget.Editor2Plugin.ContextMenuManager = {menuGroups:["Generic", "Link", "Anchor", "Image", "List", "Table"], _contextMenuGroupSets:{}, _registeredGroups:{}, _menus:{}, registerGroup:function (name, handler) {
|
18 |
dojo.widget.Editor2Plugin.ContextMenuManager = {menuGroups:["Generic", "Link", "Anchor", "Image", "List", "Table"], _contextMenuGroupSets:{}, _registeredGroups:{}, _menus:{}, registerGroup:function (name, handler) {
|
17 |
if (this._registeredGroups[name]) {
|
19 |
if (this._registeredGroups[name]) {
|
18 |
alert("dojo.widget.Editor2Plugin.ContextMenuManager.registerGroup: menu group " + name + "is already registered. Ignored.");
|
20 |
alert("dojo.widget.Editor2Plugin.ContextMenuManager.registerGroup: menu group " + name + "is already registered. Ignored.");
|
19 |
return;
|
21 |
return;
|
20 |
}
|
22 |
}
|
21 |
this._registeredGroups[name] = handler;
|
23 |
this._registeredGroups[name] = handler;
|
22 |
}, removeGroup:function (name) {
|
24 |
}, removeGroup:function (name) {
|
23 |
delete this._registeredGroups[name];
|
25 |
delete this._registeredGroups[name];
|
24 |
}, getGroup:function (name, contextmenuplugin) {
|
26 |
}, getGroup:function (name, contextmenuplugin) {
|
25 |
if (this._registeredGroups[name]) {
|
27 |
if (this._registeredGroups[name]) {
|
26 |
var item = this._registeredGroups[name](name, contextmenuplugin);
|
28 |
var item = this._registeredGroups[name](name, contextmenuplugin);
|
27 |
if (item) {
|
29 |
if (item) {
|
28 |
return item;
|
30 |
return item;
|
29 |
}
|
31 |
}
|
30 |
}
|
32 |
}
|
31 |
switch (name) {
|
33 |
switch (name) {
|
32 |
case "Generic":
|
34 |
case "Generic":
|
33 |
case "Link":
|
35 |
case "Link":
|
34 |
case "Image":
|
36 |
case "Image":
|
35 |
return new dojo.widget.Editor2Plugin[name + "ContextMenuGroup"](contextmenuplugin);
|
37 |
return new dojo.widget.Editor2Plugin[name + "ContextMenuGroup"](contextmenuplugin);
|
36 |
case "Anchor":
|
38 |
case "Anchor":
|
37 |
case "List":
|
39 |
case "List":
|
38 |
}
|
40 |
}
|
39 |
}, registerGroupSet:function (name, set) {
|
41 |
}, registerGroupSet:function (name, set) {
|
40 |
this._contextMenuGroupSets[name] = set;
|
42 |
this._contextMenuGroupSets[name] = set;
|
41 |
}, removeGroupSet:function (name) {
|
43 |
}, removeGroupSet:function (name) {
|
42 |
var set = this._contextMenuGroupSets[name];
|
44 |
var set = this._contextMenuGroupSets[name];
|
43 |
delete this._contextMenuGroupSets[name];
|
45 |
delete this._contextMenuGroupSets[name];
|
44 |
return set;
|
46 |
return set;
|
45 |
}, getContextMenu:function (editor) {
|
47 |
}, getContextMenu:function (editor) {
|
46 |
var set = editor.contextMenuGroupSet || "defaultDojoEditor2MenuGroupSet";
|
48 |
var set = editor.contextMenuGroupSet || "defaultDojoEditor2MenuGroupSet";
|
47 |
if (this._menus[set]) {
|
49 |
if (this._menus[set]) {
|
48 |
this._menus[set].bindEditor(editor);
|
50 |
this._menus[set].bindEditor(editor);
|
49 |
return this._menus[set];
|
51 |
return this._menus[set];
|
50 |
}
|
52 |
}
|
51 |
var gs = (editor.contextMenuGroupSet && this._contextMenuGroupSets[editor.contextMenuGroupSet]) || this.menuGroups;
|
53 |
var gs = (editor.contextMenuGroupSet && this._contextMenuGroupSets[editor.contextMenuGroupSet]) || this.menuGroups;
|
52 |
var menu = new dojo.widget.Editor2Plugin.ContextMenu(editor, gs);
|
54 |
var menu = new dojo.widget.Editor2Plugin.ContextMenu(editor, gs);
|
53 |
this._menus[set] = menu;
|
55 |
this._menus[set] = menu;
|
54 |
return menu;
|
56 |
return menu;
|
55 |
}};
|
57 |
}};
|
56 |
dojo.declare("dojo.widget.Editor2Plugin.ContextMenu", null, function (editor, gs) {
|
58 |
dojo.declare("dojo.widget.Editor2Plugin.ContextMenu", null, function (editor, gs) {
|
57 |
this.groups = [];
|
59 |
this.groups = [];
|
58 |
this.separators = [];
|
60 |
this.separators = [];
|
59 |
this.editor = editor;
|
61 |
this.editor = editor;
|
60 |
this.editor.registerLoadedPlugin(this);
|
62 |
this.editor.registerLoadedPlugin(this);
|
61 |
this.contextMenu = dojo.widget.createWidget("PopupMenu2", {});
|
63 |
this.contextMenu = dojo.widget.createWidget("PopupMenu2", {});
|
62 |
dojo.body().appendChild(this.contextMenu.domNode);
|
64 |
dojo.body().appendChild(this.contextMenu.domNode);
|
63 |
this.bindEditor(this.editor);
|
65 |
this.bindEditor(this.editor);
|
64 |
dojo.event.connect(this.contextMenu, "aboutToShow", this, "aboutToShow");
|
66 |
dojo.event.connect(this.contextMenu, "aboutToShow", this, "aboutToShow");
|
65 |
dojo.event.connect(this.editor, "destroy", this, "destroy");
|
67 |
dojo.event.connect(this.editor, "destroy", this, "destroy");
|
66 |
this.setup(gs);
|
68 |
this.setup(gs);
|
67 |
}, {bindEditor:function (editor) {
|
69 |
}, {bindEditor:function (editor) {
|
68 |
this.contextMenu.bindDomNode(editor.document.body);
|
70 |
this.contextMenu.bindDomNode(editor.document.body);
|
69 |
}, setup:function (gs) {
|
71 |
}, setup:function (gs) {
|
70 |
for (var i in gs) {
|
72 |
for (var i in gs) {
|
71 |
var g = dojo.widget.Editor2Plugin.ContextMenuManager.getGroup(gs[i], this);
|
73 |
var g = dojo.widget.Editor2Plugin.ContextMenuManager.getGroup(gs[i], this);
|
72 |
if (g) {
|
74 |
if (g) {
|
73 |
this.groups.push(g);
|
75 |
this.groups.push(g);
|
74 |
}
|
76 |
}
|
75 |
}
|
77 |
}
|
76 |
}, aboutToShow:function () {
|
78 |
}, aboutToShow:function () {
|
77 |
var first = true;
|
79 |
var first = true;
|
78 |
for (var i in this.groups) {
|
80 |
for (var i in this.groups) {
|
79 |
if (i > 0 && this.separators.length != this.groups.length - 1) {
|
81 |
if (i > 0 && this.separators.length != this.groups.length - 1) {
|
80 |
this.separators.push(dojo.widget.createWidget("MenuSeparator2", {}));
|
82 |
this.separators.push(dojo.widget.createWidget("MenuSeparator2", {}));
|
81 |
this.contextMenu.addChild(this.separators[this.separators.length - 1]);
|
83 |
this.contextMenu.addChild(this.separators[this.separators.length - 1]);
|
82 |
}
|
84 |
}
|
83 |
if (this.groups[i].refresh()) {
|
85 |
if (this.groups[i].refresh()) {
|
84 |
if (i > 0) {
|
86 |
if (i > 0) {
|
85 |
if (first) {
|
87 |
if (first) {
|
86 |
this.separators[i - 1].hide();
|
88 |
this.separators[i - 1].hide();
|
87 |
} else {
|
89 |
} else {
|
88 |
this.separators[i - 1].show();
|
90 |
this.separators[i - 1].show();
|
89 |
}
|
91 |
}
|
90 |
}
|
92 |
}
|
91 |
if (first) {
|
93 |
if (first) {
|
92 |
first = false;
|
94 |
first = false;
|
93 |
}
|
95 |
}
|
94 |
} else {
|
96 |
} else {
|
95 |
if (i > 0) {
|
97 |
if (i > 0) {
|
96 |
this.separators[i - 1].hide();
|
98 |
this.separators[i - 1].hide();
|
97 |
}
|
99 |
}
|
98 |
}
|
100 |
}
|
99 |
}
|
101 |
}
|
100 |
}, destroy:function () {
|
102 |
}, destroy:function () {
|
101 |
this.editor.unregisterLoadedPlugin(this);
|
103 |
this.editor.unregisterLoadedPlugin(this);
|
102 |
delete this.groups;
|
104 |
delete this.groups;
|
103 |
delete this.separators;
|
105 |
delete this.separators;
|
104 |
this.contextMenu.destroy();
|
106 |
this.contextMenu.destroy();
|
105 |
delete this.contextMenu;
|
107 |
delete this.contextMenu;
|
106 |
}});
|
108 |
}});
|
107 |
dojo.widget.defineWidget("dojo.widget.Editor2ContextMenuItem", dojo.widget.MenuItem2, {command:"", buildRendering:function () {
|
109 |
dojo.widget.defineWidget("dojo.widget.Editor2ContextMenuItem", dojo.widget.MenuItem2, {command:"", buildRendering:function () {
|
108 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
110 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
109 |
this.caption = curInst.getCommand(this.command).getText();
|
111 |
this.caption = curInst.getCommand(this.command).getText();
|
110 |
dojo.widget.Editor2ContextMenuItem.superclass.buildRendering.apply(this, arguments);
|
112 |
dojo.widget.Editor2ContextMenuItem.superclass.buildRendering.apply(this, arguments);
|
111 |
}, onClick:function () {
|
113 |
}, onClick:function () {
|
112 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
114 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
113 |
if (curInst) {
|
115 |
if (curInst) {
|
114 |
var _command = curInst.getCommand(this.command);
|
116 |
var _command = curInst.getCommand(this.command);
|
115 |
if (_command) {
|
117 |
if (_command) {
|
116 |
_command.execute();
|
118 |
_command.execute();
|
117 |
}
|
119 |
}
|
118 |
}
|
120 |
}
|
119 |
}, refresh:function () {
|
121 |
}, refresh:function () {
|
120 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
122 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
121 |
if (curInst) {
|
123 |
if (curInst) {
|
122 |
var _command = curInst.getCommand(this.command);
|
124 |
var _command = curInst.getCommand(this.command);
|
123 |
if (_command) {
|
125 |
if (_command) {
|
124 |
if (_command.getState() == dojo.widget.Editor2Manager.commandState.Disabled) {
|
126 |
if (_command.getState() == dojo.widget.Editor2Manager.commandState.Disabled) {
|
125 |
this.disable();
|
127 |
this.disable();
|
126 |
return false;
|
128 |
return false;
|
127 |
} else {
|
129 |
} else {
|
128 |
this.enable();
|
130 |
this.enable();
|
129 |
return true;
|
131 |
return true;
|
130 |
}
|
132 |
}
|
131 |
}
|
133 |
}
|
132 |
}
|
134 |
}
|
133 |
}, hide:function () {
|
135 |
}, hide:function () {
|
134 |
this.domNode.style.display = "none";
|
136 |
this.domNode.style.display = "none";
|
135 |
}, show:function () {
|
137 |
}, show:function () {
|
136 |
this.domNode.style.display = "";
|
138 |
this.domNode.style.display = "";
|
137 |
}});
|
139 |
}});
|
138 |
dojo.declare("dojo.widget.Editor2Plugin.SimpleContextMenuGroup", null, function (contextmenuplugin) {
|
140 |
dojo.declare("dojo.widget.Editor2Plugin.SimpleContextMenuGroup", null, function (contextmenuplugin) {
|
139 |
this.contextMenu = contextmenuplugin.contextMenu;
|
141 |
this.contextMenu = contextmenuplugin.contextMenu;
|
140 |
this.items = [];
|
142 |
this.items = [];
|
141 |
dojo.event.connect(contextmenuplugin, "destroy", this, "destroy");
|
143 |
dojo.event.connect(contextmenuplugin, "destroy", this, "destroy");
|
142 |
}, {refresh:function () {
|
144 |
}, {refresh:function () {
|
143 |
if (!this.items.length) {
|
145 |
if (!this.items.length) {
|
144 |
this.createItems();
|
146 |
this.createItems();
|
145 |
for (var i in this.items) {
|
147 |
for (var i in this.items) {
|
146 |
this.contextMenu.addChild(this.items[i]);
|
148 |
this.contextMenu.addChild(this.items[i]);
|
147 |
}
|
149 |
}
|
148 |
}
|
150 |
}
|
149 |
return this.checkVisibility();
|
151 |
return this.checkVisibility();
|
150 |
}, destroy:function () {
|
152 |
}, destroy:function () {
|
151 |
this.contextmenu = null;
|
153 |
this.contextmenu = null;
|
152 |
delete this.items;
|
154 |
delete this.items;
|
153 |
delete this.contextMenu;
|
155 |
delete this.contextMenu;
|
154 |
}, createItems:function () {
|
156 |
}, createItems:function () {
|
155 |
}, checkVisibility:function () {
|
157 |
}, checkVisibility:function () {
|
156 |
var show = false;
|
158 |
var show = false;
|
157 |
for (var i in this.items) {
|
159 |
for (var i in this.items) {
|
158 |
show = show || this.items[i].refresh();
|
160 |
show = show || this.items[i].refresh();
|
159 |
}
|
161 |
}
|
160 |
var action = show ? "show" : "hide";
|
162 |
var action = show ? "show" : "hide";
|
161 |
for (var i in this.items) {
|
163 |
for (var i in this.items) {
|
162 |
this.items[i][action]();
|
164 |
this.items[i][action]();
|
163 |
}
|
165 |
}
|
164 |
return show;
|
166 |
return show;
|
165 |
}});
|
167 |
}});
|
166 |
dojo.declare("dojo.widget.Editor2Plugin.GenericContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
168 |
dojo.declare("dojo.widget.Editor2Plugin.GenericContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
167 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"cut", iconClass:"dojoE2TBIcon dojoE2TBIcon_Cut"}));
|
169 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"cut", iconClass:"dojoE2TBIcon dojoE2TBIcon_Cut"}));
|
168 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"copy", iconClass:"dojoE2TBIcon dojoE2TBIcon_Copy"}));
|
170 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"copy", iconClass:"dojoE2TBIcon dojoE2TBIcon_Copy"}));
|
169 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"paste", iconClass:"dojoE2TBIcon dojoE2TBIcon_Paste"}));
|
171 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"paste", iconClass:"dojoE2TBIcon dojoE2TBIcon_Paste"}));
|
170 |
}});
|
172 |
}});
|
171 |
dojo.declare("dojo.widget.Editor2Plugin.LinkContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
173 |
dojo.declare("dojo.widget.Editor2Plugin.LinkContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
172 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"createlink", iconClass:"dojoE2TBIcon dojoE2TBIcon_Link"}));
|
174 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"createlink", iconClass:"dojoE2TBIcon dojoE2TBIcon_Link"}));
|
173 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"unlink", iconClass:"dojoE2TBIcon dojoE2TBIcon_UnLink"}));
|
175 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"unlink", iconClass:"dojoE2TBIcon dojoE2TBIcon_UnLink"}));
|
174 |
}, checkVisibility:function () {
|
176 |
}, checkVisibility:function () {
|
175 |
var show = this.items[1].refresh();
|
177 |
var show = this.items[1].refresh();
|
176 |
if (show) {
|
178 |
if (show) {
|
177 |
this.items[0].refresh();
|
179 |
this.items[0].refresh();
|
178 |
for (var i in this.items) {
|
180 |
for (var i in this.items) {
|
179 |
this.items[i].show();
|
181 |
this.items[i].show();
|
180 |
}
|
182 |
}
|
181 |
} else {
|
183 |
} else {
|
182 |
for (var i in this.items) {
|
184 |
for (var i in this.items) {
|
183 |
this.items[i].hide();
|
185 |
this.items[i].hide();
|
184 |
}
|
186 |
}
|
185 |
}
|
187 |
}
|
186 |
return show;
|
188 |
return show;
|
187 |
}});
|
189 |
}});
|
188 |
dojo.declare("dojo.widget.Editor2Plugin.ImageContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
190 |
dojo.declare("dojo.widget.Editor2Plugin.ImageContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
|
189 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"insertimage", iconClass:"dojoE2TBIcon dojoE2TBIcon_Image"}));
|
191 |
this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {command:"insertimage", iconClass:"dojoE2TBIcon dojoE2TBIcon_Image"}));
|
190 |
}, checkVisibility:function () {
|
192 |
}, checkVisibility:function () {
|
191 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
193 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
192 |
var img = dojo.withGlobal(curInst.window, "getSelectedElement", dojo.html.selection);
|
194 |
var img = dojo.withGlobal(curInst.window, "getSelectedElement", dojo.html.selection);
|
193 |
if (img && img.tagName.toLowerCase() == "img") {
|
195 |
if (img && img.tagName.toLowerCase() == "img") {
|
194 |
this.items[0].show();
|
196 |
this.items[0].show();
|
195 |
return true;
|
197 |
return true;
|
196 |
} else {
|
198 |
} else {
|
197 |
this.items[0].hide();
|
199 |
this.items[0].hide();
|
198 |
return false;
|
200 |
return false;
|
199 |
}
|
201 |
}
|
200 |
}});
|
202 |
}});
|
201 |
|
203 |
|