annex-cms 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,169 +1,304 @@
1
- if (!RedactorPlugins) var RedactorPlugins = {};
2
-
3
- RedactorPlugins.table = function()
1
+ (function($)
4
2
  {
5
- return {
6
- getTemplate: function()
7
- {
8
- return String()
9
- + '<section id="redactor-modal-table-insert">'
10
- + '<label>' + this.lang.get('rows') + '</label>'
11
- + '<input type="text" size="5" value="2" id="redactor-table-rows" />'
12
- + '<label>' + this.lang.get('columns') + '</label>'
13
- + '<input type="text" size="5" value="3" id="redactor-table-columns" />'
14
- + '</section>';
15
- },
16
- init: function()
17
- {
18
-
19
- var dropdown = {};
20
-
21
- dropdown.insert_table = { title: this.lang.get('insert_table'), func: this.table.show };
22
- dropdown.insert_row_above = { title: this.lang.get('insert_row_above'), func: this.table.addRowAbove };
23
- dropdown.insert_row_below = { title: this.lang.get('insert_row_below'), func: this.table.addRowBelow };
24
- dropdown.insert_column_left = { title: this.lang.get('insert_column_left'), func: this.table.addColumnLeft };
25
- dropdown.insert_column_right = { title: this.lang.get('insert_column_right'), func: this.table.addColumnRight };
26
- dropdown.add_head = { title: this.lang.get('add_head'), func: this.table.addHead };
27
- dropdown.delete_head = { title: this.lang.get('delete_head'), func: this.table.deleteHead };
28
- dropdown.delete_column = { title: this.lang.get('delete_column'), func: this.table.deleteColumn };
29
- dropdown.delete_row = { title: this.lang.get('delete_row'), func: this.table.deleteRow };
30
- dropdown.delete_table = { title: this.lang.get('delete_table'), func: this.table.deleteTable };
31
-
32
- this.observe.addButton('td', 'table');
33
- this.observe.addButton('th', 'table');
34
-
35
- var button = this.button.addBefore('link', 'table', this.lang.get('table'));
36
- this.button.addDropdown(button, dropdown);
37
- },
38
- show: function()
39
- {
40
- this.modal.addTemplate('table', this.table.getTemplate());
41
-
42
- this.modal.load('table', this.lang.get('insert_table'), 300);
43
- this.modal.createCancelButton();
44
-
45
- var button = this.modal.createActionButton(this.lang.get('insert'));
46
- button.on('click', this.table.insert);
3
+ $.Redactor.prototype.table = function()
4
+ {
5
+ return {
6
+ getTemplate: function()
7
+ {
8
+ return String()
9
+ + '<section id="redactor-modal-table-insert">'
10
+ + '<label>' + this.lang.get('rows') + '</label>'
11
+ + '<input type="text" size="5" value="2" id="redactor-table-rows" />'
12
+ + '<label>' + this.lang.get('columns') + '</label>'
13
+ + '<input type="text" size="5" value="3" id="redactor-table-columns" />'
14
+ + '</section>';
15
+ },
16
+ init: function()
17
+ {
18
+ var dropdown = {};
19
+
20
+ dropdown.insert_table = {
21
+ title: this.lang.get('insert_table'),
22
+ func: this.table.show,
23
+ observe: {
24
+ element: 'table',
25
+ in: {
26
+ attr: {
27
+ 'class': 'redactor-dropdown-link-inactive',
28
+ 'aria-disabled': true,
29
+ }
30
+ }
31
+ }
32
+ };
33
+
34
+ dropdown.insert_row_above = {
35
+ title: this.lang.get('insert_row_above'),
36
+ func: this.table.addRowAbove,
37
+ observe: {
38
+ element: 'table',
39
+ out: {
40
+ attr: {
41
+ 'class': 'redactor-dropdown-link-inactive',
42
+ 'aria-disabled': true,
43
+ }
44
+ }
45
+ }
46
+ };
47
+
48
+ dropdown.insert_row_below = {
49
+ title: this.lang.get('insert_row_below'),
50
+ func: this.table.addRowBelow,
51
+ observe: {
52
+ element: 'table',
53
+ out: {
54
+ attr: {
55
+ 'class': 'redactor-dropdown-link-inactive',
56
+ 'aria-disabled': true,
57
+ }
58
+ }
59
+ }
60
+ };
61
+
62
+ dropdown.insert_column_left = {
63
+ title: this.lang.get('insert_column_left'),
64
+ func: this.table.addColumnLeft,
65
+ observe: {
66
+ element: 'table',
67
+ out: {
68
+ attr: {
69
+ 'class': 'redactor-dropdown-link-inactive',
70
+ 'aria-disabled': true,
71
+ }
72
+ }
73
+ }
74
+ };
75
+
76
+ dropdown.insert_column_right = {
77
+ title: this.lang.get('insert_column_right'),
78
+ func: this.table.addColumnRight,
79
+ observe: {
80
+ element: 'table',
81
+ out: {
82
+ attr: {
83
+ 'class': 'redactor-dropdown-link-inactive',
84
+ 'aria-disabled': true,
85
+ }
86
+ }
87
+ }
88
+ };
89
+
90
+ dropdown.add_head = {
91
+ title: this.lang.get('add_head'),
92
+ func: this.table.addHead,
93
+ observe: {
94
+ element: 'table',
95
+ out: {
96
+ attr: {
97
+ 'class': 'redactor-dropdown-link-inactive',
98
+ 'aria-disabled': true,
99
+ }
100
+ }
101
+ }
102
+ };
103
+
104
+ dropdown.delete_head = {
105
+ title: this.lang.get('delete_head'),
106
+ func: this.table.deleteHead,
107
+ observe: {
108
+ element: 'table',
109
+ out: {
110
+ attr: {
111
+ 'class': 'redactor-dropdown-link-inactive',
112
+ 'aria-disabled': true,
113
+ }
114
+ }
115
+ }
116
+ };
117
+
118
+ dropdown.delete_column = {
119
+ title: this.lang.get('delete_column'),
120
+ func: this.table.deleteColumn,
121
+ observe: {
122
+ element: 'table',
123
+ out: {
124
+ attr: {
125
+ 'class': 'redactor-dropdown-link-inactive',
126
+ 'aria-disabled': true,
127
+ }
128
+ }
129
+ }
130
+ };
131
+
132
+ dropdown.delete_row = {
133
+ title: this.lang.get('delete_row'),
134
+ func: this.table.deleteRow,
135
+ observe: {
136
+ element: 'table',
137
+ out: {
138
+ attr: {
139
+ 'class': 'redactor-dropdown-link-inactive',
140
+ 'aria-disabled': true,
141
+ }
142
+ }
143
+ }
144
+ };
145
+
146
+ dropdown.delete_table = {
147
+ title: this.lang.get('delete_table'),
148
+ func: this.table.deleteTable,
149
+ observe: {
150
+ element: 'table',
151
+ out: {
152
+ attr: {
153
+ 'class': 'redactor-dropdown-link-inactive',
154
+ 'aria-disabled': true,
155
+ }
156
+ }
157
+ }
158
+ };
159
+
160
+ this.observe.addButton('td', 'table');
161
+ this.observe.addButton('th', 'table');
162
+
163
+ var button = this.button.addBefore('link', 'table', this.lang.get('table'));
164
+ this.button.addDropdown(button, dropdown);
165
+ },
166
+ show: function()
167
+ {
168
+ this.modal.addTemplate('table', this.table.getTemplate());
47
169
 
48
- this.selection.save();
49
- this.modal.show();
170
+ this.modal.load('table', this.lang.get('insert_table'), 300);
171
+ this.modal.createCancelButton();
50
172
 
51
- $('#redactor-table-rows').focus();
173
+ var button = this.modal.createActionButton(this.lang.get('insert'));
174
+ button.on('click', this.table.insert);
52
175
 
53
- },
54
- insert: function()
55
- {
176
+ this.selection.save();
177
+ this.modal.show();
56
178
 
57
- var rows = $('#redactor-table-rows').val(),
58
- columns = $('#redactor-table-columns').val(),
59
- $tableBox = $('<div>'),
60
- tableId = Math.floor(Math.random() * 99999),
61
- $table = $('<table id="table' + tableId + '"><tbody></tbody></table>'),
62
- i, $row, z, $column;
179
+ $('#redactor-table-rows').focus();
63
180
 
64
- for (i = 0; i < rows; i++)
181
+ },
182
+ insert: function()
65
183
  {
66
- $row = $('<tr>');
184
+ this.placeholder.remove();
67
185
 
68
- for (z = 0; z < columns; z++)
186
+ var rows = $('#redactor-table-rows').val(),
187
+ columns = $('#redactor-table-columns').val(),
188
+ $tableBox = $('<div>'),
189
+ tableId = Math.floor(Math.random() * 99999),
190
+ $table = $('<table id="table' + tableId + '"><tbody></tbody></table>'),
191
+ i, $row, z, $column;
192
+
193
+ for (i = 0; i < rows; i++)
69
194
  {
70
- $column = $('<td>' + this.opts.invisibleSpace + '</td>');
195
+ $row = $('<tr>');
71
196
 
72
- // set the focus to the first td
73
- if (i === 0 && z === 0)
197
+ for (z = 0; z < columns; z++)
74
198
  {
75
- $column.append(this.selection.getMarker());
199
+ $column = $('<td>' + this.opts.invisibleSpace + '</td>');
200
+
201
+ // set the focus to the first td
202
+ if (i === 0 && z === 0)
203
+ {
204
+ $column.append(this.selection.getMarker());
205
+ }
206
+
207
+ $($row).append($column);
76
208
  }
77
209
 
78
- $($row).append($column);
210
+ $table.append($row);
79
211
  }
80
212
 
81
- $table.append($row);
82
- }
213
+ $tableBox.append($table);
214
+ var html = $tableBox.html();
83
215
 
84
- $tableBox.append($table);
85
- var html = $tableBox.html();
216
+ this.modal.close();
217
+ this.selection.restore();
86
218
 
219
+ if (this.table.getTable()) return;
87
220
 
88
- this.modal.close();
89
- this.selection.restore();
221
+ this.buffer.set();
90
222
 
91
- if (this.table.getTable()) return;
223
+ var current = this.selection.getBlock() || this.selection.getCurrent();
224
+ if (current && current.tagName != 'BODY')
225
+ {
226
+ if (current.tagName == 'LI') current = $(current).closest('ul, ol');
227
+ $(current).after(html);
228
+ }
229
+ else
230
+ {
231
+ this.insert.html(html, false);
232
+ }
92
233
 
93
- this.buffer.set();
234
+ this.selection.restore();
94
235
 
95
- var current = this.selection.getBlock() || this.selection.getCurrent();
96
- if (current && current.tagName != 'BODY')
97
- {
98
- if (current.tagName == 'LI') current = $(current).closest('ul, ol');
99
- $(current).after(html);
100
- }
101
- else
102
- {
103
- this.insert.html(html);
104
- }
236
+ var table = this.$editor.find('#table' + tableId);
105
237
 
106
- this.selection.restore();
238
+ var p = table.prev("p");
107
239
 
108
- var table = this.$editor.find('#table' + tableId);
240
+ if (p.length > 0 && this.utils.isEmpty(p.html()))
241
+ {
242
+ p.remove();
243
+ }
109
244
 
110
- if (!this.opts.linebreaks && (this.utils.browser('mozilla') || this.utils.browser('msie')))
111
- {
112
- var $next = table.next();
113
- if ($next.length === 0)
245
+ if (!this.opts.linebreaks && (this.utils.browser('mozilla') || this.utils.browser('msie')))
114
246
  {
115
- table.after(this.opts.emptyHtml);
247
+ var $next = table.next();
248
+ if ($next.length === 0)
249
+ {
250
+ table.after(this.opts.emptyHtml);
251
+ }
116
252
  }
117
- }
118
253
 
119
- this.observe.buttons();
254
+ this.observe.buttons();
120
255
 
121
- table.find('span.redactor-selection-marker').remove();
122
- table.removeAttr('id');
256
+ table.find('span.redactor-selection-marker').remove();
257
+ table.removeAttr('id');
123
258
 
124
- this.code.sync();
125
- this.core.setCallback('insertedTable', table);
126
- },
127
- getTable: function()
128
- {
129
- var $table = $(this.selection.getParent()).closest('table');
259
+ this.code.sync();
260
+ this.core.setCallback('insertedTable', table);
261
+ },
262
+ getTable: function()
263
+ {
264
+ var $table = $(this.selection.getParent()).closest('table');
130
265
 
131
- if (!this.utils.isRedactorParent($table)) return false;
132
- if ($table.size() === 0) return false;
266
+ if (!this.utils.isRedactorParent($table)) return false;
267
+ if ($table.size() === 0) return false;
133
268
 
134
- return $table;
135
- },
136
- restoreAfterDelete: function($table)
137
- {
138
- this.selection.restore();
139
- $table.find('span.redactor-selection-marker').remove();
140
- this.code.sync();
141
- },
142
- deleteTable: function()
143
- {
144
- var $table = this.table.getTable();
145
- if (!$table) return;
269
+ return $table;
270
+ },
271
+ restoreAfterDelete: function($table)
272
+ {
273
+ this.selection.restore();
274
+ $table.find('span.redactor-selection-marker').remove();
275
+ this.code.sync();
276
+ },
277
+ deleteTable: function()
278
+ {
279
+ var $table = this.table.getTable();
280
+ if (!$table) return;
146
281
 
147
- this.buffer.set();
282
+ this.buffer.set();
148
283
 
149
284
 
150
- var $next = $table.next();
151
- if (!this.opts.linebreaks && $next.length !== 0)
152
- {
153
- this.caret.setStart($next);
154
- }
155
- else
156
- {
157
- this.caret.setAfter($table);
158
- }
285
+ var $next = $table.next();
286
+ if (!this.opts.linebreaks && $next.length !== 0)
287
+ {
288
+ this.caret.setStart($next);
289
+ }
290
+ else
291
+ {
292
+ this.caret.setAfter($table);
293
+ }
159
294
 
160
295
 
161
- $table.remove();
296
+ $table.remove();
162
297
 
163
- this.code.sync();
164
- },
165
- deleteRow: function()
166
- {
298
+ this.code.sync();
299
+ },
300
+ deleteRow: function()
301
+ {
167
302
  var $table = this.table.getTable();
168
303
  if (!$table) return;
169
304
 
@@ -182,8 +317,8 @@ RedactorPlugins.table = function()
182
317
  $current_tr.remove();
183
318
  this.table.restoreAfterDelete($table);
184
319
  },
185
- deleteColumn: function()
186
- {
320
+ deleteColumn: function()
321
+ {
187
322
  var $table = this.table.getTable();
188
323
  if (!$table) return;
189
324
 
@@ -205,126 +340,131 @@ RedactorPlugins.table = function()
205
340
 
206
341
  this.table.restoreAfterDelete($table);
207
342
  },
208
- addHead: function()
209
- {
210
- var $table = this.table.getTable();
211
- if (!$table) return;
212
-
213
- this.buffer.set();
214
-
215
- if ($table.find('thead').size() !== 0)
343
+ addHead: function()
216
344
  {
217
- this.table.deleteHead();
218
- return;
219
- }
345
+ var $table = this.table.getTable();
346
+ if (!$table) return;
220
347
 
221
- var tr = $table.find('tr').first().clone();
222
- tr.find('td').html(this.opts.invisibleSpace);
223
- $thead = $('<thead></thead>').append(tr);
224
- $table.prepend($thead);
348
+ this.buffer.set();
225
349
 
226
- this.code.sync();
227
-
228
- },
229
- deleteHead: function()
230
- {
231
- var $table = this.table.getTable();
232
- if (!$table) return;
233
-
234
- var $thead = $table.find('thead');
235
- if ($thead.size() === 0) return;
236
-
237
- this.buffer.set();
350
+ if ($table.find('thead').size() !== 0)
351
+ {
352
+ this.table.deleteHead();
353
+ return;
354
+ }
238
355
 
239
- $thead.remove();
240
- this.code.sync();
241
- },
242
- addRowAbove: function()
243
- {
244
- this.table.addRow('before');
245
- },
246
- addRowBelow: function()
247
- {
248
- this.table.addRow('after');
249
- },
250
- addColumnLeft: function()
251
- {
252
- this.table.addColumn('before');
253
- },
254
- addColumnRight: function()
255
- {
256
- this.table.addColumn('after');
257
- },
258
- addRow: function(type)
259
- {
260
- var $table = this.table.getTable();
261
- if (!$table) return;
356
+ var tr = $table.find('tr').first().clone();
357
+ tr.find('td').replaceWith($.proxy(function()
358
+ {
359
+ return $('<th>').html(this.opts.invisibleSpace);
360
+ }, this));
262
361
 
263
- this.buffer.set();
362
+ $thead = $('<thead></thead>').append(tr);
363
+ $table.prepend($thead);
264
364
 
265
- var $current = $(this.selection.getCurrent());
266
- var $current_tr = $current.closest('tr');
267
- var new_tr = $current_tr.clone();
365
+ this.code.sync();
268
366
 
269
- new_tr.find('th').replaceWith(function()
367
+ },
368
+ deleteHead: function()
270
369
  {
271
- var $td = $('<td>');
272
- $td[0].attributes = this.attributes;
370
+ var $table = this.table.getTable();
371
+ if (!$table) return;
273
372
 
274
- return $td.append($(this).contents());
275
- });
373
+ var $thead = $table.find('thead');
374
+ if ($thead.size() === 0) return;
276
375
 
277
- new_tr.find('td').html(this.opts.invisibleSpace);
376
+ this.buffer.set();
278
377
 
279
- if (type == 'after')
378
+ $thead.remove();
379
+ this.code.sync();
380
+ },
381
+ addRowAbove: function()
280
382
  {
281
- $current_tr.after(new_tr);
282
- }
283
- else
383
+ this.table.addRow('before');
384
+ },
385
+ addRowBelow: function()
284
386
  {
285
- $current_tr.before(new_tr);
286
- }
287
-
288
- this.code.sync();
289
- },
290
- addColumn: function (type)
291
- {
292
- var $table = this.table.getTable();
293
- if (!$table) return;
294
-
295
- var index = 0;
296
- var current = $(this.selection.getCurrent());
297
-
298
- this.buffer.set();
387
+ this.table.addRow('after');
388
+ },
389
+ addColumnLeft: function()
390
+ {
391
+ this.table.addColumn('before');
392
+ },
393
+ addColumnRight: function()
394
+ {
395
+ this.table.addColumn('after');
396
+ },
397
+ addRow: function(type)
398
+ {
399
+ var $table = this.table.getTable();
400
+ if (!$table) return;
299
401
 
300
- var $current_tr = current.closest('tr');
301
- var $current_td = current.closest('td, th');
402
+ this.buffer.set();
302
403
 
303
- $current_tr.find('td, th').each($.proxy(function(i, elem)
304
- {
305
- if ($(elem)[0] === $current_td[0]) index = i;
404
+ var $current = $(this.selection.getCurrent());
405
+ var $current_tr = $current.closest('tr');
406
+ var new_tr = $current_tr.clone();
306
407
 
307
- }, this));
408
+ new_tr.find('th').replaceWith(function()
409
+ {
410
+ var $td = $('<td>');
411
+ $td[0].attributes = this.attributes;
308
412
 
309
- $table.find('tr').each($.proxy(function(i, elem)
310
- {
311
- var $current = $(elem).find('td, th').eq(index);
413
+ return $td.append($(this).contents());
414
+ });
312
415
 
313
- var td = $current.clone();
314
- td.html(this.opts.invisibleSpace);
416
+ new_tr.find('td').html(this.opts.invisibleSpace);
315
417
 
316
418
  if (type == 'after')
317
419
  {
318
- $current.after(td);
420
+ $current_tr.after(new_tr);
319
421
  }
320
422
  else
321
423
  {
322
- $current.before(td);
424
+ $current_tr.before(new_tr);
323
425
  }
324
426
 
325
- }, this));
427
+ this.code.sync();
428
+ },
429
+ addColumn: function (type)
430
+ {
431
+ var $table = this.table.getTable();
432
+ if (!$table) return;
433
+
434
+ var index = 0;
435
+ var current = $(this.selection.getCurrent());
436
+
437
+ this.buffer.set();
438
+
439
+ var $current_tr = current.closest('tr');
440
+ var $current_td = current.closest('td, th');
326
441
 
327
- this.code.sync();
328
- }
442
+ $current_tr.find('td, th').each($.proxy(function(i, elem)
443
+ {
444
+ if ($(elem)[0] === $current_td[0]) index = i;
445
+
446
+ }, this));
447
+
448
+ $table.find('tr').each($.proxy(function(i, elem)
449
+ {
450
+ var $current = $(elem).find('td, th').eq(index);
451
+
452
+ var td = $current.clone();
453
+ td.html(this.opts.invisibleSpace);
454
+
455
+ if (type == 'after')
456
+ {
457
+ $current.after(td);
458
+ }
459
+ else
460
+ {
461
+ $current.before(td);
462
+ }
463
+
464
+ }, this));
465
+
466
+ this.code.sync();
467
+ }
468
+ };
329
469
  };
330
- };
470
+ })(jQuery);