PluginProbe
Easy Bootstrap Shortcode / 3.4
Easy Bootstrap Shortcode v3.4
trunk 2.4.0 2.5 3.4 3.5 3.6 3.7 4.0.0 4.4 4.5 4.5.4 5.0.0 5.0.1 5.0.2
easy-bootstrap-shortcodes / shortcode / tables / tables_plugin.js

tables_plugin.js in Easy Bootstrap Shortcode 3.4, at shortcode/tables/tables_plugin.js

140 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 tinymce.create('tinymce.plugins.oscitasTables', {
3 init : function(ed, url) {
4 ed.addButton('oscitastables', {
5 title : 'Create Tables',
6 image : url+'/icon.png',
7 onclick : function() {
8 jQuery.fancybox({
9 'type' : 'inline',
10 'title' : 'Tables Shortcode',
11 'href' : '#oscitas-form-table',
12
13 helpers: {
14 title : {
15 type : 'over',
16 position:'top'
17 }
18 }
19 });
20 }
21 });
22 },
23 createControl : function(n, cm) {
24 return null;
25 },
26 getInfo : function() {
27 return {
28 longname : "Tables Shortcode",
29 author : 'Oscitas Themes',
30 authorurl : 'http://www.oscitasthemes.com/',
31 infourl : 'http://www.oscitasthemes.com/',
32 version : "1.0"
33 };
34 }
35 });
36 tinymce.PluginManager.add('oscitastables', tinymce.plugins.oscitasTables);
37 })();
38
39 jQuery(function(){
40 // creates a form to be displayed everytime the button is clicked
41 // you should achieve this using AJAX instead of direct html code like this
42 var form = jQuery('<div id="oscitas-form-table"><table id="oscitas-table" class="form-table">\
43 <tr>\
44 <th><label for="oscitas-table-width">Table Width</label></th>\
45 <td><input type="text" name="icontag" id="oscitas-table-width" value="100%" /><br />\
46 </td>\
47 </tr>\
48 <tr>\
49 <th><label for="oscitas-table-columns">Columns</label></th>\
50 <td><input type="text" name="link" id="oscitas-table-columns" value="4" /><br />\
51 </td>\
52 </tr>\
53 <tr>\
54 <th><label for="oscitas-table-rows">Rows</label></th>\
55 <td><input type="text" name="title" id="oscitas-table-rows" value="4" /><br />\
56 </td>\
57 </tr>\
58 <tr>\
59 <th><label for="oscitas-table-rows">Table style</label></th>\
60 <td>\
61 <select name="tablestyle" id="oscitas-table-style">\
62 <option value="">Simple</option>\
63 <option value="table-striped">Striped</option>\
64 <option value="table-bordered">Bordered</option>\
65 <option value="table-striped table-bordered">Striped + Bordered</option>\
66 </select>\
67 <br />\
68 </td>\
69 </tr>\
70 <tr>\
71 <th><label for="oscitas-table-rows">Show hover effect</label></th>\
72 <td>\
73 <input type="checkbox" id="oscitas-table-hover" value="table-hover">\
74 <br />\
75 </td>\
76 </tr>\
77 <tr>\
78 <th><label for="oscitas-table-rows">Responsive</label></th>\
79 <td>\
80 <input type="checkbox" id="oscitas-table-scroll" value="table-responsive">\
81 <br />\
82 </td>\
83 </tr>\
84 </table>\
85 <p class="submit">\
86 <input type="button" id="oscitas-submit" class="button-primary" value="Insert Table" name="submit" />\
87 </p>\
88 </div>');
89
90 var table = form.find('table');
91 form.appendTo('body').hide();
92
93 // handles the click event of the submit button
94 form.find('#oscitas-submit').click(function(){
95 // defines the options and their default values
96 // again, this is not the most elegant way to do this
97 // but well, this gets the job done nonetheless
98
99 var columns = table.find('#oscitas-table-columns').val();
100 var rows = table.find('#oscitas-table-rows').val();
101 var value = table.find('#oscitas-table-width').val();
102 var osStyle = table.find('#oscitas-table-style').val();
103
104 var osHover = table.find('#oscitas-table-hover').prop('checked') ? ' table-hover' : '' ;
105 var osScroll = table.find('#oscitas-table-scroll').prop('checked')? 'true': 'false';
106 //creating table
107 var shortcode = '[table ';
108 shortcode += 'width ="' + value + '"';
109 shortcode += ' class ="' + osStyle +osHover+ '"';
110 shortcode += ' responsive ="' +osScroll+ '"';
111
112 shortcode += ']<br/>[table_head]<br/>';
113 for (var i=1;i<=columns;i++)
114 {
115 shortcode += '[th_column]Heading-'+i+'[/th_column]<br/>';
116 }
117 shortcode += '[/table_head]<br/>[table_body]<br/>';
118
119 for (var j=1;j<=rows;j++)
120 {
121 shortcode += '[table_row]<br/>';
122 for (var i=1;i<=columns;i++)
123 {
124 shortcode += '[row_column]value-'+i+'[/row_column]<br/>';
125 }
126
127 shortcode += '[/table_row]<br/>';
128 }
129 shortcode += '[/table_body]<br/>[/table]';
130
131
132 // inserts the shortcode into the active editor
133 tinyMCE.activeEditor.execCommand('mceInsertContent', 0, shortcode);
134
135 // closes fancybox
136 jQuery.fancybox.close();
137 });
138 });
139
140