MDL-50801 atto_table: Allow caption position to be set

This commit is contained in:
David Monllao 2015-07-09 12:06:35 +10:00
parent dda862abb5
commit 556decf159
6 changed files with 124 additions and 10 deletions

View file

@ -26,6 +26,7 @@ $string['addcolumnafter'] = 'Insert column after';
$string['addrowafter'] = 'Insert row after'; $string['addrowafter'] = 'Insert row after';
$string['both'] = 'Both'; $string['both'] = 'Both';
$string['caption'] = 'Caption'; $string['caption'] = 'Caption';
$string['captionposition'] = 'Caption position';
$string['columns'] = 'Columns'; $string['columns'] = 'Columns';
$string['createtable'] = 'Create table'; $string['createtable'] = 'Create table';
$string['deletecolumn'] = 'Delete column'; $string['deletecolumn'] = 'Delete column';

View file

@ -47,7 +47,12 @@ function atto_table_strings_for_js() {
'moverowdown', 'moverowdown',
'moverowup', 'moverowup',
'deleterow', 'deleterow',
'deletecolumn'), 'deletecolumn',
'captionposition'),
'atto_table'); 'atto_table');
$PAGE->requires->strings_for_js(array('top',
'bottom'),
'editor');
} }

View file

@ -40,6 +40,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -58,6 +65,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -79,6 +93,7 @@ var COMPONENT = 'atto_table',
'</form>', '</form>',
CSS = { CSS = {
CAPTION: 'caption', CAPTION: 'caption',
CAPTIONPOSITION: 'captionposition',
HEADERS: 'headers', HEADERS: 'headers',
ROWS: 'rows', ROWS: 'rows',
COLUMNS: 'columns', COLUMNS: 'columns',
@ -87,6 +102,7 @@ var COMPONENT = 'atto_table',
}, },
SELECTORS = { SELECTORS = {
CAPTION: '.' + CSS.CAPTION, CAPTION: '.' + CSS.CAPTION,
CAPTIONPOSITION: '.' + CSS.CAPTIONPOSITION,
HEADERS: '.' + CSS.HEADERS, HEADERS: '.' + CSS.HEADERS,
ROWS: '.' + CSS.ROWS, ROWS: '.' + CSS.ROWS,
COLUMNS: '.' + CSS.COLUMNS, COLUMNS: '.' + CSS.COLUMNS,
@ -312,6 +328,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_updateTable: function(e) { _updateTable: function(e) {
var caption, var caption,
captionposition,
headers, headers,
table, table,
captionnode; captionnode;
@ -324,16 +341,21 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Add/update the caption. // Add/update the caption.
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
table = this._lastTarget.ancestor('table'); table = this._lastTarget.ancestor('table');
captionnode = table.one('caption'); captionnode = table.one('caption');
if (!captionnode) { if (!captionnode) {
captionnode = Y.Node.create('<caption></caption'); captionnode = Y.Node.create('<caption></caption>');
table.insert(captionnode, 0); table.insert(captionnode, 0);
} }
captionnode.setHTML(caption.get('value')); captionnode.setHTML(caption.get('value'));
captionnode.setStyle('caption-side', captionposition.get('value'));
if (!captionnode.getAttribute('style')) {
captionnode.removeAttribute('style');
}
// Add the row headers. // Add the row headers.
if (headers.get('value') === 'rows' || headers.get('value') === 'both') { if (headers.get('value') === 'rows' || headers.get('value') === 'both') {
@ -405,6 +427,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_setTable: function(e) { _setTable: function(e) {
var caption, var caption,
captionposition,
rows, rows,
cols, cols,
headers, headers,
@ -419,6 +442,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}).hide(); }).hide();
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS); rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS);
cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS); cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
@ -429,8 +453,12 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click. // Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n"; var nl = "\n";
tablehtml = '<br/>' + nl + '<table>' + nl; tablehtml = '<br/>' + nl + '<table>' + nl;
tablehtml += '<caption>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
captionstyle = ' style="caption-side: ' + captionposition.get('value') + '"';
}
tablehtml += '<caption' + captionstyle + '>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
i = 0; i = 0;
if (headers.get('value') === 'columns' || headers.get('value') === 'both') { if (headers.get('value') === 'columns' || headers.get('value') === 'both') {
i = 1; i = 1;
@ -890,6 +918,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue. // Set the dialogue content, and then show the dialogue.
var node = this._getEditDialogueContent(), var node = this._getEditDialogueContent(),
captioninput = node.one(SELECTORS.CAPTION), captioninput = node.one(SELECTORS.CAPTION),
captionpositioninput = node.one(SELECTORS.CAPTIONPOSITION),
headersinput = node.one(SELECTORS.HEADERS), headersinput = node.one(SELECTORS.HEADERS),
table = this._lastTarget.ancestor('table'), table = this._lastTarget.ancestor('table'),
captionnode = table.one('caption'); captionnode = table.one('caption');
@ -900,6 +929,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captioninput.set('value', ''); captioninput.set('value', '');
} }
if (captionpositioninput && captionnode.getAttribute('style')) {
captionpositioninput.set('value', captionnode.getStyle('caption-side'));
} else {
// Default to none.
captionpositioninput.set('value', '');
}
var headersvalue = 'columns'; var headersvalue = 'columns';
if (table.one('th[scope="row"]')) { if (table.one('th[scope="row"]')) {
headersvalue = 'rows'; headersvalue = 'rows';

File diff suppressed because one or more lines are too long

View file

@ -40,6 +40,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -58,6 +65,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -79,6 +93,7 @@ var COMPONENT = 'atto_table',
'</form>', '</form>',
CSS = { CSS = {
CAPTION: 'caption', CAPTION: 'caption',
CAPTIONPOSITION: 'captionposition',
HEADERS: 'headers', HEADERS: 'headers',
ROWS: 'rows', ROWS: 'rows',
COLUMNS: 'columns', COLUMNS: 'columns',
@ -87,6 +102,7 @@ var COMPONENT = 'atto_table',
}, },
SELECTORS = { SELECTORS = {
CAPTION: '.' + CSS.CAPTION, CAPTION: '.' + CSS.CAPTION,
CAPTIONPOSITION: '.' + CSS.CAPTIONPOSITION,
HEADERS: '.' + CSS.HEADERS, HEADERS: '.' + CSS.HEADERS,
ROWS: '.' + CSS.ROWS, ROWS: '.' + CSS.ROWS,
COLUMNS: '.' + CSS.COLUMNS, COLUMNS: '.' + CSS.COLUMNS,
@ -312,6 +328,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_updateTable: function(e) { _updateTable: function(e) {
var caption, var caption,
captionposition,
headers, headers,
table, table,
captionnode; captionnode;
@ -324,16 +341,21 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Add/update the caption. // Add/update the caption.
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
table = this._lastTarget.ancestor('table'); table = this._lastTarget.ancestor('table');
captionnode = table.one('caption'); captionnode = table.one('caption');
if (!captionnode) { if (!captionnode) {
captionnode = Y.Node.create('<caption></caption'); captionnode = Y.Node.create('<caption></caption>');
table.insert(captionnode, 0); table.insert(captionnode, 0);
} }
captionnode.setHTML(caption.get('value')); captionnode.setHTML(caption.get('value'));
captionnode.setStyle('caption-side', captionposition.get('value'));
if (!captionnode.getAttribute('style')) {
captionnode.removeAttribute('style');
}
// Add the row headers. // Add the row headers.
if (headers.get('value') === 'rows' || headers.get('value') === 'both') { if (headers.get('value') === 'rows' || headers.get('value') === 'both') {
@ -405,6 +427,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_setTable: function(e) { _setTable: function(e) {
var caption, var caption,
captionposition,
rows, rows,
cols, cols,
headers, headers,
@ -419,6 +442,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}).hide(); }).hide();
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS); rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS);
cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS); cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
@ -429,8 +453,12 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click. // Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n"; var nl = "\n";
tablehtml = '<br/>' + nl + '<table>' + nl; tablehtml = '<br/>' + nl + '<table>' + nl;
tablehtml += '<caption>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
captionstyle = ' style="caption-side: ' + captionposition.get('value') + '"';
}
tablehtml += '<caption' + captionstyle + '>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
i = 0; i = 0;
if (headers.get('value') === 'columns' || headers.get('value') === 'both') { if (headers.get('value') === 'columns' || headers.get('value') === 'both') {
i = 1; i = 1;
@ -890,6 +918,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue. // Set the dialogue content, and then show the dialogue.
var node = this._getEditDialogueContent(), var node = this._getEditDialogueContent(),
captioninput = node.one(SELECTORS.CAPTION), captioninput = node.one(SELECTORS.CAPTION),
captionpositioninput = node.one(SELECTORS.CAPTIONPOSITION),
headersinput = node.one(SELECTORS.HEADERS), headersinput = node.one(SELECTORS.HEADERS),
table = this._lastTarget.ancestor('table'), table = this._lastTarget.ancestor('table'),
captionnode = table.one('caption'); captionnode = table.one('caption');
@ -900,6 +929,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captioninput.set('value', ''); captioninput.set('value', '');
} }
if (captionpositioninput && captionnode.getAttribute('style')) {
captionpositioninput.set('value', captionnode.getStyle('caption-side'));
} else {
// Default to none.
captionpositioninput.set('value', '');
}
var headersvalue = 'columns'; var headersvalue = 'columns';
if (table.one('th[scope="row"]')) { if (table.one('th[scope="row"]')) {
headersvalue = 'rows'; headersvalue = 'rows';

View file

@ -38,6 +38,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -56,6 +63,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' + '<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<br/>' + '<br/>' +
'<br/>' + '<br/>' +
'<label for="{{elementid}}_atto_table_captionposition" class="sameline">{{get_string "captionposition" component}}</label>' +
'<select class="{{CSS.CAPTIONPOSITION}}" id="{{elementid}}_atto_table_captionposition">' +
'<option value=""></option>' +
'<option value="top">{{get_string "top" "editor"}}</option>' +
'<option value="bottom">{{get_string "bottom" "editor"}}</option>' +
'</select>' +
'<br/>' +
'<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' + '<label for="{{elementid}}_atto_table_headers" class="sameline">{{get_string "headers" component}}</label>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' + '<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' + '<option value="columns">{{get_string "columns" component}}' + '</option>' +
@ -77,6 +91,7 @@ var COMPONENT = 'atto_table',
'</form>', '</form>',
CSS = { CSS = {
CAPTION: 'caption', CAPTION: 'caption',
CAPTIONPOSITION: 'captionposition',
HEADERS: 'headers', HEADERS: 'headers',
ROWS: 'rows', ROWS: 'rows',
COLUMNS: 'columns', COLUMNS: 'columns',
@ -85,6 +100,7 @@ var COMPONENT = 'atto_table',
}, },
SELECTORS = { SELECTORS = {
CAPTION: '.' + CSS.CAPTION, CAPTION: '.' + CSS.CAPTION,
CAPTIONPOSITION: '.' + CSS.CAPTIONPOSITION,
HEADERS: '.' + CSS.HEADERS, HEADERS: '.' + CSS.HEADERS,
ROWS: '.' + CSS.ROWS, ROWS: '.' + CSS.ROWS,
COLUMNS: '.' + CSS.COLUMNS, COLUMNS: '.' + CSS.COLUMNS,
@ -310,6 +326,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_updateTable: function(e) { _updateTable: function(e) {
var caption, var caption,
captionposition,
headers, headers,
table, table,
captionnode; captionnode;
@ -322,16 +339,21 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Add/update the caption. // Add/update the caption.
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
table = this._lastTarget.ancestor('table'); table = this._lastTarget.ancestor('table');
captionnode = table.one('caption'); captionnode = table.one('caption');
if (!captionnode) { if (!captionnode) {
captionnode = Y.Node.create('<caption></caption'); captionnode = Y.Node.create('<caption></caption>');
table.insert(captionnode, 0); table.insert(captionnode, 0);
} }
captionnode.setHTML(caption.get('value')); captionnode.setHTML(caption.get('value'));
captionnode.setStyle('caption-side', captionposition.get('value'));
if (!captionnode.getAttribute('style')) {
captionnode.removeAttribute('style');
}
// Add the row headers. // Add the row headers.
if (headers.get('value') === 'rows' || headers.get('value') === 'both') { if (headers.get('value') === 'rows' || headers.get('value') === 'both') {
@ -403,6 +425,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/ */
_setTable: function(e) { _setTable: function(e) {
var caption, var caption,
captionposition,
rows, rows,
cols, cols,
headers, headers,
@ -417,6 +440,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}).hide(); }).hide();
caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION); caption = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTION);
captionposition = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.CAPTIONPOSITION);
rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS); rows = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.ROWS);
cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS); cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS); headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
@ -427,8 +451,12 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click. // Note there are some spaces inserted in the cells and before and after, so that users have somewhere to click.
var nl = "\n"; var nl = "\n";
tablehtml = '<br/>' + nl + '<table>' + nl; tablehtml = '<br/>' + nl + '<table>' + nl;
tablehtml += '<caption>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
var captionstyle = '';
if (captionposition.get('value')) {
captionstyle = ' style="caption-side: ' + captionposition.get('value') + '"';
}
tablehtml += '<caption' + captionstyle + '>' + Y.Escape.html(caption.get('value')) + '</caption>' + nl;
i = 0; i = 0;
if (headers.get('value') === 'columns' || headers.get('value') === 'both') { if (headers.get('value') === 'columns' || headers.get('value') === 'both') {
i = 1; i = 1;
@ -888,6 +916,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
// Set the dialogue content, and then show the dialogue. // Set the dialogue content, and then show the dialogue.
var node = this._getEditDialogueContent(), var node = this._getEditDialogueContent(),
captioninput = node.one(SELECTORS.CAPTION), captioninput = node.one(SELECTORS.CAPTION),
captionpositioninput = node.one(SELECTORS.CAPTIONPOSITION),
headersinput = node.one(SELECTORS.HEADERS), headersinput = node.one(SELECTORS.HEADERS),
table = this._lastTarget.ancestor('table'), table = this._lastTarget.ancestor('table'),
captionnode = table.one('caption'); captionnode = table.one('caption');
@ -898,6 +927,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
captioninput.set('value', ''); captioninput.set('value', '');
} }
if (captionpositioninput && captionnode.getAttribute('style')) {
captionpositioninput.set('value', captionnode.getStyle('caption-side'));
} else {
// Default to none.
captionpositioninput.set('value', '');
}
var headersvalue = 'columns'; var headersvalue = 'columns';
if (table.one('th[scope="row"]')) { if (table.one('th[scope="row"]')) {
headersvalue = 'rows'; headersvalue = 'rows';