scrivito_table_widget 0.1.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b4b4dd403b5309ea5cfb5fe6fb957fa50e02f09
4
- data.tar.gz: 6aa97aff54af329efec45da1a7081f3a7a522cb3
3
+ metadata.gz: 0a4a7b6eb4181e5078406454520df1f294ff8f17
4
+ data.tar.gz: 5c514110b283093e0513b47b09046bcec87aca82
5
5
  SHA512:
6
- metadata.gz: 74dc31085867e65bb5ff2c78f5c90b52b5549b4e8c7136f1d5a8e1e7813068c5c64c37352efd35a04c46e9a2c0de07ce385ea5b1130d9588c4fbf34470fb5ed0
7
- data.tar.gz: aac856e902a88137a608d13170f0467a948b31579b1c960b2eaf1dff1eae0e1b24433e3418ba7077194c56e0702d12340b20431b807bc1ee8d2d3c201338a9d0
6
+ metadata.gz: 6bf3db3474bec28e88a6d0db4fb0f7847b97d37a34d1ce023c030f4d2f1c18c18d3d0e6370e777f53b12c5e40e57ee97426f18042497a418ea8633238fa2c8ea
7
+ data.tar.gz: b7f4efc333b40433ef3e85a87f4df66a867a4f5ffc06c583d7510013f9c21ebb25db5a955b92aea09341f94de402c987092c32dea561e0297408a42ba8ab3337
data/README.md CHANGED
@@ -19,9 +19,9 @@ Add this line to your editing javascript manifest:
19
19
  After that, execute:
20
20
 
21
21
  $ bundle
22
- $ rake cms:migrate:install
23
- $ rake cms:migrate
24
- $ rake cms:migrate:publish
22
+ $ rake scrivito:migrate:install
23
+ $ rake scrivito:migrate
24
+ $ rake scrivito:migrate:publish
25
25
 
26
26
  ## Changelog
27
27
  See [Changelog](https://github.com/Scrivito/scrivito_table_widget/blob/master/CHANGELOG.md) for more
@@ -0,0 +1,21 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ $(function() {
5
+ var tableString = '<table class="table"><thead><tr><th>New Table</th></tr></thead><tbody><tr><td>With Content</td></tr></body></table>';
6
+
7
+ if(scrivito.in_editable_view()) {
8
+ $('body').on('click', '.create-new-table', function(e) {
9
+ $(this).removeClass('create-new-table');
10
+ $(this).addClass('table');
11
+
12
+ $(this).html(tableString);
13
+
14
+ $(this).parent().scrivito('save', tableString);
15
+
16
+ $(this).parent().scrivito('reload');
17
+ });
18
+ } // end if
19
+ });
20
+
21
+ })(jQuery, this);
@@ -10,5 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require table_widget/jquery.edit.table
14
- //= require table_widget/tableEditor
13
+ //= require_tree ./
@@ -0,0 +1,425 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ var activeTable = null;
5
+ var activeElement = null;
6
+ var cmsField;
7
+ var initialized = false;
8
+ var keysBound = false;
9
+ var rows = 0;
10
+ var cols = 0;
11
+
12
+ $.fn.edittable = function(opts) {
13
+ // initialize
14
+ if(!initialized) {
15
+ activeTable = this.parents('table');
16
+ cmsField = this.parents('[data-editor=table-editor]');
17
+
18
+ initialized = $.fn.edittable.initialize(cmsField, this);
19
+ rows = $.fn.edittable.getRowCount();
20
+ cols = $.fn.edittable.getColCount();
21
+ $.fn.edittable.bindButtons();
22
+ } else if(activeElement.get(0) != this.get(0)) {
23
+ //$.fn.edittable.save(cmsField);
24
+ }
25
+
26
+ if(!keysBound) {
27
+ $.fn.edittable.bindKeys();
28
+ }
29
+
30
+ // edit
31
+ if($(this).get(0).tagName == "TD" || $(this).get(0).tagName == "TH") {
32
+ activeElement = this;
33
+ cmsField.attr('contenteditable', true);
34
+ $.fn.edittable.setButtonPositions();
35
+ }
36
+ };
37
+
38
+ $.fn.edittable.bindKeys = function() {
39
+ $('body').keyup(function(e) {
40
+ var code = e.keyCode || e.which;
41
+ if(initialized) {
42
+ $.fn.edittable.setButtonPositions();
43
+ }
44
+ });
45
+ keysBound = true;
46
+ };
47
+
48
+ $.fn.edittable.getRowCount = function() {
49
+ return activeTable.find("tbody tr").length;
50
+ };
51
+
52
+ $.fn.edittable.getColCount = function() {
53
+ return activeTable.find("tbody tr").first().children().length;
54
+ };
55
+
56
+ $.fn.edittable.setButtonPositions = function() {
57
+ var base = activeElement.position();
58
+ var width = activeElement.outerWidth();
59
+ var height = activeElement.outerHeight();
60
+
61
+ $('.table-buttons.top').css({ top: "-11px", left: (base.left - 11), width: width + 23});
62
+ $('.table-buttons.edit').css({ top: (base.top - 16), left: (base.left + 5)});
63
+ $('.table-buttons.left').css({ top: (base.top - 12), left: -17, height: height + 24});
64
+ $('.table-buttons.bottom').css({ bottom: "-4px", left: (base.left + width/2 - 12)});
65
+ $('.table-buttons.right').css({ top: (base.top + height/2 - 11), right: -23});
66
+
67
+ if(activeElement.get(0).tagName == "TH") {
68
+ $('.table-buttons .add-top').hide();
69
+ } else {
70
+ $('.table-buttons .add-top').show();
71
+ }
72
+ }
73
+
74
+ $.fn.edittable.initialize = function(cmsField, element) {
75
+ var buttons_top = "<div class='table-buttons top'>"+ $.fn.edittable.buttonsTop() +"</div>";
76
+ var buttons_bottom = "<div class='table-buttons bottom'>"+ $.fn.edittable.buttonsBottom() +"</div>";
77
+ var buttons_left = "<div class='table-buttons left'>"+ $.fn.edittable.buttonsLeft() +"</div>";
78
+ var buttons_right = "<div class='table-buttons right'>"+ $.fn.edittable.buttonsRight() +"</div>";
79
+ var buttons_edit = "<div class='table-buttons edit'>"+ $.fn.edittable.buttonsEdit() +"</div>";
80
+ var buttons_main = "<div class='table-options main'>"+ $.fn.edittable.buttonsMain() +"</div>";
81
+ $("<div class='edit-table'>" + buttons_main + buttons_top + buttons_left + buttons_right + buttons_edit + buttons_bottom + "</div>").insertBefore(cmsField);
82
+ $("<div class='helper-line'></div>").insertBefore(cmsField);
83
+ return true;
84
+ }
85
+
86
+ $.fn.edittable.clear = function() {
87
+ if(initialized) {
88
+ var text = activeTable.get(0).outerHTML;
89
+ var field = cmsField;
90
+ activeTable = null;
91
+ activeElement = null;
92
+ initialized = false;
93
+ cmsField = null;
94
+ $('.edit-table').remove();
95
+ rows = 0;
96
+ cols = 0;
97
+ return {text: text, cmsField: field};
98
+ }
99
+ }
100
+
101
+ $.fn.edittable.save = function(cmsField) {
102
+ var text = activeTable.get(0).outerHTML;
103
+ $(cmsField).scrivito('save', text);
104
+ }
105
+
106
+ /****
107
+ * Button bars
108
+ ****/
109
+
110
+ $.fn.edittable.buttonsTop = function() {
111
+ return $.fn.edittable.button("", "+", "add-left") +
112
+ $.fn.edittable.button("", "+", "add-right");
113
+ }
114
+
115
+ $.fn.edittable.buttonsEdit = function() {
116
+ return $.fn.edittable.button("", "B", "table-bold") +
117
+ $.fn.edittable.button("", "I", "table-italic") +
118
+ $.fn.edittable.button("", "L", "table-left") +
119
+ $.fn.edittable.button("", "C", "table-center") +
120
+ $.fn.edittable.button("", "R", "table-right");
121
+ }
122
+
123
+ $.fn.edittable.buttonsBottom = function() {
124
+ return $.fn.edittable.button("", "-", "delete-column");
125
+ }
126
+
127
+ $.fn.edittable.buttonsLeft = function() {
128
+ return $.fn.edittable.button("", "+", "add-top") +
129
+ $.fn.edittable.button("", "+", "add-bottom");
130
+ }
131
+
132
+ $.fn.edittable.buttonsRight = function() {
133
+ return $.fn.edittable.button("", "-", "delete-row");
134
+ }
135
+
136
+ $.fn.edittable.buttonsMain = function() {
137
+ return $.fn.edittable.button("none", "striped", "stripe-table alert-gray") +
138
+ $.fn.edittable.button("none", "condenced", "condence-table alert-gray") +
139
+ $.fn.edittable.button("none", "hover", "hover-table alert-gray") +
140
+ $.fn.edittable.button("none", "border", "border-table alert-gray") +
141
+ $.fn.edittable.button("none", "first-column", "first-column alert-gray") +
142
+ $.fn.edittable.button("none", "success", "add-success alert-success") +
143
+ $.fn.edittable.button("none", "info", "add-info alert-info") +
144
+ $.fn.edittable.button("none", "warning", "add-warning alert-warning") +
145
+ $.fn.edittable.button("none", "danger", "add-danger alert-danger");
146
+ }
147
+
148
+ $.fn.edittable.button = function(icon, text, f) {
149
+ var faIcon = icon == "none" ? "" : "<i class='fa fa-"+ icon +"'></i>";
150
+ var button = "<div class='"+ f +"'>" + faIcon + text +"</div>";
151
+ return button;
152
+ }
153
+
154
+ /****
155
+ * Button click handlers
156
+ ****/
157
+
158
+ $.fn.edittable.bindButtons = function() {
159
+ $('.table-widget').find('.add-top').on('click', function() { $.fn.edittable.addTop(); });
160
+ $('.table-widget').find('.add-bottom').on('click', function() { $.fn.edittable.addBottom(); });
161
+ $('.table-widget').find('.add-left').on('click', function() { $.fn.edittable.addLeft(); });
162
+ $('.table-widget').find('.add-right').on('click', function() { $.fn.edittable.addRight(); });
163
+ $('.table-widget').find('.table-bold').on('click', function() { $.fn.edittable.bold(); });
164
+ $('.table-widget').find('.table-italic').on('click', function() { $.fn.edittable.italic(); });
165
+ $('.table-widget').find('.delete-row').on('click', function() { $.fn.edittable.removeRow(); });
166
+ $('.table-widget').find('.delete-column').on('click', function() { $.fn.edittable.removeColumn(); });
167
+ $('.table-widget').find('.stripe-table').on('click', function() { $.fn.edittable.tableStriped(); });
168
+ $('.table-widget').find('.condence-table').on('click', function() { $.fn.edittable.tableCondensed(); });
169
+ $('.table-widget').find('.hover-table').on('click', function() { $.fn.edittable.tableHover(); });
170
+ $('.table-widget').find('.border-table').on('click', function() { $.fn.edittable.tableBorder(); });
171
+ $('.table-widget').find('.first-column').on('click', function() { $.fn.edittable.firstColumn(); });
172
+ $('.table-widget').find('.add-success').on('click', function() { $.fn.edittable.addSuccess(); });
173
+ $('.table-widget').find('.add-info').on('click', function() { $.fn.edittable.addInfo(); });
174
+ $('.table-widget').find('.add-warning').on('click', function() { $.fn.edittable.addWarning(); });
175
+ $('.table-widget').find('.add-danger').on('click', function() { $.fn.edittable.addDanger(); });
176
+ $('.table-widget').find('.table-left').on('click', function() { $.fn.edittable.tableLeft(); });
177
+ $('.table-widget').find('.table-center').on('click', function() { $.fn.edittable.tableCenter(); });
178
+ $('.table-widget').find('.table-right').on('click', function() { $.fn.edittable.tableRight(); });
179
+
180
+ $('.table-widget').find('.add-left, .add-right').on('mouseover', function() { $.fn.edittable.addHoverVerticalAdd($(this)); });
181
+ $('.table-widget').find('.add-top, .add-bottom').on('mouseover', function() { $.fn.edittable.addHoverHorizontalAdd($(this)); });
182
+
183
+
184
+ $('.table-widget').find('.delete-column').on('mouseover', function() { $.fn.edittable.deleteHoverColumn($(this)); });
185
+ $('.table-widget').find('.delete-row').on('mouseover', function() { $.fn.edittable.deleteHoverRow($(this)); });
186
+
187
+ $('.table-widget').find('.add-left, .add-right, .add-top, .add-bottom, .delete-column, .delete-row').on('mouseout', function() { $.fn.edittable.resetHelperLine(); });
188
+ }
189
+
190
+ /****
191
+ * Hover button methods
192
+ ****/
193
+
194
+ $.fn.edittable.addHoverVerticalAdd = function(elem) {
195
+ var pos = elem.position();
196
+ var barPos = $('.table-buttons.top').position();
197
+
198
+ $('.helper-line').css({
199
+ height: activeTable.outerHeight(),
200
+ width: 2,
201
+ top: 0,
202
+ left: barPos.left + pos.left + 11,
203
+ background: '#439439'
204
+ }).fadeIn(100);
205
+ }
206
+
207
+ $.fn.edittable.addHoverHorizontalAdd = function(elem) {
208
+ var pos = elem.position();
209
+ var barPos = $('.table-buttons.left').position();
210
+
211
+ $('.helper-line').css({
212
+ height: 2,
213
+ width: activeTable.outerWidth(),
214
+ top: barPos.top + pos.top + 11,
215
+ left: 0,
216
+ background: '#439439'
217
+ }).fadeIn(100);
218
+ }
219
+
220
+ $.fn.edittable.deleteHoverColumn = function(elem) {
221
+ var index = activeElement.index() + 1;
222
+ var elems = activeTable.find('td:nth-child('+ index +'), th:nth-child('+ index +')');
223
+ elems.addClass('delete-marker');
224
+ }
225
+
226
+ $.fn.edittable.deleteHoverRow = function(elem) {
227
+ var row = activeElement.parents('tr');
228
+ row.addClass('delete-marker');
229
+ }
230
+
231
+ $.fn.edittable.resetHelperLine = function() {
232
+ $('.helper-line').css({
233
+ height: 0,
234
+ width: 0,
235
+ top: 0,
236
+ left: 0,
237
+ border: 'none'
238
+ }).fadeOut(100);
239
+
240
+ activeTable.find('.delete-marker').removeClass('delete-marker');
241
+ activeTable.find('[class=""]').removeAttr('class');
242
+ }
243
+
244
+ /****
245
+ * Button methods
246
+ ****/
247
+
248
+ $.fn.edittable.bold = function() {
249
+ activeElement.toggleClass('bold');
250
+ $.fn.edittable.save(cmsField);
251
+ }
252
+
253
+ $.fn.edittable.italic = function() {
254
+ activeElement.toggleClass('italic');
255
+ $.fn.edittable.save(cmsField);
256
+ }
257
+
258
+ $.fn.edittable.addTop = function() {
259
+ var newRow = activeElement.parents('tr').get(0).outerHTML;
260
+
261
+ $(newRow).insertBefore( activeElement.parents('tr') );
262
+ rows += 1;
263
+ $.fn.edittable.setButtonPositions();
264
+ $.fn.edittable.save(cmsField);
265
+ }
266
+
267
+ $.fn.edittable.addBottom = function() {
268
+ var newRow = "<tr>"+ new Array(cols + 1).join("<td>Content</td>"); +"</tr>";
269
+
270
+ if(activeElement.get(0).tagName == 'TD') {
271
+ $(newRow).insertAfter( activeElement.parents('tr') );
272
+ } else {
273
+ $(newRow).insertBefore( activeTable.find('tbody tr').first() );
274
+ }
275
+
276
+ rows += 1;
277
+ $.fn.edittable.setButtonPositions();
278
+ $.fn.edittable.save(cmsField);
279
+ }
280
+
281
+ $.fn.edittable.addLeft = function() {
282
+ var pos = activeElement.index();
283
+
284
+ activeTable.find("thead tr").each(function(index, row) {
285
+ $($(row).find("th")[pos]).before("<th>Head</th>");
286
+ });
287
+
288
+ activeTable.find("tbody tr").each(function(index, row) {
289
+ $($(row).find("td")[pos]).before("<td>Content</td>");
290
+ });
291
+
292
+ cols += 1;
293
+ $.fn.edittable.setButtonPositions();
294
+ $.fn.edittable.save(cmsField);
295
+ };
296
+
297
+ $.fn.edittable.addRight = function() {
298
+ var pos = activeElement.index();
299
+
300
+ activeTable.find("thead tr").each(function(index, row) {
301
+ $($(row).find("th")[pos]).after("<th>Head</th>");
302
+ });
303
+
304
+ activeTable.find("tbody tr").each(function(index, row) {
305
+ $($(row).find("td")[pos]).after("<td>Content</td>");
306
+ });
307
+
308
+ cols += 1;
309
+ $.fn.edittable.setButtonPositions();
310
+ $.fn.edittable.save(cmsField);
311
+ };
312
+
313
+ $.fn.edittable.removeColumn = function() {
314
+ var pos = activeElement.index();
315
+ var activeRow = activeElement.parents('tr');
316
+ var next = pos == 0 ? '0' : pos-1;
317
+
318
+ if(cols > 0) {
319
+ activeTable.find("tr").each(function(index, row) {
320
+ $(row).children()[pos].remove();
321
+ });
322
+
323
+ activeRow.find('td')[next].click();
324
+
325
+ cols -= 1;
326
+ }
327
+
328
+
329
+ $.fn.edittable.setButtonPositions();
330
+ $.fn.edittable.save(cmsField);
331
+ };
332
+
333
+ $.fn.edittable.removeRow = function() {
334
+ var pos = activeElement.index();
335
+ var next = pos == 0 ? '0' : pos-1;
336
+ var activeRowIndex = activeElement.parents('tr').index();
337
+
338
+ if(rows > 0) {
339
+ activeElement.parents("tr").remove();
340
+ $(activeTable.find('tbody tr')[activeRowIndex]).find('td').click();
341
+ }
342
+ $.fn.edittable.setButtonPositions();
343
+ $.fn.edittable.save(cmsField);
344
+ };
345
+
346
+ $.fn.edittable.tableStriped = function() {
347
+ activeTable.toggleClass('table-striped');
348
+ $.fn.edittable.save(cmsField);
349
+ };
350
+
351
+ $.fn.edittable.tableCondensed = function() {
352
+ activeTable.toggleClass('table-condensed');
353
+ $.fn.edittable.setButtonPositions();
354
+ $.fn.edittable.save(cmsField);
355
+ };
356
+
357
+ $.fn.edittable.tableHover = function() {
358
+ activeTable.toggleClass('table-hover');
359
+ $.fn.edittable.save(cmsField);
360
+ };
361
+
362
+ $.fn.edittable.tableBorder = function() {
363
+ activeTable.toggleClass('table-bordered');
364
+ $.fn.edittable.save(cmsField);
365
+ };
366
+
367
+ $.fn.edittable.firstColumn = function() {
368
+ activeTable.toggleClass('column-first');
369
+ $.fn.edittable.save(cmsField);
370
+ };
371
+
372
+ $.fn.edittable.addSuccess = function() {
373
+ activeElement.removeClass('info');
374
+ activeElement.removeClass('warning');
375
+ activeElement.removeClass('danger');
376
+ activeElement.toggleClass('success');
377
+ $.fn.edittable.save(cmsField);
378
+ };
379
+
380
+ $.fn.edittable.addInfo = function() {
381
+ activeElement.removeClass('success');
382
+ activeElement.removeClass('warning');
383
+ activeElement.removeClass('danger');
384
+ activeElement.toggleClass('info');
385
+ $.fn.edittable.save(cmsField);
386
+ };
387
+
388
+ $.fn.edittable.addWarning = function() {
389
+ activeElement.removeClass('info');
390
+ activeElement.removeClass('success');
391
+ activeElement.removeClass('danger');
392
+ activeElement.toggleClass('warning');
393
+ $.fn.edittable.save(cmsField);
394
+ };
395
+
396
+ $.fn.edittable.addDanger = function() {
397
+ activeElement.removeClass('info');
398
+ activeElement.removeClass('warning');
399
+ activeElement.removeClass('success');
400
+ activeElement.toggleClass('danger');
401
+ $.fn.edittable.save(cmsField);
402
+ };
403
+
404
+ $.fn.edittable.tableLeft = function() {
405
+ activeElement.removeClass('center');
406
+ activeElement.removeClass('right');
407
+ activeElement.addClass('left');
408
+ $.fn.edittable.save(cmsField);
409
+ };
410
+
411
+ $.fn.edittable.tableCenter = function() {
412
+ activeElement.removeClass('left');
413
+ activeElement.removeClass('right');
414
+ activeElement.addClass('center');
415
+ $.fn.edittable.save(cmsField);
416
+ };
417
+
418
+ $.fn.edittable.tableRight = function() {
419
+ activeElement.removeClass('center');
420
+ activeElement.removeClass('left');
421
+ activeElement.addClass('right');
422
+ $.fn.edittable.save(cmsField);
423
+ };
424
+
425
+ })(jQuery, this);
@@ -12,22 +12,23 @@
12
12
  },
13
13
 
14
14
  blurFunction: function(cmsField) {
15
- var text = $.fn.edittable.table(cmsField);
16
- return cmsField.parents(tableEditor.selector).scrivito('save', text);
15
+ var response = $.fn.edittable.clear();
16
+ if(response != undefined) return $(response.cmsField).scrivito('save', response.text);
17
17
  }
18
18
  };
19
19
 
20
20
  // Set click event
21
21
  scrivito.on('load', function() {
22
- return $('body').on('click', tableEditor.selector, function(event) {
22
+ return $('body').on('click', '.table-widget', function(event) {
23
23
  if(scrivito.in_editable_view()) {
24
24
  tableEditor.clickFunction($(event.target));
25
25
  };
26
+ event.stopPropagation();
26
27
  });
27
28
  });
28
29
 
29
30
  scrivito.on('load', function() {
30
- return $('body').on('blur', tableEditor.selector, function(event) {
31
+ return $('body').on('click', function(event) {
31
32
  if(scrivito.in_editable_view()) {
32
33
  tableEditor.blurFunction($(event.target));
33
34
  };
@@ -0,0 +1,31 @@
1
+ table.table td.bold {
2
+ font-weight: bold;
3
+ }
4
+
5
+ table.table th.bold {
6
+ font-weight: normal;
7
+ }
8
+
9
+ table.table th.italic,
10
+ table.table td.italic {
11
+ font-style: italic;
12
+ }
13
+
14
+ table.table.column-first tr td:first-child {
15
+ font-weight: bold;
16
+ }
17
+
18
+ table.table th.left,
19
+ table.table td.left {
20
+ text-align: left;
21
+ }
22
+
23
+ table.table th.center,
24
+ table.table td.center {
25
+ text-align: center;
26
+ }
27
+
28
+ table.table th.right,
29
+ table.table td.right {
30
+ text-align: right;
31
+ }
@@ -0,0 +1,119 @@
1
+ .table-buttons {
2
+ position: absolute;
3
+ margin: 0;
4
+ overflow: hidden;
5
+ z-index: 2;
6
+ }
7
+
8
+ .table-buttons div,
9
+ .table-options div {
10
+ float: left;
11
+ min-width: 22px;
12
+ height: 22px;
13
+ font-size: 13px;
14
+ line-height: 13px;
15
+ text-align: center;
16
+ color: #fff;
17
+ cursor: pointer;
18
+ margin-right: 1px;
19
+ margin-bottom: 1px;
20
+ padding: 4px 6px;
21
+ }
22
+
23
+ .table-options div {
24
+ margin-bottom: 0;
25
+ }
26
+
27
+ .table-buttons div {
28
+ background: #444444;
29
+ }
30
+
31
+ .table-buttons div.table-bold {
32
+ font-weight: bold;
33
+ }
34
+
35
+ .table-buttons div.table-italic {
36
+ font-style: italic;
37
+ }
38
+
39
+ .table-buttons div.delete-row,
40
+ .table-buttons div.delete-column {
41
+ background-color: #c5463f;
42
+ }
43
+
44
+ .table-buttons div.add-top,
45
+ .table-buttons div.add-bottom,
46
+ .table-buttons div.add-left,
47
+ .table-buttons div.add-right {
48
+ background-color: #439439;
49
+ }
50
+
51
+ .table-options {
52
+ position: absolute;
53
+ top: -32px;
54
+ margin: 0;
55
+ overflow: hidden;
56
+ }
57
+
58
+ .table-buttons.left div {
59
+ float: none;
60
+ }
61
+
62
+ .table-buttons.top {
63
+ height: 25px;
64
+ }
65
+
66
+ .table-buttons.top .add-left {
67
+ position: absolute;
68
+ left: 0;
69
+ }
70
+
71
+ .table-buttons.top .add-right {
72
+ position: absolute;
73
+ right: 0;
74
+ }
75
+
76
+ .table-buttons.left {
77
+ width: 25px;
78
+ }
79
+
80
+ .table-buttons.left .add-top {
81
+ position: absolute;
82
+ top: 0;
83
+ }
84
+
85
+ .table-buttons.left .add-bottom {
86
+ position: absolute;
87
+ bottom: 0;
88
+ }
89
+
90
+ .table-widget {
91
+ position: relative;
92
+ }
93
+
94
+ .alert-gray {
95
+ background-color: #444444;
96
+ }
97
+
98
+ .table-options .alert-success {
99
+ margin-left: 5px;
100
+ }
101
+
102
+ .helper-line {
103
+ position: absolute;
104
+ display: none;
105
+ }
106
+
107
+ .delete-marker td,
108
+ .delete-marker th,
109
+ th.delete-marker,
110
+ td.delete-marker,
111
+ tr.delete-marker {
112
+ background-color: #c5463f !important;
113
+ color: white !important;
114
+ border-color: #A33C36 !important;
115
+ }
116
+
117
+ td.active-field {
118
+ outline: 2px solid #444;
119
+ }
@@ -1,13 +1,4 @@
1
- <div class="editing-dialog-thumbnail">
2
- <div class="visualization">
3
- <span class="icon editing-icon-headline"></span>
4
- </div>
5
-
6
- <div class="title">
7
- Table
8
- </div>
9
-
10
- <div class="description">
11
- A Editable Table.
12
- </div>
1
+ <div class="details-view">
2
+ <h4>Style</h4>
3
+ <%= scrivito_toggle_button_editor widget, :style %>
13
4
  </div>
@@ -1 +1,13 @@
1
- <%= scrivito_tag(:div, widget, :table, data: {editor: 'table-editor'}) %>
1
+ <% if widget.table.blank? %>
2
+ <%= scrivito_tag(:div, widget, :table) do %>
3
+ <div class="create-new-table">
4
+ <div class="alert alert-info">
5
+ There is no table present. Click this message to insert a new one.
6
+ </div>
7
+ </div>
8
+ <% end %>
9
+ <% else %>
10
+ <div class="table-widget">
11
+ <%= scrivito_tag(:div, widget, :table, data: {editor: 'table-editor'}, class: 'table-responsive')%>
12
+ </div>
13
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module ScrivitoTableWidget
2
- VERSION = "0.1.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ class CreateTableWidget < ::Scrivito::Migration
2
+ def up
3
+ Scrivito::ObjClass.create(
4
+ name: 'TableWidget',
5
+ type: 'publication',
6
+ is_binary: false,
7
+ title: 'TableWidget',
8
+ attributes: [
9
+ {name: "style", type: "enum", values: ["table","table-striped","table-bordered","table-hover","table-condensed"]},
10
+ {name: "table", type: "html"}
11
+ ],
12
+ )
13
+ end
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_table_widget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-07 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,9 +62,12 @@ files:
62
62
  - LICENSE
63
63
  - README.md
64
64
  - Rakefile
65
- - app/assets/javascripts/table_widget/editing.js
66
- - app/assets/javascripts/table_widget/jquery.edit.table.js
67
- - app/assets/javascripts/table_widget/tableEditor.js
65
+ - app/assets/javascripts/scrivito_table_widget/createTable.js
66
+ - app/assets/javascripts/scrivito_table_widget/editing.js
67
+ - app/assets/javascripts/scrivito_table_widget/jquery.edit.table.js
68
+ - app/assets/javascripts/scrivito_table_widget/tableEditor.js
69
+ - app/assets/stylesheets/scrivito_table_widget/application.css
70
+ - app/assets/stylesheets/scrivito_table_widget/editing.css
68
71
  - app/models/table_widget.rb
69
72
  - app/views/table_widget/details.html.erb
70
73
  - app/views/table_widget/show.html.erb
@@ -73,6 +76,7 @@ files:
73
76
  - lib/scrivito_table_widget/engine.rb
74
77
  - lib/scrivito_table_widget/version.rb
75
78
  - lib/tasks/scrivito_table_widget_tasks.rake
79
+ - scrivito/migrate/0_create_table_widget.rb
76
80
  homepage: https://www.scrivito.com
77
81
  licenses:
78
82
  - LGPL-3.0
@@ -93,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
97
  version: '0'
94
98
  requirements: []
95
99
  rubyforge_project:
96
- rubygems_version: 2.3.0
100
+ rubygems_version: 2.2.2
97
101
  signing_key:
98
102
  specification_version: 4
99
103
  summary: Scrivito Widget for a table.
@@ -1,130 +0,0 @@
1
- (function($, App) {
2
- 'use strict';
3
-
4
- var activeElement = null;
5
- var initialized = false;
6
- var activeTable = null;
7
- var keysBound = false;
8
- var rows = 0;
9
- var cols = 0;
10
-
11
- $.fn.edittable = function(opts) {
12
- $.fn.edittable.options = $.extend({
13
- css_class: 'table table-responsive table-striped',
14
- header: true
15
- }, opts);
16
-
17
- activeTable = this.prop("tagName") == "DIV" ? this : this.parents("[data-editor=table-editor]");
18
-
19
- if(!keysBound) {
20
- $.fn.edittable.bindKeys();
21
- }
22
-
23
- if(!initialized || activeTable != this) {
24
- $.fn.edittable.initialize(this);
25
- }
26
-
27
- activeElement = this.prop("tagName") == "DIV" ? this.find("td, th").first() : this;
28
- activeElement.attr("contenteditable", true);
29
-
30
- rows = $.fn.edittable.getRowCount();
31
- cols = $.fn.edittable.getColCount();
32
- };
33
-
34
- $.fn.edittable.getRowCount = function() {
35
- return activeTable.find("tbody tr").length;
36
- };
37
-
38
- $.fn.edittable.getColCount = function() {
39
- return activeTable.find("tbody tr").first().children().length;
40
- };
41
-
42
- $.fn.edittable.initialize = function(element) {
43
- if(element.prop("tagName") == "DIV" && element.html() === "") {
44
- $.fn.edittable.createNewTable(element);
45
- }
46
- initialized = true;
47
- };
48
-
49
- $.fn.edittable.table = function(element) {
50
- var tableContent = activeTable.html();
51
-
52
- activeElement.removeAttr("contenteditable");
53
- activeElement = null;
54
- activeTable = null;
55
- initialized = false;
56
-
57
- rows = 0;
58
- cols = 0;
59
- return tableContent;
60
- };
61
-
62
- $.fn.edittable.createNewTable = function(element) {
63
- if($.fn.edittable.options.header) {
64
- element.html("<table class='"+ $.fn.edittable.options.css_class +"'><thead><tr><th>TableHead</th></tr></thead><tbody><tr><td>Content</td></tr></tbody></table>");
65
- } else {
66
- element.html("<table class='"+ $.fn.edittable.options.css_class +"'><tbody><tr><td>Content</td></tr></tbody></table>");
67
- }
68
- };
69
-
70
- $.fn.edittable.bindKeys = function() {
71
- $('body').keydown(function(e) {
72
- if (e.ctrlKey || e.metaKey) {
73
- if(e.keyCode == 8) { // CMD + Backspace
74
- e.preventDefault();
75
- $.fn.edittable.removeColumn();
76
- }
77
- if(e.keyCode == 13) { // CMD + Enter
78
- e.preventDefault();
79
- $.fn.edittable.removeRow();
80
- }
81
- }
82
- if(e.altKey) {
83
- if(e.keyCode == 9) { // Alt+Tab
84
- e.preventDefault();
85
- $.fn.edittable.addColumn();
86
- }
87
- if(e.keyCode == 13) { // Alt+Enter
88
- e.preventDefault();
89
- $.fn.edittable.addRow();
90
- }
91
- }
92
- });
93
- keysBound = true;
94
- };
95
-
96
- $.fn.edittable.addRow = function() {
97
- var newRow = "<tr>"+ new Array(cols + 1).join("<td>Content</td>"); +"</tr>";
98
- if(activeElement.prop("tagName") == "TH") {
99
- activeTable.find("tbody").prepend(newRow);
100
- } else {
101
- activeElement.parents("tr").first().after(newRow);
102
- }
103
- rows += 1;
104
- };
105
-
106
- $.fn.edittable.addColumn = function() {
107
- var pos = activeElement.index();
108
- $(activeTable.find("thead tr").find("th")[pos]).after("<th>TableHead</th>");
109
- activeTable.find("tbody tr").each(function(index, row) {
110
- $($(row).find("td")[pos]).after("<td>Content</td>");
111
- });
112
- cols += 1;
113
- };
114
-
115
- $.fn.edittable.removeColumn = function() {
116
- var pos = activeElement.index();
117
- if(window.confirm("Delete this column?")) {
118
- activeTable.find("tr").each(function(index, row) {
119
- $(row).children()[pos].remove();
120
- });
121
- }
122
- };
123
-
124
- $.fn.edittable.removeRow = function() {
125
- if(window.confirm("Delete this row?")) {
126
- activeElement.parents("tr").remove();
127
- }
128
- };
129
-
130
- })(jQuery, this);