(function() { tinymce.create('tinymce.plugins.oscitasTables', { init : function(ed, url) { ed.addButton('oscitastables', { title : 'Create Tables', image : url+'/icon.png', onclick : function() { jQuery.fancybox({ 'type' : 'inline', 'title' : 'Tables Shortcode', 'href' : '#oscitas-form-table', helpers: { title : { type : 'over', position:'top' } } }); } }); }, createControl : function(n, cm) { return null; }, getInfo : function() { return { longname : "Tables Shortcode", author : 'Oscitas Themes', authorurl : 'http://www.oscitasthemes.com/', infourl : 'http://www.oscitasthemes.com/', version : "1.0" }; } }); tinymce.PluginManager.add('oscitastables', tinymce.plugins.oscitasTables); })(); jQuery(function(){ // creates a form to be displayed everytime the button is clicked // you should achieve this using AJAX instead of direct html code like this var form = jQuery('
\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \

\

\

\
\ \
\
\ \
\
\ \
\
\

\ \

\
'); var table = form.find('table'); form.appendTo('body').hide(); // handles the click event of the submit button form.find('#oscitas-submit').click(function(){ // defines the options and their default values // again, this is not the most elegant way to do this // but well, this gets the job done nonetheless var columns = table.find('#oscitas-table-columns').val(); var rows = table.find('#oscitas-table-rows').val(); var value = table.find('#oscitas-table-width').val(); var osStyle = table.find('#oscitas-table-style').val(); var osHover = table.find('#oscitas-table-hover').prop('checked') ? ' table-hover' : '' ; var osScroll = table.find('#oscitas-table-scroll').prop('checked')? 'true': 'false'; //creating table var shortcode = '[table '; shortcode += 'width ="' + value + '"'; shortcode += ' class ="' + osStyle +osHover+ '"'; shortcode += ' responsive ="' +osScroll+ '"'; shortcode += ']
[table_head]
'; for (var i=1;i<=columns;i++) { shortcode += '[th_column]Heading-'+i+'[/th_column]
'; } shortcode += '[/table_head]
[table_body]
'; for (var j=1;j<=rows;j++) { shortcode += '[table_row]
'; for (var i=1;i<=columns;i++) { shortcode += '[row_column]value-'+i+'[/row_column]
'; } shortcode += '[/table_row]
'; } shortcode += '[/table_body]
[/table]'; // inserts the shortcode into the active editor tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode); // closes fancybox jQuery.fancybox.close(); }); });