📄 edit.js
字号:
// 上移(forward)或下移(backward)一层
function zIndex(action){
var objReference = null;
var RangeType = HtmlEdit.document.selection.type;
if (RangeType != "Control") return;
var selectedRange = HtmlEdit.document.selection.createRange();
for (var i=0; i<selectedRange.length; i++){
objReference = selectedRange.item(i);
if (action=='forward'){
objReference.style.zIndex +=1;
}else{
objReference.style.zIndex -=1;
}
objReference.style.position='absolute';
}
}
// 是否选中指定类型的控件
function isControlSelected(tag){
if (HtmlEdit.document.selection.type == "Control") {
var oControlRange = HtmlEdit.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == tag) {
return true;
}
}
return false;
}
// 改变编辑区高度
function sizeChange(size){
if (!BrowserInfo.IsIE55OrMore){
alert("此功能需要IE5.5版本以上的支持!");
return false;
}
for (var i=0; i<parent.frames.length; i++){
if (parent.frames[i].document==self.document){
var obj=parent.frames[i].frameElement;
var height = parseInt(obj.offsetHeight);
if (height+size>=300){
obj.height=height+size;
}
break;
}
}
}
// 热点链接
function mapEdit(){
if (!validateMode()) return;
var b = false;
if (HtmlEdit.document.selection.type == "Control") {
var oControlRange = HtmlEdit.document.selection.createRange();
if (oControlRange(0).tagName.toUpperCase() == "IMG") {
b = true;
}
}
if (!b){
alert("热点链接只能作用于图片");
return;
}
window.open("dialog/map.htm", 'mapEdit'+sLinkFieldName, 'toolbar=no,location=no,directories=no,status=not,menubar=no,scrollbars=no,resizable=yes,width=450,height=300');
}
// 大文件内容自动拆分
function splitTextField(objField, html) {
var strFieldName = objField.name;
var objForm = objField.form;
var objDocument = objField.document;
objField.value = html;
//表单限制值设定,限制值是102399,考虑到中文设为一半
var FormLimit = 50000 ;
// 再次处理时,先赋空值
for (var i=1;i<objDocument.getElementsByName(strFieldName).length;i++) {
objDocument.getElementsByName(strFieldName)[i].value = "";
}
//如果表单值超过限制,拆成多个对象
if (html.length > FormLimit) {
objField.value = html.substr(0, FormLimit) ;
html = html.substr(FormLimit) ;
while (html.length > 0) {
var objTEXTAREA = objDocument.createElement("TEXTAREA") ;
objTEXTAREA.name = strFieldName ;
objTEXTAREA.style.display = "none" ;
objTEXTAREA.value = html.substr(0, FormLimit) ;
objForm.appendChild(objTEXTAREA) ;
html = html.substr(FormLimit) ;
}
}
}
// 修正Undo/Redo
var history = new Object;
history.data = [];
history.position = 0;
history.bookmark = [];
// 保存历史
function saveHistory() {
if (bEditMode){
if (history.data[history.position] != HtmlEdit.document.body.innerHTML){
var nBeginLen = history.data.length;
var nPopLen = history.data.length - history.position;
for (var i=1; i<nPopLen; i++){
history.data.pop();
history.bookmark.pop();
}
history.data[history.data.length] = HtmlEdit.document.body.innerHTML;
if (HtmlEdit.document.selection.type != "Control"){
history.bookmark[history.bookmark.length] = HtmlEdit.document.selection.createRange().getBookmark();
} else {
var oControl = HtmlEdit.document.selection.createRange();
history.bookmark[history.bookmark.length] = oControl[0];
}
if (nBeginLen!=0){
history.position++;
}
}
}
}
// 初始历史
function initHistory() {
history.data.length = 0;
history.bookmark.length = 0;
history.position = 0;
}
// 返回历史
function goHistory(value) {
saveHistory();
// undo
if (value == -1){
if (history.position > 0){
HtmlEdit.document.body.innerHTML = history.data[--history.position];
setHistoryCursor();
}
// redo
} else {
if (history.position < history.data.length -1){
HtmlEdit.document.body.innerHTML = history.data[++history.position];
setHistoryCursor();
}
}
}
// 设置当前书签
function setHistoryCursor() {
if (history.bookmark[history.position]){
r = HtmlEdit.document.body.createTextRange()
if (history.bookmark[history.position] != "[object]"){
if (r.moveToBookmark(history.bookmark[history.position])){
r.collapse(false);
r.select();
}
}
}
}
// End Undo / Redo Fix
// 工具栏事件发生
function doToolbar(){
if (bEditMode){
saveHistory();
}
}
//table.js
// 插入表格
function TableInsert(){
if (!isTableSelected()){
ShowDialog('dialog/table.htm', 350, 380, true);
}
}
// 修改表格属性
function TableProp(){
if (isTableSelected()||isCursorInTableCell()){
ShowDialog('dialog/table.htm?action=modify', 350, 380, true);
}
}
// 修改单元格属性
function TableCellProp(){
if (isCursorInTableCell()){
ShowDialog('dialog/tablecell.htm', 350, 280, true);
}
}
// 拆分单元格
function TableCellSplit(){
if (isCursorInTableCell()){
ShowDialog('dialog/tablecellsplit.htm', 200, 150, true);
}
}
// 修改表格行属性
function TableRowProp(){
if (isCursorInTableCell()){
ShowDialog('dialog/tablecell.htm?action=row', 350, 280, true);
}
}
// 插入行(在上方)
function TableRowInsertAbove() {
if (isCursorInTableCell()){
var numCols = 0
allCells = selectedTR.cells
for (var i=0;i<allCells.length;i++) {
numCols = numCols + allCells[i].getAttribute('colSpan')
}
var newTR = selectedTable.insertRow(selectedTR.rowIndex)
for (i = 0; i < numCols; i++) {
newTD = newTR.insertCell()
newTD.innerHTML = " "
if (borderShown == "yes") {
newTD.runtimeStyle.border = "1px dotted #BFBFBF"
}
}
}
}
// 插入行(在下方)
function TableRowInsertBelow() {
if (isCursorInTableCell()){
var numCols = 0
allCells = selectedTR.cells
for (var i=0;i<allCells.length;i++) {
numCols = numCols + allCells[i].getAttribute('colSpan')
}
var newTR = selectedTable.insertRow(selectedTR.rowIndex+1)
for (i = 0; i < numCols; i++) {
newTD = newTR.insertCell()
newTD.innerHTML = " "
if (borderShown == "yes") {
newTD.runtimeStyle.border = "1px dotted #BFBFBF"
}
}
}
}
// 合并行(向下方)
function TableRowMerge() {
if (isCursorInTableCell()) {
var rowSpanTD = selectedTD.getAttribute('rowSpan')
allRows = selectedTable.rows
if (selectedTR.rowIndex +1 != allRows.length) {
var allCellsInNextRow = allRows[selectedTR.rowIndex+selectedTD.rowSpan].cells
var addRowSpan = allCellsInNextRow[selectedTD.cellIndex].getAttribute('rowSpan')
var moveTo = selectedTD.rowSpan
if (!addRowSpan) addRowSpan = 1;
selectedTD.rowSpan = selectedTD.rowSpan + addRowSpan
allRows[selectedTR.rowIndex + moveTo].deleteCell(selectedTD.cellIndex)
}
}
}
// 拆分行
function TableRowSplit(nRows){
if (!isCursorInTableCell()) return;
if (nRows<2) return;
var addRows = nRows - 1;
var addRowsNoSpan = addRows;
var nsLeftColSpan = 0;
for (var i=0; i<selectedTD.cellIndex; i++){
nsLeftColSpan += selectedTR.cells[i].colSpan;
}
var allRows = selectedTable.rows;
// rowspan>1时
while (selectedTD.rowSpan > 1 && addRowsNoSpan > 0){
var nextRow = allRows[selectedTR.rowIndex+selectedTD.rowSpan-1];
selectedTD.rowSpan -= 1;
var ncLeftColSpan = 0;
var position = -1;
for (var n=0; n<nextRow.cells.length; n++){
ncLeftColSpan += nextRow.cells[n].getAttribute('colSpan');
if (ncLeftColSpan>nsLeftColSpan){
position = n;
break;
}
}
var newTD=nextRow.insertCell(position);
newTD.innerHTML = " ";
if (borderShown == "yes") {
newTD.runtimeStyle.border = "1px dotted #BFBFBF";
}
addRowsNoSpan -= 1;
}
// rowspan=1时
for (var n=0; n<addRowsNoSpan; n++){
var numCols = 0
allCells = selectedTR.cells
for (var i=0;i<allCells.length;i++) {
numCols = numCols + allCells[i].getAttribute('colSpan')
}
var newTR = selectedTable.insertRow(selectedTR.rowIndex+1)
// 上方行的rowspan达到这行
for (var j=0; j<selectedTR.rowIndex; j++){
for (var k=0; k<allRows[j].cells.length; k++){
if ((allRows[j].cells[k].rowSpan>1)&&(allRows[j].cells[k].rowSpan>=selectedTR.rowIndex-allRows[j].rowIndex+1)){
allRows[j].cells[k].rowSpan += 1;
}
}
}
// 当前行
for (i = 0; i < allCells.length; i++) {
if (i!=selectedTD.cellIndex){
selectedTR.cells[i].rowSpan += 1;
}else{
newTD = newTR.insertCell();
newTD.colSpan = selectedTD.colSpan;
newTD.innerHTML = " ";
if (borderShown == "yes") {
newTD.runtimeStyle.border = "1px dotted #BFBFBF";
}
}
}
}
}
// 删除行
function TableRowDelete() {
if (isCursorInTableCell()) {
selectedTable.deleteRow(selectedTR.rowIndex)
}
}
// 插入列(在左侧)
function TableColInsertLeft() {
if (isCursorInTableCell()) {
moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
allRows = selectedTable.rows
for (i=0;i<allRows.length;i++) {
rowCount = allRows[i].cells.length - 1
position = rowCount - moveFromEnd
if (position < 0) {
position = 0
}
newCell = allRows[i].insertCell(position)
newCell.innerHTML = " "
if (borderShown == "yes") {
newCell.runtimeStyle.border = "1px dotted #BFBFBF"
}
}
}
}
// 插入列(在右侧)
function TableColInsertRight() {
if (isCursorInTableCell()) {
moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
allRows = selectedTable.rows
for (i=0;i<allRows.length;i++) {
rowCount = allRows[i].cells.length - 1
position = rowCount - moveFromEnd
if (position < 0) {
position = 0
}
newCell = allRows[i].insertCell(position+1)
newCell.innerHTML = " "
if (borderShown == "yes") {
newCell.runtimeStyle.border = "1px dotted #BFBFBF"
}
}
}
}
// 合并列
function TableColMerge() {
if (isCursorInTableCell()) {
var colSpanTD = selectedTD.getAttribute('colSpan')
allCells = selectedTR.cells
if (selectedTD.cellIndex + 1 != selectedTR.cells.length) {
var addColspan = allCells[selectedTD.cellIndex+1].getAttribute('colSpan')
selectedTD.colSpan = colSpanTD + addColspan
selectedTR.deleteCell(selectedTD.cellIndex+1)
}
}
}
// 删除列
function TableColDelete() {
if (isCursorInTableCell()) {
moveFromEnd = (selectedTR.cells.length-1) - (selectedTD.cellIndex)
allRows = selectedTable.rows
for (var i=0;i<allRows.length;i++) {
endOfRow = allRows[i].cells.length - 1
position = endOfRow - moveFromEnd
if (position < 0) {
position = 0
}
allCellsInRow = allRows[i].cells
if (allCellsInRow[position].colSpan > 1) {
allCellsInRow[position].colSpan = allCellsInRow[position].colSpan - 1
} else {
allRows[i].deleteCell(position)
}
}
}
}
// 拆分列
function TableColSplit(nCols){
if (!isCursorInTableCell()) return;
if (nCols<2) return;
var addCols = nCols - 1;
var addColsNoSpan = addCols;
var newCell;
var nsLeftColSpan = 0;
var nsLeftRowSpanMoreOne = 0;
for (var i=0; i<selectedTD.cellIndex; i++){
nsLeftColSpan += selectedTR.cells[i].colSpan;
if (selectedTR.cells[i].rowSpan > 1){
nsLeftRowSpanMoreOne += 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -