From 3a6511a530015813f7bfda5547f8fc9de750efcf Mon Sep 17 00:00:00 2001 From: Jetha Chan Date: Tue, 1 Apr 2014 12:40:33 +0800 Subject: [PATCH] MDL-44758 editor-atto: prevent table-in-table creation Prevent new table creation, displaying table context menu instead when cursor is within caption, when multiple cells are selected, when selection contains both nodes within and outside of the table, and when selection contains nodes from multiple tables. --- .../moodle-atto_table-button-debug.js | Bin 19203 -> 20438 bytes .../moodle-atto_table-button-min.js | Bin 7918 -> 8227 bytes .../moodle-atto_table-button.js | Bin 19203 -> 20438 bytes .../plugins/table/yui/src/button/js/button.js | 67 +++++++++++++----- 4 files changed, 51 insertions(+), 16 deletions(-) diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js index 9cf781fbf86ed49d2fac634c3c2d60d9aaed089f..fb51c1a83cc53ef994afc532a16bb3fd1bfbcbea 100644 GIT binary patch delta 1345 zcmbVMU2D`(5M|W|U6Fom+iY9Qv=x$-m{L(_EiEmjRbQ;2K1;fpZ9>y~L+(v0lv2e9 zK_4&Zqklo@kMPwe|ArsGz?qxuE|pTyJnWLWGiT1sIX7=V*1mtPefczYtBq+2E1=^< z1uu6|KPwU)?xgsfe>UjQYb~1-=c}38ylS?atM?Qf#;9Y=LFOQ&rc#6~%)@=u6cjQ- zz*mXVl$a2#paheSI%aU=+I^*Ewyrm%&?xj~RJPhmQmU*2Keu7cVgVdIA*5r*Gp`4n z6Ijbp7rB6=9Vt@`#qodeAZFB4=0VkL-u}P5fYk%&6r!yYPYRDmYr#=jOI+>FD!?|4 z6edD>=H|lm>AU9pOD7ML1LWZm+C`qzyr3{e!ji&=YM2o0vcamLs?|e>He1FSJrTRz z-DE|cNrlRXB*4I8camI@2CP zMUsvcyOOlzZE9l^jq^NX-VBVJ@rl6~y^(a7Q=(;fF(y{DDrwF||Ft?9mw=UfnW5j) zg?$uD+Dc_>!th)UxUJ=SFN*^K!&m!ayD6^~D7lYbDY_KknT5Lz1J0F4tbP!RHj-O% z&()Dn%k`lhW~``7Z+U?nxsdu)79ZX+F#iN1S`y zUoyY)Gd~a8v^qFM_kav33lTwB`c=yc+^17eu`JR^xEcgv1a!EEm_aJ#9^HfT-kPCi z<1#JVWHXNWwm4MplQZFZ!|(fe#rmMHG6}Vn%Y7b}=3_^i+TzHhwSwwefs(u)gjs4% S*KHu<^0btNYr2qA|=uPBaE0# zP#aZfziYA(4DVK}C^3kTC7GX=a#qEcRrz@z8ujd@x+s0OI*XM?_j?=5(1*%G9|vt( cKXK^IeWj~?n?_!L(rZ61&{w=NnZh*s0fd!qTmS$7 diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js index da3625dce3df9bffe81477897a5a2bb297a29583..a8aee067d8707c029d35f993a51a618f50c0c461 100644 GIT binary patch delta 550 zcma)(u}i~16vpXPY@I983TcFL2jS@4aHtf!=~A5>N=#l&AiXPhFFKS^{{ojxx{8CF z(8a$>T-?2Dn&P0~a>L!d@BO~-`{2*VZ|{vU(8X<_9OM`$noVv1$612GbqW{u7($v7 z>MOuZ2?vh|u=S(8=jfF~I+l0q-)A5)0>wjfzY8??CK~1Z1cy=}2t18S-BFSvs6o+b z9u}|7ujOwm2h&W1m`FiNJm4ZrQ*T3QCWsqLjV|?(*?CAIM2OC11e#E$!=XaC8-p%~Dhv4%l)4 hZE35Q-KU*eqxfuhR#&Z7t+?+rihBEC^|*Ig{{}6R#lrvq delta 181 zcmZ4N@XmI_4lec*&FZqmB8ABdIOXjE5{pvvO8oLuQZ+PnimZ!LOG=CK6!PpfQuXrl zQZ@24^%C=vQ;SRTi;6XrN-}g5N>Y?`6b&@>QWKLiG$y-pE1RmRX%yL}YS!wMWMmct z4YAiK(JM(z%1L!j&B?JX0t@TK7iZ*`hk!(VQ}aqSN+xr2OESX9bnb7PFY_+soLnp| Vzj=zdFe4+^WJ9T{&5Dvt>;ToyJ1zhK diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js index 9cf781fbf86ed49d2fac634c3c2d60d9aaed089f..fb51c1a83cc53ef994afc532a16bb3fd1bfbcbea 100644 GIT binary patch delta 1345 zcmbVMU2D`(5M|W|U6Fom+iY9Qv=x$-m{L(_EiEmjRbQ;2K1;fpZ9>y~L+(v0lv2e9 zK_4&Zqklo@kMPwe|ArsGz?qxuE|pTyJnWLWGiT1sIX7=V*1mtPefczYtBq+2E1=^< z1uu6|KPwU)?xgsfe>UjQYb~1-=c}38ylS?atM?Qf#;9Y=LFOQ&rc#6~%)@=u6cjQ- zz*mXVl$a2#paheSI%aU=+I^*Ewyrm%&?xj~RJPhmQmU*2Keu7cVgVdIA*5r*Gp`4n z6Ijbp7rB6=9Vt@`#qodeAZFB4=0VkL-u}P5fYk%&6r!yYPYRDmYr#=jOI+>FD!?|4 z6edD>=H|lm>AU9pOD7ML1LWZm+C`qzyr3{e!ji&=YM2o0vcamLs?|e>He1FSJrTRz z-DE|cNrlRXB*4I8camI@2CP zMUsvcyOOlzZE9l^jq^NX-VBVJ@rl6~y^(a7Q=(;fF(y{DDrwF||Ft?9mw=UfnW5j) zg?$uD+Dc_>!th)UxUJ=SFN*^K!&m!ayD6^~D7lYbDY_KknT5Lz1J0F4tbP!RHj-O% z&()Dn%k`lhW~``7Z+U?nxsdu)79ZX+F#iN1S`y zUoyY)Gd~a8v^qFM_kav33lTwB`c=yc+^17eu`JR^xEcgv1a!EEm_aJ#9^HfT-kPCi z<1#JVWHXNWwm4MplQZFZ!|(fe#rmMHG6}Vn%Y7b}=3_^i+TzHhwSwwefs(u)gjs4% S*KHu<^0btNYr2qA|=uPBaE0# zP#aZfziYA(4DVK}C^3kTC7GX=a#qEcRrz@z8ujd@x+s0OI*XM?_j?=5(1*%G9|vt( cKXK^IeWj~?n?_!L(rZ61&{w=NnZh*s0fd!qTmS$7 diff --git a/lib/editor/atto/plugins/table/yui/src/button/js/button.js b/lib/editor/atto/plugins/table/yui/src/button/js/button.js index f0e52b76d44..ee9f31a5c80 100644 --- a/lib/editor/atto/plugins/table/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/table/yui/src/button/js/button.js @@ -148,30 +148,27 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi * @private */ _displayTableEditor: function(e) { - var selection = this.get('host').getSelectionParentNode(), - cell; - - if (!selection) { - // We don't have a current selection at all, so show the standard dialogue. - return this._displayDialogue(e); - } - - // Check all of the table cells found in the selection. - Y.one(selection).ancestors('th, td', true).each(function(node) { - if (this.editor.contains(node)) { - cell = node; - } - }, this); - + var cell = this._getSuitableTableCell(); if (cell) { // Add the cell to the EventFacade to save duplication in when showing the menu. e.tableCell = cell; return this._showTableMenu(e); } - return this._displayDialogue(e); }, + /** + * Returns whether or not the parameter node exists within the editor. + * + * @method _stopAtContentEditableFilter + * @param {Node} node + * @private + * @return {boolean} whether or not the parameter node exists within the editor. + */ + _stopAtContentEditableFilter: function(node) { + this.editor.contains(node); + }, + /** * Return the dialogue content for the tool, attaching any required * events. @@ -194,6 +191,44 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi return this._content; }, + /** + * Given the current selection, return a table cell suitable for table editing + * purposes, i.e. the first table cell selected, or the first cell in the table + * that the selection exists in, or null if not within a table. + * + * @method _getSuitableTableCell + * @private + * @return {Node} suitable target cell, or null if not within a table + */ + _getSuitableTableCell: function() { + var targetcell = null, + host = this.get('host'); + + host.getSelectedNodes().some(function (node) { + if (node.ancestor('td, th, caption', true, this._stopAtContentEditableFilter)) { + targetcell = node; + + var caption = node.ancestor('caption', true, this._stopAtContentEditableFilter); + if (caption) { + var table = caption.get('parentNode'); + if (table) { + targetcell = table.one('td, th'); + } + } + + // Once we've found a cell to target, we shouldn't need to keep looking. + return true; + } + }); + + if (targetcell) { + var selection = host.getSelectionFromNode(targetcell); + host.setSelection(selection); + } + + return targetcell; + }, + /** * Handle creation of a new table. * -- 2.43.0