Add Classes and ID to table properties
-
We are building a website using Bootstrap 3 and needed to have tinymce table plugin to build our tables. We loved your plugin, but we had just a couple of problems. Mainly, for twitter bootstrap to work, we needed to add classes and ids to the table.
We took your code and modified it to do this with just a couple of changes to the plugin for the v4 plugin. The main changes were made to the tableDialog function and it was just adding a couple of items in. I thought that you would like to see these changes and include them in a future release.
function tableDialog() { var dom = editor.dom, tableElm, data; tableElm = dom.getParent(editor.selection.getStart(), 'table'); data = { width: removePxSuffix(dom.getStyle(tableElm, 'width') || dom.getAttrib(tableElm, 'width')), height: removePxSuffix(dom.getStyle(tableElm, 'height') || dom.getAttrib(tableElm, 'height')), cellspacing: dom.getAttrib(tableElm, 'cellspacing'), cellpadding: dom.getAttrib(tableElm, 'cellpadding'), border: dom.getAttrib(tableElm, 'border'), cssClasses: dom.getAttrib(tableElm, 'class').replace(' mce-item-table', '').replace('mce-item-table', ''), cssId: dom.getAttrib(tableElm, 'id'), caption: !!dom.select('caption', tableElm)[0] }; console.log(data); each('left center right'.split(' '), function(name) { if (editor.formatter.matchNode(tableElm, 'align' + name)) { data.align = name; } }); editor.windowManager.open({ title: "Table properties", items: { type: 'form', layout: 'grid', columns: 2, data: data, defaults: { type: 'textbox', maxWidth: 50 }, items: [ {label: 'Width', name: 'width'}, {label: 'Height', name: 'height'}, {label: 'CSS Classes', name: 'cssClasses', maxWidth: 200}, {label: 'CSS ID', name: 'cssId', maxWidth: 200}, {label: 'Cell spacing', name: 'cellspacing'}, {label: 'Cell padding', name: 'cellpadding'}, {label: 'Border', name: 'border'}, {label: 'Caption', name: 'caption', type: 'checkbox'}, { label: 'Alignment', minWidth: 90, name: 'align', type: 'listbox', text: 'None', maxWidth: null, values: [ {text: 'None', value: ''}, {text: 'Left', value: 'left'}, {text: 'Center', value: 'center'}, {text: 'Right', value: 'right'} ] } ] }, onsubmit: function() { var data = this.toJSON(), captionElm; console.log(data); editor.undoManager.transact(function() { editor.dom.setAttribs(tableElm, { cellspacing: data.cellspacing, cellpadding: data.cellpadding, border: data.border, class: data.cssClasses, id: data.cssId }); editor.dom.setStyles(tableElm, { width: addSizeSuffix(data.width), height: addSizeSuffix(data.height) }); // Toggle caption on/off captionElm = dom.select('caption', tableElm)[0]; if (captionElm && !data.caption) { dom.remove(captionElm); } if (!captionElm && data.caption) { captionElm = dom.create('caption'); captionElm.innerHTML = !Env.ie ? '<br data-mce-bogus="1"/>' : '\u00a0'; tableElm.insertBefore(captionElm, tableElm.firstChild); } unApplyAlign(tableElm); if (data.align) { editor.formatter.apply('align' + data.align, {}, tableElm); } editor.focus(); editor.addVisual(); }); } }); }
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘Add Classes and ID to table properties’ is closed to new replies.