Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_14980201
ueditor
提交
1750fe4a
U
ueditor
项目概览
qq_14980201
/
ueditor
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
ueditor
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1750fe4a
编写于
2月 21, 2013
作者:
T
taoqili
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
table.core
上级
af68a8eb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
149 addition
and
182 deletion
+149
-182
_examples/editor_api.js
_examples/editor_api.js
+3
-1
_src/plugins/table.action.js
_src/plugins/table.action.js
+103
-139
_src/plugins/table.cmds.js
_src/plugins/table.cmds.js
+15
-13
_src/plugins/table.core.js
_src/plugins/table.core.js
+28
-29
未找到文件。
_examples/editor_api.js
浏览文件 @
1750fe4a
...
...
@@ -59,7 +59,9 @@
'
plugins/highlightcode.js
'
,
'
plugins/puretxtpaste.js
'
,
'
plugins/video.js
'
,
'
plugins/table.js
'
,
'
plugins/table.core.js
'
,
'
plugins/table.cmds.js
'
,
'
plugins/table.action.js
'
,
'
plugins/contextmenu.js
'
,
'
plugins/basestyle.js
'
,
'
plugins/elementpath.js
'
,
...
...
_src/plugins/table.js
→
_src/plugins/table.
action.
js
浏览文件 @
1750fe4a
...
...
@@ -8,19 +8,24 @@
UE
.
plugins
[
'
table
'
]
=
function
()
{
var
me
=
this
,
debug
=
true
,
U
ETable
=
UE
.
UETable
,
getUETable
=
function
(
tdOrTable
)
{
return
U
E
.
UETable
.
getUETable
(
tdOrTable
);
U
T
=
UE
.
UETable
,
getUETable
=
function
(
tdOrTable
)
{
return
U
T
.
getUETable
(
tdOrTable
);
},
getUETableBySelected
=
function
(
editor
)
{
return
U
ETable
.
getUETableBySelected
(
editor
);
getUETableBySelected
=
function
(
editor
)
{
return
U
T
.
getUETableBySelected
(
editor
);
},
getDefaultValue
=
function
(
editor
,
table
){
return
UE
.
UETable
.
getDefaultValue
(
editor
,
table
);
getDefaultValue
=
function
(
editor
,
table
)
{
return
UT
.
getDefaultValue
(
editor
,
table
);
},
removeSelectedClass
=
function
(
cells
)
{
return
UT
.
removeSelectedClass
(
cells
);
};
function
showError
(
e
)
{
if
(
debug
)
throw
e
;
}
//处理拖动及框选相关方法
var
startTd
=
null
,
//鼠标按下时的锚点td
currentTd
=
null
,
//当前鼠标经过时的td
...
...
@@ -168,17 +173,18 @@ UE.plugins['table'] = function () {
tableCopyList
=
null
;
table
=
getUETableBySelected
(
me
);
if
(
table
)
{
var
tds
=
table
.
selectedTds
;
var
tds
=
table
.
selectedTds
,
ut
=
getUETable
(
table
);
isFullCol
=
table
.
isFullCol
();
isFullRow
=
table
.
isFullRow
();
tableCopyList
=
[
[
cloneCell
(
tds
[
0
])]
[
ut
.
cloneCell
(
tds
[
0
])]
];
for
(
var
i
=
1
,
ci
;
ci
=
tds
[
i
];
i
++
)
{
if
(
ci
.
parentNode
!==
tds
[
i
-
1
].
parentNode
)
{
tableCopyList
.
push
([
cloneCell
(
ci
)])
tableCopyList
.
push
([
ut
.
cloneCell
(
ci
)]);
}
else
{
tableCopyList
[
tableCopyList
.
length
-
1
].
push
(
cloneCell
(
ci
))
tableCopyList
[
tableCopyList
.
length
-
1
].
push
(
ut
.
cloneCell
(
ci
));
}
}
...
...
@@ -283,7 +289,7 @@ UE.plugins['table'] = function () {
for
(
var
i
=
0
,
ci
;
ci
=
tableCopyList
[
i
++
];)
{
var
tr
=
table
.
insertRow
(
table
.
rows
.
length
);
for
(
var
j
=
0
,
cj
;
cj
=
ci
[
j
++
];)
{
cloneTd
=
cloneCell
(
cj
);
cloneTd
=
ut
.
cloneCell
(
cj
);
domUtils
.
removeAttributes
(
cloneTd
,
[
'
class
'
]);
tr
.
appendChild
(
cloneTd
)
}
...
...
@@ -357,7 +363,7 @@ UE.plugins['table'] = function () {
},
100
);
});
me
.
addListener
(
"
selectionchange
"
,
function
()
{
toggleDragableState
(
me
,
false
,
""
,
null
);
toggleDrag
g
ableState
(
me
,
false
,
""
,
null
);
});
...
...
@@ -373,7 +379,7 @@ UE.plugins['table'] = function () {
start
=
domUtils
.
findParentByTagName
(
start
,
[
'
td
'
,
'
th
'
],
true
);
utils
.
each
(
domUtils
.
getElementsByTagName
(
me
.
document
,
'
table
'
),
function
(
table
)
{
if
(
me
.
fireEvent
(
"
excludetable
"
,
table
)
===
true
)
return
;
table
.
ueTable
=
new
U
ETable
(
table
);
table
.
ueTable
=
new
U
T
(
table
);
utils
.
each
(
domUtils
.
getElementsByTagName
(
me
.
document
,
'
td
'
),
function
(
td
)
{
if
(
domUtils
.
isEmptyBlock
(
td
)
&&
td
!==
start
)
{
...
...
@@ -395,7 +401,7 @@ UE.plugins['table'] = function () {
me
.
options
.
tableDragable
&&
toggleDragButton
(
true
,
this
,
me
);
};
table
.
onmouseout
=
function
()
{
toggleDragableState
(
me
,
false
,
""
,
null
);
toggleDrag
g
ableState
(
me
,
false
,
""
,
null
);
hideDragLine
(
me
);
};
table
.
onclick
=
function
(
evt
)
{
...
...
@@ -472,20 +478,20 @@ UE.plugins['table'] = function () {
}
}
}
if
(
h
==
'
h
'
)
{
if
(
h
==
'
h
'
)
{
var
ut
=
getUETable
(
target
),
cells
=
ut
.
getSameEndPosCells
(
target
,
"
x
"
),
cells
=
ut
.
getSameEndPosCells
(
target
,
"
x
"
),
table
=
ut
.
table
;
table
.
removeAttribute
(
"
width
"
);
utils
.
each
(
cells
,
function
(
cell
)
{
utils
.
each
(
cells
,
function
(
cell
)
{
cell
.
removeAttribute
(
"
width
"
);
});
setTimeout
(
function
()
{
var
width
=
cells
[
0
].
offsetWidth
-
20
;
utils
.
each
(
cells
,
function
(
cell
)
{
cell
.
setAttribute
(
"
width
"
,
width
);
setTimeout
(
function
()
{
var
width
=
cells
[
0
].
offsetWidth
-
20
;
utils
.
each
(
cells
,
function
(
cell
)
{
cell
.
setAttribute
(
"
width
"
,
width
);
})
table
.
setAttribute
(
"
width
"
,
table
.
offsetWidth
);
table
.
setAttribute
(
"
width
"
,
table
.
offsetWidth
);
})
}
...
...
@@ -494,7 +500,7 @@ UE.plugins['table'] = function () {
}
});
switchBo
derColor
(
true
);
switchBo
rderColor
(
me
,
true
);
});
//仅IE8以上支持
...
...
@@ -504,7 +510,7 @@ UE.plugins['table'] = function () {
domUtils
.
on
(
me
.
document
,
"
mouseout
"
,
function
(
evt
)
{
var
target
=
evt
.
target
||
evt
.
srcElement
;
if
(
target
.
tagName
==
"
TABLE
"
)
{
toggleDragableState
(
me
,
false
,
""
,
null
);
toggleDrag
g
ableState
(
me
,
false
,
""
,
null
);
}
});
...
...
@@ -552,7 +558,7 @@ UE.plugins['table'] = function () {
});
browser
.
ie
&&
me
.
addListener
(
'
selectionchange
'
,
function
()
{
toggleDragableState
(
this
,
false
,
""
,
null
);
toggleDrag
g
ableState
(
this
,
false
,
""
,
null
);
});
me
.
addListener
(
"
keydown
"
,
function
(
type
,
evt
)
{
var
me
=
this
;
...
...
@@ -569,15 +575,15 @@ UE.plugins['table'] = function () {
});
me
.
addListener
(
"
beforegetcontent
"
,
function
()
{
switchBo
derColor
(
false
);
browser
.
ie
&&
utils
.
each
(
me
.
document
.
getElementsByTagName
(
'
caption
'
),
function
(
ci
)
{
switchBo
rderColor
(
this
,
false
);
browser
.
ie
&&
utils
.
each
(
this
.
document
.
getElementsByTagName
(
'
caption
'
),
function
(
ci
)
{
if
(
domUtils
.
isEmptyNode
(
ci
))
{
ci
.
innerHTML
=
'
'
}
});
});
me
.
addListener
(
"
aftergetcontent
"
,
function
()
{
switchBo
derColor
(
true
);
switchBo
rderColor
(
this
,
true
);
});
me
.
addListener
(
"
getAllHtml
"
,
function
()
{
removeSelectedClass
(
me
.
document
.
getElementsByTagName
(
"
td
"
));
...
...
@@ -710,7 +716,7 @@ UE.plugins['table'] = function () {
me
.
document
.
body
.
style
.
webkitUserSelect
=
'
none
'
;
me
.
selection
.
getNative
()[
browser
.
ie
?
'
empty
'
:
'
removeAllRanges
'
]();
pos
=
mouseCoords
(
evt
);
toggleDragableState
(
me
,
true
,
""
,
pos
,
target
);
toggleDrag
g
ableState
(
me
,
true
,
""
,
pos
,
target
);
if
(
onDrag
==
"
h
"
)
{
dragLine
.
style
.
left
=
getPermissionX
(
dragTd
,
evt
)
+
"
px
"
;
}
else
if
(
onDrag
==
"
v
"
)
{
...
...
@@ -743,7 +749,7 @@ UE.plugins['table'] = function () {
target
=
getUETable
(
target
).
getPreviewCell
(
target
,
state
==
"
v
"
);
}
//位于第一行的顶部或者第一列的左边时不可拖动
toggleDragableState
(
me
,
target
?
!!
state
:
false
,
target
?
state
:
''
,
pos
,
target
);
toggleDrag
g
ableState
(
me
,
target
?
!!
state
:
false
,
target
?
state
:
''
,
pos
,
target
);
}
// toggleDragButton(inTable(pos,table),table);
}
else
{
...
...
@@ -754,12 +760,13 @@ UE.plugins['table'] = function () {
showError
(
e
);
}
}
var
dragButtomTimer
;
var
dragButtonTimer
;
function
toggleDragButton
(
show
,
table
,
editor
)
{
if
(
!
show
)
{
if
(
dragOver
)
return
;
dragButto
m
Timer
=
setTimeout
(
function
()
{
dragButto
n
Timer
=
setTimeout
(
function
()
{
!
dragOver
&&
dragButton
&&
dragButton
.
parentNode
&&
dragButton
.
parentNode
.
removeChild
(
dragButton
);
},
2000
);
}
else
{
...
...
@@ -838,7 +845,6 @@ UE.plugins['table'] = function () {
}
}
/**
* 获取拖动时允许的X轴坐标
* @param dragTd
...
...
@@ -858,8 +864,6 @@ UE.plugins['table'] = function () {
/**
* 获取拖动时允许的Y轴坐标
* @param dragTd
* @param evt
*/
function
getPermissionY
(
dragTd
,
evt
)
{
try
{
...
...
@@ -869,15 +873,12 @@ UE.plugins['table'] = function () {
}
catch
(
e
)
{
showError
(
e
);
}
}
/**
* 移动状态切换
* @param dragable
* @param dir
*/
function
toggleDrag
ableState
(
editor
,
dra
gable
,
dir
,
mousePos
,
cell
)
{
function
toggleDrag
gableState
(
editor
,
drag
gable
,
dir
,
mousePos
,
cell
)
{
try
{
editor
.
body
.
style
.
cursor
=
dir
==
"
h
"
?
"
col-resize
"
:
dir
==
"
v
"
?
"
row-resize
"
:
"
text
"
;
if
(
browser
.
ie
)
{
...
...
@@ -888,13 +889,12 @@ UE.plugins['table'] = function () {
hideDragLine
(
editor
)
}
}
onBorder
=
dragable
;
onBorder
=
drag
g
able
;
}
catch
(
e
)
{
showError
(
e
);
}
}
/**
* 获取鼠标与当前单元格的相对位置
* @param ele
...
...
@@ -918,7 +918,6 @@ UE.plugins['table'] = function () {
}
function
mouseDownEvent
(
type
,
evt
)
{
//右键菜单单独处理
if
(
evt
.
button
==
2
)
{
var
ut
=
getUETableBySelected
(
me
),
...
...
@@ -983,77 +982,6 @@ UE.plugins['table'] = function () {
}
}
function
removeSelectedClass
(
cells
)
{
utils
.
each
(
cells
,
function
(
cell
)
{
domUtils
.
removeClasses
(
cell
,
"
selectTdClass
"
);
})
}
function
addSelectedClass
(
cells
)
{
utils
.
each
(
cells
,
function
(
cell
)
{
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
})
}
function
getWidth
(
cell
)
{
if
(
!
cell
)
return
0
;
return
parseInt
(
domUtils
.
getComputedStyle
(
cell
,
"
width
"
),
10
);
}
function
changeColWidth
(
cell
,
changeValue
)
{
if
(
Math
.
abs
(
changeValue
)
<
10
)
return
;
var
ut
=
getUETable
(
cell
);
if
(
ut
)
{
var
table
=
ut
.
table
,
backTableWidth
=
getWidth
(
table
),
defaultValue
=
getDefaultValue
(
me
,
table
),
//这里不考虑一个都没有情况,如果一个都没有,可以认为该表格的结构可以精简
leftCells
=
ut
.
getSameEndPosCells
(
cell
,
"
x
"
),
backLeftWidth
=
getWidth
(
leftCells
[
0
])
-
defaultValue
.
tdPadding
*
2
-
defaultValue
.
tdBorder
,
rightCells
=
ut
.
getSameStartPosXCells
(
cell
),
backRightWidth
=
getWidth
(
rightCells
[
0
])
-
defaultValue
.
tdPadding
*
2
-
defaultValue
.
tdBorder
;
//整列被rowspan时存在
utils
.
each
(
leftCells
,
function
(
cell
)
{
if
(
cell
.
style
.
width
)
cell
.
style
.
width
=
""
;
if
(
changeValue
<
0
)
cell
.
style
.
wordBreak
=
"
break-all
"
;
cell
.
setAttribute
(
"
width
"
,
backLeftWidth
+
changeValue
);
});
utils
.
each
(
rightCells
,
function
(
cell
)
{
if
(
cell
.
style
.
width
)
cell
.
style
.
width
=
""
;
if
(
changeValue
>
0
)
cell
.
style
.
wordBreak
=
"
break-all
"
;
cell
.
setAttribute
(
"
width
"
,
backRightWidth
-
changeValue
);
});
//如果是在表格最右边拖动,则还需要调整表格宽度,否则在合并过的单元格中输入文字,表格会被撑开
if
(
!
cell
.
nextSibling
)
{
if
(
table
.
style
.
width
)
table
.
style
.
width
=
""
;
table
.
setAttribute
(
"
width
"
,
backTableWidth
+
changeValue
);
}
}
}
function
changeRowHeight
(
td
,
changeValue
)
{
if
(
Math
.
abs
(
changeValue
)
<
10
)
return
;
var
ut
=
getUETable
(
td
);
if
(
ut
)
{
var
cells
=
ut
.
getSameEndPosCells
(
td
,
"
y
"
),
//备份需要连带变化的td的原始高度,否则后期无法获取正确的值
backHeight
=
cells
[
0
]
?
cells
[
0
].
offsetHeight
:
0
;
for
(
var
i
=
0
,
cell
;
cell
=
cells
[
i
++
];)
{
setCellHeight
(
cell
,
changeValue
,
backHeight
);
}
}
}
function
setCellHeight
(
cell
,
height
,
backHeight
)
{
var
lineHight
=
parseInt
(
domUtils
.
getComputedStyle
(
cell
,
"
line-height
"
),
10
),
tmpHeight
=
backHeight
+
height
;
height
=
tmpHeight
<
lineHight
?
lineHight
:
tmpHeight
;
if
(
cell
.
style
.
height
)
cell
.
style
.
height
=
""
;
cell
.
rowSpan
==
1
?
cell
.
setAttribute
(
"
height
"
,
height
)
:
(
cell
.
removeAttribute
&&
cell
.
removeAttribute
(
"
height
"
));
}
function
mouseUpEvent
(
type
,
evt
)
{
if
(
evt
.
button
==
2
)
return
;
var
me
=
this
;
...
...
@@ -1154,6 +1082,64 @@ UE.plugins['table'] = function () {
evt
.
preventDefault
?
evt
.
preventDefault
()
:
(
evt
.
returnValue
=
false
);
}
function
setCellHeight
(
cell
,
height
,
backHeight
)
{
var
lineHight
=
parseInt
(
domUtils
.
getComputedStyle
(
cell
,
"
line-height
"
),
10
),
tmpHeight
=
backHeight
+
height
;
height
=
tmpHeight
<
lineHight
?
lineHight
:
tmpHeight
;
if
(
cell
.
style
.
height
)
cell
.
style
.
height
=
""
;
cell
.
rowSpan
==
1
?
cell
.
setAttribute
(
"
height
"
,
height
)
:
(
cell
.
removeAttribute
&&
cell
.
removeAttribute
(
"
height
"
));
}
function
getWidth
(
cell
)
{
if
(
!
cell
)
return
0
;
return
parseInt
(
domUtils
.
getComputedStyle
(
cell
,
"
width
"
),
10
);
}
function
changeColWidth
(
cell
,
changeValue
)
{
if
(
Math
.
abs
(
changeValue
)
<
10
)
return
;
var
ut
=
getUETable
(
cell
);
if
(
ut
)
{
var
table
=
ut
.
table
,
backTableWidth
=
getWidth
(
table
),
defaultValue
=
getDefaultValue
(
me
,
table
),
//这里不考虑一个都没有情况,如果一个都没有,可以认为该表格的结构可以精简
leftCells
=
ut
.
getSameEndPosCells
(
cell
,
"
x
"
),
backLeftWidth
=
getWidth
(
leftCells
[
0
])
-
defaultValue
.
tdPadding
*
2
-
defaultValue
.
tdBorder
,
rightCells
=
ut
.
getSameStartPosXCells
(
cell
),
backRightWidth
=
getWidth
(
rightCells
[
0
])
-
defaultValue
.
tdPadding
*
2
-
defaultValue
.
tdBorder
;
//整列被rowspan时存在
utils
.
each
(
leftCells
,
function
(
cell
)
{
if
(
cell
.
style
.
width
)
cell
.
style
.
width
=
""
;
if
(
changeValue
<
0
)
cell
.
style
.
wordBreak
=
"
break-all
"
;
cell
.
setAttribute
(
"
width
"
,
backLeftWidth
+
changeValue
);
});
utils
.
each
(
rightCells
,
function
(
cell
)
{
if
(
cell
.
style
.
width
)
cell
.
style
.
width
=
""
;
if
(
changeValue
>
0
)
cell
.
style
.
wordBreak
=
"
break-all
"
;
cell
.
setAttribute
(
"
width
"
,
backRightWidth
-
changeValue
);
});
//如果是在表格最右边拖动,则还需要调整表格宽度,否则在合并过的单元格中输入文字,表格会被撑开
if
(
!
cell
.
nextSibling
)
{
if
(
table
.
style
.
width
)
table
.
style
.
width
=
""
;
table
.
setAttribute
(
"
width
"
,
backTableWidth
+
changeValue
);
}
}
}
function
changeRowHeight
(
td
,
changeValue
)
{
if
(
Math
.
abs
(
changeValue
)
<
10
)
return
;
var
ut
=
getUETable
(
td
);
if
(
ut
)
{
var
cells
=
ut
.
getSameEndPosCells
(
td
,
"
y
"
),
//备份需要连带变化的td的原始高度,否则后期无法获取正确的值
backHeight
=
cells
[
0
]
?
cells
[
0
].
offsetHeight
:
0
;
for
(
var
i
=
0
,
cell
;
cell
=
cells
[
i
++
];)
{
setCellHeight
(
cell
,
changeValue
,
backHeight
);
}
}
}
function
getDragLine
(
editor
,
doc
)
{
if
(
mousedown
)
return
;
...
...
@@ -1167,9 +1153,6 @@ UE.plugins['table'] = function () {
'
onselectstart
'
:
'
return false
'
,
style
:
"
background-color:blue;position:absolute;padding:0;margin:0;background-image:none;border:0px none;opacity:0;filter:alpha(opacity=0)
"
});
// domUtils.on(dragLine,['resizestart','dragstart','selectstart'],function(evt){
// domUtils.preventDefault(evt);
// });
editor
.
body
.
appendChild
(
dragLine
);
}
...
...
@@ -1210,10 +1193,11 @@ UE.plugins['table'] = function () {
/**
* 当表格边框颜色为白色时设置为虚线,true为添加虚线
* @param editor
* @param flag
*/
function
switchBo
derColor
(
flag
)
{
var
tableArr
=
domUtils
.
getElementsByTagName
(
me
.
body
,
"
table
"
),
color
;
function
switchBo
rderColor
(
editor
,
flag
)
{
var
tableArr
=
domUtils
.
getElementsByTagName
(
editor
.
body
,
"
table
"
),
color
;
for
(
var
i
=
0
,
node
;
node
=
tableArr
[
i
++
];)
{
var
td
=
domUtils
.
getElementsByTagName
(
node
,
"
td
"
);
if
(
td
[
0
])
{
...
...
@@ -1239,24 +1223,4 @@ UE.plugins['table'] = function () {
//排除了非td内部以及用于代码高亮部分的td
return
target
&&
!
(
editor
.
fireEvent
(
"
excludetable
"
,
target
)
===
true
)
?
target
:
null
;
}
function
cloneCell
(
cell
,
ingoreMerge
)
{
if
(
!
cell
||
utils
.
isString
(
cell
))
{
return
this
.
table
.
ownerDocument
.
createElement
(
cell
||
'
td
'
);
}
var
flag
=
domUtils
.
hasClass
(
cell
,
"
selectTdClass
"
);
flag
&&
domUtils
.
removeClasses
(
cell
,
"
selectTdClass
"
);
var
tmpCell
=
cell
.
cloneNode
(
true
);
if
(
ingoreMerge
)
{
tmpCell
.
rowSpan
=
tmpCell
.
colSpan
=
1
;
}
tmpCell
.
style
.
borderLeftStyle
=
""
;
tmpCell
.
style
.
borderTopStyle
=
""
;
tmpCell
.
style
.
borderLeftColor
=
cell
.
style
.
borderRightColor
;
tmpCell
.
style
.
borderLeftWidth
=
cell
.
style
.
borderRightWidth
;
tmpCell
.
style
.
borderTopColor
=
cell
.
style
.
borderBottomColor
;
tmpCell
.
style
.
borderTopWidth
=
cell
.
style
.
borderBottomWidth
;
flag
&&
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
return
tmpCell
;
}
};
_src/plugins/table.cmds.js
浏览文件 @
1750fe4a
...
...
@@ -6,22 +6,20 @@
* To change this template use File | Settings | File Templates.
*/
;(
function
(){
var
getTableItemsByRange
=
function
(
editor
){
return
UE
.
UETable
.
getTableItemsByRange
(
editor
);
var
UT
=
UE
.
UETable
,
getTableItemsByRange
=
function
(
editor
){
return
UT
.
getTableItemsByRange
(
editor
);
},
getUETableBySelected
=
function
(
editor
){
return
U
E
.
UETable
.
getUETableBySelected
(
editor
)
return
U
T
.
getUETableBySelected
(
editor
)
},
getDefaultValue
=
function
(
editor
,
table
){
return
U
E
.
UETable
.
getDefaultValue
(
editor
,
table
);
return
U
T
.
getDefaultValue
(
editor
,
table
);
},
getUETable
=
function
(
tdOrTable
){
return
U
E
.
UETable
.
getUETable
(
tdOrTable
);
return
U
T
.
getUETable
(
tdOrTable
);
};
function
getSelectedArr
(
editor
)
{
var
ut
=
getTableItemsByRange
(
editor
).
cell
||
getUETableBySelected
(
editor
);
return
ut
?
(
ut
.
nodeType
?
[
ut
]
:
ut
.
selectedTds
)
:
[];
}
UE
.
commands
[
'
inserttable
'
]
=
{
queryCommandState
:
function
()
{
...
...
@@ -528,7 +526,7 @@
table
=
tableItems
.
table
;
if
(
table
)
{
if
(
cmd
==
'
adaptbywindow
'
)
{
resetTdWidth
(
table
);
resetTdWidth
(
table
,
this
);
}
else
{
var
cells
=
domUtils
.
getElementsByTagName
(
table
,
"
td th
"
);
utils
.
each
(
cells
,
function
(
cell
){
...
...
@@ -748,20 +746,24 @@
}
};
function
resetTdWidth
(
table
){
function
resetTdWidth
(
table
,
editor
){
var
tds
=
table
.
getElementsByTagName
(
"
td
"
);
utils
.
each
(
tds
,
function
(
td
)
{
td
.
removeAttribute
(
"
width
"
);
});
table
.
setAttribute
(
'
width
'
,
getTableWidth
(
me
,
true
,
getDefaultValue
(
me
,
table
)));
table
.
setAttribute
(
'
width
'
,
getTableWidth
(
editor
,
true
,
getDefaultValue
(
editor
,
table
)));
setTimeout
(
function
(){
utils
.
each
(
tds
,
function
(
td
){
(
td
.
colSpan
==
1
)
&&
td
.
setAttribute
(
"
width
"
,
td
.
offsetWidth
+
""
);
})
},
0
)
},
0
)
;
}
function
getTableWidth
(
editor
,
needIEHack
,
defaultValue
)
{
var
body
=
editor
.
body
;
return
body
.
offsetWidth
-
(
needIEHack
?
parseInt
(
domUtils
.
getComputedStyle
(
body
,
'
margin-left
'
),
10
)
*
2
:
0
)
-
defaultValue
.
tableBorder
*
2
-
(
editor
.
options
.
offsetWidth
||
0
);
}
function
getSelectedArr
(
editor
)
{
var
ut
=
getTableItemsByRange
(
editor
).
cell
||
getUETableBySelected
(
editor
);
return
ut
?
(
ut
.
nodeType
?
[
ut
]
:
ut
.
selectedTds
)
:
[];
}
})();
\ No newline at end of file
_src/plugins/table.core.js
浏览文件 @
1750fe4a
...
...
@@ -19,38 +19,24 @@
this
.
update
(
table
);
};
//================================utils=========================
UETable
.
cloneCell
=
function
(
cell
,
ingoreMerge
)
{
if
(
!
cell
||
utils
.
isString
(
cell
)){
return
this
.
table
.
ownerDocument
.
createElement
(
cell
||
'
td
'
);
}
var
flag
=
domUtils
.
hasClass
(
cell
,
"
selectTdClass
"
);
flag
&&
domUtils
.
removeClasses
(
cell
,
"
selectTdClass
"
);
var
tmpCell
=
cell
.
cloneNode
(
true
);
if
(
ingoreMerge
){
tmpCell
.
rowSpan
=
tmpCell
.
colSpan
=
1
;
}
tmpCell
.
style
.
borderLeftStyle
=
""
;
tmpCell
.
style
.
borderTopStyle
=
""
;
tmpCell
.
style
.
borderLeftColor
=
cell
.
style
.
borderRightColor
;
tmpCell
.
style
.
borderLeftWidth
=
cell
.
style
.
borderRightWidth
;
tmpCell
.
style
.
borderTopColor
=
cell
.
style
.
borderBottomColor
;
tmpCell
.
style
.
borderTopWidth
=
cell
.
style
.
borderBottomWidth
;
flag
&&
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
return
tmpCell
;
};
//===以下为静态工具方法===
UETable
.
removeSelectedClass
=
function
(
cells
)
{
utils
.
each
(
cells
,
function
(
cell
)
{
domUtils
.
removeClasses
(
cell
,
"
selectTdClass
"
);
})
};
UETable
.
addSelectedClass
=
function
(
cells
){
utils
.
each
(
cells
,
function
(
cell
)
{
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
})
};
UETable
.
isEmptyBlock
=
function
(
node
)
{
var
reg
=
new
RegExp
(
domUtils
.
fillChar
,
'
g
'
);
if
(
node
[
browser
.
ie
?
'
innerText
'
:
'
textContent
'
].
replace
(
/^
\s
*$/
,
''
).
replace
(
reg
,
''
).
length
>
0
)
{
return
0
;
}
for
(
var
n
in
dtd
.
$isNotEmpty
)
{
if
(
node
.
getElementsByTagName
(
n
).
length
)
{
for
(
var
i
in
dtd
.
$isNotEmpty
)
if
(
dtd
.
$isNotEmpty
.
hasOwnProperty
(
i
)
)
{
if
(
node
.
getElementsByTagName
(
i
).
length
)
{
return
0
;
}
}
...
...
@@ -275,7 +261,25 @@
setCellContent
:
function
(
cell
,
content
)
{
cell
.
innerHTML
=
content
||
(
browser
.
ie
?
domUtils
.
fillChar
:
"
<br />
"
);
},
cloneCell
:
UETable
.
cloneCell
,
cloneCell
:
function
(
cell
,
ignoreMerge
){
if
(
!
cell
||
utils
.
isString
(
cell
)){
return
this
.
table
.
ownerDocument
.
createElement
(
cell
||
'
td
'
);
}
var
flag
=
domUtils
.
hasClass
(
cell
,
"
selectTdClass
"
);
flag
&&
domUtils
.
removeClasses
(
cell
,
"
selectTdClass
"
);
var
tmpCell
=
cell
.
cloneNode
(
true
);
if
(
ignoreMerge
){
tmpCell
.
rowSpan
=
tmpCell
.
colSpan
=
1
;
}
tmpCell
.
style
.
borderLeftStyle
=
""
;
tmpCell
.
style
.
borderTopStyle
=
""
;
tmpCell
.
style
.
borderLeftColor
=
cell
.
style
.
borderRightColor
;
tmpCell
.
style
.
borderLeftWidth
=
cell
.
style
.
borderRightWidth
;
tmpCell
.
style
.
borderTopColor
=
cell
.
style
.
borderBottomColor
;
tmpCell
.
style
.
borderTopWidth
=
cell
.
style
.
borderBottomWidth
;
flag
&&
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
return
tmpCell
;
},
/**
* 获取跟当前单元格的右边竖线为左边的所有未合并单元格
*/
...
...
@@ -546,7 +550,7 @@
*/
setSelected
:
function
(
range
)
{
var
cells
=
this
.
getCells
(
range
);
addSelectedClass
(
cells
);
UETable
.
addSelectedClass
(
cells
);
this
.
selectedTds
=
cells
;
this
.
cellsRange
=
range
;
},
...
...
@@ -1007,10 +1011,5 @@
this
.
setSelected
(
range
);
}
};
function
addSelectedClass
(
cells
)
{
utils
.
each
(
cells
,
function
(
cell
)
{
domUtils
.
addClass
(
cell
,
"
selectTdClass
"
);
})
}
function
showError
(
e
)
{}
})();
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录