From 002d0d894d7aba35f3b763b44cc22a6b60fe38f8 Mon Sep 17 00:00:00 2001 From: taoqili Date: Sat, 21 Jan 2012 18:46:39 +0800 Subject: [PATCH 01/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 100 ++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 68 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 4bc13f901..8a8aa9ada 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -34,7 +34,7 @@ UE.plugins['table'] = function () { 'defaultRows':5, 'tdvalign':'top', 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_", - 'tableDragable':false + 'tableDragable':true }); var commands = { 'deletetable':1, @@ -382,10 +382,23 @@ UE.plugins['table'] = function () { } } }); - table.onmousemove = function () { - me.options.tableDragable && toggleDragButton(true, this, me); + var overFlag = false; + table.onmouseover = function () { + if (!overFlag) { + overFlag = true; + me.options.tableDragable && me.fireEvent("showDragPopup"); + } }; - table.onmouseout = function () { + table.onmouseout = function (evt) { + evt = evt || me.window.event; + var mousePos = mouseCoords(evt), + x = mousePos.x, + y = mousePos.y, + p = domUtils.getXY(table); + if (x <= p.x || x >= (p.x + table.offsetWidth) || y <= p.y || y >= (p.y + table.offsetHeight)) { + me.options.tableDragable && me.fireEvent("hideDragPopup"); + overFlag = false; + } toggleDragableState(me, false, "", null); hideDragLine(me); }; @@ -719,75 +732,12 @@ UE.plugins['table'] = function () { //位于第一行的顶部或者第一列的左边时不可拖动 toggleDragableState(me, target ? !!state : false, target ? state : '', pos, target); } -// toggleDragButton(inTable(pos,table),table); - } else { - toggleDragButton(false, table, me); } } catch (e) { showError(e); } } - var dragButtomTimer; - - function toggleDragButton(show, table, editor) { - if (!show) { - if (dragOver)return; - dragButtomTimer = setTimeout(function () { - !dragOver && dragButton && dragButton.parentNode && dragButton.parentNode.removeChild(dragButton); - }, 2000); - } else { - createDragButton(table, editor); - } - } - - function createDragButton(table, editor) { - var pos = domUtils.getXY(table), - doc = table.ownerDocument; - if (dragButton && dragButton.parentNode)return dragButton; - dragButton = doc.createElement("div"); - dragButton.contentEditable = false; - dragButton.innerHTML = ""; - dragButton.style.cssText = "width:15px;height:15px;background-image:url(" + editor.options.UEDITOR_HOME_URL + "dialogs/table/dragicon.png);position: absolute;cursor:move;top:" + (pos.y - 15) + "px;left:" + (pos.x) + "px;"; - domUtils.unSelectable(dragButton); - dragButton.onmouseover = function (evt) { - dragOver = true; - }; - dragButton.onmouseout = function (evt) { - dragOver = false; - }; - domUtils.on(dragButton, 'click', function (type, evt) { - doClick(evt, this); - }); - domUtils.on(dragButton, 'dblclick', function (type, evt) { - doDblClick(evt); - }); - domUtils.on(dragButton, 'dragstart', function (type, evt) { - domUtils.preventDefault(evt); - }); - var timer; - - function doClick(evt, button) { - // 部分浏览器下需要清理 - clearTimeout(timer); - timer = setTimeout(function () { - editor.fireEvent("tableClicked", table, button); - }, 300); - } - - function doDblClick(evt) { - clearTimeout(timer); - var ut = getUETable(table), - start = table.rows[0].cells[0], - end = ut.getLastCell(), - range = ut.getCellsRange(start, end); - editor.selection.getRange().setStart(start, 0).setCursor(false, true); - ut.setSelected(range); - } - - doc.body.appendChild(dragButton); - } - // function inPosition(table, pos) { // var tablePos = domUtils.getXY(table), @@ -1777,7 +1727,13 @@ UE.plugins['table'] = function () { utils.each(tds, function (td) { td.removeAttribute("width"); }); - table.setAttribute('width', '100%'); + table.setAttribute('width', getTableWidth(this,needIEHack,getDefaultValue(this,table))); + setTimeout(function(){ + utils.each(tds,function(td){ + td.setAttribute("width",td.offsetWidth); + }) + },0) + } else { var ut = getUETable(table), preTds = cell?ut.getSameEndPosCells(cell, "x"):table.getElementsByTagName("td"); @@ -2799,6 +2755,14 @@ UE.plugins['table'] = function () { this.update(); return results; }, + split:function(cell,rowsNum,colsNum){ + var cellInfo = this.getCellInfo(cell), + rowSpan = cellInfo.rowSpan, + colSpan = cellInfo.colSpan, + rowIndex = cellInfo.rowIndex; + if(rowSpan>1 && rowsNum%rowSpan!==0 || colSpan>1 && colsNum%colSpan!==0 ) return false; + + }, getPreviewMergedCellsNum:function (rowIndex, colIndex) { var indexRow = this.indexTable[rowIndex], num = 0; From ac1e644e6c435153abe008cc04d160508db9dfb3 Mon Sep 17 00:00:00 2001 From: taoqili Date: Sat, 21 Jan 2012 18:55:29 +0800 Subject: [PATCH 02/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 8a8aa9ada..978f895ad 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1730,7 +1730,7 @@ UE.plugins['table'] = function () { table.setAttribute('width', getTableWidth(this,needIEHack,getDefaultValue(this,table))); setTimeout(function(){ utils.each(tds,function(td){ - td.setAttribute("width",td.offsetWidth); + td.setAttribute("width",td.offsetWidth+""); }) },0) From 45bb9646b0588589da5183f16b8d50117cd479b3 Mon Sep 17 00:00:00 2001 From: taoqili Date: Sat, 21 Jan 2012 18:57:30 +0800 Subject: [PATCH 03/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _examples/completeDemo.html | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/_examples/completeDemo.html b/_examples/completeDemo.html index fb2857acf..39bb522ac 100755 --- a/_examples/completeDemo.html +++ b/_examples/completeDemo.html @@ -67,6 +67,12 @@ ue.addListener('ready',function(){ this.focus() }); + ue.addListener("showDragPopup",function(type,table){ +// console.log("over"); + }); + ue.addListener("hideDragPopup",function(type,table){ +// console.log("out"); + }); function createEditor(){ enableBtn(); UE.getEditor('editor') From 907f94f47a157586b22edc97823d21afdb30e867 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 23 Jan 2013 15:55:29 +0800 Subject: [PATCH 04/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 978f895ad..ab8f932f5 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -207,7 +207,7 @@ UE.plugins['table'] = function () { } cell.innerHTML = cj.innerHTML; cj.getAttribute('width') && cell.setAttribute('width', cj.getAttribute('width')); - cj.getAttribute('valign') && cell.setAttribute('valign', cj.getAttribute('valign')); + cj.getAttribute('vAlign') && cell.setAttribute('vAlign', cj.getAttribute('vAlign')); cj.getAttribute('align') && cell.setAttribute('align', cj.getAttribute('align')); cj.style.cssText && (cell.style.cssText = cj.style.cssText) } @@ -216,7 +216,7 @@ UE.plugins['table'] = function () { break; cj.innerHTML = ci[j].innerHTML; ci[j].getAttribute('width') && cj.setAttribute('width', ci[j].getAttribute('width')); - ci[j].getAttribute('valign') && cj.setAttribute('valign', ci[j].getAttribute('valign')); + ci[j].getAttribute('vAlign') && cj.setAttribute('vAlign', ci[j].getAttribute('vAlign')); ci[j].getAttribute('align') && cj.setAttribute('align', ci[j].getAttribute('align')); ci[j].style.cssText && (cj.style.cssText = ci[j].style.cssText) } @@ -245,7 +245,7 @@ UE.plugins['table'] = function () { td.innerHTML = cj.innerHTML; //todo 定制处理 cj.getAttribute('width') && td.setAttribute('width', cj.getAttribute('width')); - cj.getAttribute('valign') && td.setAttribute('valign', cj.getAttribute('valign')); + cj.getAttribute('vAlign') && td.setAttribute('vAlign', cj.getAttribute('vAlign')); cj.getAttribute('align') && td.setAttribute('align', cj.getAttribute('align')); cj.style.cssText && (td.style.cssText = cj.style.cssText); preNode = td; @@ -1195,7 +1195,7 @@ UE.plugins['table'] = function () { for (var r = 0; r < rowsNum; r++) { html.push(''); for (var c = 0; c < colsNum; c++) { - html.push('' + (browser.ie ? domUtils.fillChar : '
') + '') + html.push('' + (browser.ie ? domUtils.fillChar : '
') + '') } html.push('') } @@ -1209,9 +1209,14 @@ UE.plugins['table'] = function () { tdvalign:this.options.tdvalign }) } + var range = this.selection.getRange(), + start = range.startContainer, + firstParentBlock = domUtils.findParent(start,function(node){ + return domUtils.isBlockElm(node); + },true); var me = this, defaultValue = getDefaultValue(me), - tableWidth = getTableWidth(me, needIEHack, defaultValue), + tableWidth = getTableWidth(me, needIEHack, defaultValue) - (firstParentBlock ? parseInt(domUtils.getXY(firstParentBlock).x,10):0), tdWidth = Math.floor(tableWidth / opt.numCols - defaultValue.tdPadding * 2 - defaultValue.tdBorder); //todo其他属性 !opt.tdvalign && (opt.tdvalign = me.options.tdvalign); @@ -1281,11 +1286,11 @@ UE.plugins['table'] = function () { queryCommandState:function () { return getSelectedArr(this).length ? 0 : -1; }, - execCommand:function (cmd, valign) { + execCommand:function (cmd, vAlign) { var selectedTds = getSelectedArr(this); if (selectedTds.length) { for (var i = 0, ci; ci = selectedTds[i++];) { - ci.setAttribute('vAlign', valign); + ci.setAttribute('vAlign', vAlign); } } } @@ -2543,7 +2548,7 @@ UE.plugins['table'] = function () { for (var colIndex = 0; colIndex < numCols; colIndex++) { cell = this.cloneCell(sourceCell,true); this.setCellContent(cell); - cell.setAttribute('valign', cell.getAttribute('valign')); + cell.setAttribute('vAlign', cell.getAttribute('vAlign')); row.appendChild(cell); } } else { @@ -2652,7 +2657,7 @@ UE.plugins['table'] = function () { preCell = tableRow.cells[colIndex == 0 ? colIndex : tableRow.cells.length]; cell = this.cloneCell(sourceCell,true); //tableRow.insertCell(colIndex == 0 ? colIndex : tableRow.cells.length); this.setCellContent(cell); - cell.setAttribute('valign', cell.getAttribute('valign')); + cell.setAttribute('vAlign', cell.getAttribute('vAlign')); preCell && cell.setAttribute('width', preCell.getAttribute('width')); if (!colIndex) { tableRow.insertBefore(cell, tableRow.cells[0]); @@ -2673,7 +2678,7 @@ UE.plugins['table'] = function () { cell = this.cloneCell(sourceCell,true);//tableRow.insertCell(cellInfo.cellIndex); this.setCellContent(cell); - cell.setAttribute('valign', cell.getAttribute('valign')); + cell.setAttribute('vAlign', cell.getAttribute('vAlign')); preCell && cell.setAttribute('width', preCell.getAttribute('width')) tableRow.insertBefore(cell, preCell); } @@ -2745,7 +2750,7 @@ UE.plugins['table'] = function () { tmpCell = tableRow.insertCell(colIndex - this.getPreviewMergedCellsNum(i, colIndex)); tmpCell.colSpan = cellInfo.colSpan; this.setCellContent(tmpCell); - tmpCell.setAttribute('valign', cell.getAttribute('valign')); + tmpCell.setAttribute('vAlign', cell.getAttribute('vAlign')); tmpCell.setAttribute('align', cell.getAttribute('align')); if (cell.style.cssText) { tmpCell.style.cssText = cell.style.cssText; @@ -2792,7 +2797,7 @@ UE.plugins['table'] = function () { tmpCell = tableRow.insertCell(this.indexTable[rowIndex][j].cellIndex + 1); tmpCell.rowSpan = cellInfo.rowSpan; this.setCellContent(tmpCell); - tmpCell.setAttribute('valign',cell.getAttribute('valign')); + tmpCell.setAttribute('vAlign',cell.getAttribute('vAlign')); tmpCell.setAttribute('align',cell.getAttribute('align')); tmpCell.setAttribute('width',backWidth); if (cell.style.cssText) { @@ -2802,7 +2807,7 @@ UE.plugins['table'] = function () { if (cell.tagName == 'TH') { var th = cell.ownerDocument.createElement('th'); th.appendChild(tmpCell.firstChild); - th.setAttribute('valign', cell.getAttribute('valign')); + th.setAttribute('vAlign', cell.getAttribute('vAlign')); th.rowSpan = tmpCell.rowSpan; tableRow.insertBefore(th, tmpCell); domUtils.remove(tmpCell) From 80c665227ead7f8a10939b0e9439bea66d9baa38 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 23 Jan 2013 19:13:11 +0800 Subject: [PATCH 05/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 69 ++++++++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 27 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index ab8f932f5..71f42d782 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1723,39 +1723,54 @@ UE.plugins['table'] = function () { return getTableItemsByRange(this).table ? 0 : -1 }, execCommand:function (cmd) { + var me = this; + function resetTdWidth(table){ + + var tds = table.getElementsByTagName("td"); + utils.each(tds, function (td) { + td.removeAttribute("width"); + }); + table.setAttribute('width', getTableWidth(me,needIEHack,getDefaultValue(me,table))); + setTimeout(function(){ + utils.each(tds,function(td){ + (td.colSpan ==1) && td.setAttribute("width",td.offsetWidth+""); + }) + },0) + } + var tableItems = getTableItemsByRange(this), table = tableItems.table, cell = tableItems.cell; if (table) { if (cmd == 'adaptbywindow') { - var tds = table.getElementsByTagName("td"); - utils.each(tds, function (td) { - td.removeAttribute("width"); - }); - table.setAttribute('width', getTableWidth(this,needIEHack,getDefaultValue(this,table))); - setTimeout(function(){ - utils.each(tds,function(td){ - td.setAttribute("width",td.offsetWidth+""); - }) - },0) - + resetTdWidth(table); } else { - var ut = getUETable(table), - preTds = cell?ut.getSameEndPosCells(cell, "x"):table.getElementsByTagName("td"); - if (preTds.length) { - table.style.width = ""; - table.removeAttribute("width"); - utils.each(preTds, function (td) { - td.removeAttribute("width"); - }); - - var defaultValue = getDefaultValue(me, table); - var width = table.offsetWidth, - bodyWidth = me.body.offsetWidth; - if (width > bodyWidth) { - table.setAttribute('width', getTableWidth(me, needIEHack, defaultValue)); + if(cell){ + var ut = getUETable(table), + preTds = ut.getSameEndPosCells(cell, "x"); + if (preTds.length) { + var flag = false; + utils.each(preTds,function(td){ + if(!isEmptyBlock(td)){ + flag = true; + return false; + } + }); + if(!flag)return; + utils.each(preTds, function (td) { + (td.colSpan==1) && td.removeAttribute("width"); + }); + table.style.width = ""; + table.removeAttribute("width"); + var defaultValue = getDefaultValue(me, table); + var width = table.offsetWidth, + bodyWidth = me.body.offsetWidth; + if (width > bodyWidth) { + table.setAttribute('width', getTableWidth(me, needIEHack, defaultValue)); + } } - + }else{ + resetTdWidth(table); } } } @@ -2698,7 +2713,7 @@ UE.plugins['table'] = function () { } var tds = domUtils.getElementsByTagName(this.table, "td"); utils.each(tds, function (td) { - td.setAttribute("width", width); + (td.colSpan==1) && td.setAttribute("width", width); }) }, deleteCol:function (colIndex) { From 94ddf43015bde87669d06717c72ea9daf08b4b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=92?= Date: Wed, 23 Jan 2013 19:56:23 +0800 Subject: [PATCH 06/20] [fixed]by xuheng --- _src/plugins/table.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 4bc13f901..179cb02cf 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1806,7 +1806,7 @@ UE.plugins['table'] = function () { queryCommandState:function () { var ut = getUETableBySelected(this); if (!ut) return -1; - return ut.isFullRow() || ut.isFullCol() ? 0 : -1; + return ut.isFullCol()&&ut.cellsRange.beginColIndex!=ut.cellsRange.endColIndex? 0 : -1; }, execCommand:function (cmd) { var me = this, @@ -1859,7 +1859,7 @@ UE.plugins['table'] = function () { var ut = getUETableBySelected(this); if (!ut) return -1; if (ut.selectedTds && /th/ig.test(ut.selectedTds[0].tagName)) return -1; - return ut.isFullRow() || ut.isFullCol() ? 0 : -1; + return ut.isFullRow()&&ut.cellsRange.beginRowIndex!=ut.cellsRange.endRowIndex? 0 : -1; }, execCommand:function (cmd) { var me = this, From 2852c5ab476bf324cc9eb1bded4483d48bc69cd3 Mon Sep 17 00:00:00 2001 From: taoqili Date: Thu, 24 Jan 2013 15:25:38 +0800 Subject: [PATCH 07/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 1 + 1 file changed, 1 insertion(+) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 71f42d782..daff6f7c3 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -36,6 +36,7 @@ UE.plugins['table'] = function () { 'cursorpath':me.options.UEDITOR_HOME_URL + "themes/default/images/cursor_", 'tableDragable':true }); + me.getUETable = getUETable; var commands = { 'deletetable':1, 'inserttable':1, From 8b3ecf64e28ae8223257232dabda69e089cdff4b Mon Sep 17 00:00:00 2001 From: taoqili Date: Fri, 25 Jan 2013 15:52:36 +0800 Subject: [PATCH 08/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 1ca6e77d3..11b1e9de6 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -387,7 +387,7 @@ UE.plugins['table'] = function () { table.onmouseover = function () { if (!overFlag) { overFlag = true; - me.options.tableDragable && me.fireEvent("showDragPopup"); + me.options.tableDragable && me.fireEvent("showDragPopup",table); } }; table.onmouseout = function (evt) { @@ -397,7 +397,7 @@ UE.plugins['table'] = function () { y = mousePos.y, p = domUtils.getXY(table); if (x <= p.x || x >= (p.x + table.offsetWidth) || y <= p.y || y >= (p.y + table.offsetHeight)) { - me.options.tableDragable && me.fireEvent("hideDragPopup"); + me.options.tableDragable && me.fireEvent("hideDragPopup",table); overFlag = false; } toggleDragableState(me, false, "", null); @@ -2652,7 +2652,8 @@ UE.plugins['table'] = function () { var rowsNum = this.rowsNum, rowIndex = 0, tableRow, cell, - backWidth = parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10); + overflow = (this.table.offsetWidth + sourceCell.offsetWidth) > this.table.ownerDocument.body.offsetWidth, + backWidth = overflow ? parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10):(sourceCell.offsetWidth-22); function replaceTdToTh(rowIndex, cell, tableRow) { if (rowIndex == 0) { From 84efa495993ca856f4efc5a0a9cec04299321a09 Mon Sep 17 00:00:00 2001 From: taoqili Date: Fri, 25 Jan 2013 17:05:23 +0800 Subject: [PATCH 09/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 11b1e9de6..6f4997685 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -2702,13 +2702,15 @@ UE.plugins['table'] = function () { replaceTdToTh(rowIndex, cell, tableRow); } } + //框选时插入不触发contentchange,需要手动更新索引 this.update(); - this.updateWidth(backWidth,defaultValue||{tdPadding:10,tdBorder:1}); + this.updateWidth(backWidth); }, - updateWidth:function (width,defaultValue) { + updateWidth:function (width) { + this.table.setAttribute("width",""); var table = this.table, - tmpWidth = getWidth(table) - defaultValue.tdPadding * 2 - defaultValue.tdBorder + width; + tmpWidth = getWidth(table); if( tmpWidth Date: Mon, 28 Jan 2013 14:21:42 +0800 Subject: [PATCH 10/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 6f4997685..265173918 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -2653,7 +2653,7 @@ UE.plugins['table'] = function () { rowIndex = 0, tableRow, cell, overflow = (this.table.offsetWidth + sourceCell.offsetWidth) > this.table.ownerDocument.body.offsetWidth, - backWidth = overflow ? parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20 - (this.colsNum + 1)) / (this.colsNum + 1), 10):(sourceCell.offsetWidth-22); + backWidth = overflow ? parseInt((this.table.offsetWidth - (this.colsNum + 1) * 20) / (this.colsNum + 1), 10):(sourceCell.offsetWidth-22); function replaceTdToTh(rowIndex, cell, tableRow) { if (rowIndex == 0) { @@ -2779,12 +2779,12 @@ UE.plugins['table'] = function () { this.update(); return results; }, - split:function(cell,rowsNum,colsNum){ + split2Rows:function(cell,rowsNum){ var cellInfo = this.getCellInfo(cell), rowSpan = cellInfo.rowSpan, - colSpan = cellInfo.colSpan, rowIndex = cellInfo.rowIndex; - if(rowSpan>1 && rowsNum%rowSpan!==0 || colSpan>1 && colsNum%colSpan!==0 ) return false; + if( rowSpan>1 && rowsNum % rowSpan!==0 && rowSpan%rowsNum!==0 ) return false; + var cols = this.getSameStartPosXCells(cell); }, getPreviewMergedCellsNum:function (rowIndex, colIndex) { From 32e83de0f4083e03e2eef5db8eefb05e4d78d0a0 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 30 Jan 2013 09:45:26 +0800 Subject: [PATCH 11/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 265173918..e13837ab9 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1239,6 +1239,20 @@ UE.plugins['table'] = function () { } } }; + UE.commands['insertparagraphaftertable'] = { + queryCommandState:function () { + return getTableItemsByRange(this).cell ? 0 : -1; + }, + execCommand:function () { + var table = getTableItemsByRange(this).table; + if (table) { + var p = this.document.createElement("p"); + p.innerHTML = browser.ie ? ' ' : '
'; + domUtils.insertAfter(table,p); + this.selection.getRange().setStart(p, 0).setCursor(); + } + } + }; UE.commands['deletetable'] = { queryCommandState:function () { @@ -1281,6 +1295,12 @@ UE.plugins['table'] = function () { ci.setAttribute('align', align); } } + }, + queryCommandValue:function(cmd){ + var selectedTds = getSelectedArr(this); + if(selectedTds.length){ + return selectedTds[0].getAttribute('align'); + } } }; UE.commands['cellvalign'] = { @@ -1294,6 +1314,12 @@ UE.plugins['table'] = function () { ci.setAttribute('vAlign', vAlign); } } + }, + queryCommandValue:function(cmd){ + var selectedTds = getSelectedArr(this); + if(selectedTds.length){ + return selectedTds[0].getAttribute('vAlign'); + } } }; UE.commands['insertcaption'] = { From 6c0f52629cd0f4d05f0d4d73fd7d51820baf5e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=92?= Date: Wed, 30 Jan 2013 10:34:46 +0800 Subject: [PATCH 12/20] [fixed]by xuheng --- _src/plugins/table.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index e13837ab9..076a37ff3 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1871,7 +1871,8 @@ UE.plugins['table'] = function () { function getAverageHeight() { var averageHeight, rowNum, sumHeight = 0, tb = ut.table, - tbAttr = getDefaultValue(me, tb); + tbAttr = getDefaultValue(me, tb), + tdpadding = parseInt(domUtils.getComputedStyle(tb.getElementsByTagName('td')[0], "padding-top")); if (ut.isFullCol()) { var captionArr = domUtils.getElementsByTagName(tb, "caption"), @@ -1902,7 +1903,7 @@ UE.plugins['table'] = function () { if (browser.ie && browser.version < 9) { averageHeight = Math.ceil(sumHeight / rowNum); } else { - averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2; + averageHeight = Math.ceil(sumHeight / rowNum) - tbAttr.tdBorder * 2-tdpadding*2; } return averageHeight; } From 533efe78c03a0dec54f6e1280ecfb552a56c4933 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=81=92?= Date: Wed, 30 Jan 2013 10:39:10 +0800 Subject: [PATCH 13/20] [fixed]by xuheng --- _src/plugins/table.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 076a37ff3..600518299 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1947,6 +1947,15 @@ UE.plugins['table'] = function () { domUtils.setAttributes(cell, data); }); } + }, + queryCommandValue:function(cmd){ + var selectedTds = getSelectedArr(this); + if(selectedTds.length){ + return { + vAlign:selectedTds[0].getAttribute('vAlign'), + align:selectedTds[0].getAttribute('align') + } + } } }; //表格对齐方式 From 1ddffafb0555f93e92314e36e3f0922f0615f895 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 30 Jan 2013 14:48:53 +0800 Subject: [PATCH 14/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 81 +++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 41 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index e13837ab9..c7b8d7e75 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -62,7 +62,8 @@ UE.plugins['table'] = function () { "adaptbycustomer":1, "insertparagraph":1, "averagedistributecol":1, - "averagedistributerow":1 + "averagedistributerow":1, + "fixedwidth":1 }; me.ready(function () { utils.cssRule('table', @@ -314,7 +315,6 @@ UE.plugins['table'] = function () { domUtils.fillNode(me.document, td); } removeStyleSize(td, true); -// domUtils.removeAttributes(td, ['style']) }); }); } @@ -1751,19 +1751,7 @@ UE.plugins['table'] = function () { }, execCommand:function (cmd) { var me = this; - function resetTdWidth(table){ - var tds = table.getElementsByTagName("td"); - utils.each(tds, function (td) { - td.removeAttribute("width"); - }); - table.setAttribute('width', getTableWidth(me,needIEHack,getDefaultValue(me,table))); - setTimeout(function(){ - utils.each(tds,function(td){ - (td.colSpan ==1) && td.setAttribute("width",td.offsetWidth+""); - }) - },0) - } var tableItems = getTableItemsByRange(this), table = tableItems.table, @@ -1772,33 +1760,11 @@ UE.plugins['table'] = function () { if (cmd == 'adaptbywindow') { resetTdWidth(table); } else { - if(cell){ - var ut = getUETable(table), - preTds = ut.getSameEndPosCells(cell, "x"); - if (preTds.length) { - var flag = false; - utils.each(preTds,function(td){ - if(!isEmptyBlock(td)){ - flag = true; - return false; - } - }); - if(!flag)return; - utils.each(preTds, function (td) { - (td.colSpan==1) && td.removeAttribute("width"); - }); - table.style.width = ""; - table.removeAttribute("width"); - var defaultValue = getDefaultValue(me, table); - var width = table.offsetWidth, - bodyWidth = me.body.offsetWidth; - if (width > bodyWidth) { - table.setAttribute('width', getTableWidth(me, needIEHack, defaultValue)); - } - } - }else{ - resetTdWidth(table); - } + var cells = domUtils.getElementsByTagName(table,"td th"); + utils.each(cells,function(cell){ + cell.removeAttribute("width"); + }); + table.removeAttribute("width"); } } } @@ -2010,6 +1976,39 @@ UE.plugins['table'] = function () { } } }; + UE.commands['fixedwidth'] = { + queryCommandState:function(){ + return 0; + }, + execCommand:function(cmd){ + var rng = this.selection.getRange(), + table = domUtils.findParentByTagName(rng.startContainer, 'table'), + cells = domUtils.getElementsByTagName(table,"td th"); + + var tmpWidth =[]; + utils.each(cells,function(cell){ + if(cell.colSpan==1 && !cell.getAttribute("width") ) tmpWidth.push(cell.offsetWidth-20); + }); + utils.each(cells,function(cell){ + var width = tmpWidth.shift(); + if(cell.colSpan==1 && !cell.getAttribute("width") ) cell.setAttribute("width",(width < 22 ? 0: width)); + }) + table.setAttribute("width",table.offsetWidth); + } + + }; + function resetTdWidth(table){ + var tds = table.getElementsByTagName("td"); + utils.each(tds, function (td) { + td.removeAttribute("width"); + }); + table.setAttribute('width', getTableWidth(me,needIEHack,getDefaultValue(me,table))); + setTimeout(function(){ + utils.each(tds,function(td){ + (td.colSpan ==1) && td.setAttribute("width",td.offsetWidth+""); + }) + },0) + } /** * UE表格操作类 From 394b15214edaf1d817fda480256f3747505529c7 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 30 Jan 2013 14:59:49 +0800 Subject: [PATCH 15/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index c7b8d7e75..74f142778 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -477,7 +477,7 @@ UE.plugins['table'] = function () { } } } - h == 'h' && me.execCommand('adaptbytext'); + h == 'h' && me.execCommand('adaptcolbytext'); } } } @@ -1743,6 +1743,9 @@ UE.plugins['table'] = function () { }; } } + UE.commands["adaptcolbytext"] = { + + }; UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = { @@ -1751,8 +1754,6 @@ UE.plugins['table'] = function () { }, execCommand:function (cmd) { var me = this; - - var tableItems = getTableItemsByRange(this), table = tableItems.table, cell = tableItems.cell; From 7c48835041739dc16dde00fcd9232e1cf373b204 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 30 Jan 2013 15:29:13 +0800 Subject: [PATCH 16/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 74f142778..ca0247744 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -477,7 +477,23 @@ UE.plugins['table'] = function () { } } } - h == 'h' && me.execCommand('adaptcolbytext'); + if(h == 'h') { + var ut = getUETable(target), + cells = ut.getSameEndPosCells(target,"x"), + table = ut.table; + table.removeAttribute("width"); + 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); + }) + table.setAttribute("width",table.offsetWidth) + }) + + } } } } @@ -1743,9 +1759,6 @@ UE.plugins['table'] = function () { }; } } - UE.commands["adaptcolbytext"] = { - - }; UE.commands["adaptbytext"] = UE.commands["adaptbywindow"] = { From b1a35068a620ba0d46dbeec7d71cd218d2dcc268 Mon Sep 17 00:00:00 2001 From: taoqili Date: Wed, 30 Jan 2013 16:06:09 +0800 Subject: [PATCH 17/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 9ca9edacd..879924bb5 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1008,10 +1008,10 @@ UE.plugins['table'] = function () { start = domUtils.findParentByTagName(range.startContainer, ['td', 'th', 'caption'], true); end = domUtils.findParentByTagName(range.endContainer, ['td', 'th', 'caption'], true); if (start !== end) { - me.selection.clearRange() + me.selection && me.selection.clearRange() } } else { - me.selection.clearRange() + me.selection && me.selection.clearRange() } } mousedown = false; From b11c6b540008a1bf71818c704eabd2d0fdf763d9 Mon Sep 17 00:00:00 2001 From: taoqili Date: Thu, 31 Jan 2013 12:43:08 +0800 Subject: [PATCH 18/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 879924bb5..aa2810f9b 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -489,7 +489,7 @@ UE.plugins['table'] = function () { var width = cells[0].offsetWidth -20; utils.each(cells,function(cell){ cell.setAttribute("width",width); - }) + }); table.setAttribute("width",table.offsetWidth) }) @@ -1766,7 +1766,6 @@ UE.plugins['table'] = function () { return getTableItemsByRange(this).table ? 0 : -1 }, execCommand:function (cmd) { - var me = this; var tableItems = getTableItemsByRange(this), table = tableItems.table, cell = tableItems.cell; From 2d01d819f3cb1373555789a22853a00a1059bf6b Mon Sep 17 00:00:00 2001 From: taoqili Date: Fri, 1 Feb 2013 16:44:54 +0800 Subject: [PATCH 19/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index aa2810f9b..184cbeca1 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -71,10 +71,10 @@ UE.plugins['table'] = function () { '.selectTdClass{background-color:#edf5fa !important}' + 'table.noBorderTable td,table.noBorderTable th,table.noBorderTable caption{border:1px dashed #ddd !important}' + //插入的表格的默认样式 - 'table{line-height:22px; margin-bottom:10px;border-collapse:collapse;display:table;}' + - 'td,th{ background:white; padding: 0 10px;border: 1px solid #DDD;line-height: 22px;}' + - 'caption{border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' + - 'th{border-top:2px solid #BBB;background:#F7F7F7;}' + + 'table{ line-height:22px; margin-bottom:10px;border-collapse:collapse;display:table;}' + + 'td,th{ background:white; padding: 0 10px;line-height: 22px;}' + + 'caption{ border:1px dashed #DDD;border-bottom:0;padding:3px;text-align:center;}' + + 'th{ border-top:2px solid #BBB;background:#F7F7F7;}' + 'td p{margin:0;padding:0;}', me.document); var tableCopyList, isFullCol, isFullRow; @@ -623,7 +623,7 @@ UE.plugins['table'] = function () { if (isEmptyBlock(td)) { range.setStart(td, 0).setCursor(false, true) } else { - range.selectNodeContents(td).select(); + range.selectNodeContents(td).select(true); } state = me.queryCommandState(cmd); value = me.queryCommandValue(cmd); @@ -1202,7 +1202,7 @@ UE.plugins['table'] = function () { UE.commands['inserttable'] = { queryCommandState:function () { - return getTableItemsByRange(this).table ? -1 : 0; + return 0; }, execCommand:function (cmd, opt) { function createTable(opt, tableWidth, tdWidth) { @@ -1216,14 +1216,14 @@ UE.plugins['table'] = function () { } html.push('') } - return '' + html.join('') + '
' + return '' + html.join('') + '
' } if (!opt) { opt = utils.extend({}, { numCols:this.options.defaultCols, numRows:this.options.defaultRows, - tdvalign:this.options.tdvalign + 9898:this.options.tdvalign }) } var range = this.selection.getRange(), From 0a2534a811e42f17934ffcac17951724043530d5 Mon Sep 17 00:00:00 2001 From: taoqili Date: Fri, 1 Feb 2013 17:03:17 +0800 Subject: [PATCH 20/20] =?UTF-8?q?=E9=A2=84=E8=A7=88=E6=97=B6=E5=8E=BB?= =?UTF-8?q?=E9=99=A4=E8=A1=A8=E6=A0=BC=E6=A1=86=E9=80=89=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _src/plugins/table.js | 11 ++++++++--- dialogs/table/edittable.html | 10 ++++++++++ dialogs/table/edittable.js | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/_src/plugins/table.js b/_src/plugins/table.js index 184cbeca1..808126c34 100644 --- a/_src/plugins/table.js +++ b/_src/plugins/table.js @@ -1963,17 +1963,22 @@ UE.plugins['table'] = function () { queryCommandState:function () { return getTableItemsByRange(this).table ? 0 : -1 }, - execCommand:function (cmd, color) { + execCommand:function (cmd, opt) { var rng = this.selection.getRange(), table = domUtils.findParentByTagName(rng.startContainer, 'table'); + if (table) { var arr = domUtils.getElementsByTagName(table, "td").concat( domUtils.getElementsByTagName(table, "th"), domUtils.getElementsByTagName(table, "caption") ); - utils.each(arr, function (node) { - node.style.borderColor = color; + + domUtils.setAttributes(table,{ + border:opt.width, + borderColor:opt.color||"#ddd" }); + if(opt["style"]) table.style.borderStyle = opt["style"]; + } } }; diff --git a/dialogs/table/edittable.html b/dialogs/table/edittable.html index f9545d6ae..ac7ad901b 100644 --- a/dialogs/table/edittable.html +++ b/dialogs/table/edittable.html @@ -39,6 +39,15 @@

+
  • + 宽度 + +
  • +
  • + 样式 + +
  • +
    @@ -50,6 +59,7 @@

    +
    diff --git a/dialogs/table/edittable.js b/dialogs/table/edittable.js index 05c30e583..1a8ab7a95 100644 --- a/dialogs/table/edittable.js +++ b/dialogs/table/edittable.js @@ -179,7 +179,7 @@ } else { editor.queryCommandState("deletecaption") != -1 && editor.execCommand("deletecaption"); } - editor.execCommand("edittable", tone.value); + editor.execCommand("edittable", {color:tone.value,width:$G("J_width").value,"style":$G("J_style").value}); autoSizeContent.checked ? adaptByTextTable() : ""; autoSizePage.checked ? editor.execCommand("adaptbywindow") : "";