InsertTableDialog.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:8k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.widget.Editor2Plugin.InsertTableDialog");
  9. dojo.widget.defineWidget("dojo.widget.Editor2InsertTableDialog", dojo.widget.Editor2DialogContent, {templateString:"<div>n<table cellSpacing="1" cellPadding="1" width="100%" border="0">nt<tr>ntt<td valign="top">nttt<table cellSpacing="0" cellPadding="0" border="0">ntttt<tr>nnttttt<td><span>Rows</span>:</td>nttttt<td>&nbsp;<input dojoAttachPoint="table_rows" type="text" maxLength="3" size="2" value="3"></td>ntttt</tr>ntttt<tr>nttttt<td><span>Columns</span>:</td>nttttt<td>&nbsp;<input dojoAttachPoint="table_cols" type="text" maxLength="2" size="2" value="2"></td>ntttt</tr>nntttt<tr>nttttt<td>&nbsp;</td>nttttt<td>&nbsp;</td>ntttt</tr>ntttt<tr>nttttt<td><span>Border size</span>:</td>nttttt<td>&nbsp;<INPUT dojoAttachPoint="table_border" type="text" maxLength="2" size="2" value="1"></td>ntttt</tr>nntttt<tr>nttttt<td><span>Alignment</span>:</td>nttttt<td>&nbsp;<select dojoAttachPoint="table_align">nttttttt<option value="" selected>&lt;Not set&gt;</option>nttttttt<option value="left">Left</option>nttttttt<option value="center">Center</option>nttttttt<option value="right">Right</option>ntttttt</select></td>ntttt</tr>nttt</table>ntt</td>ntt<td>&nbsp;&nbsp;&nbsp;</td>ntt<td align="right" valign="top">nttt<table cellSpacing="0" cellPadding="0" border="0">ntttt<tr>nttttt<td><span>Width</span>:</td>nttttt<td>&nbsp;<input dojoAttachPoint="table_width" type="text" maxLength="4" size="3"></td>nttttt<td>&nbsp;<select dojoAttachPoint="table_widthtype">nttttttt<option value="percent" selected>percent</option>nttttttt<option value="pixels">pixels</option>ntttttt</select></td>nntttt</tr>ntttt<tr>nttttt<td><span>Height</span>:</td>nttttt<td>&nbsp;<INPUT dojoAttachPoint="table_height" type="text" maxLength="4" size="3"></td>nttttt<td>&nbsp;<span>pixels</span></td>ntttt</tr>ntttt<tr>nttttt<td>&nbsp;</td>nttttt<td>&nbsp;</td>nttttt<td>&nbsp;</td>ntttt</tr>ntttt<tr>nttttt<td nowrap><span>Cell spacing</span>:</td>nttttt<td>&nbsp;<input dojoAttachPoint="table_cellspacing" type="text" maxLength="2" size="2" value="1"></td>nttttt<td>&nbsp;</td>nntttt</tr>ntttt<tr>nttttt<td nowrap><span>Cell padding</span>:</td>nttttt<td>&nbsp;<input dojoAttachPoint="table_cellpadding" type="text" maxLength="2" size="2" value="1"></td>nttttt<td>&nbsp;</td>ntttt</tr>nttt</table>ntt</td>nt</tr>n</table>n<table cellSpacing="0" cellPadding="0" width="100%" border="0">nt<tr>ntt<td nowrap><span>Caption</span>:</td>ntt<td>&nbsp;</td>ntt<td width="100%" nowrap>&nbsp;nttt<input dojoAttachPoint="table_caption" type="text" style="WIDTH: 90%"></td>nt</tr>nt<tr>ntt<td nowrap><span>Summary</span>:</td>ntt<td>&nbsp;</td>ntt<td width="100%" nowrap>&nbsp;nttt<input dojoAttachPoint="table_summary" type="text" style="WIDTH: 90%"></td>nt</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 () {
  10. var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
  11. curInst.saveSelection();
  12. this.tableNode = dojo.withGlobal(curInst.window, "getSelectedElement", dojo.html.selection);
  13. if (!this.tableNode || this.tableNode.tagName.toLowerCase() != "table") {
  14. this.tableNode = dojo.withGlobal(curInst.window, "getAncestorElement", dojo.html.selection, ["table"]);
  15. }
  16. var tableAttributes = {};
  17. this.extraAttribText = "";
  18. if (this.tableNode) {
  19. this["table_rows"].value = this.tableNode.rows.length;
  20. this["table_rows"].disabled = true;
  21. this["table_cols"].value = this.tableNode.rows[0].cells.length;
  22. this["table_cols"].disabled = true;
  23. if (this.tableNode.caption) {
  24. this["table_caption"].value = this.tableNode.caption.innerHTML;
  25. } else {
  26. this["table_caption"].value = "";
  27. }
  28. var width = this.tableNode.style.width || this.tableNode.width;
  29. if (width) {
  30. this["table_width"].value = parseInt(width);
  31. if (width.indexOf("%") > -1) {
  32. this["table_widthtype"].value = "percent";
  33. } else {
  34. this["table_widthtype"].value = "pixels";
  35. }
  36. } else {
  37. this["table_width"].value = "100";
  38. }
  39. var height = this.tableNode.style.height || this.tableNode.height;
  40. if (height) {
  41. this["table_height"].value = parseInt(width);
  42. } else {
  43. this["table_height"].value = "";
  44. }
  45. var attrs = this.tableNode.attributes;
  46. for (var i = 0; i < attrs.length; i++) {
  47. if (dojo.lang.find(this.editableAttributes, attrs[i].name.toLowerCase()) > -1) {
  48. tableAttributes[attrs[i].name] = attrs[i].value;
  49. } else {
  50. this.extraAttribText += attrs[i].name + "="" + attrs[i].value + "" ";
  51. }
  52. }
  53. } else {
  54. this["table_rows"].value = 3;
  55. this["table_rows"].disabled = false;
  56. this["table_cols"].value = 2;
  57. this["table_cols"].disabled = false;
  58. this["table_width"].value = 100;
  59. this["table_widthtype"].value = "percent";
  60. this["table_height"].value = "";
  61. }
  62. for (var i = 0; i < this.editableAttributes.length; ++i) {
  63. name = this.editableAttributes[i];
  64. this["table_" + name].value = (tableAttributes[name] == undefined) ? "" : tableAttributes[name];
  65. if (name == "height" && tableAttributes[name] != undefined) {
  66. this["table_" + name].value = tableAttributes[name];
  67. }
  68. }
  69. return true;
  70. }, ok:function () {
  71. var curInst = dojo.widget.Editor2Manager.getCurrentInstance();
  72. var args = {};
  73. args["rows"] = this["table_rows"].value;
  74. args["cols"] = this["table_cols"].value;
  75. args["caption"] = this["table_caption"].value;
  76. args["tableattrs"] = "";
  77. if (this["table_widthtype"].value == "percent") {
  78. args["tableattrs"] += "width="" + this["table_width"].value + "%" ";
  79. } else {
  80. args["tableattrs"] += "width="" + this["table_width"].value + "px" ";
  81. }
  82. for (var i = 0; i < this.editableAttributes.length; ++i) {
  83. var name = this.editableAttributes[i];
  84. var value = this["table_" + name].value;
  85. if (value.length > 0) {
  86. args["tableattrs"] += name + "="" + value + "" ";
  87. }
  88. }
  89. if (!args["tableattrs"]) {
  90. args["tableattrs"] = "";
  91. }
  92. if (dojo.render.html.ie && !this["table_border"].value) {
  93. args["tableattrs"] += "class="dojoShowIETableBorders" ";
  94. }
  95. var html = "<table " + args["tableattrs"] + ">";
  96. if (args["caption"]) {
  97. html += "<caption>" + args["caption"] + "</caption>";
  98. }
  99. var outertbody = "<tbody>";
  100. if (this.tableNode) {
  101. var tbody = this.tableNode.getElementsByTagName("tbody")[0];
  102. outertbody = tbody.outerHTML;
  103. if (!outertbody) {
  104. var cnode = tbody.cloneNode(true);
  105. var tmpnode = tbody.ownerDocument.createElement("div");
  106. tmpnode.appendChild(cnode);
  107. outertbody = tmpnode.innerHTML;
  108. }
  109. dojo.withGlobal(curInst.window, "selectElement", dojo.html.selection, [this.tableNode]);
  110. } else {
  111. var cols = "<tr>";
  112. for (var i = 0; i < +args.cols; i++) {
  113. cols += "<td></td>";
  114. }
  115. cols += "</tr>";
  116. for (var i = 0; i < args.rows; i++) {
  117. outertbody += cols;
  118. }
  119. outertbody += "</tbody>";
  120. }
  121. html += outertbody + "</table>";
  122. curInst.restoreSelection();
  123. curInst.execCommand("inserthtml", html);
  124. this.cancel();
  125. }});