diff --git a/lib/editor/atto/plugins/table/lang/en/atto_table.php b/lib/editor/atto/plugins/table/lang/en/atto_table.php
index 950e076a1bf..be079497e04 100644
--- a/lib/editor/atto/plugins/table/lang/en/atto_table.php
+++ b/lib/editor/atto/plugins/table/lang/en/atto_table.php
@@ -45,15 +45,22 @@ $string['borders'] = 'Borders';
$string['bordersize'] = 'Size of borders';
$string['borderstyles'] = 'Style of borders';
$string['borderstyles_desc'] = 'Allowed border styles, separated by commas';
-$string['borderstyles_default'] = 'solid,dashed,dotted';
$string['caption'] = 'Caption';
$string['captionposition'] = 'Caption position';
$string['columns'] = 'Columns';
$string['createtable'] = 'Create table';
$string['deletecolumn'] = 'Delete column';
$string['deleterow'] = 'Delete row';
+$string['dashed'] = 'Dashed';
+$string['dotted'] = 'Dotted';
+$string['double'] = 'Double';
$string['edittable'] = 'Edit table';
+$string['groove'] = 'Groove';
$string['headers'] = 'Define headers on';
+$string['hidden'] = 'Hidden';
+$string['inherit'] = 'Inherit';
+$string['initial'] = 'Initial';
+$string['inset'] = 'Inset';
$string['movecolumnleft'] = 'Move column left';
$string['movecolumnright'] = 'Move column right';
$string['moverowdown'] = 'Move row down';
@@ -63,10 +70,14 @@ $string['none'] = 'None';
$string['numberofcolumns'] = 'Number of columns';
$string['numberofrows'] = 'Number of rows';
$string['outer'] = 'Around table';
+$string['outset'] = 'Outset';
$string['pluginname'] = 'Table';
+$string['ridge'] = 'Ridge';
$string['rows'] = 'Rows';
$string['settings'] = 'Table settings';
-$string['updatetable'] = 'Update table';
-$string['width'] = 'Table width (in %)';
+$string['solid'] = 'Solid';
$string['themedefault'] = 'Theme default';
$string['transparent'] = 'Transparent';
+$string['unset'] = 'Unset';
+$string['updatetable'] = 'Update table';
+$string['width'] = 'Table width (in %)';
diff --git a/lib/editor/atto/plugins/table/lib.php b/lib/editor/atto/plugins/table/lib.php
index d865713b738..d729a2c4d20 100644
--- a/lib/editor/atto/plugins/table/lib.php
+++ b/lib/editor/atto/plugins/table/lib.php
@@ -60,8 +60,19 @@ function atto_table_strings_for_js() {
'width',
'outer',
'noborder',
- 'transparent',
- 'themedefault'),
+ 'inherit',
+ 'themedefault',
+ 'initial',
+ 'unset',
+ 'hidden',
+ 'dotted',
+ 'dashed',
+ 'solid',
+ 'double',
+ 'groove',
+ 'ridge',
+ 'inset',
+ 'outset'),
'atto_table');
$PAGE->requires->strings_for_js(array('top',
diff --git a/lib/editor/atto/plugins/table/settings.php b/lib/editor/atto/plugins/table/settings.php
index 4462a954384..24406f40a12 100644
--- a/lib/editor/atto/plugins/table/settings.php
+++ b/lib/editor/atto/plugins/table/settings.php
@@ -50,16 +50,18 @@ if ($ADMIN->fulltree) {
$name = new lang_string('borderstyles', 'atto_table');
$desc = new lang_string('borderstyles_desc', 'atto_table');
- $default = ['none' => 'none',
- 'hidden' => 'hidden',
- 'dotted' => 'dotted',
- 'dashed' => 'dashed',
- 'solid' => 'solid',
- 'double' => 'double',
- 'groove' => 'groove',
- 'ridge' => 'ridge',
- 'inset' => 'inset',
- 'outset' => 'outset'];
+ $default = array('initial' => new lang_string('initial', 'atto_table'),
+ 'unset' => new lang_string('unset', 'atto_table'),
+ 'none' => new lang_string('none', 'atto_table'),
+ 'hidden' => new lang_string('hidden', 'atto_table'),
+ 'dotted' => new lang_string('dotted', 'atto_table'),
+ 'dashed' => new lang_string('dashed', 'atto_table'),
+ 'solid' => new lang_string('solid', 'atto_table'),
+ 'double' => new lang_string('double', 'atto_table'),
+ 'groove' => new lang_string('groove', 'atto_table'),
+ 'ridge' => new lang_string('ridge', 'atto_table'),
+ 'inset' => new lang_string('inset', 'atto_table'),
+ 'outset' => new lang_string('outset', 'atto_table'));
$setting = new admin_setting_configmultiselect('atto_table/borderstyles',
$name,
diff --git a/lib/editor/atto/plugins/table/tests/behat/table.feature b/lib/editor/atto/plugins/table/tests/behat/table.feature
index 4ae0c0cddf6..05be36378ba 100644
--- a/lib/editor/atto/plugins/table/tests/behat/table.feature
+++ b/lib/editor/atto/plugins/table/tests/behat/table.feature
@@ -35,6 +35,71 @@ Feature: Atto tables
And I press "Save changes"
Then ".blog_entry table caption" "css_element" should be visible
+ @javascript
+ Scenario: Check table setting defaults on new table
+ Given the following config values are set as admin:
+ | config | value | plugin |
+ | allowborders | 1 | atto_table |
+ | allowborderstyles | 1 | atto_table |
+ | allowbordersize | 1 | atto_table |
+ | allowbordercolour | 1 | atto_table |
+ | allowbackgroundcolour | 1 | atto_table |
+ | allowwidth | 1 | atto_table |
+ And I log in as "admin"
+ And I follow "Profile" in the user menu
+ And I follow "Blog entries"
+ And I follow "Add a new entry"
+ And I set the field "Entry title" to "How to make a table"
+ And I set the field "Blog entry body" to "Table test"
+ And I select the text in the "Blog entry body" Atto editor
+ And I click on "Show more buttons" "button"
+ When I click on "Table" "button"
+ Then the ".moodle-dialogue-base .atto_form .borderstyle" "css_element" should be disabled
+ And the ".moodle-dialogue-base .atto_form .bordersize" "css_element" should be disabled
+ And the "borderColour" "radio" should be disabled
+ And the field "borders" matches value "default"
+ And the field "Theme default" matches value "1"
+ And the field "Table width (in %)" matches value ""
+
+ @javascript
+ Scenario: Edit a table restores settings
+ Given the following config values are set as admin:
+ | config | value | plugin |
+ | allowborders | 1 | atto_table |
+ | allowborderstyles | 1 | atto_table |
+ | allowbordersize | 1 | atto_table |
+ | allowbordercolour | 1 | atto_table |
+ | allowbackgroundcolour | 1 | atto_table |
+ | allowwidth | 1 | atto_table |
+ And I log in as "admin"
+ And I follow "Profile" in the user menu
+ And I follow "Blog entries"
+ And I follow "Add a new entry"
+ And I set the field "Entry title" to "How to make a table"
+ And I set the field "Blog entry body" to "
"
+ And I select the text in the "Blog entry body" Atto editor
+ And I click on "Show more buttons" "button"
+ And I click on "Table" "button"
+ And I click on "Edit table" "link"
+ And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
+ And I set the field "Table width (in %)" to "100"
+ And I set the field "Borders" to "Around table"
+ And I set the field "Style of borders" to "Dashed"
+ And I set the field "Size of borders" to "2"
+ And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .bordercolour" "css_element"
+ And I press "Update table"
+ And I select the text in the "Blog entry body" Atto editor
+ And I click on "Table" "button"
+ When I click on "Edit table" "link"
+ # Check that the background colour is set correctly.
+ Then the field with xpath "//label/input[@name='backgroundColour' and @value='#FFFFFF']" matches value "1"
+ And the field "Table width (in %)" matches value "100"
+ And the field "Borders" matches value "Around table"
+ And the field "Style of borders" matches value "dashed"
+ And the field "Size of borders" matches value "2"
+ # Check that the border colour is set correctly.
+ And the field with xpath "//label/input[@name='borderColour' and @value='#FFFFFF']" matches value "1"
+
@javascript
Scenario: Create a table with background colour and width with border settings off
Given the following config values are set as admin:
@@ -67,7 +132,8 @@ Feature: Atto tables
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"background-color:#FFFFFF;width:100%;\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
@javascript
Scenario: Edit a table with background colour and width with border settings off
@@ -102,7 +168,8 @@ Feature: Atto tables
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"width:100%;background-color:rgb(255,255,255);\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
@javascript
Scenario: Create a table with background colour and width with borders on
@@ -137,7 +204,8 @@ Feature: Atto tables
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:1px solid #FFFFFF;background-color:#FFFFFF;width:100%;\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
@javascript
Scenario: Edit a table with background colour and width with borders on
@@ -167,13 +235,14 @@ Feature: Atto tables
Then ".moodle-dialogue-base .atto_form .customwidth" "css_element" should exist
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
- And I set the field "Borders" to "Around table"
+ And I set the field "Borders" to "Around each cell"
And I press "Update table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:1px solid rgb(255,255,255);width:100%;background-color:rgb(255,255,255);\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
@javascript
Scenario: Create a table with background colour and width with borders and border styling on
@@ -203,13 +272,15 @@ Feature: Atto tables
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I press "Create table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:1px dashed #FFFFFF;background-color:#FFFFFF;width:100%;\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "border-style:dashed;"
@javascript
Scenario: Edit a table with background colour and width with borders and border styling on
@@ -240,13 +311,15 @@ Feature: Atto tables
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I press "Update table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:1px dashed rgb(255,255,255);width:100%;background-color:rgb(255,255,255);\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "border-style:dashed;"
@javascript
Scenario: Create a table with background colour and width with borders, border styling, and border size on
@@ -276,14 +349,17 @@ Feature: Atto tables
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I set the field "Size of borders" to "2"
And I press "Create table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:2px dashed #FFFFFF;background-color:#FFFFFF;width:100%;\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "border-style:dashed;"
+ And I should see "border-width:2px;"
@javascript
Scenario: Edit a table with background colour and width with borders, border styling, and border size on
@@ -314,14 +390,17 @@ Feature: Atto tables
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I set the field "Size of borders" to "2"
And I press "Update table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:2px dashed rgb(255,255,255);width:100%;background-color:rgb(255,255,255);\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "border-style:dashed;"
+ And I should see "border-width:2px;"
@javascript
Scenario: Create a table with all settings on
@@ -351,7 +430,7 @@ Feature: Atto tables
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I set the field "Size of borders" to "2"
And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .bordercolour" "css_element"
And I press "Create table"
@@ -359,7 +438,11 @@ Feature: Atto tables
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:2px dashed #FFFFFF;background-color:#FFFFFF;width:100%;\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "dashed"
+ And I should see "2px"
+ And I should see "rgb(255,255,255)"
@javascript
Scenario: Edit a table with background colour and width with borders, border styling, and border size on
@@ -387,15 +470,19 @@ Feature: Atto tables
Then ".moodle-dialogue-base .atto_form .bordercolour" "css_element" should exist
Then ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element" should exist
Then ".moodle-dialogue-base .atto_form .customwidth" "css_element" should exist
- And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
+ And I click on "FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .backgroundcolour" "css_element"
And I set the field "Table width (in %)" to "100"
And I set the field "Borders" to "Around table"
- And I set the field "Style of borders" to "dashed"
+ And I set the field "Style of borders" to "Dashed"
And I set the field "Size of borders" to "2"
- And I click on "#FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .bordercolour" "css_element"
+ And I click on "FFFFFF" "radio" in the ".moodle-dialogue-base .atto_form .bordercolour" "css_element"
And I press "Update table"
And I press "Save changes"
And I follow "Edit"
And I click on "Show more buttons" "button"
And I click on "HTML" "button"
- Then I should see "style=\"border:2px dashed rgb(255,255,255);width:100%;background-color:rgb(255,255,255);\""
+ Then I should see "background-color:rgb(255,255,255);"
+ And I should see "width:100%;"
+ And I should see "dashed"
+ And I should see "2px"
+ And I should see "rgb(255,255,255)"
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 1beb527dec2..d5e3bba597f 100644
--- 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
@@ -35,7 +35,7 @@ YUI.add('moodle-atto_table-button', function (Y, NAME) {
var COMPONENT = 'atto_table',
DEFAULT = {
- BORDERSTYLE: 'solid',
+ BORDERSTYLE: 'inherit',
BORDERWIDTH: '1'
},
DIALOGUE = {
@@ -78,9 +78,8 @@ var COMPONENT = 'atto_table',
'{{get_string "appearance" component}} ' +
'{{#if allowBorders}}' +
'{{get_string "borders" component}} ' +
- '' +
+ '' +
'{{get_string "themedefault" component}}' + ' ' +
- '{{get_string "noborder" component}}' + ' ' +
'{{get_string "outer" component}}' + ' ' +
'{{get_string "all" component}}' + ' ' +
' ' +
@@ -88,9 +87,10 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderStyles}}' +
'' +
'{{get_string "borderstyles" component}} ' +
- '' +
+ '' +
+ '{{get_string "inherit" component}} ' +
'{{#each borderStyles}}' +
- '' + '{{this}}' + ' ' +
+ '' + '{{get_string this ../component}}' + ' ' +
'{{/each}}' +
' ' +
' ' +
@@ -98,7 +98,7 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderSize}}' +
'' +
'{{get_string "bordersize" component}} ' +
- ' ' +
'{{CSS.BORDERSIZEUNIT}} ' +
' ' +
@@ -112,10 +112,10 @@ var COMPONENT = 'atto_table',
'style="background-color:transparent;color:transparent">' +
' ' +
+ 'type="radio" name="borderColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
'' +
'{{#each availableColours}}' +
'' +
' ' +
+ 'type="radio" name="backgroundColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
' ' +
'{{#each availableColours}}' +
@@ -289,6 +289,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue.
dialogue.set('bodyContent', this._getDialogueContent(false))
.show();
+
+ this._updateAvailableSettings();
}
},
@@ -334,7 +336,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/
_getDialogueContent: function(edit) {
var template = Y.Handlebars.compile(TEMPLATE);
- var availableColours = this.get('availableColors');
+ var allowBorders = this.get('allowBorders');
this._content = Y.Node.create(template({
CSS: CSS,
@@ -343,13 +345,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
edit: edit,
nonedit: !edit,
allowStyling: this.get('allowStyling'),
- allowBorders: this.get('allowBorders'),
+ allowBorders: allowBorders,
allowBorderStyles: this.get('allowBorderStyles'),
borderStyles: this.get('borderStyles'),
allowBorderSize: this.get('allowBorderSize'),
allowBorderColour: this.get('allowBorderColour'),
allowBackgroundColour: this.get('allowBackgroundColour'),
- availableColours: availableColours,
+ availableColours: this.get('availableColors'),
allowWidth: this.get('allowWidth')
}));
@@ -360,9 +362,48 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this._content.one('.submit').on('click', this._setTable, this);
}
+ if (allowBorders) {
+ this._content.one('[name="borders"]').on('change', this._updateAvailableSettings, this);
+ }
+
return this._content;
},
+ /**
+ * Disables options within the dialogue if they shouldn't be available.
+ * E.g.
+ * If borders are set to "Theme default" then the border size, style and
+ * colour options are disabled.
+ *
+ * @method _updateAvailableSettings
+ * @private
+ */
+ _updateAvailableSettings: function() {
+ var tableForm = this._content,
+ enableBorders = tableForm.one('[name="borders"]'),
+ borderStyle = tableForm.one('[name="borderstyles"]'),
+ borderSize = tableForm.one('[name="bordersize"]'),
+ borderColour = tableForm.all('[name="borderColour"]'),
+ disabledValue = 'removeAttribute';
+
+ if (enableBorders.get('value') === 'default') {
+ disabledValue = 'setAttribute';
+ }
+
+ if (borderStyle) {
+ borderStyle[disabledValue]('disabled');
+ }
+
+ if (borderSize) {
+ borderSize[disabledValue]('disabled');
+ }
+
+ if (borderColour) {
+ borderColour[disabledValue]('disabled');
+ }
+
+ },
+
/**
* 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
@@ -436,10 +477,6 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderstyle,
bordercolour,
backgroundcolour,
- backgroundcolourvalue = '#FFFFFF',
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
table,
width,
captionnode;
@@ -461,51 +498,16 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolour = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.SELECTEDBACKGROUNDCOLOUR);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (backgroundcolour) {
- backgroundcolourvalue = backgroundcolour.get('value');
- }
-
table = this._lastTarget.ancestor('table');
- // Clear the inline border styling
- table.removeAttribute('style');
- table.all('td, th').each(function() {
- this.removeAttribute('style');
+ this._setAppearance(table, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
});
- if (borders) {
- if (borders.get('value') === 'outer') {
- table.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- } else if (borders.get('value') === 'all') {
- table.all('td, th').each(function() {
- this.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- });
- } else if (borders.get('value') === 'none') {
- table.setStyle('border', 'none');
- }
- }
-
- if (width && width.get('value')) {
- table.setStyle('width', width.get('value') + CSS.WIDTHUNIT);
- }
-
- if (backgroundcolourvalue !== '') {
- table.setStyle('background-color', backgroundcolourvalue);
- }
-
captionnode = table.one('caption');
if (!captionnode) {
captionnode = Y.Node.create(' ');
@@ -589,14 +591,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
var caption,
captionposition,
borders,
- bordertable = '',
- bordercell = '',
bordersize,
borderstyle,
bordercolour,
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
rows,
cols,
headers,
@@ -624,52 +621,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (borders) {
- if (borders.get('value') === 'outer') {
- bordertable = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- } else if (borders.get('value') === 'all') {
- bordercell = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- }
- }
-
- if (backgroundcolour) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) +
- 'background-color: ' + backgroundcolour.get('value') + ';"';
- } else {
- bordertable = ' style="background-color: ' + backgroundcolour.get('value') + ';"';
- }
- }
-
- if (width && width.get('value')) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) + 'width: ' +
- width.get('value') + CSS.WIDTHUNIT + ';"';
- } else {
- bordertable = ' style="width: ' + width.get('value') + CSS.WIDTHUNIT + ';"';
- }
- }
-
// Set the selection.
this.get('host').setSelection(this._currentSelection);
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n";
- tablehtml = ' ' + nl + '' + nl;
+ var tableId = Y.guid();
+ tablehtml = ' ' + nl + '' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
@@ -681,7 +639,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
i = 1;
tablehtml += '' + nl + '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
tablehtml += ' ' + nl + ' ' + nl;
}
@@ -690,9 +648,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
tablehtml += '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
if (j === 0 && (headers.get('value') === 'rows' || headers.get('value') === 'both')) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
} else {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
}
tablehtml += ' ' + nl;
@@ -702,6 +660,17 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.get('host').insertContentAtFocusPoint(tablehtml);
+ var tableNode = Y.one('#' + tableId);
+ this._setAppearance(tableNode, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
+ });
+ tableNode.removeAttribute('id');
+
// Mark the content as updated.
this.markUpdated();
},
@@ -1148,6 +1117,73 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
return false;
},
+ /**
+ * Set the appropriate styles on the given table node according to
+ * the provided configuration.
+ *
+ * @method _setAppearance
+ * @param {Node} The table node to be modified.
+ * @param {Object} Configuration object (associative array) containing the form nodes for
+ * border styling.
+ * @private
+ */
+ _setAppearance: function(tableNode, configuration) {
+ var borderhex,
+ borderSizeValue,
+ borderStyleValue,
+ backgroundcolourvalue;
+
+ if (configuration.borderColour) {
+ borderhex = configuration.borderColour.get('value');
+ }
+
+ if (configuration.borderSize) {
+ borderSizeValue = configuration.borderSize.get('value');
+ }
+
+ if (configuration.borderStyle) {
+ borderStyleValue = configuration.borderStyle.get('value');
+ }
+
+ if (configuration.backgroundColour) {
+ backgroundcolourvalue = configuration.backgroundColour.get('value');
+ }
+
+ // Clear the inline border styling
+ tableNode.removeAttribute('style');
+ tableNode.all('td, th').each(function(cell) {
+ cell.removeAttribute('style');
+ }, this);
+
+ if (configuration.borders) {
+ if (configuration.borders.get('value') === 'outer') {
+ tableNode.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ tableNode.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ tableNode.setStyle('borderColor', borderhex);
+ }
+ } else if (configuration.borders.get('value') === 'all') {
+ tableNode.all('td, th').each(function(cell) {
+ cell.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ cell.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ cell.setStyle('borderColor', borderhex);
+ }
+ }, this);
+ }
+ }
+
+ if (backgroundcolourvalue !== 'none') {
+ tableNode.setStyle('background-color', backgroundcolourvalue);
+ }
+
+ if (configuration.width && configuration.width.get('value')) {
+ tableNode.setStyle('width', configuration.width.get('value') + CSS.WIDTHUNIT);
+ }
+ },
+
/**
* Edit table (show the dialogue).
*
@@ -1174,7 +1210,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolours = node.all(SELECTORS.BACKGROUNDCOLOURS),
width = node.one(SELECTORS.WIDTH),
table = this._lastTarget.ancestor('table'),
- captionnode = table.one('caption');
+ captionnode = table.one('caption'),
+ hexColour,
+ matchedInput;
if (captionnode) {
captioninput.set('value', captionnode.getHTML());
@@ -1193,9 +1231,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captionpositioninput.set('value', '');
}
- if (table.getStyle('background-color') !== 'transparent' && this.get('allowBackgroundColour')) {
- var hexColour = Y.Color.toHex(table.getStyle('background-color'));
- var matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
+ if (table.getStyle('background-color') && this.get('allowBackgroundColour')) {
+ hexColour = Y.Color.toHex(table.getStyle('background-color'));
+ matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1207,11 +1245,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderConfiguration = this._getBorderConfiguration(table);
if (borderConfiguration) {
- if (borderConfiguration.borderStyle && borderConfiguration.borderStyle === 'none') {
- borderValue = 'none';
- } else {
- borderValue = 'outer';
- }
+ borderValue = 'outer';
} else {
borderConfiguration = this._getBorderConfiguration(table.one('td'));
if (borderConfiguration) {
@@ -1226,8 +1260,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
bordersize.set('value', borderSize);
borderinput.set('value', borderValue);
- var hexColour = borderConfiguration.borderColor;
- var matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
+ hexColour = borderConfiguration.borderColor;
+ matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1244,6 +1278,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
headersinput.set('value', headersvalue);
dialogue.set('bodyContent', node).show();
+ this._updateAvailableSettings();
},
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 eea33a8ffdc..a6b446ac166 100644
--- 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
@@ -1,4 +1,4 @@
-YUI.add("moodle-atto_table-button",function(e,t){var n="atto_table",r={BORDERSTYLE:"solid",BORDERWIDTH:"1"},i={WIDTH:"450px"},s='',o={CAPTION:"caption",CAPTIONPOSITION:"captionposition",HEADERS:"headers",ROWS:"rows",COLUMNS:"columns",SUBMIT:"submit",FORM:"atto_form",BORDERS:"borders",BORDERSIZE:"bordersize",BORDERSIZEUNIT:"px",BORDERCOLOUR:"bordercolour",BORDERSTYLE:"borderstyle",BACKGROUNDCOLOUR:"backgroundcolour",WIDTH:"customwidth",WIDTHUNIT:"%",AVAILABLECOLORS:"availablecolors",COLOURROW:"colourrow"},u={CAPTION:"."+o.CAPTION,CAPTIONPOSITION:"."+o.CAPTIONPOSITION,HEADERS:"."+o.HEADERS,ROWS:"."+o.ROWS,COLUMNS:"."+o.COLUMNS,SUBMIT:"."+o.SUBMIT,BORDERS:"."+o.BORDERS,BORDERSIZE:"."+o.BORDERSIZE,BORDERCOLOURS:"."+o.BORDERCOLOUR+' input[name="borderColour"]',SELECTEDBORDERCOLOUR:"."+o.BORDERCOLOUR+' input[name="borderColour"]:checked',BORDERSTYLE:"."+o.BORDERSTYLE,BACKGROUNDCOLOURS
-:"."+o.BACKGROUNDCOLOUR+' input[name="backgroundColour"]',SELECTEDBACKGROUNDCOLOUR:"."+o.BACKGROUNDCOLOUR+' input[name="backgroundColour"]:checked',FORM:".atto_form",WIDTH:"."+o.WIDTH,AVAILABLECOLORS:"."+o.AVAILABLECOLORS};e.namespace("M.atto_table").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_contextMenu:null,_lastTarget:null,_menuOptions:null,initializer:function(){this.addButton({icon:"e/table",callback:this._displayTableEditor,tags:"table"}),e.UA.gecko&&(document.execCommand("enableInlineTableEditing",!1,!1),document.execCommand("enableObjectResizing",!1,!1))},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection!==!1&&!this._currentSelection.collapsed){var e=this.getDialogue({headerContent:M.util.get_string("createtable",n),focusAfterHide:!0,focusOnShowSelector:u.CAPTION,width:i.WIDTH});e.set("bodyContent",this._getDialogueContent(!1)).show()}},_displayTableEditor:function(e){var t=this._getSuitableTableCell();return t?(e.tableCell=t,this._showTableMenu(e)):this._displayDialogue(e)},_stopAtContentEditableFilter:function(e){this.editor.contains(e)},_getDialogueContent:function(t){var r=e.Handlebars.compile(s),i=this.get("availableColors");return this._content=e.Node.create(r({CSS:o,elementid:this.get("host").get("elementid"),component:n,edit:t,nonedit:!t,allowStyling:this.get("allowStyling"),allowBorders:this.get("allowBorders"),allowBorderStyles:this.get("allowBorderStyles"),borderStyles:this.get("borderStyles"),allowBorderSize:this.get("allowBorderSize"),allowBorderColour:this.get("allowBorderColour"),allowBackgroundColour:this.get("allowBackgroundColour"),availableColours:i,allowWidth:this.get("allowWidth")})),t?this._content.one(".submit").on("click",this._updateTable,this):this._content.one(".submit").on("click",this._setTable,this),this._content},_getSuitableTableCell:function(){var e=null,t=this.get("host");t.getSelectedNodes().some(function(t){if(t.ancestor("td, th, caption",!0,this._stopAtContentEditableFilter)){e=t;var n=t.ancestor("caption",!0,this._stopAtContentEditableFilter);if(n){var r=n.get("parentNode");r&&(e=r.one("td, th"))}return!0}});if(e){var n=t.getSelectionFromNode(e);t.setSelection(n)}return e},_changeNodeType:function(t,n){var r=e.Node.create("<"+n+">"+n+">");return r.setAttrs(t.getAttrs()),t.get("childNodes").each(function(e){r.append(e.remove())}),t.replace(r),r},_updateTable:function(t){var n,r,i,s,a,f,l,c,h="#FFFFFF",p="1",d="solid",v="#FFFFFF",m,g,y;t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=t.currentTarget.ancestor(u.FORM).one(u.CAPTION),r=t.currentTarget.ancestor(u.FORM).one(u.CAPTIONPOSITION),i=t.currentTarget.ancestor(u.FORM).one(u.HEADERS),s=t.currentTarget.ancestor(u.FORM).one(u.BORDERS),a=t.currentTarget.ancestor(u.FORM).one(u.BORDERSIZE),l=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBORDERCOLOUR),f=t.currentTarget.ancestor(u.FORM).one(u.BORDERSTYLE),c=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBACKGROUNDCOLOUR),g=t.currentTarget.ancestor(u.FORM).one(u.WIDTH),l&&(v=l.get("value")),a&&(p=a.get("value")),f&&(d=f.get("value")),c&&(h=c.get("value")),m=this._lastTarget.ancestor("table"),m.removeAttribute("style"),m.all("td, th").each(function(){this.removeAttribute("style")}),s&&(s.get("value")==="outer"?m.setStyle("border",p+o.BORDERSIZEUNIT+" "+d+" "+v):s.get("value")==="all"?m.all("td, th").each(function(){this.setStyle("border",p+o.BORDERSIZEUNIT+" "+d+" "+v)}):s.get("value")==="none"&&m.setStyle("border","none")),g&&g.get("value")&&m.setStyle("width",g.get("value")+o.WIDTHUNIT),h!==""&&m.setStyle("background-color",h),y=m.one("caption"),y||(y=e.Node.create(" "),m.insert(y,0)),y.setHTML(n.get("value")),y.setStyle("caption-side",r.get("value")),y.getAttribute("style")||y.removeAttribute("style"),(i.get("value")==="rows"||i.get("value")==="both")&&m.all("tr").each(function(e){var t=e.all("th, td"),n=t.shift(),r;n.get("tagName")==="TD"?(r=this._changeNodeType(n,"th"),r.setAttribute("scope","row")):n.setAttribute("scope","row"),t.each(function(e){e.get("tagName")==="TH"&&(r=this._changeNodeType(e,"td"),r.removeAttribute("scope"))},this)},this);if(i.get("value")==="columns"||i.get("value")==="both"){var b=m.all("tr"),w=b.shift(),E;w.all("td, th").each(function(e){e.get("tagName")==="TD"?(E=this._changeNodeType(e,"th"),E.setAttribute("scope","col")):e.setAttribute("scope","col")},this),b.each(function(e){var t=e.all("th, td");i.get("value")==="both"&&t.shift(),t.each(function(e){e.get("tagName")==="TH"&&(E=this._changeNodeType(e,"td"),E.removeAttribute("scope"))},this)},this)}this.markUpdated()},_setTable:function(t){var n,r,i,s="",a="",f,l,c,h="1",p="solid",d="#FFFFFF",v,m,g,y,b,w,E,S;t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=t.currentTarget.ancestor(u.FORM).one(u.CAPTION),r=t.currentTarget.ancestor(u.FORM).one(u.CAPTIONPOSITION),i=t.currentTarget.ancestor(u.FORM).one(u.BORDERS),f=t.currentTarget.ancestor(u.FORM).one(u.BORDERSIZE),c=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBORDERCOLOUR),l=t.currentTarget.ancestor(u.FORM).one(u.BORDERSTYLE),b=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBACKGROUNDCOLOUR),v=t.currentTarget.ancestor(u.FORM).one(u.ROWS),m=t.currentTarget.ancestor(u.FORM).one(u.COLUMNS),g=t.currentTarget.ancestor(u.FORM).one(u.HEADERS),w=t.currentTarget.ancestor(u.FORM).one(u.WIDTH),c&&(d=c.get("value")),f&&(h=f.get("value")),l&&(p=l.get("value")),i&&(i.get("value")==="outer"?s=' style="border: '+h+o.BORDERSIZEUNIT+" "+p+" "+d+';"':i.get("value")==="all"&&(a=' style="border: '+h+o.BORDERSIZEUNIT+" "+p+" "+d+';"')),b&&(s!==""?s=s.substring(0,s.length-1)+"background-color: "+b.get("value")+';"':s=' style="background-color: '+b.get("value")+';"'),w&&w.get("value")&&(s!==""?s=s.substring(0,s.length-1)+"width: "+w.get("value")+o.WIDTHUNIT+';"':s=' style="width: '+w.get("value")+o.WIDTHUNIT+';"'),this.get("host").setSelection(this._currentSelection);var x="\n";y=" "+
-x+""+x;var T="";r.get("value")&&(T=' style="caption-side: '+r.get("value")+'"'),y+=""+e.Escape.html(n.get("value"))+" "+x,E=0;if(g.get("value")==="columns"||g.get("value")==="both"){E=1,y+=""+x+""+x;for(S=0;S"+x;y+=" "+x+" "+x}y+=""+x;for(;E"+x;for(S=0;S"+x:y+=' "+x;y+=""+x}y+=" "+x,y+="
"+x+" ",this.get("host").insertContentAtFocusPoint(y),this.markUpdated()},_findColumnCells:function(){var t=this._getColumnIndex(this._lastTarget),n=this._lastTarget.ancestor("table").all("tr"),r=new e.NodeList,i=new e.NodeList,s=new e.NodeList;return n.each(function(e){var n=e.all("td, th"),o=n.item(t),u=n.item(t-1),a=n.item(t+1);r.push(o),u&&i.push(u),a&&s.push(a)}),{current:r,prev:i,next:s}},_hideInvalidEntries:function(e){var t=this._lastTarget.ancestor("table"),n=this._lastTarget.ancestor("tr"),r=t.all("tr"),i=r.indexOf(n),s=r.item(i-1),o=s?s.one("td"):null;!n||!o?e.one('[data-change="moverowup"]').hide():e.one('[data-change="moverowup"]').show();var u=r.item(i+1),a=n?n.one("td"):!1;!n||!u||!a?e.one('[data-change="moverowdown"]').hide():e.one('[data-change="moverowdown"]').show();var f=this._findColumnCells();f.prev.filter("td").size()>0?e.one('[data-change="movecolumnleft"]').show():e.one('[data-change="movecolumnleft"]').hide();var l=f.current.filter("td").size()>0;f.next.size()>0&&l?e.one('[data-change="movecolumnright"]').show():e.one('[data-change="movecolumnright"]').hide(),f.current.filter("td").size()>0?e.one('[data-change="deletecolumn"]').show():e.one('[data-change="deletecolumn"]').hide(),!n||!n.one("td")?e.one('[data-change="deleterow"]').hide():e.one('[data-change="deleterow"]').show()},_showTableMenu:function(t){t.preventDefault();var r;this._contextMenu||(this._menuOptions=[{text:M.util.get_string("addcolumnafter",n),data:{change:"addcolumnafter"}},{text:M.util.get_string("addrowafter",n),data:{change:"addrowafter"}},{text:M.util.get_string("moverowup",n),data:{change:"moverowup"}},{text:M.util.get_string("moverowdown",n),data:{change:"moverowdown"}},{text:M.util.get_string("movecolumnleft",n),data:{change:"movecolumnleft"}},{text:M.util.get_string("movecolumnright",n),data:{change:"movecolumnright"}},{text:M.util.get_string("deleterow",n),data:{change:"deleterow"}},{text:M.util.get_string("deletecolumn",n),data:{change:"deletecolumn"}},{text:M.util.get_string("edittable",n),data:{change:"edittable"}}],this._contextMenu=new e.M.editor_atto.Menu({items:this._menuOptions}),r=this._contextMenu.get("boundingBox"),r.delegate("click",this._handleTableChange,"a",this)),r=this._contextMenu.get("boundingBox"),this._lastTarget=t.tableCell.ancestor(".editor_atto_content td, .editor_atto_content th",!0),this._hideInvalidEntries(r),e.Array.each(this.get("host").openMenus,function(e){e.set("focusAfterHide",null)});var i=this.buttons[this.name];this.get("host")._setTabFocus(i),this._contextMenu.show(),this._contextMenu.align(this.buttons.table,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),this._contextMenu.set("focusAfterHide",i),r.one("a")&&r.one("a").focus(),this.get("host").openMenus=[this._contextMenu]},_handleTableChange:function(e){e.preventDefault(),this._contextMenu.set("focusAfterHide",this.get("host").editor),this._contextMenu.hide(e);switch(e.target.getData("change")){case"addcolumnafter":this._addColumnAfter();break;case"addrowafter":this._addRowAfter();break;case"deleterow":this._deleteRow();break;case"deletecolumn":this._deleteColumn();break;case"edittable":this._editTable();break;case"moverowdown":this._moveRowDown();break;case"moverowup":this._moveRowUp();break;case"movecolumnleft":this._moveColumnLeft();break;case"movecolumnright":this._moveColumnRight()}},_getRowIndex:function(e){var t=e.ancestor("table"),n=e.ancestor("tr");if(!t||!n)return;var r=t.all("tr");return r.indexOf(n)},_getColumnIndex:function(e){var t=e.ancestor("tr");if(!t)return;var n=t.all("td, th");return n.indexOf(e)},_deleteRow:function(){var e=this._lastTarget.ancestor("tr");e&&e.one("td")&&e.remove(!0),this.markUpdated()},_moveRowUp:function(){var e=this._lastTarget.ancestor("tr"),t=e.previous("tr");if(!e||!t)return;e.swap(t),this.markUpdated()},_moveColumnLeft:function(){var e=this._findColumnCells();if(e.current.size()>0&&e.prev.size()>0&&e.current.size()===e.prev.size()){var t=0;for(t=0;t "),1)},_removeCaption:function(){var e=this._lastTarget.ancestor("table"),t=e.one("caption");t&&t.remove(!0)},_moveColumnRight:function(){var e=this._findColumnCells();if(e.next.size()>0&&e.current.size()===e.next.size()&&e.current.filter("td").size()>0){var t=0;for(t=0;t");t.replace(n),t=n}t.setHTML(" ")}),t.ancestor("thead")?(t=r,n.insert(i,t)):t.insert(i,"after"),this.markUpdated()},_addColumnAfter:function(){var t=this._findColumnCells(),n=!0,r=t.next;t.next.size()<=0&&(n=!1,r=t.current),e.each(r,function(e){var t=e.cloneNode();t.setHTML(" "),n?e.get("parentNode").insert(t,e):(e.get("parentNode").insert(t,e),e.swap(t))},this),this.markUpdated()}},{ATTRS:{allowBorders:{value:!0},allowBorderStyles:{value:!0},borderStyles:{value:["solid","dashed","dotted"],setter:function(t){return t?t.replace(/ /g,"").split(","):e.Attribute.INVALID_VALUE}},allowBorderSize:{value:!0},allowBorderColour:{value:!0},allowBackgroundColour:{value:!0},allowWidth:{value:!0},allowStyling:{readOnly:!0,getter:function(){return this.get("allowBorders")||this.get("allowBackgroundColour")||this.get("allowWidth")}},availableColors:{value:["#FFFFFF","#EF4540","#FFCF35","#98CA3E","#7D9FD3","#333333"],readOnly:!0}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin","moodle-editor_atto-menu","event","event-valuechange"]});
+YUI.add("moodle-atto_table-button",function(e,t){var n="atto_table",r={BORDERSTYLE:"inherit",BORDERWIDTH:"1"},i={WIDTH:"450px"},s='',o={CAPTION:"caption",CAPTIONPOSITION:"captionposition",HEADERS:"headers",ROWS:"rows",COLUMNS:"columns",SUBMIT:"submit",FORM:"atto_form",BORDERS:"borders",BORDERSIZE:"bordersize",BORDERSIZEUNIT:"px",BORDERCOLOUR:"bordercolour",BORDERSTYLE:"borderstyle",BACKGROUNDCOLOUR:"backgroundcolour",WIDTH:"customwidth",WIDTHUNIT:"%",AVAILABLECOLORS:"availablecolors",COLOURROW:"colourrow"},u={CAPTION:"."+o.CAPTION,CAPTIONPOSITION:"."+o.CAPTIONPOSITION,HEADERS:"."+o.HEADERS,ROWS:"."+o.ROWS,COLUMNS:"."+o.COLUMNS,SUBMIT:"."+o.SUBMIT,BORDERS:"."+o.BORDERS,BORDERSIZE:"."+o.BORDERSIZE,BORDERCOLOURS:"."+o.BORDERCOLOUR+' input[name="borderColour"]',SELECTEDBORDERCOLOUR:"."+o.BORDERCOLOUR+' input[name="borderColour"]:checked'
+,BORDERSTYLE:"."+o.BORDERSTYLE,BACKGROUNDCOLOURS:"."+o.BACKGROUNDCOLOUR+' input[name="backgroundColour"]',SELECTEDBACKGROUNDCOLOUR:"."+o.BACKGROUNDCOLOUR+' input[name="backgroundColour"]:checked',FORM:".atto_form",WIDTH:"."+o.WIDTH,AVAILABLECOLORS:"."+o.AVAILABLECOLORS};e.namespace("M.atto_table").Button=e.Base.create("button",e.M.editor_atto.EditorPlugin,[],{_currentSelection:null,_contextMenu:null,_lastTarget:null,_menuOptions:null,initializer:function(){this.addButton({icon:"e/table",callback:this._displayTableEditor,tags:"table"}),e.UA.gecko&&(document.execCommand("enableInlineTableEditing",!1,!1),document.execCommand("enableObjectResizing",!1,!1))},_displayDialogue:function(){this._currentSelection=this.get("host").getSelection();if(this._currentSelection!==!1&&!this._currentSelection.collapsed){var e=this.getDialogue({headerContent:M.util.get_string("createtable",n),focusAfterHide:!0,focusOnShowSelector:u.CAPTION,width:i.WIDTH});e.set("bodyContent",this._getDialogueContent(!1)).show(),this._updateAvailableSettings()}},_displayTableEditor:function(e){var t=this._getSuitableTableCell();return t?(e.tableCell=t,this._showTableMenu(e)):this._displayDialogue(e)},_stopAtContentEditableFilter:function(e){this.editor.contains(e)},_getDialogueContent:function(t){var r=e.Handlebars.compile(s),i=this.get("allowBorders");return this._content=e.Node.create(r({CSS:o,elementid:this.get("host").get("elementid"),component:n,edit:t,nonedit:!t,allowStyling:this.get("allowStyling"),allowBorders:i,allowBorderStyles:this.get("allowBorderStyles"),borderStyles:this.get("borderStyles"),allowBorderSize:this.get("allowBorderSize"),allowBorderColour:this.get("allowBorderColour"),allowBackgroundColour:this.get("allowBackgroundColour"),availableColours:this.get("availableColors"),allowWidth:this.get("allowWidth")})),t?this._content.one(".submit").on("click",this._updateTable,this):this._content.one(".submit").on("click",this._setTable,this),i&&this._content.one('[name="borders"]').on("change",this._updateAvailableSettings,this),this._content},_updateAvailableSettings:function(){var e=this._content,t=e.one('[name="borders"]'),n=e.one('[name="borderstyles"]'),r=e.one('[name="bordersize"]'),i=e.all('[name="borderColour"]'),s="removeAttribute";t.get("value")==="default"&&(s="setAttribute"),n&&n[s]("disabled"),r&&r[s]("disabled"),i&&i[s]("disabled")},_getSuitableTableCell:function(){var e=null,t=this.get("host");t.getSelectedNodes().some(function(t){if(t.ancestor("td, th, caption",!0,this._stopAtContentEditableFilter)){e=t;var n=t.ancestor("caption",!0,this._stopAtContentEditableFilter);if(n){var r=n.get("parentNode");r&&(e=r.one("td, th"))}return!0}});if(e){var n=t.getSelectionFromNode(e);t.setSelection(n)}return e},_changeNodeType:function(t,n){var r=e.Node.create("<"+n+">"+n+">");return r.setAttrs(t.getAttrs()),t.get("childNodes").each(function(e){r.append(e.remove())}),t.replace(r),r},_updateTable:function(t){var n,r,i,s,o,a,f,l,c,h,p;t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=t.currentTarget.ancestor(u.FORM).one(u.CAPTION),r=t.currentTarget.ancestor(u.FORM).one(u.CAPTIONPOSITION),i=t.currentTarget.ancestor(u.FORM).one(u.HEADERS),s=t.currentTarget.ancestor(u.FORM).one(u.BORDERS),o=t.currentTarget.ancestor(u.FORM).one(u.BORDERSIZE),f=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBORDERCOLOUR),a=t.currentTarget.ancestor(u.FORM).one(u.BORDERSTYLE),l=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBACKGROUNDCOLOUR),h=t.currentTarget.ancestor(u.FORM).one(u.WIDTH),c=this._lastTarget.ancestor("table"),this._setAppearance(c,{width:h,borders:s,borderColour:f,borderSize:o,borderStyle:a,backgroundColour:l}),p=c.one("caption"),p||(p=e.Node.create(" "),c.insert(p,0)),p.setHTML(n.get("value")),p.setStyle("caption-side",r.get("value")),p.getAttribute("style")||p.removeAttribute("style"),(i.get("value")==="rows"||i.get("value")==="both")&&c.all("tr").each(function(e){var t=e.all("th, td"),n=t.shift(),r;n.get("tagName")==="TD"?(r=this._changeNodeType(n,"th"),r.setAttribute("scope","row")):n.setAttribute("scope","row"),t.each(function(e){e.get("tagName")==="TH"&&(r=this._changeNodeType(e,"td"),r.removeAttribute("scope"))},this)},this);if(i.get("value")==="columns"||i.get("value")==="both"){var d=c.all("tr"),v=d.shift(),m;v.all("td, th").each(function(e){e.get("tagName")==="TD"?(m=this._changeNodeType(e,"th"),m.setAttribute("scope","col")):e.setAttribute("scope","col")},this),d.each(function(e){var t=e.all("th, td");i.get("value")==="both"&&t.shift(),t.each(function(e){e.get("tagName")==="TH"&&(m=this._changeNodeType(e,"td"),m.removeAttribute("scope"))},this)},this)}this.markUpdated()},_setTable:function(t){var n,r,i,s,o,a,f,l,c,h,p,d,v,m;t.preventDefault(),this.getDialogue({focusAfterHide:null}).hide(),n=t.currentTarget.ancestor(u.FORM).one(u.CAPTION),r=t.currentTarget.ancestor(u.FORM).one(u.CAPTIONPOSITION),i=t.currentTarget.ancestor(u.FORM).one(u.BORDERS),s=t.currentTarget.ancestor(u.FORM).one(u.BORDERSIZE),a=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBORDERCOLOUR),o=t.currentTarget.ancestor(u.FORM).one(u.BORDERSTYLE),p=t.currentTarget.ancestor(u.FORM).one(u.SELECTEDBACKGROUNDCOLOUR),f=t.currentTarget.ancestor(u.FORM).one(u.ROWS),l=t.currentTarget.ancestor(u.FORM).one(u.COLUMNS),c=t.currentTarget.ancestor(u.FORM).one(u.HEADERS),d=t.currentTarget.ancestor(u.FORM).one(u.WIDTH),this.get("host").setSelection(this._currentSelection);var g="\n",y=e.guid();h=" "+g+''+g;var b="";r.get("value")&&(b=' style="caption-side: '+r.get("value")+'"'),h+=""+e.Escape.html(n.get("value"))+" "+g,v=0;if(c.get("value")==="columns"||c.get("value")==="both"){v=1,h+=""+g+""+g;for(m=0;m'+g;h+=" "+g+" "+g}h+=""+g;for(;v"+g;for(m=0;m"+g:h+=' '+
+g;h+=""+g}h+=" "+g,h+="
"+g+" ",this.get("host").insertContentAtFocusPoint(h);var w=e.one("#"+y);this._setAppearance(w,{width:d,borders:i,borderColour:a,borderSize:s,borderStyle:o,backgroundColour:p}),w.removeAttribute("id"),this.markUpdated()},_findColumnCells:function(){var t=this._getColumnIndex(this._lastTarget),n=this._lastTarget.ancestor("table").all("tr"),r=new e.NodeList,i=new e.NodeList,s=new e.NodeList;return n.each(function(e){var n=e.all("td, th"),o=n.item(t),u=n.item(t-1),a=n.item(t+1);r.push(o),u&&i.push(u),a&&s.push(a)}),{current:r,prev:i,next:s}},_hideInvalidEntries:function(e){var t=this._lastTarget.ancestor("table"),n=this._lastTarget.ancestor("tr"),r=t.all("tr"),i=r.indexOf(n),s=r.item(i-1),o=s?s.one("td"):null;!n||!o?e.one('[data-change="moverowup"]').hide():e.one('[data-change="moverowup"]').show();var u=r.item(i+1),a=n?n.one("td"):!1;!n||!u||!a?e.one('[data-change="moverowdown"]').hide():e.one('[data-change="moverowdown"]').show();var f=this._findColumnCells();f.prev.filter("td").size()>0?e.one('[data-change="movecolumnleft"]').show():e.one('[data-change="movecolumnleft"]').hide();var l=f.current.filter("td").size()>0;f.next.size()>0&&l?e.one('[data-change="movecolumnright"]').show():e.one('[data-change="movecolumnright"]').hide(),f.current.filter("td").size()>0?e.one('[data-change="deletecolumn"]').show():e.one('[data-change="deletecolumn"]').hide(),!n||!n.one("td")?e.one('[data-change="deleterow"]').hide():e.one('[data-change="deleterow"]').show()},_showTableMenu:function(t){t.preventDefault();var r;this._contextMenu||(this._menuOptions=[{text:M.util.get_string("addcolumnafter",n),data:{change:"addcolumnafter"}},{text:M.util.get_string("addrowafter",n),data:{change:"addrowafter"}},{text:M.util.get_string("moverowup",n),data:{change:"moverowup"}},{text:M.util.get_string("moverowdown",n),data:{change:"moverowdown"}},{text:M.util.get_string("movecolumnleft",n),data:{change:"movecolumnleft"}},{text:M.util.get_string("movecolumnright",n),data:{change:"movecolumnright"}},{text:M.util.get_string("deleterow",n),data:{change:"deleterow"}},{text:M.util.get_string("deletecolumn",n),data:{change:"deletecolumn"}},{text:M.util.get_string("edittable",n),data:{change:"edittable"}}],this._contextMenu=new e.M.editor_atto.Menu({items:this._menuOptions}),r=this._contextMenu.get("boundingBox"),r.delegate("click",this._handleTableChange,"a",this)),r=this._contextMenu.get("boundingBox"),this._lastTarget=t.tableCell.ancestor(".editor_atto_content td, .editor_atto_content th",!0),this._hideInvalidEntries(r),e.Array.each(this.get("host").openMenus,function(e){e.set("focusAfterHide",null)});var i=this.buttons[this.name];this.get("host")._setTabFocus(i),this._contextMenu.show(),this._contextMenu.align(this.buttons.table,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),this._contextMenu.set("focusAfterHide",i),r.one("a")&&r.one("a").focus(),this.get("host").openMenus=[this._contextMenu]},_handleTableChange:function(e){e.preventDefault(),this._contextMenu.set("focusAfterHide",this.get("host").editor),this._contextMenu.hide(e);switch(e.target.getData("change")){case"addcolumnafter":this._addColumnAfter();break;case"addrowafter":this._addRowAfter();break;case"deleterow":this._deleteRow();break;case"deletecolumn":this._deleteColumn();break;case"edittable":this._editTable();break;case"moverowdown":this._moveRowDown();break;case"moverowup":this._moveRowUp();break;case"movecolumnleft":this._moveColumnLeft();break;case"movecolumnright":this._moveColumnRight()}},_getRowIndex:function(e){var t=e.ancestor("table"),n=e.ancestor("tr");if(!t||!n)return;var r=t.all("tr");return r.indexOf(n)},_getColumnIndex:function(e){var t=e.ancestor("tr");if(!t)return;var n=t.all("td, th");return n.indexOf(e)},_deleteRow:function(){var e=this._lastTarget.ancestor("tr");e&&e.one("td")&&e.remove(!0),this.markUpdated()},_moveRowUp:function(){var e=this._lastTarget.ancestor("tr"),t=e.previous("tr");if(!e||!t)return;e.swap(t),this.markUpdated()},_moveColumnLeft:function(){var e=this._findColumnCells();if(e.current.size()>0&&e.prev.size()>0&&e.current.size()===e.prev.size()){var t=0;for(t=0;t "),1)},_removeCaption:function(){var e=this._lastTarget.ancestor("table"),t=e.one("caption");t&&t.remove(!0)},_moveColumnRight:function(){var e=this._findColumnCells();if(e.next.size()>0&&e.current.size()===e.next.size()&&e.current.filter("td").size()>0){var t=0;for(t=0;t");t.replace(n),t=n}t.setHTML(" ")}),t.ancestor("thead")?(t=r,n.insert(i,t)):t.insert(i,"after"),this.markUpdated()},_addColumnAfter:function(){var t=this._findColumnCells(),n=!0,r=t.next;t.next.size()<=0&&(n=!1,r=t.current),e.each(r,function(e){var t=e.cloneNode();t.setHTML(" "),n?e.get("parentNode").insert(t,e):(e.get("parentNode").insert(t,e),e.swap(t))},this),this.markUpdated()}},{ATTRS:{allowBorders:{value:!0},allowBorderStyles:{value:!0},borderStyles:{value:["solid","dashed","dotted"],setter:function(t){return t?t.replace(/ /g,"").split(","):e.Attribute.INVALID_VALUE}},allowBorderSize:{value:!0},allowBorderColour:{value:!0},allowBackgroundColour:{value:!0},allowWidth:{value:!0},allowStyling:{readOnly:!0,getter:function(){return this.get("allowBorders")||this.get("allowBackgroundColour")||this.get("allowWidth")}},availableColors:{value:["#FFFFFF","#EF4540","#FFCF35","#98CA3E","#7D9FD3","#333333"],readOnly:!0}}})},"@VERSION@",{requires:["moodle-editor_atto-plugin","moodle-editor_atto-menu","event","event-valuechange"]});
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 1beb527dec2..d5e3bba597f 100644
--- 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
@@ -35,7 +35,7 @@ YUI.add('moodle-atto_table-button', function (Y, NAME) {
var COMPONENT = 'atto_table',
DEFAULT = {
- BORDERSTYLE: 'solid',
+ BORDERSTYLE: 'inherit',
BORDERWIDTH: '1'
},
DIALOGUE = {
@@ -78,9 +78,8 @@ var COMPONENT = 'atto_table',
'{{get_string "appearance" component}} ' +
'{{#if allowBorders}}' +
'{{get_string "borders" component}} ' +
- '' +
+ '' +
'{{get_string "themedefault" component}}' + ' ' +
- '{{get_string "noborder" component}}' + ' ' +
'{{get_string "outer" component}}' + ' ' +
'{{get_string "all" component}}' + ' ' +
' ' +
@@ -88,9 +87,10 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderStyles}}' +
'' +
'{{get_string "borderstyles" component}} ' +
- '' +
+ '' +
+ '{{get_string "inherit" component}} ' +
'{{#each borderStyles}}' +
- '' + '{{this}}' + ' ' +
+ '' + '{{get_string this ../component}}' + ' ' +
'{{/each}}' +
' ' +
' ' +
@@ -98,7 +98,7 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderSize}}' +
'' +
'{{get_string "bordersize" component}} ' +
- ' ' +
'{{CSS.BORDERSIZEUNIT}} ' +
' ' +
@@ -112,10 +112,10 @@ var COMPONENT = 'atto_table',
'style="background-color:transparent;color:transparent">' +
' ' +
+ 'type="radio" name="borderColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
'' +
'{{#each availableColours}}' +
'' +
' ' +
+ 'type="radio" name="backgroundColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
' ' +
'{{#each availableColours}}' +
@@ -289,6 +289,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue.
dialogue.set('bodyContent', this._getDialogueContent(false))
.show();
+
+ this._updateAvailableSettings();
}
},
@@ -334,7 +336,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/
_getDialogueContent: function(edit) {
var template = Y.Handlebars.compile(TEMPLATE);
- var availableColours = this.get('availableColors');
+ var allowBorders = this.get('allowBorders');
this._content = Y.Node.create(template({
CSS: CSS,
@@ -343,13 +345,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
edit: edit,
nonedit: !edit,
allowStyling: this.get('allowStyling'),
- allowBorders: this.get('allowBorders'),
+ allowBorders: allowBorders,
allowBorderStyles: this.get('allowBorderStyles'),
borderStyles: this.get('borderStyles'),
allowBorderSize: this.get('allowBorderSize'),
allowBorderColour: this.get('allowBorderColour'),
allowBackgroundColour: this.get('allowBackgroundColour'),
- availableColours: availableColours,
+ availableColours: this.get('availableColors'),
allowWidth: this.get('allowWidth')
}));
@@ -360,9 +362,48 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this._content.one('.submit').on('click', this._setTable, this);
}
+ if (allowBorders) {
+ this._content.one('[name="borders"]').on('change', this._updateAvailableSettings, this);
+ }
+
return this._content;
},
+ /**
+ * Disables options within the dialogue if they shouldn't be available.
+ * E.g.
+ * If borders are set to "Theme default" then the border size, style and
+ * colour options are disabled.
+ *
+ * @method _updateAvailableSettings
+ * @private
+ */
+ _updateAvailableSettings: function() {
+ var tableForm = this._content,
+ enableBorders = tableForm.one('[name="borders"]'),
+ borderStyle = tableForm.one('[name="borderstyles"]'),
+ borderSize = tableForm.one('[name="bordersize"]'),
+ borderColour = tableForm.all('[name="borderColour"]'),
+ disabledValue = 'removeAttribute';
+
+ if (enableBorders.get('value') === 'default') {
+ disabledValue = 'setAttribute';
+ }
+
+ if (borderStyle) {
+ borderStyle[disabledValue]('disabled');
+ }
+
+ if (borderSize) {
+ borderSize[disabledValue]('disabled');
+ }
+
+ if (borderColour) {
+ borderColour[disabledValue]('disabled');
+ }
+
+ },
+
/**
* 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
@@ -436,10 +477,6 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderstyle,
bordercolour,
backgroundcolour,
- backgroundcolourvalue = '#FFFFFF',
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
table,
width,
captionnode;
@@ -461,51 +498,16 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolour = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.SELECTEDBACKGROUNDCOLOUR);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (backgroundcolour) {
- backgroundcolourvalue = backgroundcolour.get('value');
- }
-
table = this._lastTarget.ancestor('table');
- // Clear the inline border styling
- table.removeAttribute('style');
- table.all('td, th').each(function() {
- this.removeAttribute('style');
+ this._setAppearance(table, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
});
- if (borders) {
- if (borders.get('value') === 'outer') {
- table.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- } else if (borders.get('value') === 'all') {
- table.all('td, th').each(function() {
- this.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- });
- } else if (borders.get('value') === 'none') {
- table.setStyle('border', 'none');
- }
- }
-
- if (width && width.get('value')) {
- table.setStyle('width', width.get('value') + CSS.WIDTHUNIT);
- }
-
- if (backgroundcolourvalue !== '') {
- table.setStyle('background-color', backgroundcolourvalue);
- }
-
captionnode = table.one('caption');
if (!captionnode) {
captionnode = Y.Node.create(' ');
@@ -589,14 +591,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
var caption,
captionposition,
borders,
- bordertable = '',
- bordercell = '',
bordersize,
borderstyle,
bordercolour,
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
rows,
cols,
headers,
@@ -624,52 +621,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (borders) {
- if (borders.get('value') === 'outer') {
- bordertable = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- } else if (borders.get('value') === 'all') {
- bordercell = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- }
- }
-
- if (backgroundcolour) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) +
- 'background-color: ' + backgroundcolour.get('value') + ';"';
- } else {
- bordertable = ' style="background-color: ' + backgroundcolour.get('value') + ';"';
- }
- }
-
- if (width && width.get('value')) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) + 'width: ' +
- width.get('value') + CSS.WIDTHUNIT + ';"';
- } else {
- bordertable = ' style="width: ' + width.get('value') + CSS.WIDTHUNIT + ';"';
- }
- }
-
// Set the selection.
this.get('host').setSelection(this._currentSelection);
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n";
- tablehtml = ' ' + nl + '' + nl;
+ var tableId = Y.guid();
+ tablehtml = ' ' + nl + '' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
@@ -681,7 +639,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
i = 1;
tablehtml += '' + nl + '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
tablehtml += ' ' + nl + ' ' + nl;
}
@@ -690,9 +648,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
tablehtml += '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
if (j === 0 && (headers.get('value') === 'rows' || headers.get('value') === 'both')) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
} else {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
}
tablehtml += ' ' + nl;
@@ -702,6 +660,17 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.get('host').insertContentAtFocusPoint(tablehtml);
+ var tableNode = Y.one('#' + tableId);
+ this._setAppearance(tableNode, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
+ });
+ tableNode.removeAttribute('id');
+
// Mark the content as updated.
this.markUpdated();
},
@@ -1148,6 +1117,73 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
return false;
},
+ /**
+ * Set the appropriate styles on the given table node according to
+ * the provided configuration.
+ *
+ * @method _setAppearance
+ * @param {Node} The table node to be modified.
+ * @param {Object} Configuration object (associative array) containing the form nodes for
+ * border styling.
+ * @private
+ */
+ _setAppearance: function(tableNode, configuration) {
+ var borderhex,
+ borderSizeValue,
+ borderStyleValue,
+ backgroundcolourvalue;
+
+ if (configuration.borderColour) {
+ borderhex = configuration.borderColour.get('value');
+ }
+
+ if (configuration.borderSize) {
+ borderSizeValue = configuration.borderSize.get('value');
+ }
+
+ if (configuration.borderStyle) {
+ borderStyleValue = configuration.borderStyle.get('value');
+ }
+
+ if (configuration.backgroundColour) {
+ backgroundcolourvalue = configuration.backgroundColour.get('value');
+ }
+
+ // Clear the inline border styling
+ tableNode.removeAttribute('style');
+ tableNode.all('td, th').each(function(cell) {
+ cell.removeAttribute('style');
+ }, this);
+
+ if (configuration.borders) {
+ if (configuration.borders.get('value') === 'outer') {
+ tableNode.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ tableNode.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ tableNode.setStyle('borderColor', borderhex);
+ }
+ } else if (configuration.borders.get('value') === 'all') {
+ tableNode.all('td, th').each(function(cell) {
+ cell.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ cell.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ cell.setStyle('borderColor', borderhex);
+ }
+ }, this);
+ }
+ }
+
+ if (backgroundcolourvalue !== 'none') {
+ tableNode.setStyle('background-color', backgroundcolourvalue);
+ }
+
+ if (configuration.width && configuration.width.get('value')) {
+ tableNode.setStyle('width', configuration.width.get('value') + CSS.WIDTHUNIT);
+ }
+ },
+
/**
* Edit table (show the dialogue).
*
@@ -1174,7 +1210,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolours = node.all(SELECTORS.BACKGROUNDCOLOURS),
width = node.one(SELECTORS.WIDTH),
table = this._lastTarget.ancestor('table'),
- captionnode = table.one('caption');
+ captionnode = table.one('caption'),
+ hexColour,
+ matchedInput;
if (captionnode) {
captioninput.set('value', captionnode.getHTML());
@@ -1193,9 +1231,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captionpositioninput.set('value', '');
}
- if (table.getStyle('background-color') !== 'transparent' && this.get('allowBackgroundColour')) {
- var hexColour = Y.Color.toHex(table.getStyle('background-color'));
- var matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
+ if (table.getStyle('background-color') && this.get('allowBackgroundColour')) {
+ hexColour = Y.Color.toHex(table.getStyle('background-color'));
+ matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1207,11 +1245,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderConfiguration = this._getBorderConfiguration(table);
if (borderConfiguration) {
- if (borderConfiguration.borderStyle && borderConfiguration.borderStyle === 'none') {
- borderValue = 'none';
- } else {
- borderValue = 'outer';
- }
+ borderValue = 'outer';
} else {
borderConfiguration = this._getBorderConfiguration(table.one('td'));
if (borderConfiguration) {
@@ -1226,8 +1260,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
bordersize.set('value', borderSize);
borderinput.set('value', borderValue);
- var hexColour = borderConfiguration.borderColor;
- var matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
+ hexColour = borderConfiguration.borderColor;
+ matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1244,6 +1278,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
headersinput.set('value', headersvalue);
dialogue.set('bodyContent', node).show();
+ this._updateAvailableSettings();
},
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 b72ef947016..679fa4b0e8d 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
@@ -33,7 +33,7 @@
var COMPONENT = 'atto_table',
DEFAULT = {
- BORDERSTYLE: 'solid',
+ BORDERSTYLE: 'inherit',
BORDERWIDTH: '1'
},
DIALOGUE = {
@@ -76,9 +76,8 @@ var COMPONENT = 'atto_table',
'{{get_string "appearance" component}} ' +
'{{#if allowBorders}}' +
'{{get_string "borders" component}} ' +
- '' +
+ '' +
'{{get_string "themedefault" component}}' + ' ' +
- '{{get_string "noborder" component}}' + ' ' +
'{{get_string "outer" component}}' + ' ' +
'{{get_string "all" component}}' + ' ' +
' ' +
@@ -86,9 +85,10 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderStyles}}' +
'' +
'{{get_string "borderstyles" component}} ' +
- '' +
+ '' +
+ '{{get_string "inherit" component}} ' +
'{{#each borderStyles}}' +
- '' + '{{this}}' + ' ' +
+ '' + '{{get_string this ../component}}' + ' ' +
'{{/each}}' +
' ' +
' ' +
@@ -96,7 +96,7 @@ var COMPONENT = 'atto_table',
'{{#if allowBorderSize}}' +
'' +
'{{get_string "bordersize" component}} ' +
- ' ' +
'{{CSS.BORDERSIZEUNIT}} ' +
' ' +
@@ -110,10 +110,10 @@ var COMPONENT = 'atto_table',
'style="background-color:transparent;color:transparent">' +
' ' +
+ 'type="radio" name="borderColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
'' +
'{{#each availableColours}}' +
'' +
' ' +
+ 'type="radio" name="backgroundColour" value="none" checked="checked"'+
+ 'title="{{get_string "themedefault" component}}">' +
- '{{get_string "transparent" component}}' +
+ '{{get_string "themedefault" component}}' +
' ' +
'{{#each availableColours}}' +
@@ -287,6 +287,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue.
dialogue.set('bodyContent', this._getDialogueContent(false))
.show();
+
+ this._updateAvailableSettings();
}
},
@@ -332,7 +334,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/
_getDialogueContent: function(edit) {
var template = Y.Handlebars.compile(TEMPLATE);
- var availableColours = this.get('availableColors');
+ var allowBorders = this.get('allowBorders');
this._content = Y.Node.create(template({
CSS: CSS,
@@ -341,13 +343,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
edit: edit,
nonedit: !edit,
allowStyling: this.get('allowStyling'),
- allowBorders: this.get('allowBorders'),
+ allowBorders: allowBorders,
allowBorderStyles: this.get('allowBorderStyles'),
borderStyles: this.get('borderStyles'),
allowBorderSize: this.get('allowBorderSize'),
allowBorderColour: this.get('allowBorderColour'),
allowBackgroundColour: this.get('allowBackgroundColour'),
- availableColours: availableColours,
+ availableColours: this.get('availableColors'),
allowWidth: this.get('allowWidth')
}));
@@ -358,9 +360,48 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this._content.one('.submit').on('click', this._setTable, this);
}
+ if (allowBorders) {
+ this._content.one('[name="borders"]').on('change', this._updateAvailableSettings, this);
+ }
+
return this._content;
},
+ /**
+ * Disables options within the dialogue if they shouldn't be available.
+ * E.g.
+ * If borders are set to "Theme default" then the border size, style and
+ * colour options are disabled.
+ *
+ * @method _updateAvailableSettings
+ * @private
+ */
+ _updateAvailableSettings: function() {
+ var tableForm = this._content,
+ enableBorders = tableForm.one('[name="borders"]'),
+ borderStyle = tableForm.one('[name="borderstyles"]'),
+ borderSize = tableForm.one('[name="bordersize"]'),
+ borderColour = tableForm.all('[name="borderColour"]'),
+ disabledValue = 'removeAttribute';
+
+ if (enableBorders.get('value') === 'default') {
+ disabledValue = 'setAttribute';
+ }
+
+ if (borderStyle) {
+ borderStyle[disabledValue]('disabled');
+ }
+
+ if (borderSize) {
+ borderSize[disabledValue]('disabled');
+ }
+
+ if (borderColour) {
+ borderColour[disabledValue]('disabled');
+ }
+
+ },
+
/**
* 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
@@ -434,10 +475,6 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderstyle,
bordercolour,
backgroundcolour,
- backgroundcolourvalue = '#FFFFFF',
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
table,
width,
captionnode;
@@ -459,51 +496,16 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolour = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.SELECTEDBACKGROUNDCOLOUR);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (backgroundcolour) {
- backgroundcolourvalue = backgroundcolour.get('value');
- }
-
table = this._lastTarget.ancestor('table');
- // Clear the inline border styling
- table.removeAttribute('style');
- table.all('td, th').each(function() {
- this.removeAttribute('style');
+ this._setAppearance(table, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
});
- if (borders) {
- if (borders.get('value') === 'outer') {
- table.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- } else if (borders.get('value') === 'all') {
- table.all('td, th').each(function() {
- this.setStyle('border', borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex);
- });
- } else if (borders.get('value') === 'none') {
- table.setStyle('border', 'none');
- }
- }
-
- if (width && width.get('value')) {
- table.setStyle('width', width.get('value') + CSS.WIDTHUNIT);
- }
-
- if (backgroundcolourvalue !== '') {
- table.setStyle('background-color', backgroundcolourvalue);
- }
-
captionnode = table.one('caption');
if (!captionnode) {
captionnode = Y.Node.create(' ');
@@ -587,14 +589,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
var caption,
captionposition,
borders,
- bordertable = '',
- bordercell = '',
bordersize,
borderstyle,
bordercolour,
- borderSizeValue = '1',
- borderStyleValue = 'solid',
- borderhex = '#FFFFFF',
rows,
cols,
headers,
@@ -622,52 +619,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
width = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.WIDTH);
- if (bordercolour) {
- borderhex = bordercolour.get('value');
- }
-
- if (bordersize) {
- borderSizeValue = bordersize.get('value');
- }
-
- if (borderstyle) {
- borderStyleValue = borderstyle.get('value');
- }
-
- if (borders) {
- if (borders.get('value') === 'outer') {
- bordertable = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- } else if (borders.get('value') === 'all') {
- bordercell = ' style="border: ' + borderSizeValue + CSS.BORDERSIZEUNIT + ' ' +
- borderStyleValue + ' ' + borderhex + ';"';
- }
- }
-
- if (backgroundcolour) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) +
- 'background-color: ' + backgroundcolour.get('value') + ';"';
- } else {
- bordertable = ' style="background-color: ' + backgroundcolour.get('value') + ';"';
- }
- }
-
- if (width && width.get('value')) {
- if (bordertable !== '') {
- bordertable = bordertable.substring(0, bordertable.length-1) + 'width: ' +
- width.get('value') + CSS.WIDTHUNIT + ';"';
- } else {
- bordertable = ' style="width: ' + width.get('value') + CSS.WIDTHUNIT + ';"';
- }
- }
-
// Set the selection.
this.get('host').setSelection(this._currentSelection);
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n";
- tablehtml = ' ' + nl + '' + nl;
+ var tableId = Y.guid();
+ tablehtml = ' ' + nl + '' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
@@ -679,7 +637,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
i = 1;
tablehtml += '' + nl + '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
tablehtml += ' ' + nl + ' ' + nl;
}
@@ -688,9 +646,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
tablehtml += '' + nl;
for (j = 0; j < parseInt(cols.get('value'), 10); j++) {
if (j === 0 && (headers.get('value') === 'rows' || headers.get('value') === 'both')) {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
} else {
- tablehtml += ' ' + nl;
+ tablehtml += ' ' + nl;
}
}
tablehtml += ' ' + nl;
@@ -700,6 +658,17 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
this.get('host').insertContentAtFocusPoint(tablehtml);
+ var tableNode = Y.one('#' + tableId);
+ this._setAppearance(tableNode, {
+ width: width,
+ borders: borders,
+ borderColour: bordercolour,
+ borderSize: bordersize,
+ borderStyle: borderstyle,
+ backgroundColour: backgroundcolour
+ });
+ tableNode.removeAttribute('id');
+
// Mark the content as updated.
this.markUpdated();
},
@@ -1146,6 +1115,73 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
return false;
},
+ /**
+ * Set the appropriate styles on the given table node according to
+ * the provided configuration.
+ *
+ * @method _setAppearance
+ * @param {Node} The table node to be modified.
+ * @param {Object} Configuration object (associative array) containing the form nodes for
+ * border styling.
+ * @private
+ */
+ _setAppearance: function(tableNode, configuration) {
+ var borderhex,
+ borderSizeValue,
+ borderStyleValue,
+ backgroundcolourvalue;
+
+ if (configuration.borderColour) {
+ borderhex = configuration.borderColour.get('value');
+ }
+
+ if (configuration.borderSize) {
+ borderSizeValue = configuration.borderSize.get('value');
+ }
+
+ if (configuration.borderStyle) {
+ borderStyleValue = configuration.borderStyle.get('value');
+ }
+
+ if (configuration.backgroundColour) {
+ backgroundcolourvalue = configuration.backgroundColour.get('value');
+ }
+
+ // Clear the inline border styling
+ tableNode.removeAttribute('style');
+ tableNode.all('td, th').each(function(cell) {
+ cell.removeAttribute('style');
+ }, this);
+
+ if (configuration.borders) {
+ if (configuration.borders.get('value') === 'outer') {
+ tableNode.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ tableNode.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ tableNode.setStyle('borderColor', borderhex);
+ }
+ } else if (configuration.borders.get('value') === 'all') {
+ tableNode.all('td, th').each(function(cell) {
+ cell.setStyle('borderWidth', borderSizeValue + CSS.BORDERSIZEUNIT);
+ cell.setStyle('borderStyle', borderStyleValue);
+
+ if (borderhex !== 'none') {
+ cell.setStyle('borderColor', borderhex);
+ }
+ }, this);
+ }
+ }
+
+ if (backgroundcolourvalue !== 'none') {
+ tableNode.setStyle('background-color', backgroundcolourvalue);
+ }
+
+ if (configuration.width && configuration.width.get('value')) {
+ tableNode.setStyle('width', configuration.width.get('value') + CSS.WIDTHUNIT);
+ }
+ },
+
/**
* Edit table (show the dialogue).
*
@@ -1172,7 +1208,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
backgroundcolours = node.all(SELECTORS.BACKGROUNDCOLOURS),
width = node.one(SELECTORS.WIDTH),
table = this._lastTarget.ancestor('table'),
- captionnode = table.one('caption');
+ captionnode = table.one('caption'),
+ hexColour,
+ matchedInput;
if (captionnode) {
captioninput.set('value', captionnode.getHTML());
@@ -1191,9 +1229,9 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captionpositioninput.set('value', '');
}
- if (table.getStyle('background-color') !== 'transparent' && this.get('allowBackgroundColour')) {
- var hexColour = Y.Color.toHex(table.getStyle('background-color'));
- var matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
+ if (table.getStyle('background-color') && this.get('allowBackgroundColour')) {
+ hexColour = Y.Color.toHex(table.getStyle('background-color'));
+ matchedInput = backgroundcolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1205,11 +1243,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
borderConfiguration = this._getBorderConfiguration(table);
if (borderConfiguration) {
- if (borderConfiguration.borderStyle && borderConfiguration.borderStyle === 'none') {
- borderValue = 'none';
- } else {
- borderValue = 'outer';
- }
+ borderValue = 'outer';
} else {
borderConfiguration = this._getBorderConfiguration(table.one('td'));
if (borderConfiguration) {
@@ -1224,8 +1258,8 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
bordersize.set('value', borderSize);
borderinput.set('value', borderValue);
- var hexColour = borderConfiguration.borderColor;
- var matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
+ hexColour = borderConfiguration.borderColor;
+ matchedInput = bordercolours.filter('[value="' + hexColour + '"]');
if (matchedInput) {
matchedInput.set("checked", true);
@@ -1242,6 +1276,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}
headersinput.set('value', headersvalue);
dialogue.set('bodyContent', node).show();
+ this._updateAvailableSettings();
},