Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1372 Rev 1422
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.TableOperation");
13
dojo.provide("dojo.widget.Editor2Plugin.TableOperation");
12
dojo.require("dojo.widget.Editor2");
14
dojo.require("dojo.widget.Editor2");
13
dojo.event.topic.subscribe("dojo.widget.RichText::init", function (editor) {
15
dojo.event.topic.subscribe("dojo.widget.RichText::init", function (editor) {
14
	if (dojo.render.html.ie) {
16
	if (dojo.render.html.ie) {
15
		editor.contentDomPreFilters.push(dojo.widget.Editor2Plugin.TableOperation.showIETableBorder);
17
		editor.contentDomPreFilters.push(dojo.widget.Editor2Plugin.TableOperation.showIETableBorder);
16
		editor.contentDomPostFilters.push(dojo.widget.Editor2Plugin.TableOperation.removeIEFakeClass);
18
		editor.contentDomPostFilters.push(dojo.widget.Editor2Plugin.TableOperation.removeIEFakeClass);
17
	}
19
	}
18
	editor.getCommand("toggletableborder");
20
	editor.getCommand("toggletableborder");
19
});
21
});
20
dojo.lang.declare("dojo.widget.Editor2Plugin.deleteTableCommand", dojo.widget.Editor2Command, {execute:function () {
22
dojo.lang.declare("dojo.widget.Editor2Plugin.deleteTableCommand", dojo.widget.Editor2Command, {execute:function () {
21
	var table = dojo.withGlobal(this._editor.window, "getAncestorElement", dojo.html.selection, ["table"]);
23
	var table = dojo.withGlobal(this._editor.window, "getAncestorElement", dojo.html.selection, ["table"]);
22
	if (table) {
24
	if (table) {
23
		dojo.withGlobal(this._editor.window, "selectElement", dojo.html.selection, [table]);
25
		dojo.withGlobal(this._editor.window, "selectElement", dojo.html.selection, [table]);
24
		this._editor.execCommand("inserthtml", " ");
26
		this._editor.execCommand("inserthtml", " ");
25
	}
27
	}
26
}, getState:function () {
28
}, getState:function () {
27
	if (this._editor._lastStateTimestamp > this._updateTime || this._state == undefined) {
29
	if (this._editor._lastStateTimestamp > this._updateTime || this._state == undefined) {
28
		this._updateTime = this._editor._lastStateTimestamp;
30
		this._updateTime = this._editor._lastStateTimestamp;
29
		var table = dojo.withGlobal(this._editor.window, "hasAncestorElement", dojo.html.selection, ["table"]);
31
		var table = dojo.withGlobal(this._editor.window, "hasAncestorElement", dojo.html.selection, ["table"]);
30
		this._state = table ? dojo.widget.Editor2Manager.commandState.Enabled : dojo.widget.Editor2Manager.commandState.Disabled;
32
		this._state = table ? dojo.widget.Editor2Manager.commandState.Enabled : dojo.widget.Editor2Manager.commandState.Disabled;
31
	}
33
	}
32
	return this._state;
34
	return this._state;
33
}, getText:function () {
35
}, getText:function () {
34
	return "Delete Table";
36
	return "Delete Table";
35
}});
37
}});
36
dojo.lang.declare("dojo.widget.Editor2Plugin.toggleTableBorderCommand", dojo.widget.Editor2Command, function () {
38
dojo.lang.declare("dojo.widget.Editor2Plugin.toggleTableBorderCommand", dojo.widget.Editor2Command, function () {
37
	this._showTableBorder = false;
39
	this._showTableBorder = false;
38
	dojo.event.connect(this._editor, "editorOnLoad", this, "execute");
40
	dojo.event.connect(this._editor, "editorOnLoad", this, "execute");
39
}, {execute:function () {
41
}, {execute:function () {
40
	if (this._showTableBorder) {
42
	if (this._showTableBorder) {
41
		this._showTableBorder = false;
43
		this._showTableBorder = false;
42
		if (dojo.render.html.moz) {
44
		if (dojo.render.html.moz) {
43
			this._editor.removeStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_gecko.css"));
45
			this._editor.removeStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_gecko.css"));
44
		} else {
46
		} else {
45
			if (dojo.render.html.ie) {
47
			if (dojo.render.html.ie) {
46
				this._editor.removeStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_ie.css"));
48
				this._editor.removeStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_ie.css"));
47
			}
49
			}
48
		}
50
		}
49
	} else {
51
	} else {
50
		this._showTableBorder = true;
52
		this._showTableBorder = true;
51
		if (dojo.render.html.moz) {
53
		if (dojo.render.html.moz) {
52
			this._editor.addStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_gecko.css"));
54
			this._editor.addStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_gecko.css"));
53
		} else {
55
		} else {
54
			if (dojo.render.html.ie) {
56
			if (dojo.render.html.ie) {
55
				this._editor.addStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_ie.css"));
57
				this._editor.addStyleSheet(dojo.uri.moduleUri("dojo.widget", "templates/Editor2/showtableborder_ie.css"));
56
			}
58
			}
57
		}
59
		}
58
	}
60
	}
59
}, getText:function () {
61
}, getText:function () {
60
	return "Toggle Table Border";
62
	return "Toggle Table Border";
61
}, getState:function () {
63
}, getState:function () {
62
	return this._showTableBorder ? dojo.widget.Editor2Manager.commandState.Latched : dojo.widget.Editor2Manager.commandState.Enabled;
64
	return this._showTableBorder ? dojo.widget.Editor2Manager.commandState.Latched : dojo.widget.Editor2Manager.commandState.Enabled;
63
}});
65
}});
64
dojo.widget.Editor2Plugin.TableOperation = {getCommand:function (editor, name) {
66
dojo.widget.Editor2Plugin.TableOperation = {getCommand:function (editor, name) {
65
	switch (name.toLowerCase()) {
67
	switch (name.toLowerCase()) {
66
	  case "toggletableborder":
68
	  case "toggletableborder":
67
		return new dojo.widget.Editor2Plugin.toggleTableBorderCommand(editor, name);
69
		return new dojo.widget.Editor2Plugin.toggleTableBorderCommand(editor, name);
68
	  case "inserttable":
70
	  case "inserttable":
69
		return new dojo.widget.Editor2DialogCommand(editor, "inserttable", {contentFile:"dojo.widget.Editor2Plugin.InsertTableDialog", contentClass:"Editor2InsertTableDialog", title:"Insert/Edit Table", width:"450px", height:"250px"});
71
		return new dojo.widget.Editor2DialogCommand(editor, "inserttable", {contentFile:"dojo.widget.Editor2Plugin.InsertTableDialog", contentClass:"Editor2InsertTableDialog", title:"Insert/Edit Table", width:"450px", height:"250px"});
70
	  case "deletetable":
72
	  case "deletetable":
71
		return new dojo.widget.Editor2Plugin.deleteTableCommand(editor, name);
73
		return new dojo.widget.Editor2Plugin.deleteTableCommand(editor, name);
72
	}
74
	}
73
}, getToolbarItem:function (name) {
75
}, getToolbarItem:function (name) {
74
	var name = name.toLowerCase();
76
	var name = name.toLowerCase();
75
	var item;
77
	var item;
76
	switch (name) {
78
	switch (name) {
77
	  case "inserttable":
79
	  case "inserttable":
78
	  case "toggletableborder":
80
	  case "toggletableborder":
79
		item = new dojo.widget.Editor2ToolbarButton(name);
81
		item = new dojo.widget.Editor2ToolbarButton(name);
80
	}
82
	}
81
	return item;
83
	return item;
82
}, getContextMenuGroup:function (name, contextmenuplugin) {
84
}, getContextMenuGroup:function (name, contextmenuplugin) {
83
	return new dojo.widget.Editor2Plugin.TableContextMenuGroup(contextmenuplugin);
85
	return new dojo.widget.Editor2Plugin.TableContextMenuGroup(contextmenuplugin);
84
}, showIETableBorder:function (dom) {
86
}, showIETableBorder:function (dom) {
85
	var tables = dom.getElementsByTagName("table");
87
	var tables = dom.getElementsByTagName("table");
86
	dojo.lang.forEach(tables, function (t) {
88
	dojo.lang.forEach(tables, function (t) {
87
		dojo.html.addClass(t, "dojoShowIETableBorders");
89
		dojo.html.addClass(t, "dojoShowIETableBorders");
88
	});
90
	});
89
	return dom;
91
	return dom;
90
}, removeIEFakeClass:function (dom) {
92
}, removeIEFakeClass:function (dom) {
91
	var tables = dom.getElementsByTagName("table");
93
	var tables = dom.getElementsByTagName("table");
92
	dojo.lang.forEach(tables, function (t) {
94
	dojo.lang.forEach(tables, function (t) {
93
		dojo.html.removeClass(t, "dojoShowIETableBorders");
95
		dojo.html.removeClass(t, "dojoShowIETableBorders");
94
	});
96
	});
95
	return dom;
97
	return dom;
96
}};
98
}};
97
dojo.widget.Editor2Manager.registerHandler(dojo.widget.Editor2Plugin.TableOperation.getCommand);
99
dojo.widget.Editor2Manager.registerHandler(dojo.widget.Editor2Plugin.TableOperation.getCommand);
98
dojo.widget.Editor2ToolbarItemManager.registerHandler(dojo.widget.Editor2Plugin.TableOperation.getToolbarItem);
100
dojo.widget.Editor2ToolbarItemManager.registerHandler(dojo.widget.Editor2Plugin.TableOperation.getToolbarItem);
99
if (dojo.widget.Editor2Plugin.ContextMenuManager) {
101
if (dojo.widget.Editor2Plugin.ContextMenuManager) {
100
	dojo.widget.Editor2Plugin.ContextMenuManager.registerGroup("Table", dojo.widget.Editor2Plugin.TableOperation.getContextMenuGroup);
102
	dojo.widget.Editor2Plugin.ContextMenuManager.registerGroup("Table", dojo.widget.Editor2Plugin.TableOperation.getContextMenuGroup);
101
	dojo.declare("dojo.widget.Editor2Plugin.TableContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
103
	dojo.declare("dojo.widget.Editor2Plugin.TableContextMenuGroup", dojo.widget.Editor2Plugin.SimpleContextMenuGroup, {createItems:function () {
102
		this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {caption:"Delete Table", command:"deletetable"}));
104
		this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {caption:"Delete Table", command:"deletetable"}));
103
		this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {caption:"Table Property", command:"inserttable", iconClass:"TB_Button_Icon TB_Button_Table"}));
105
		this.items.push(dojo.widget.createWidget("Editor2ContextMenuItem", {caption:"Table Property", command:"inserttable", iconClass:"TB_Button_Icon TB_Button_Table"}));
104
	}, checkVisibility:function () {
106
	}, checkVisibility:function () {
105
		var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
107
		var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
106
		var table = dojo.withGlobal(curInst.window, "hasAncestorElement", dojo.html.selection, ["table"]);
108
		var table = dojo.withGlobal(curInst.window, "hasAncestorElement", dojo.html.selection, ["table"]);
107
		if (dojo.withGlobal(curInst.window, "hasAncestorElement", dojo.html.selection, ["table"])) {
109
		if (dojo.withGlobal(curInst.window, "hasAncestorElement", dojo.html.selection, ["table"])) {
108
			this.items[0].show();
110
			this.items[0].show();
109
			this.items[1].show();
111
			this.items[1].show();
110
			return true;
112
			return true;
111
		} else {
113
		} else {
112
			this.items[0].hide();
114
			this.items[0].hide();
113
			this.items[1].hide();
115
			this.items[1].hide();
114
			return false;
116
			return false;
115
		}
117
		}
116
	}});
118
	}});
117
}
119
}
118
 
120