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.InsertTableDialog");
|
|
|
14 |
dojo.widget.defineWidget("dojo.widget.Editor2InsertTableDialog", dojo.widget.Editor2DialogContent, {templateString:"<div>\n<table cellSpacing=\"1\" cellPadding=\"1\" width=\"100%\" border=\"0\">\n\t<tr>\n\t\t<td valign=\"top\">\n\t\t\t<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n\t\t\t\t<tr>\n\n\t\t\t\t\t<td><span>Rows</span>:</td>\n\t\t\t\t\t<td> <input dojoAttachPoint=\"table_rows\" type=\"text\" maxLength=\"3\" size=\"2\" value=\"3\"></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>Columns</span>:</td>\n\t\t\t\t\t<td> <input dojoAttachPoint=\"table_cols\" type=\"text\" maxLength=\"2\" size=\"2\" value=\"2\"></td>\n\t\t\t\t</tr>\n\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>Border size</span>:</td>\n\t\t\t\t\t<td> <INPUT dojoAttachPoint=\"table_border\" type=\"text\" maxLength=\"2\" size=\"2\" value=\"1\"></td>\n\t\t\t\t</tr>\n\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>Alignment</span>:</td>\n\t\t\t\t\t<td> <select dojoAttachPoint=\"table_align\">\n\t\t\t\t\t\t\t<option value=\"\" selected><Not set></option>\n\t\t\t\t\t\t\t<option value=\"left\">Left</option>\n\t\t\t\t\t\t\t<option value=\"center\">Center</option>\n\t\t\t\t\t\t\t<option value=\"right\">Right</option>\n\t\t\t\t\t\t</select></td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t\t<td> </td>\n\t\t<td align=\"right\" valign=\"top\">\n\t\t\t<table cellSpacing=\"0\" cellPadding=\"0\" border=\"0\">\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>Width</span>:</td>\n\t\t\t\t\t<td> <input dojoAttachPoint=\"table_width\" type=\"text\" maxLength=\"4\" size=\"3\"></td>\n\t\t\t\t\t<td> <select dojoAttachPoint=\"table_widthtype\">\n\t\t\t\t\t\t\t<option value=\"percent\" selected>percent</option>\n\t\t\t\t\t\t\t<option value=\"pixels\">pixels</option>\n\t\t\t\t\t\t</select></td>\n\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td><span>Height</span>:</td>\n\t\t\t\t\t<td> <INPUT dojoAttachPoint=\"table_height\" type=\"text\" maxLength=\"4\" size=\"3\"></td>\n\t\t\t\t\t<td> <span>pixels</span></td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td nowrap><span>Cell spacing</span>:</td>\n\t\t\t\t\t<td> <input dojoAttachPoint=\"table_cellspacing\" type=\"text\" maxLength=\"2\" size=\"2\" value=\"1\"></td>\n\t\t\t\t\t<td> </td>\n\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t\t<td nowrap><span>Cell padding</span>:</td>\n\t\t\t\t\t<td> <input dojoAttachPoint=\"table_cellpadding\" type=\"text\" maxLength=\"2\" size=\"2\" value=\"1\"></td>\n\t\t\t\t\t<td> </td>\n\t\t\t\t</tr>\n\t\t\t</table>\n\t\t</td>\n\t</tr>\n</table>\n<table cellSpacing=\"0\" cellPadding=\"0\" width=\"100%\" border=\"0\">\n\t<tr>\n\t\t<td nowrap><span>Caption</span>:</td>\n\t\t<td> </td>\n\t\t<td width=\"100%\" nowrap> \n\t\t\t<input dojoAttachPoint=\"table_caption\" type=\"text\" style=\"WIDTH: 90%\"></td>\n\t</tr>\n\t<tr>\n\t\t<td nowrap><span>Summary</span>:</td>\n\t\t<td> </td>\n\t\t<td width=\"100%\" nowrap> \n\t\t\t<input dojoAttachPoint=\"table_summary\" type=\"text\" style=\"WIDTH: 90%\"></td>\n\t</tr>\n</table>\n<table><tr>\n<td><button dojoType='Button' dojoAttachEvent='onClick:ok'>Ok</button></td>\n<td><button dojoType='Button' dojoAttachEvent='onClick:cancel'>Cancel</button></td>\n</tr></table>\n</div>\n", editableAttributes:["summary", "height", "cellspacing", "cellpadding", "border", "align"], loadContent:function () {
|
|
|
15 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
|
|
16 |
curInst.saveSelection();
|
|
|
17 |
this.tableNode = dojo.withGlobal(curInst.window, "getSelectedElement", dojo.html.selection);
|
|
|
18 |
if (!this.tableNode || this.tableNode.tagName.toLowerCase() != "table") {
|
|
|
19 |
this.tableNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["table"]);
|
|
|
20 |
}
|
|
|
21 |
var tableAttributes = {};
|
|
|
22 |
this.extraAttribText = "";
|
|
|
23 |
if (this.tableNode) {
|
|
|
24 |
this["table_rows"].value = this.tableNode.rows.length;
|
|
|
25 |
this["table_rows"].disabled = true;
|
|
|
26 |
this["table_cols"].value = this.tableNode.rows[0].cells.length;
|
|
|
27 |
this["table_cols"].disabled = true;
|
|
|
28 |
if (this.tableNode.caption) {
|
|
|
29 |
this["table_caption"].value = this.tableNode.caption.innerHTML;
|
|
|
30 |
} else {
|
|
|
31 |
this["table_caption"].value = "";
|
|
|
32 |
}
|
|
|
33 |
var width = this.tableNode.style.width || this.tableNode.width;
|
|
|
34 |
if (width) {
|
|
|
35 |
this["table_width"].value = parseInt(width);
|
|
|
36 |
if (width.indexOf("%") > -1) {
|
|
|
37 |
this["table_widthtype"].value = "percent";
|
|
|
38 |
} else {
|
|
|
39 |
this["table_widthtype"].value = "pixels";
|
|
|
40 |
}
|
|
|
41 |
} else {
|
|
|
42 |
this["table_width"].value = "100";
|
|
|
43 |
}
|
|
|
44 |
var height = this.tableNode.style.height || this.tableNode.height;
|
|
|
45 |
if (height) {
|
|
|
46 |
this["table_height"].value = parseInt(width);
|
|
|
47 |
} else {
|
|
|
48 |
this["table_height"].value = "";
|
|
|
49 |
}
|
|
|
50 |
var attrs = this.tableNode.attributes;
|
|
|
51 |
for (var i = 0; i < attrs.length; i++) {
|
|
|
52 |
if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
|
|
|
53 |
tableAttributes[attrs[i].name] = attrs[i].value;
|
|
|
54 |
} else {
|
|
|
55 |
this.extraAttribText += attrs[i].name + "=\"" + attrs[i].value + "\" ";
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
} else {
|
|
|
59 |
this["table_rows"].value = 3;
|
|
|
60 |
this["table_rows"].disabled = false;
|
|
|
61 |
this["table_cols"].value = 2;
|
|
|
62 |
this["table_cols"].disabled = false;
|
|
|
63 |
this["table_width"].value = 100;
|
|
|
64 |
this["table_widthtype"].value = "percent";
|
|
|
65 |
this["table_height"].value = "";
|
|
|
66 |
}
|
|
|
67 |
for (var i = 0; i < this.editableAttributes.length; ++i) {
|
|
|
68 |
name = this.editableAttributes[i];
|
|
|
69 |
this["table_" + name].value = (tableAttributes[name] == undefined) ? "" : tableAttributes[name];
|
|
|
70 |
if (name == "height" && tableAttributes[name] != undefined) {
|
|
|
71 |
this["table_" + name].value = tableAttributes[name];
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
return true;
|
|
|
75 |
}, ok:function () {
|
|
|
76 |
var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
|
|
|
77 |
var args = {};
|
|
|
78 |
args["rows"] = this["table_rows"].value;
|
|
|
79 |
args["cols"] = this["table_cols"].value;
|
|
|
80 |
args["caption"] = this["table_caption"].value;
|
|
|
81 |
args["tableattrs"] = "";
|
|
|
82 |
if (this["table_widthtype"].value == "percent") {
|
|
|
83 |
args["tableattrs"] += "width=\"" + this["table_width"].value + "%\" ";
|
|
|
84 |
} else {
|
|
|
85 |
args["tableattrs"] += "width=\"" + this["table_width"].value + "px\" ";
|
|
|
86 |
}
|
|
|
87 |
for (var i = 0; i < this.editableAttributes.length; ++i) {
|
|
|
88 |
var name = this.editableAttributes[i];
|
|
|
89 |
var value = this["table_" + name].value;
|
|
|
90 |
if (value.length > 0) {
|
|
|
91 |
args["tableattrs"] += name + "=\"" + value + "\" ";
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
if (!args["tableattrs"]) {
|
|
|
95 |
args["tableattrs"] = "";
|
|
|
96 |
}
|
|
|
97 |
if (dojo.render.html.ie && !this["table_border"].value) {
|
|
|
98 |
args["tableattrs"] += "class=\"dojoShowIETableBorders\" ";
|
|
|
99 |
}
|
|
|
100 |
var html = "<table " + args["tableattrs"] + ">";
|
|
|
101 |
if (args["caption"]) {
|
|
|
102 |
html += "<caption>" + args["caption"] + "</caption>";
|
|
|
103 |
}
|
|
|
104 |
var outertbody = "<tbody>";
|
|
|
105 |
if (this.tableNode) {
|
|
|
106 |
var tbody = this.tableNode.getElementsByTagName("tbody")[0];
|
|
|
107 |
outertbody = tbody.outerHTML;
|
|
|
108 |
if (!outertbody) {
|
|
|
109 |
var cnode = tbody.cloneNode(true);
|
|
|
110 |
var tmpnode = tbody.ownerDocument.createElement("div");
|
|
|
111 |
tmpnode.appendChild(cnode);
|
|
|
112 |
outertbody = tmpnode.innerHTML;
|
|
|
113 |
}
|
|
|
114 |
dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.tableNode]);
|
|
|
115 |
} else {
|
|
|
116 |
var cols = "<tr>";
|
|
|
117 |
for (var i = 0; i < +args.cols; i++) {
|
|
|
118 |
cols += "<td></td>";
|
|
|
119 |
}
|
|
|
120 |
cols += "</tr>";
|
|
|
121 |
for (var i = 0; i < args.rows; i++) {
|
|
|
122 |
outertbody += cols;
|
|
|
123 |
}
|
|
|
124 |
outertbody += "</tbody>";
|
|
|
125 |
}
|
|
|
126 |
html += outertbody + "</table>";
|
|
|
127 |
curInst.restoreSelection();
|
|
|
128 |
curInst.execCommand("inserthtml", html);
|
|
|
129 |
this.cancel();
|
|
|
130 |
}});
|
|
|
131 |
|