JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4b
[ckeditor.git] / _source / plugins / tabletools / plugin.js
index 1f1f4d1..0ef39f0 100644 (file)
@@ -400,51 +400,6 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                range.select( true );\r
        }\r
 \r
-       function buildTableMap( table )\r
-       {\r
-\r
-               var aRows = table.$.rows ;\r
-\r
-               // Row and Column counters.\r
-               var r = -1 ;\r
-\r
-               var aMap = [];\r
-\r
-               for ( var i = 0 ; i < aRows.length ; i++ )\r
-               {\r
-                       r++ ;\r
-                       !aMap[r] && ( aMap[r] = [] );\r
-\r
-                       var c = -1 ;\r
-\r
-                       for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
-                       {\r
-                               var oCell = aRows[i].cells[j] ;\r
-\r
-                               c++ ;\r
-                               while ( aMap[r][c] )\r
-                                       c++ ;\r
-\r
-                               var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
-                               var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
-\r
-                               for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
-                               {\r
-                                       if ( !aMap[r + rs] )\r
-                                               aMap[r + rs] = new Array() ;\r
-\r
-                                       for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
-                                       {\r
-                                               aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
-                                       }\r
-                               }\r
-\r
-                               c += iColSpan - 1 ;\r
-                       }\r
-               }\r
-               return aMap ;\r
-       }\r
-\r
        function cellInRow( tableMap, rowIndex, cell )\r
        {\r
                var oRow = tableMap[ rowIndex ];\r
@@ -498,7 +453,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var     cell,\r
                        firstCell = cells[ 0 ],\r
                        table = firstCell.getAscendant( 'table' ),\r
-                       map = buildTableMap( table ),\r
+                       map = CKEDITOR.tools.buildTableMap( table ),\r
                        mapHeight = map.length,\r
                        mapWidth = map[ 0 ].length,\r
                        startRow = firstCell.getParent().$.rowIndex,\r
@@ -633,7 +588,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var cell = cells[ 0 ],\r
                        tr = cell.getParent(),\r
                        table = tr.getAscendant( 'table' ),\r
-                       map = buildTableMap( table ),\r
+                       map = CKEDITOR.tools.buildTableMap( table ),\r
                        rowIndex = tr.$.rowIndex,\r
                        colIndex = cellInRow( map, rowIndex, cell ),\r
                        rowSpan = cell.$.rowSpan,\r
@@ -709,7 +664,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                var cell = cells[ 0 ],\r
                        tr = cell.getParent(),\r
                        table = tr.getAscendant( 'table' ),\r
-                       map = buildTableMap( table ),\r
+                       map = CKEDITOR.tools.buildTableMap( table ),\r
                        rowIndex = tr.$.rowIndex,\r
                        colIndex = cellInRow( map, rowIndex, cell ),\r
                        colSpan = cell.$.colSpan,\r
@@ -1088,7 +1043,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                        {\r
                                editor.contextMenu.addListener( function( element, selection )\r
                                        {\r
-                                               if ( !element )\r
+                                               if ( !element || element.isReadOnly() )\r
                                                        return null;\r
 \r
                                                while ( element )\r
@@ -1114,3 +1069,52 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
        };\r
        CKEDITOR.plugins.add( 'tabletools', CKEDITOR.plugins.tabletools );\r
 })();\r
+\r
+/**\r
+ * Create a two-dimension array that reflects the actual layout of table cells,\r
+ * with cell spans, with mappings to the original td elements.\r
+ * @param table {CKEDITOR.dom.element}\r
+ */\r
+CKEDITOR.tools.buildTableMap = function ( table )\r
+{\r
+       var aRows = table.$.rows ;\r
+\r
+       // Row and Column counters.\r
+       var r = -1 ;\r
+\r
+       var aMap = [];\r
+\r
+       for ( var i = 0 ; i < aRows.length ; i++ )\r
+       {\r
+               r++ ;\r
+               !aMap[r] && ( aMap[r] = [] );\r
+\r
+               var c = -1 ;\r
+\r
+               for ( var j = 0 ; j < aRows[i].cells.length ; j++ )\r
+               {\r
+                       var oCell = aRows[i].cells[j] ;\r
+\r
+                       c++ ;\r
+                       while ( aMap[r][c] )\r
+                               c++ ;\r
+\r
+                       var iColSpan = isNaN( oCell.colSpan ) ? 1 : oCell.colSpan ;\r
+                       var iRowSpan = isNaN( oCell.rowSpan ) ? 1 : oCell.rowSpan ;\r
+\r
+                       for ( var rs = 0 ; rs < iRowSpan ; rs++ )\r
+                       {\r
+                               if ( !aMap[r + rs] )\r
+                                       aMap[r + rs] = [];\r
+\r
+                               for ( var cs = 0 ; cs < iColSpan ; cs++ )\r
+                               {\r
+                                       aMap[r + rs][c + cs] = aRows[i].cells[j] ;\r
+                               }\r
+                       }\r
+\r
+                       c += iColSpan - 1 ;\r
+               }\r
+       }\r
+       return aMap ;\r
+};\r