Subversion Repositories Applications.papyrus

Rev

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