Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

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