Skip to content

Commit

Permalink
MDL-50801 atto_table: Allow caption position to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Aug 19, 2015
1 parent dda862a commit 556decf
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 10 deletions.
1 change: 1 addition & 0 deletions lib/editor/atto/plugins/table/lang/en/atto_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$string['addrowafter'] = 'Insert row after';
$string['both'] = 'Both';
$string['caption'] = 'Caption';
$string['captionposition'] = 'Caption position';
$string['columns'] = 'Columns';
$string['createtable'] = 'Create table';
$string['deletecolumn'] = 'Delete column';
Expand Down
7 changes: 6 additions & 1 deletion lib/editor/atto/plugins/table/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ function atto_table_strings_for_js() {
'moverowdown',
'moverowup',
'deleterow',
'deletecolumn'),
'deletecolumn',
'captionposition'),
'atto_table');

$PAGE->requires->strings_for_js(array('top',
'bottom'),
'editor');
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<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>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' +
Expand All @@ -58,6 +65,13 @@ var COMPONENT = 'atto_table',
'<input class="{{CSS.CAPTION}} fullwidth" id="{{elementid}}_atto_table_caption" required />' +
'<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>' +
'<select class="{{CSS.HEADERS}}" id="{{elementid}}_atto_table_headers">' +
'<option value="columns">{{get_string "columns" component}}' + '</option>' +
Expand All @@ -79,6 +93,7 @@ var COMPONENT = 'atto_table',
'</form>',
CSS = {
CAPTION: 'caption',
CAPTIONPOSITION: 'captionposition',
HEADERS: 'headers',
ROWS: 'rows',
COLUMNS: 'columns',
Expand All @@ -87,6 +102,7 @@ var COMPONENT = 'atto_table',
},
SELECTORS = {
CAPTION: '.' + CSS.CAPTION,
CAPTIONPOSITION: '.' + CSS.CAPTIONPOSITION,
HEADERS: '.' + CSS.HEADERS,
ROWS: '.' + CSS.ROWS,
COLUMNS: '.' + CSS.COLUMNS,
Expand Down Expand Up @@ -312,6 +328,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/
_updateTable: function(e) {
var caption,
captionposition,
headers,
table,
captionnode;
Expand All @@ -324,16 +341,21 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi

// Add/update the 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);

table = this._lastTarget.ancestor('table');

captionnode = table.one('caption');
if (!captionnode) {
captionnode = Y.Node.create('<caption></caption');
captionnode = Y.Node.create('<caption></caption>');
table.insert(captionnode, 0);
}
captionnode.setHTML(caption.get('value'));
captionnode.setStyle('caption-side', captionposition.get('value'));
if (!captionnode.getAttribute('style')) {
captionnode.removeAttribute('style');
}

// Add the row headers.
if (headers.get('value') === 'rows' || headers.get('value') === 'both') {
Expand Down Expand Up @@ -405,6 +427,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
*/
_setTable: function(e) {
var caption,
captionposition,
rows,
cols,
headers,
Expand All @@ -419,6 +442,7 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
}).hide();

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);
cols = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.COLUMNS);
headers = e.currentTarget.ancestor(SELECTORS.FORM).one(SELECTORS.HEADERS);
Expand All @@ -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.
var nl = "\n";
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;
if (headers.get('value') === 'columns' || headers.get('value') === 'both') {
i = 1;
Expand Down Expand Up @@ -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.
var node = this._getEditDialogueContent(),
captioninput = node.one(SELECTORS.CAPTION),
captionpositioninput = node.one(SELECTORS.CAPTIONPOSITION),
headersinput = node.one(SELECTORS.HEADERS),
table = this._lastTarget.ancestor('table'),
captionnode = table.one('caption');
Expand All @@ -900,6 +929,13 @@ Y.namespace('M.atto_table').Button = Y.Base.create('button', Y.M.editor_atto.Edi
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';
if (table.one('th[scope="row"]')) {
headersvalue = 'rows';
Expand Down
Loading

0 comments on commit 556decf

Please sign in to comment.