You are here

bueditor.button.custom_table.yml in BUEditor 8.2

Same filename and directory in other branches
  1. 8 config/install/bueditor.button.custom_table.yml
config/install/bueditor.button.custom_table.yml

File

config/install/bueditor.button.custom_table.yml
View source
  1. # Custom button that inserts table html.
  2. id: custom_table
  3. label: 'Table'
  4. tooltip: 'Insert table'
  5. cname: 'ficon-table'
  6. code: |
  7. js:
  8. // Form fields
  9. var fields = [
  10. {type: 'number', value: 2, required: true, attributes: {min: 1}, name: 'rows', title: 'Rows'},
  11. {type: 'number', value: 2, required: true, attributes: {min: 1}, name: 'cols', title: 'Columns'}
  12. ];
  13. // Submit handler
  14. var submitHandler = function(htmlObj, Popup, E) {
  15. // Get number of cols and rows.
  16. var i, attr = htmlObj.attributes, cols = Math.max(attr.cols * 1, 1), rows = Math.max(attr.rows * 1, 1);
  17. // Prevent them to be printed as attribute values.
  18. attr.cols = attr.rows = null;
  19. // Create cells
  20. var cells = '';
  21. for (i = 0; i < cols; i++) {
  22. cells += '\n ' + BUE.html('td', 'Data' + (i + 1));
  23. }
  24. // Create table body
  25. var body = '';
  26. for (i = 0; i < rows; i++) {
  27. body += '\n ' + BUE.html('tr', cells + '\n ', {'class': i % 2 ? 'even' : 'odd'});
  28. }
  29. body = BUE.html('tbody', body + '\n');
  30. // Create table head
  31. var head = BUE.html('thead', '\n '+ BUE.html('tr', cells.replace(/td/g, 'th').replace(/Data/g, 'Header') + '\n ') + '\n');
  32. // Create the table
  33. var table = BUE.html('table', '\n' + head + '\n' + body + '\n', attr);
  34. // Insert
  35. E.setSelection(table, 'end');
  36. };
  37. // Open tag dialog
  38. E.tagDialog('custom_table', fields, {title: 'Insert table', submit: submitHandler});
  39. langcode: en