vue_crud 0.1.9.6 → 0.1.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/vue_crud/froala_generator.rb +12 -0
  3. data/lib/generators/vue_crud/sortable.rb +10 -0
  4. data/lib/generators/vue_crud/templates/assets/images/froala_editor/color_picker.png +0 -0
  5. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/froala_editor.js +11089 -0
  6. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/en_gb.js +178 -0
  7. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/zh_cn.js +234 -0
  8. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/languages/zh_tw.js +234 -0
  9. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/align.js +119 -0
  10. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/char_counter.js +150 -0
  11. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/code_beautifier.js +3271 -0
  12. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/code_view.js +311 -0
  13. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/colors.js +350 -0
  14. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/draggable.js +379 -0
  15. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/emoticons.js +347 -0
  16. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/entities.js +113 -0
  17. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/file.js +609 -0
  18. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/font_family.js +178 -0
  19. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/font_size.js +116 -0
  20. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/forms.js +415 -0
  21. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/fullscreen.js +209 -0
  22. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/image.js +2401 -0
  23. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/image_manager.js +921 -0
  24. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/inline_style.js +86 -0
  25. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/line_breaker.js +435 -0
  26. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/link.js +997 -0
  27. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/lists.js +382 -0
  28. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/paragraph_format.js +293 -0
  29. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/paragraph_style.js +139 -0
  30. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/quick_insert.js +342 -0
  31. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/quote.js +138 -0
  32. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/save.js +176 -0
  33. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/table.js +3123 -0
  34. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/url.js +113 -0
  35. data/lib/generators/vue_crud/templates/assets/javascripts/froala_editor/plugins/video.js +1135 -0
  36. data/lib/generators/vue_crud/templates/assets/javascripts/sortable.js +1249 -0
  37. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/froala_editor.scss +1008 -0
  38. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/froala_style.scss +273 -0
  39. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/char_counter.scss +46 -0
  40. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/code_view.scss +102 -0
  41. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/colors.scss +129 -0
  42. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/draggable.scss +32 -0
  43. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/emoticons.scss +27 -0
  44. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/file.scss +135 -0
  45. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/fullscreen.scss +28 -0
  46. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/image.scss +233 -0
  47. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/image_manager.scss +370 -0
  48. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/line_breaker.scss +26 -0
  49. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/quick_insert.scss +56 -0
  50. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/table.scss +156 -0
  51. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/plugins/video.scss +136 -0
  52. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/dark.scss +1087 -0
  53. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/gray.scss +1087 -0
  54. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/red.scss +1087 -0
  55. data/lib/generators/vue_crud/templates/assets/stylesheets/froala_editor/themes/royal.scss +1087 -0
  56. data/lib/generators/vue_crud/templates/vue_crud.html +54 -71
  57. data/lib/vue_crud/version.rb +1 -1
  58. data/vendor/assets/javascripts/vue_crud.js +212 -59
  59. metadata +56 -2
@@ -0,0 +1,382 @@
1
+ /*!
2
+ * froala_editor v2.3.3 (https://www.froala.com/wysiwyg-editor)
3
+ * License https://froala.com/wysiwyg-editor/terms/
4
+ * Copyright 2014-2016 Froala Labs
5
+ */
6
+
7
+ (function (factory) {
8
+ if (typeof define === 'function' && define.amd) {
9
+ // AMD. Register as an anonymous module.
10
+ define(['jquery'], factory);
11
+ } else if (typeof module === 'object' && module.exports) {
12
+ // Node/CommonJS
13
+ module.exports = function( root, jQuery ) {
14
+ if ( jQuery === undefined ) {
15
+ // require('jQuery') returns a factory that requires window to
16
+ // build a jQuery instance, we normalize how we use modules
17
+ // that require this pattern but the window provided is a noop
18
+ // if it's defined (how jquery works)
19
+ if ( typeof window !== 'undefined' ) {
20
+ jQuery = require('jquery');
21
+ }
22
+ else {
23
+ jQuery = require('jquery')(root);
24
+ }
25
+ }
26
+ factory(jQuery);
27
+ return jQuery;
28
+ };
29
+ } else {
30
+ // Browser globals
31
+ factory(jQuery);
32
+ }
33
+ }(function ($) {
34
+
35
+ 'use strict';
36
+
37
+ $.FE.PLUGINS.lists = function (editor) {
38
+ function _openFlag(tag_name) {
39
+ return '<span class="fr-open-' + tag_name.toLowerCase() + '"></span>';
40
+ }
41
+
42
+ function _closeFlag(tag_name) {
43
+ return '<span class="fr-close-' + tag_name.toLowerCase() + '"></span>';
44
+ }
45
+
46
+ /**
47
+ * Replace list type.
48
+ */
49
+ function _replace(blocks, tag_name) {
50
+ var lists = [];
51
+ for (var i = 0; i < blocks.length; i++) {
52
+ var parent_node = blocks[i].parentNode;
53
+ if (blocks[i].tagName == 'LI' && parent_node.tagName != tag_name && lists.indexOf(parent_node) < 0) {
54
+ lists.push(parent_node);
55
+ }
56
+ }
57
+
58
+ for (i = lists.length - 1; i >= 0; i--) {
59
+ var $l = $(lists[i]);
60
+ $l.replaceWith('<' + tag_name.toLowerCase() + '>' + $l.html() + '</' + tag_name.toLowerCase() + '>');
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Format blocks.
66
+ */
67
+ function _format(blocks, tag_name) {
68
+ _replace(blocks, tag_name);
69
+
70
+ // Format those blocks that are not LI.
71
+ var default_tag = editor.html.defaultTag();
72
+ for (var i = 0; i < blocks.length; i++) {
73
+ if (blocks[i].tagName != 'LI') {
74
+ // Default tag.
75
+ if (default_tag && blocks[i].tagName.toLowerCase() == default_tag) {
76
+ $(blocks[i]).replaceWith('<' + tag_name + '><li' + editor.node.attributes(blocks[i]) + '>' + $(blocks[i]).html() + '</li></' + tag_name + '>');
77
+ }
78
+ else {
79
+ $(blocks[i]).wrap('<' + tag_name + '><li></li></' + tag_name + '>');
80
+ }
81
+ }
82
+ }
83
+
84
+ editor.clean.lists();
85
+ }
86
+
87
+ /**
88
+ * Unformat.
89
+ */
90
+ function _unformat(blocks) {
91
+ var i;
92
+ var j;
93
+
94
+ // If there are LI that have parents selected, then remove them.
95
+ for (i = blocks.length - 1; i >= 0; i--) {
96
+ for (j = i - 1; j >= 0; j--) {
97
+ if ($(blocks[j]).find(blocks[i]).length || blocks[j] == blocks[i]) {
98
+ blocks.splice(i, 1);
99
+ break;
100
+ }
101
+ }
102
+ }
103
+
104
+ // Unwrap remaining LI.
105
+ var lists = [];
106
+ for (i = 0; i < blocks.length; i++) {
107
+ var $li = $(blocks[i]);
108
+ var parent_node = blocks[i].parentNode;
109
+
110
+ $li.before(_closeFlag(parent_node.tagName));
111
+
112
+ // Nested case.
113
+ if (parent_node.parentNode.tagName == 'LI') {
114
+ $li.before(_closeFlag('LI'));
115
+ $li.after(_openFlag('LI'));
116
+ }
117
+ else {
118
+ // Append BR if the node is not empty.
119
+ if (!editor.node.isEmpty($li.get(0), true) && $li.find(editor.html.blockTagsQuery()).length === 0) {
120
+ $li.append('<br>');
121
+ }
122
+ $li.append(_openFlag('LI'));
123
+ $li.prepend(_closeFlag('LI'));
124
+ }
125
+
126
+ $li.after(_openFlag(parent_node.tagName));
127
+
128
+ // Nested case. We should look for an upper parent.
129
+ if (parent_node.parentNode.tagName == 'LI') {
130
+ parent_node = parent_node.parentNode.parentNode;
131
+ }
132
+
133
+ if (lists.indexOf(parent_node) < 0) {
134
+ lists.push(parent_node);
135
+ }
136
+ }
137
+
138
+ // Replace the open and close tags.
139
+ for (i = 0; i < lists.length; i++) {
140
+ var $l = $(lists[i]);
141
+ var html = $l.html();
142
+ html = html.replace(/<span class="fr-close-([a-z]*)"><\/span>/g, '</$1>');
143
+ html = html.replace(/<span class="fr-open-([a-z]*)"><\/span>/g, '<$1>');
144
+ $l.replaceWith(editor.node.openTagString($l.get(0)) + html + editor.node.closeTagString($l.get(0)));
145
+ }
146
+
147
+ // Clean empty lists.
148
+ editor.$el.find('li:empty').remove();
149
+ editor.$el.find('ul:empty, ol:empty').remove();
150
+
151
+ editor.clean.lists();
152
+ editor.html.wrap();
153
+ }
154
+
155
+ /**
156
+ * Check if should unformat lists.
157
+ */
158
+ function _shouldUnformat(blocks, tag_name) {
159
+ var do_unformat = true;
160
+ for (var i = 0; i < blocks.length; i++) {
161
+ // Something else than LI is selected.
162
+ if (blocks[i].tagName != 'LI') {
163
+ return false;
164
+ }
165
+
166
+ // There is a different kind of list selected. Replace is the appropiate action.
167
+ if (blocks[i].parentNode.tagName != tag_name) {
168
+ do_unformat = false;
169
+ }
170
+ }
171
+
172
+ return do_unformat;
173
+ }
174
+
175
+ /**
176
+ * Call the list actions.
177
+ */
178
+ function format(tag_name) {
179
+ // Wrap.
180
+ editor.selection.save();
181
+ editor.html.wrap(true, true, true, true);
182
+ editor.selection.restore();
183
+
184
+ var blocks = editor.selection.blocks();
185
+
186
+ // Normalize nodes by keeping the LI.
187
+ // <li><h1>foo<h1></li> will return h1.
188
+ for (var i = 0; i < blocks.length; i++) {
189
+ if (blocks[i].tagName != 'LI' && blocks[i].parentNode.tagName == 'LI') {
190
+ blocks[i] = blocks[i].parentNode;
191
+ }
192
+ }
193
+
194
+ // Save selection so that we can play at wish.
195
+ editor.selection.save();
196
+
197
+ // Decide if to format or unformat list.
198
+ if (_shouldUnformat(blocks, tag_name)) {
199
+ _unformat(blocks);
200
+ }
201
+ else {
202
+ _format(blocks, tag_name);
203
+ }
204
+
205
+ // Unwrap.
206
+ editor.html.unwrap();
207
+
208
+ // Restore the selection.
209
+ editor.selection.restore();
210
+ }
211
+
212
+ /**
213
+ * Refresh list buttons.
214
+ */
215
+ function refresh($btn, tag_name) {
216
+ var $el = $(editor.selection.element());
217
+ if ($el.get(0) != editor.$el.get(0)) {
218
+ var li = $el.get(0);
219
+ if (li.tagName != 'LI') {
220
+ li = $el.parents('li').get(0);
221
+ }
222
+
223
+ if (li && li.parentNode.tagName == tag_name && editor.$el.get(0).contains(li.parentNode)) {
224
+ $btn.addClass('fr-active');
225
+ }
226
+ }
227
+ }
228
+
229
+ /**
230
+ * Indent selected list items.
231
+ */
232
+ function _indent (blocks) {
233
+ editor.selection.save();
234
+ for (var i = 0; i < blocks.length; i++) {
235
+ // There should be a previous li.
236
+ var prev_li = blocks[i].previousSibling;
237
+ if (prev_li) {
238
+ var nl = $(blocks[i]).find('> ul, > ol').get(0);
239
+
240
+ // Current LI has a nested list.
241
+ if (nl) {
242
+ var $li = $('<li>').prependTo($(nl));
243
+ var node = editor.node.contents(blocks[i])[0];
244
+ while (node && !editor.node.isList(node)) {
245
+ var tmp = node.nextSibling;
246
+ $li.append(node);
247
+ node = tmp;
248
+ }
249
+
250
+ $(prev_li).append($(nl));
251
+ $(blocks[i]).remove();
252
+ }
253
+ else {
254
+ var prev_nl = $(prev_li).find('> ul, > ol').get(0);
255
+ if (prev_nl) {
256
+ $(prev_nl).append($(blocks[i]));
257
+ }
258
+ else {
259
+ var $new_nl = $('<' + blocks[i].parentNode.tagName + '>');
260
+ $(prev_li).append($new_nl);
261
+ $new_nl.append($(blocks[i]));
262
+ }
263
+ }
264
+ }
265
+ }
266
+
267
+ editor.clean.lists();
268
+ editor.selection.restore();
269
+ }
270
+
271
+ /**
272
+ * Outdent selected list items.
273
+ */
274
+ function _outdent (blocks) {
275
+ editor.selection.save();
276
+ _unformat(blocks);
277
+ editor.selection.restore();
278
+ }
279
+
280
+ /**
281
+ * Hook into the indent/outdent events.
282
+ */
283
+ function _afterCommand (cmd) {
284
+ if (cmd == 'indent' || cmd == 'outdent') {
285
+ var do_indent = false;
286
+ var blocks = editor.selection.blocks();
287
+ var blks = [];
288
+ for (var i = 0; i < blocks.length; i++) {
289
+ if (blocks[i].tagName == 'LI') {
290
+ do_indent = true;
291
+ blks.push(blocks[i]);
292
+ }
293
+ else if (blocks[i].parentNode.tagName == 'LI') {
294
+ do_indent = true;
295
+ blks.push(blocks[i].parentNode);
296
+ }
297
+ }
298
+
299
+ if (do_indent) {
300
+ if (cmd == 'indent') _indent(blks);
301
+ else _outdent(blks);
302
+ }
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Init.
308
+ */
309
+ function _init () {
310
+ editor.events.on('commands.after', _afterCommand);
311
+
312
+ // TAB key in lists.
313
+ editor.events.on('keydown', function (e) {
314
+ if (e.which == $.FE.KEYCODE.TAB) {
315
+ var do_indent;
316
+ var blocks = editor.selection.blocks();
317
+ var blks = [];
318
+ for (var i = 0; i < blocks.length; i++) {
319
+ if (blocks[i].tagName == 'LI') {
320
+ do_indent = true;
321
+ blks.push(blocks[i]);
322
+ }
323
+ else if (blocks[i].parentNode.tagName == 'LI') {
324
+ do_indent = true;
325
+ blks.push(blocks[i].parentNode);
326
+ }
327
+ }
328
+
329
+ if (do_indent) {
330
+ e.preventDefault();
331
+ e.stopPropagation();
332
+
333
+ if (!e.shiftKey) _indent(blks);
334
+ else _outdent(blks);
335
+
336
+ return false;
337
+ }
338
+ }
339
+ }, true);
340
+ }
341
+
342
+ return {
343
+ _init: _init,
344
+ format: format,
345
+ refresh: refresh
346
+ }
347
+ }
348
+
349
+ // Register the font size command.
350
+ $.FE.RegisterCommand('formatUL', {
351
+ title: 'Unordered List',
352
+ refresh: function ($btn) {
353
+ this.lists.refresh($btn, 'UL');
354
+ },
355
+ callback: function () {
356
+ this.lists.format('UL');
357
+ },
358
+ plugin: 'lists'
359
+ })
360
+
361
+ // Register the font size command.
362
+ $.FE.RegisterCommand('formatOL', {
363
+ title: 'Ordered List',
364
+ refresh: function ($btn) {
365
+ this.lists.refresh($btn, 'OL');
366
+ },
367
+ callback: function () {
368
+ this.lists.format('OL');
369
+ },
370
+ plugin: 'lists'
371
+ })
372
+
373
+ // Add the list icons.
374
+ $.FE.DefineIcon('formatUL', {
375
+ NAME: 'list-ul'
376
+ });
377
+
378
+ $.FE.DefineIcon('formatOL', {
379
+ NAME: 'list-ol'
380
+ });
381
+
382
+ }));
@@ -0,0 +1,293 @@
1
+ /*!
2
+ * froala_editor v2.3.3 (https://www.froala.com/wysiwyg-editor)
3
+ * License https://froala.com/wysiwyg-editor/terms/
4
+ * Copyright 2014-2016 Froala Labs
5
+ */
6
+
7
+ (function (factory) {
8
+ if (typeof define === 'function' && define.amd) {
9
+ // AMD. Register as an anonymous module.
10
+ define(['jquery'], factory);
11
+ } else if (typeof module === 'object' && module.exports) {
12
+ // Node/CommonJS
13
+ module.exports = function( root, jQuery ) {
14
+ if ( jQuery === undefined ) {
15
+ // require('jQuery') returns a factory that requires window to
16
+ // build a jQuery instance, we normalize how we use modules
17
+ // that require this pattern but the window provided is a noop
18
+ // if it's defined (how jquery works)
19
+ if ( typeof window !== 'undefined' ) {
20
+ jQuery = require('jquery');
21
+ }
22
+ else {
23
+ jQuery = require('jquery')(root);
24
+ }
25
+ }
26
+ factory(jQuery);
27
+ return jQuery;
28
+ };
29
+ } else {
30
+ // Browser globals
31
+ factory(jQuery);
32
+ }
33
+ }(function ($) {
34
+
35
+ 'use strict';
36
+
37
+ $.extend($.FE.DEFAULTS, {
38
+ paragraphFormat: {
39
+ N: 'Normal',
40
+ H1: 'Heading 1',
41
+ H2: 'Heading 2',
42
+ H3: 'Heading 3',
43
+ H4: 'Heading 4',
44
+ PRE: 'Code'
45
+ },
46
+ paragraphFormatSelection: false
47
+ })
48
+
49
+ $.FE.PLUGINS.paragraphFormat = function (editor) {
50
+
51
+ /**
52
+ * Style content inside LI when LI is selected.
53
+ * This case happens only when the LI contains a nested list or when it has no block tag inside.
54
+ */
55
+ function _styleLiWithoutBlocks($li, val) {
56
+ var defaultTag = editor.html.defaultTag();
57
+
58
+ // If val is null or default tag already do nothing.
59
+ if (val && val.toLowerCase() != defaultTag) {
60
+ // Deal with nested lists.
61
+ if ($li.find('ul, ol').length > 0) {
62
+ var $el = $('<' + val + '>');
63
+ $li.prepend($el);
64
+ var node = editor.node.contents($li.get(0))[0];
65
+ while (node && ['UL', 'OL'].indexOf(node.tagName) < 0) {
66
+ var next_node = node.nextSibling;
67
+ $el.append(node);
68
+ node = next_node;
69
+ }
70
+ }
71
+
72
+ // Wrap list content.
73
+ else {
74
+ $li.html('<' + val + '>' + $li.html() + '</' + val + '>');
75
+ }
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Style content inside LI.
81
+ */
82
+ function _styleLiWithBlocks($blk, val) {
83
+ var defaultTag = editor.html.defaultTag();
84
+
85
+ // Prepare a temp div.
86
+ if (!val) val = 'div class="fr-temp-div" data-empty="true"';
87
+
88
+ // In list we don't have P so just unwrap content.
89
+ if (val.toLowerCase() == defaultTag) {
90
+ $blk.replaceWith($blk.html());
91
+ }
92
+
93
+ // Replace the current block with the new one.
94
+ else {
95
+ $blk.replaceWith($('<' + val + '>').html($blk.html()));
96
+ }
97
+ }
98
+
99
+ /**
100
+ * Style content inside TD.
101
+ */
102
+ function _styleTdWithBlocks($blk, val) {
103
+ var defaultTag = editor.html.defaultTag();
104
+
105
+ // Prepare a temp div.
106
+ if (!val) val = 'div class="fr-temp-div"' + (editor.node.isEmpty($blk.get(0), true) ? ' data-empty="true"' : '');
107
+
108
+ // Return to the regular case. We don't use P inside TD/TH.
109
+ if (val.toLowerCase() == defaultTag) {
110
+ // If node is not empty, then add a BR.
111
+ if (!editor.node.isEmpty($blk.get(0), true)) {
112
+ $blk.append('<br/>');
113
+ }
114
+
115
+ $blk.replaceWith($blk.html());
116
+ }
117
+
118
+ // Replace with the new tag.
119
+ else {
120
+ $blk.replaceWith($('<' + val + '>').html($blk.html()));
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Basic style.
126
+ */
127
+ function _style($blk, val) {
128
+ if (!val) val = 'div class="fr-temp-div"' + (editor.node.isEmpty($blk.get(0), true) ? ' data-empty="true"' : '');
129
+ $blk.replaceWith($('<' + val + ' ' + editor.node.attributes($blk.get(0)) + '>').html($blk.html()));
130
+ }
131
+
132
+ /**
133
+ * Apply style.
134
+ */
135
+ function apply (val) {
136
+ // Normal.
137
+ if (val == 'N') val = editor.html.defaultTag();
138
+
139
+ // Wrap.
140
+ editor.selection.save();
141
+ editor.html.wrap(true, true, true, true);
142
+ editor.selection.restore();
143
+
144
+ // Get blocks.
145
+ var blocks = editor.selection.blocks();
146
+
147
+ // Save selection to restore it later.
148
+ editor.selection.save();
149
+
150
+ editor.$el.find('pre').attr('skip', true);
151
+
152
+ // Go through each block and apply style to it.
153
+ for (var i = 0; i < blocks.length; i++) {
154
+ if (blocks[i].tagName != val && !editor.node.isList(blocks[i])) {
155
+ var $blk = $(blocks[i]);
156
+
157
+ // Style the content inside LI when there is selection right in LI.
158
+ if (blocks[i].tagName == 'LI') {
159
+ _styleLiWithoutBlocks($blk, val);
160
+ }
161
+
162
+ // Style the content inside LI when we have other tag in LI.
163
+ else if (blocks[i].parentNode.tagName == 'LI' && blocks[i]) {
164
+ _styleLiWithBlocks($blk, val);
165
+ }
166
+
167
+ // Style the content inside TD/TH.
168
+ else if (['TD', 'TH'].indexOf(blocks[i].parentNode.tagName) >= 0) {
169
+ _styleTdWithBlocks($blk, val);
170
+ }
171
+
172
+ // Regular case.
173
+ else {
174
+ _style($blk, val);
175
+ }
176
+ }
177
+ }
178
+
179
+ // Join PRE together.
180
+ editor.$el.find('pre:not([skip="true"]) + pre:not([skip="true"])').each(function () {
181
+ $(this).prev().append('<br>' + $(this).html());
182
+ $(this).remove();
183
+ });
184
+ editor.$el.find('pre').removeAttr('skip');
185
+
186
+ // Unwrap temp divs.
187
+ editor.html.unwrap();
188
+
189
+ // Restore selection.
190
+ editor.selection.restore();
191
+ }
192
+
193
+ function refreshOnShow($btn, $dropdown) {
194
+ var blocks = editor.selection.blocks();
195
+
196
+ if (blocks.length) {
197
+ var blk = blocks[0];
198
+ var tag = 'N';
199
+ var default_tag = editor.html.defaultTag();
200
+ if (blk.tagName.toLowerCase() != default_tag && blk != editor.$el.get(0)) {
201
+ tag = blk.tagName;
202
+ }
203
+
204
+ $dropdown.find('.fr-command[data-param1="' + tag + '"]').addClass('fr-active');
205
+ }
206
+ else {
207
+ $dropdown.find('.fr-command[data-param1="N"]').addClass('fr-active');
208
+ }
209
+ }
210
+
211
+ function refresh ($btn) {
212
+ if (editor.opts.paragraphFormatSelection) {
213
+ var blocks = editor.selection.blocks();
214
+
215
+ if (blocks.length) {
216
+ var blk = blocks[0];
217
+ var tag = 'N';
218
+ var default_tag = editor.html.defaultTag();
219
+ if (blk.tagName.toLowerCase() != default_tag && blk != editor.$el.get(0)) {
220
+ tag = blk.tagName;
221
+ }
222
+
223
+ if (['LI', 'TD', 'TH'].indexOf(tag) >= 0) {
224
+ tag = 'N';
225
+ }
226
+
227
+ $btn.find('> span').text(editor.opts.paragraphFormat[tag]);
228
+ }
229
+ else {
230
+ $btn.find('> span').text(editor.opts.paragraphFormat.N);
231
+ }
232
+ }
233
+ }
234
+
235
+ return {
236
+ apply: apply,
237
+ refreshOnShow: refreshOnShow,
238
+ refresh: refresh
239
+ }
240
+ }
241
+
242
+ // Register the font size command.
243
+ $.FE.RegisterShortcut($.FE.KEYCODE.ZERO, 'paragraphFormat', 'N', '0', false, true);
244
+ $.FE.RegisterShortcut($.FE.KEYCODE.ONE, 'paragraphFormat', 'H1', '1', false, true);
245
+ $.FE.RegisterShortcut($.FE.KEYCODE.TWO, 'paragraphFormat', 'H2', '2', false, true);
246
+ $.FE.RegisterShortcut($.FE.KEYCODE.THREE, 'paragraphFormat', 'H3', '3', false, true);
247
+ $.FE.RegisterShortcut($.FE.KEYCODE.FOUR, 'paragraphFormat', 'H4', '4', false, true);
248
+ $.FE.RegisterCommand('paragraphFormat', {
249
+ type: 'dropdown',
250
+ displaySelection: function (editor) {
251
+ return editor.opts.paragraphFormatSelection;
252
+ },
253
+ defaultSelection: 'Normal',
254
+ displaySelectionWidth: 100,
255
+ html: function () {
256
+ var c = '<ul class="fr-dropdown-list">';
257
+ var options = this.opts.paragraphFormat;
258
+ for (var val in options) {
259
+ if (options.hasOwnProperty(val)) {
260
+ var shortcut = this.shortcuts.get('paragraphFormat.' + val);
261
+ if (shortcut) {
262
+ shortcut = '<span class="fr-shortcut">' + shortcut + '</span>';
263
+ }
264
+ else {
265
+ shortcut = '';
266
+ }
267
+
268
+ c += '<li><' + (val == 'N' ? this.html.defaultTag() || 'DIV' : val) + ' style="padding: 0 !important; margin: 0 !important;"><a class="fr-command" data-cmd="paragraphFormat" data-param1="' + val + '" title="' + this.language.translate(options[val]) + '">' + this.language.translate(options[val]) + '</a></' + (val == 'N' ? this.html.defaultTag() || 'DIV' : val) + '></li>';
269
+ }
270
+ }
271
+ c += '</ul>';
272
+
273
+ return c;
274
+ },
275
+ title: 'Paragraph Format',
276
+ callback: function (cmd, val) {
277
+ this.paragraphFormat.apply(val);
278
+ },
279
+ refresh: function ($btn) {
280
+ this.paragraphFormat.refresh($btn);
281
+ },
282
+ refreshOnShow: function ($btn, $dropdown) {
283
+ this.paragraphFormat.refreshOnShow($btn, $dropdown);
284
+ },
285
+ plugin: 'paragraphFormat'
286
+ })
287
+
288
+ // Add the font size icon.
289
+ $.FE.DefineIcon('paragraphFormat', {
290
+ NAME: 'paragraph'
291
+ });
292
+
293
+ }));