新增可自定义表格宽度

This commit is contained in:
xiao-fajia 2024-07-30 19:42:09 +08:00
parent d4db130917
commit 9ff340e303
3 changed files with 86 additions and 21 deletions

View File

@ -39,9 +39,16 @@
<label><input type="radio" id="J_autoSizeContent" name="size"/><var id="lang_autoSizeContent"></var></label> <label><input type="radio" id="J_autoSizeContent" name="size"/><var id="lang_autoSizeContent"></var></label>
</li> </li>
<li> <li>
<label><input type="radio" id="J_autoSizePage" name="size"/><var <label><input type="radio" id="J_autoSizePage" name="size"/><var id="lang_autoSizePage"></var></label>
id="lang_autoSizePage"></var></label>
</li> </li>
<!--设置自定义宽度 start-->
<li>
<label><input type="radio" id="J_setSizePage" name="size" />自定义页面宽度</label>
</li>
<li>
<input id="J_setText" type="text" style="display:none;width:60px;" value="40%" onchange="SetText(this)"/>
</li>
<!--end-->
</ul> </ul>
<div class="clear"></div> <div class="clear"></div>
</div> </div>

View File

@ -12,6 +12,8 @@
sorttable = $G("J_sorttable"), sorttable = $G("J_sorttable"),
autoSizeContent = $G("J_autoSizeContent"), autoSizeContent = $G("J_autoSizeContent"),
autoSizePage = $G("J_autoSizePage"), autoSizePage = $G("J_autoSizePage"),
setSizePage = $G("J_setSizePage"),//设置自定义宽度
setSizeText = $G("J_setText"),//设置自定义宽度
tone = $G("J_tone"), tone = $G("J_tone"),
me, me,
preview = $G("J_preview"); preview = $G("J_preview");
@ -52,6 +54,7 @@
domUtils.on(sorttable, "click", me.sorttableHanler); domUtils.on(sorttable, "click", me.sorttableHanler);
domUtils.on(autoSizeContent, "click", me.autoSizeContentHanler); domUtils.on(autoSizeContent, "click", me.autoSizeContentHanler);
domUtils.on(autoSizePage, "click", me.autoSizePageHanler); domUtils.on(autoSizePage, "click", me.autoSizePageHanler);
domUtils.on(setSizePage, "click", me.setSizePageHanler);//设置自定义宽度
domUtils.on(tone, "click", function () { domUtils.on(tone, "click", function () {
colorPop.showAnchor(tone); colorPop.showAnchor(tone);
@ -157,6 +160,8 @@
autoSizeContentHanler: function () { autoSizeContentHanler: function () {
var example = $G("J_example"); var example = $G("J_example");
example.removeAttribute("width"); example.removeAttribute("width");
var txtSize = $G("J_setText");
txtSize.style.display = "none";
}, },
autoSizePageHanler: function () { autoSizePageHanler: function () {
var example = $G("J_example"); var example = $G("J_example");
@ -165,6 +170,18 @@
td.removeAttribute("width"); td.removeAttribute("width");
}); });
example.setAttribute('width', '100%'); example.setAttribute('width', '100%');
var txtSize = $G("J_setText");
txtSize.style.display = "none";
},
setSizePageHanler: function () { //设置自定义宽度
var example = $G("J_example");
var txtSize = $G("J_setText");
txtSize.style.display = "block";
var tds = example.getElementsByTagName(example, "td");
utils.each(tds, function (td) {
td.removeAttribute("width");
});
example.setAttribute('width', txtSize.value);
}, },
updateSortSpan: function () { updateSortSpan: function () {
var example = $G("J_example"), var example = $G("J_example"),
@ -230,7 +247,10 @@
editor.queryCommandState(cmds[1]) != -1 && editor.execCommand(cmds[1]); editor.queryCommandState(cmds[1]) != -1 && editor.execCommand(cmds[1]);
} }
} }
//设置自定义宽度
if (setSizePage.checked) {
editor.execCommand("settablesize", setSizeText.value);
}
editor.execCommand("edittable", tone.value); editor.execCommand("edittable", tone.value);
autoSizeContent.checked ? editor.execCommand('adaptbytext') : ""; autoSizeContent.checked ? editor.execCommand('adaptbytext') : "";
autoSizePage.checked ? editor.execCommand("adaptbywindow") : ""; autoSizePage.checked ? editor.execCommand("adaptbywindow") : "";

View File

@ -25528,15 +25528,39 @@ UE.plugins["audio"] = function () {
} }
}; };
UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = { // UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = {
// queryCommandState: function () {
// return getTableItemsByRange(this).table ? 0 : -1;
// },
// execCommand: function (cmd) {
// var tableItems = getTableItemsByRange(this),
// table = tableItems.table;
// if (table) {
// if (cmd == "adaptbywindow") {
// resetTdWidth(table, this);
// } else {
// var cells = domUtils.getElementsByTagName(table, "td th");
// utils.each(cells, function (cell) {
// cell.removeAttribute("width");
// });
// table.removeAttribute("width");
// }
// }
// }
// };
//修改表格属性 宽度设置
UE.commands["adaptbytext"] =
UE.commands["adaptbywindow"] = {
queryCommandState: function () { queryCommandState: function () {
return getTableItemsByRange(this).table ? 0 : -1; return getTableItemsByRange(this).table ? 0 : -1
}, },
execCommand: function (cmd) { execCommand: function (cmd) {
var tableItems = getTableItemsByRange(this), var tableItems = getTableItemsByRange(this),
table = tableItems.table; table = tableItems.table;
if (table) { if (table) {
if (cmd == "adaptbywindow") { if (cmd == 'adaptbywindow') {
table.removeAttribute("width");
resetTdWidth(table, this); resetTdWidth(table, this);
} else { } else {
var cells = domUtils.getElementsByTagName(table, "td th"); var cells = domUtils.getElementsByTagName(table, "td th");
@ -25544,6 +25568,7 @@ UE.plugins["audio"] = function () {
cell.removeAttribute("width"); cell.removeAttribute("width");
}); });
table.removeAttribute("width"); table.removeAttribute("width");
table.width = "100%";
} }
} }
} }
@ -25778,6 +25803,19 @@ UE.plugins["audio"] = function () {
} }
} }
}; };
//表格属性 宽度设置
UE.commands['settablesize'] = {
queryCommandState: function () {
return getTableItemsByRange(this).table ? 0 : -1
},
execCommand: function (cmd, width) {
var rng = this.selection.getRange(),
table = domUtils.findParentByTagName(rng.startContainer, 'table');
if (table) {
table.width = width;
}
}
};
//单元格属性 //单元格属性
UE.commands["edittd"] = { UE.commands["edittd"] = {
queryCommandState: function () { queryCommandState: function () {