annex-cms 0.1.8 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,70 +1,69 @@
1
1
  if (!RedactorPlugins) var RedactorPlugins = {};
2
2
 
3
- RedactorPlugins.save = {
4
- init: function()
5
- {
6
- this.buttonAdd('save', 'Save', function(){
7
- this.saveContent();
8
- });
9
- this.buttonAddSeparator();
10
- this.buttonSetRight('save');
3
+ RedactorPlugins.save = function()
4
+ {
5
+ return {
6
+ init: function()
7
+ {
8
+ var button = this.button.add('save', 'Save');
9
+ this.button.addCallback(button, this.save.content);
11
10
 
12
- save_shortcut = $.proxy(function(e){
13
- var editor_active = this.getEditor().hasClass('redactor_editor');
11
+ save_shortcut = $.proxy(function(e){
12
+ var editor_active = this.$editor.hasClass('redactor-editor');
14
13
 
15
- if ( editor_active )
16
- this.saveContent();
14
+ if (editor_active)
15
+ this.save.content();
17
16
 
18
- return editor_active;
19
- }, this);
17
+ return editor_active;
18
+ }, this);
20
19
 
21
- $(document).keydown(function(e){
22
- if ((e.which == '115' || e.which == '83' ) && (e.ctrlKey || e.metaKey))
23
- {
24
- if ( save_shortcut() )
20
+ $(document).keydown(function(e){
21
+ if ((e.which == '115' || e.which == '83' ) && (e.ctrlKey || e.metaKey))
25
22
  {
26
- e.preventDefault();
23
+ if ( save_shortcut() )
24
+ {
25
+ e.preventDefault();
27
26
 
28
- return false;
27
+ return false;
28
+ }
29
29
  }
30
- }
31
30
 
32
- return true;
33
- });
34
- },
35
- saveContent: function() {
31
+ return true;
32
+ });
33
+ },
34
+ content: function() {
35
+ var post_url = '/annex/blocks',
36
+ route = this.$editor.attr('data-route'),
37
+ identifier = this.$editor.attr('data-identifier'),
38
+ html_content = {};
36
39
 
37
- var post_url = '/annex/blocks',
38
- route = this.getEditor().attr('data-route'),
39
- identifier = this.getEditor().attr('data-identifier'),
40
- html_content = {};
40
+ var callback = $.proxy(function() {
41
+ var $this = this;
42
+ var editor = this.$editor;
41
43
 
42
- var callback = $.proxy(function() {
43
- var $this = this;
44
- var editor = this.getEditor();
44
+ editor.addClass('saved')
45
+ .delay(1000)
46
+ .queue(function(next){
47
+ $(this).removeClass('saved');
48
+ next();
49
+ });
45
50
 
46
- editor.addClass('saved')
47
- .delay(1000)
48
- .queue(function(next){
49
- $(this).removeClass('saved');
50
- next();
51
- });
51
+ setTimeout(function(){ $this.core.destroy(); }, 2000);
52
+ }, this);
52
53
 
53
- setTimeout(function(){ $this.destroy(); }, 2000);
54
- }, this);
54
+ html_content[identifier] = this.code.get();
55
55
 
56
- html_content[identifier] = this.get();
57
-
58
- $.ajax({
59
- type: 'POST',
60
- url: post_url,
61
- data: {
62
- route: route,
63
- content: html_content
64
- },
65
- success: callback,
66
- dataType: 'json'
67
- });
68
- }
56
+ $.ajax({
57
+ type: 'POST',
58
+ url: post_url,
59
+ data: {
60
+ route: route,
61
+ content: html_content
62
+ },
63
+ success: callback,
64
+ dataType: 'json'
65
+ });
66
+ }
67
+ };
69
68
  };
70
69
 
@@ -0,0 +1,330 @@
1
+ if (!RedactorPlugins) var RedactorPlugins = {};
2
+
3
+ RedactorPlugins.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
+
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);
47
+
48
+ this.selection.save();
49
+ this.modal.show();
50
+
51
+ $('#redactor-table-rows').focus();
52
+
53
+ },
54
+ insert: function()
55
+ {
56
+
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;
63
+
64
+ for (i = 0; i < rows; i++)
65
+ {
66
+ $row = $('<tr>');
67
+
68
+ for (z = 0; z < columns; z++)
69
+ {
70
+ $column = $('<td>' + this.opts.invisibleSpace + '</td>');
71
+
72
+ // set the focus to the first td
73
+ if (i === 0 && z === 0)
74
+ {
75
+ $column.append(this.selection.getMarker());
76
+ }
77
+
78
+ $($row).append($column);
79
+ }
80
+
81
+ $table.append($row);
82
+ }
83
+
84
+ $tableBox.append($table);
85
+ var html = $tableBox.html();
86
+
87
+
88
+ this.modal.close();
89
+ this.selection.restore();
90
+
91
+ if (this.table.getTable()) return;
92
+
93
+ this.buffer.set();
94
+
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
+ }
105
+
106
+ this.selection.restore();
107
+
108
+ var table = this.$editor.find('#table' + tableId);
109
+
110
+ if (!this.opts.linebreaks && (this.utils.browser('mozilla') || this.utils.browser('msie')))
111
+ {
112
+ var $next = table.next();
113
+ if ($next.length === 0)
114
+ {
115
+ table.after(this.opts.emptyHtml);
116
+ }
117
+ }
118
+
119
+ this.observe.buttons();
120
+
121
+ table.find('span.redactor-selection-marker').remove();
122
+ table.removeAttr('id');
123
+
124
+ this.code.sync();
125
+ this.core.setCallback('insertedTable', table);
126
+ },
127
+ getTable: function()
128
+ {
129
+ var $table = $(this.selection.getParent()).closest('table');
130
+
131
+ if (!this.utils.isRedactorParent($table)) return false;
132
+ if ($table.size() === 0) return false;
133
+
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;
146
+
147
+ this.buffer.set();
148
+
149
+
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
+ }
159
+
160
+
161
+ $table.remove();
162
+
163
+ this.code.sync();
164
+ },
165
+ deleteRow: function()
166
+ {
167
+ var $table = this.table.getTable();
168
+ if (!$table) return;
169
+
170
+ var $current = $(this.selection.getCurrent());
171
+
172
+ this.buffer.set();
173
+
174
+ var $current_tr = $current.closest('tr');
175
+ var $focus_tr = $current_tr.prev().length ? $current_tr.prev() : $current_tr.next();
176
+ if ($focus_tr.length)
177
+ {
178
+ var $focus_td = $focus_tr.children('td, th').first();
179
+ if ($focus_td.length) $focus_td.prepend(this.selection.getMarker());
180
+ }
181
+
182
+ $current_tr.remove();
183
+ this.table.restoreAfterDelete($table);
184
+ },
185
+ deleteColumn: function()
186
+ {
187
+ var $table = this.table.getTable();
188
+ if (!$table) return;
189
+
190
+ this.buffer.set();
191
+
192
+ var $current = $(this.selection.getCurrent());
193
+ var $current_td = $current.closest('td, th');
194
+ var index = $current_td[0].cellIndex;
195
+
196
+ $table.find('tr').each($.proxy(function(i, elem)
197
+ {
198
+ var $elem = $(elem);
199
+ var focusIndex = index - 1 < 0 ? index + 1 : index - 1;
200
+ if (i === 0) $elem.find('td, th').eq(focusIndex).prepend(this.selection.getMarker());
201
+
202
+ $elem.find('td, th').eq(index).remove();
203
+
204
+ }, this));
205
+
206
+ this.table.restoreAfterDelete($table);
207
+ },
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)
216
+ {
217
+ this.table.deleteHead();
218
+ return;
219
+ }
220
+
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);
225
+
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();
238
+
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;
262
+
263
+ this.buffer.set();
264
+
265
+ var $current = $(this.selection.getCurrent());
266
+ var $current_tr = $current.closest('tr');
267
+ var new_tr = $current_tr.clone();
268
+
269
+ new_tr.find('th').replaceWith(function()
270
+ {
271
+ var $td = $('<td>');
272
+ $td[0].attributes = this.attributes;
273
+
274
+ return $td.append($(this).contents());
275
+ });
276
+
277
+ new_tr.find('td').html(this.opts.invisibleSpace);
278
+
279
+ if (type == 'after')
280
+ {
281
+ $current_tr.after(new_tr);
282
+ }
283
+ else
284
+ {
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();
299
+
300
+ var $current_tr = current.closest('tr');
301
+ var $current_td = current.closest('td, th');
302
+
303
+ $current_tr.find('td, th').each($.proxy(function(i, elem)
304
+ {
305
+ if ($(elem)[0] === $current_td[0]) index = i;
306
+
307
+ }, this));
308
+
309
+ $table.find('tr').each($.proxy(function(i, elem)
310
+ {
311
+ var $current = $(elem).find('td, th').eq(index);
312
+
313
+ var td = $current.clone();
314
+ td.html(this.opts.invisibleSpace);
315
+
316
+ if (type == 'after')
317
+ {
318
+ $current.after(td);
319
+ }
320
+ else
321
+ {
322
+ $current.before(td);
323
+ }
324
+
325
+ }, this));
326
+
327
+ this.code.sync();
328
+ }
329
+ };
330
+ };
@@ -0,0 +1,70 @@
1
+ if (!RedactorPlugins) var RedactorPlugins = {};
2
+
3
+ RedactorPlugins.video = function()
4
+ {
5
+ return {
6
+ reUrlYoutube: /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com\S*[^\w\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w.-]*(?:['"][^<>]*>|<\/a>))[?=&+%\w.-]*/ig,
7
+ reUrlVimeo: /https?:\/\/(www\.)?vimeo.com\/(\d+)($|\/)/,
8
+ getTemplate: function()
9
+ {
10
+ return String()
11
+ + '<section id="redactor-modal-video-insert">'
12
+ + '<label>' + this.lang.get('video_html_code') + '</label>'
13
+ + '<textarea id="redactor-insert-video-area" style="height: 160px;"></textarea>'
14
+ + '</section>';
15
+ },
16
+ init: function()
17
+ {
18
+ var button = this.button.addAfter('image', 'video', this.lang.get('video'));
19
+ this.button.addCallback(button, this.video.show);
20
+ },
21
+ show: function()
22
+ {
23
+ this.modal.addTemplate('video', this.video.getTemplate());
24
+
25
+ this.modal.load('video', this.lang.get('video'), 700);
26
+ this.modal.createCancelButton();
27
+
28
+ var button = this.modal.createActionButton(this.lang.get('insert'));
29
+ button.on('click', this.video.insert);
30
+
31
+ this.selection.save();
32
+ this.modal.show();
33
+
34
+ $('#redactor-insert-video-area').focus();
35
+
36
+ },
37
+ insert: function()
38
+ {
39
+ var data = $('#redactor-insert-video-area').val();
40
+ data = this.clean.stripTags(data);
41
+
42
+ // parse if it is link on youtube & vimeo
43
+ var iframeStart = '<iframe style="width: 500px; height: 281px;" src="',
44
+ iframeEnd = '" frameborder="0" allowfullscreen></iframe>';
45
+
46
+ if (data.match(this.video.reUrlYoutube))
47
+ {
48
+ data = data.replace(this.video.reUrlYoutube, iframeStart + '//www.youtube.com/embed/$1' + iframeEnd);
49
+ }
50
+ else if (data.match(this.video.reUrlVimeo))
51
+ {
52
+ data = data.replace(this.video.reUrlVimeo, iframeStart + '//player.vimeo.com/video/$2' + iframeEnd);
53
+ }
54
+
55
+ this.selection.restore();
56
+ this.modal.close();
57
+
58
+ var current = this.selection.getBlock() || this.selection.getCurrent();
59
+
60
+ if (current) $(current).after(data);
61
+ else
62
+ {
63
+ this.insert.html(data);
64
+ }
65
+
66
+ this.code.sync();
67
+ }
68
+
69
+ };
70
+ };
@@ -1,5 +1,12 @@
1
1
  //= require annex/cms
2
2
  //= require annex/jquery.redactor
3
- //= require annex/jquery.redactor.save
3
+ //= require annex/jquery.redactor.definedlinks
4
+ //= require annex/jquery.redactor.fontsize
5
+ //= require annex/jquery.redactor.fontcolor
6
+ //= require annex/jquery.redactor.table
7
+ //= require annex/jquery.redactor.filemanager
8
+ //= require annex/jquery.redactor.imagemanager
9
+ //= require annex/jquery.redactor.video
4
10
  //= require annex/jquery.redactor.clips
5
- //= require annex/jquery.redactor.fullscreen
11
+ //= require annex/jquery.redactor.fullscreen
12
+ //= require annex/jquery.redactor.save