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,311 @@
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
+ codeMirror: true,
39
+ codeMirrorOptions: {
40
+ lineNumbers: true,
41
+ tabMode: 'indent',
42
+ indentWithTabs: true,
43
+ lineWrapping: true,
44
+ mode: 'text/html',
45
+ tabSize: 2
46
+ },
47
+ codeBeautifierOptions: {
48
+ end_with_newline: true,
49
+ indent_inner_html: true,
50
+ extra_liners: ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'pre', 'ul', 'ol', 'table', 'dl'],
51
+ brace_style: 'expand',
52
+ indent_char: '\t',
53
+ indent_size: 1,
54
+ wrap_line_length: 0
55
+ }
56
+ })
57
+
58
+ $.FE.PLUGINS.codeView = function (editor) {
59
+ var $html_area;
60
+ var code_mirror;
61
+
62
+ /**
63
+ * Check if code view is enabled.
64
+ */
65
+ function isActive () {
66
+ return editor.$box.hasClass('fr-code-view');
67
+ }
68
+
69
+ function get () {
70
+ if (code_mirror) {
71
+ return code_mirror.getValue();
72
+ } else {
73
+ return $html_area.val();
74
+ }
75
+ }
76
+
77
+ /**
78
+ * Get back to edit mode.
79
+ */
80
+ function _showText ($btn) {
81
+ var html = get();
82
+
83
+ // Code mirror enabled.
84
+ editor.html.set(html);
85
+
86
+ // Blur the element.
87
+ editor.$el.blur();
88
+
89
+ // Toolbar no longer disabled.
90
+ editor.$tb.find(' > .fr-command').not($btn).removeClass('fr-disabled');
91
+ $btn.removeClass('fr-active');
92
+
93
+ editor.events.focus(true);
94
+ editor.placeholder.refresh();
95
+
96
+ editor.undo.saveStep();
97
+ }
98
+
99
+ /**
100
+ * Get to code mode.
101
+ */
102
+ function _showHTML ($btn) {
103
+ if (!$html_area) _initArea();
104
+
105
+ // Enable code mirror.
106
+ if (!code_mirror && editor.opts.codeMirror && typeof CodeMirror != 'undefined') {
107
+ code_mirror = CodeMirror.fromTextArea($html_area.get(0), editor.opts.codeMirrorOptions);
108
+ }
109
+
110
+ editor.undo.saveStep();
111
+
112
+ // Clean white tags but ignore selection.
113
+ editor.html.cleanEmptyTags();
114
+ editor.html.cleanWhiteTags(true);
115
+
116
+ // Blur the element.
117
+ if (editor.core.hasFocus()) {
118
+ if (!editor.core.isEmpty()) {
119
+ editor.selection.save();
120
+ editor.$el.find('.fr-marker[data-type="true"]:first').replaceWith('<span class="fr-tmp fr-sm">F</span>');
121
+ editor.$el.find('.fr-marker[data-type="false"]:last').replaceWith('<span class="fr-tmp fr-em">F</span>');
122
+ }
123
+ }
124
+
125
+ // Get HTML.
126
+ var html = editor.html.get(false, true);
127
+ editor.$el.find('span.fr-tmp').remove();
128
+
129
+ if (editor.core.hasFocus()) editor.$el.blur();
130
+
131
+ html = html.replace(/<span class="fr-tmp fr-sm">F<\/span>/, 'FROALA-SM');
132
+ html = html.replace(/<span class="fr-tmp fr-em">F<\/span>/, 'FROALA-EM');
133
+
134
+ // Beautify HTML.
135
+ if (editor.codeBeautifier) {
136
+ html = editor.codeBeautifier.run(html, editor.opts.codeBeautifierOptions);
137
+ }
138
+
139
+ var s_index;
140
+ var e_index;
141
+
142
+ // Code mirror is enabled.
143
+ if (code_mirror) {
144
+ s_index = html.indexOf('FROALA-SM');
145
+ e_index = html.indexOf('FROALA-EM');
146
+
147
+ if (s_index > e_index) {
148
+ s_index = e_index;
149
+ }
150
+ else {
151
+ e_index = e_index - 9;
152
+ }
153
+
154
+ html = html.replace(/FROALA-SM/g, '').replace(/FROALA-EM/g, '')
155
+ var s_line = html.substring(0, s_index).length - html.substring(0, s_index).replace(/\n/g, '').length;
156
+ var e_line = html.substring(0, e_index).length - html.substring(0, e_index).replace(/\n/g, '').length;
157
+
158
+ s_index = html.substring(0, s_index).length - html.substring(0, html.substring(0, s_index).lastIndexOf('\n') + 1).length;
159
+ e_index = html.substring(0, e_index).length - html.substring(0, html.substring(0, e_index).lastIndexOf('\n') + 1).length;
160
+
161
+ code_mirror.setSize(null, editor.opts.height ? editor.opts.height : 'auto');
162
+ if (editor.opts.heightMin) editor.$box.find('.CodeMirror-scroll').css('min-height', editor.opts.heightMin);
163
+ code_mirror.setValue(html);
164
+ code_mirror.focus();
165
+ code_mirror.setSelection({ line: s_line, ch: s_index }, { line: e_line, ch: e_index })
166
+ code_mirror.refresh();
167
+ code_mirror.clearHistory();
168
+ }
169
+
170
+ // No code mirror.
171
+ else {
172
+ s_index = html.indexOf('FROALA-SM');
173
+ e_index = html.indexOf('FROALA-EM') - 9;
174
+
175
+ if (editor.opts.heightMin) {
176
+ $html_area.css('min-height', editor.opts.heightMin);
177
+ }
178
+
179
+ if (editor.opts.height) {
180
+ $html_area.css('height', editor.opts.height);
181
+ }
182
+
183
+ if (editor.opts.heightMax) {
184
+ $html_area.css('max-height', editor.opts.height || editor.opts.heightMax);
185
+ }
186
+
187
+ $html_area.val(html.replace(/FROALA-SM/g, '').replace(/FROALA-EM/g, ''));
188
+ $html_area.focus();
189
+ $html_area.get(0).setSelectionRange(s_index, e_index);
190
+ }
191
+
192
+ // Disable buttons.
193
+ editor.$tb.find(' > .fr-command').not($btn).addClass('fr-disabled');
194
+ $btn.addClass('fr-active');
195
+
196
+ if (!editor.helpers.isMobile() && editor.opts.toolbarInline) {
197
+ editor.toolbar.hide();
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Toggle the code view.
203
+ */
204
+ function toggle (val) {
205
+ if (typeof val == 'undefined') val = !isActive();
206
+
207
+ var $btn = editor.$tb.find('.fr-command[data-cmd="html"]');
208
+
209
+ if (!val) {
210
+ editor.$box.toggleClass('fr-code-view', false);
211
+ _showText($btn);
212
+ } else {
213
+ editor.popups.hideAll();
214
+ editor.$box.toggleClass('fr-code-view', true);
215
+ _showHTML($btn);
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Destroy.
221
+ */
222
+ function _destroy () {
223
+ if (isActive()) {
224
+ toggle(editor.$tb.find('button[data-cmd="html"]'));
225
+ }
226
+
227
+ if (code_mirror) code_mirror.toTextArea();
228
+ $html_area.val('').removeData().remove();
229
+ $html_area = null;
230
+
231
+ if ($back_button) {
232
+ $back_button.remove();
233
+ $back_button = null;
234
+ }
235
+ }
236
+
237
+ function _initArea () {
238
+ // Add the coding textarea to the wrapper.
239
+ $html_area = $('<textarea class="fr-code" tabindex="-1">');
240
+ editor.$wp.append($html_area);
241
+
242
+ $html_area.attr('dir', editor.opts.direction);
243
+
244
+ // Exit code view button for inline toolbar.
245
+ if (!editor.$box.hasClass('fr-basic')) {
246
+ $back_button = $('<a data-cmd="html" title="Code View" class="fr-command fr-btn html-switch' + (editor.helpers.isMobile() ? '' : ' fr-desktop') + '" role="button" tabindex="-1"><i class="fa fa-code"></i></button>');
247
+ editor.$box.append($back_button);
248
+
249
+ editor.events.bindClick(editor.$box, 'a.html-switch', function () {
250
+ toggle(false);
251
+ });
252
+ }
253
+
254
+ var cancel = function () {
255
+ return !isActive();
256
+ }
257
+
258
+ // Disable refresh of the buttons while enabled.
259
+ editor.events.on('buttons.refresh', cancel);
260
+ editor.events.on('copy', cancel, true);
261
+ editor.events.on('cut', cancel, true);
262
+ editor.events.on('paste', cancel, true);
263
+
264
+ editor.events.on('destroy', _destroy, true);
265
+
266
+ editor.events.on('html.set', function () {
267
+ if (isActive()) toggle(true);
268
+ });
269
+
270
+ editor.events.on('form.submit', function () {
271
+ if (isActive()) {
272
+ // Code mirror enabled.
273
+ editor.html.set(get());
274
+
275
+ editor.events.trigger('contentChanged', [], true);
276
+ }
277
+ }, true);
278
+ }
279
+
280
+ /**
281
+ * Initialize.
282
+ */
283
+ var $back_button;
284
+ function _init () {
285
+ if (!editor.$wp) return false;
286
+ }
287
+
288
+ return {
289
+ _init: _init,
290
+ toggle: toggle,
291
+ isActive: isActive,
292
+ get: get
293
+ }
294
+ };
295
+
296
+ $.FE.RegisterCommand('html', {
297
+ title: 'Code View',
298
+ undo: false,
299
+ focus: false,
300
+ forcedRefresh: true,
301
+ callback: function () {
302
+ this.codeView.toggle();
303
+ },
304
+ plugin: 'codeView'
305
+ })
306
+
307
+ $.FE.DefineIcon('html', {
308
+ NAME: 'code'
309
+ });
310
+
311
+ }));
@@ -0,0 +1,350 @@
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.POPUP_TEMPLATES, {
38
+ 'colors.picker': '[_BUTTONS_][_TEXT_COLORS_][_BACKGROUND_COLORS_]'
39
+ })
40
+
41
+ // Extend defaults.
42
+ $.extend($.FE.DEFAULTS, {
43
+ colorsText: [
44
+ '#61BD6D', '#1ABC9C', '#54ACD2', '#2C82C9', '#9365B8', '#475577', '#CCCCCC',
45
+ '#41A85F', '#00A885', '#3D8EB9', '#2969B0', '#553982', '#28324E', '#000000',
46
+ '#F7DA64', '#FBA026', '#EB6B56', '#E25041', '#A38F84', '#EFEFEF', 'REMOVE',
47
+ '#FAC51C', '#F37934', '#D14841', '#B8312F', '#7C706B', '#FFFFFF', 'PICKER'
48
+ ],
49
+ colorsBackground: [
50
+ '#61BD6D', '#1ABC9C', '#54ACD2', '#2C82C9', '#9365B8', '#475577', '#CCCCCC',
51
+ '#41A85F', '#00A885', '#3D8EB9', '#2969B0', '#553982', '#28324E', '#000000',
52
+ '#F7DA64', '#FBA026', '#EB6B56', '#E25041', '#A38F84', '#EFEFEF', 'REMOVE',
53
+ '#FAC51C', '#F37934', '#D14841', '#B8312F', '#7C706B', '#FFFFFF', 'PICKER'
54
+ ],
55
+ colorsStep: 7,
56
+ colorsDefaultTab: 'text',
57
+ colorsButtons: ['colorsBack', '|', '-']
58
+ });
59
+
60
+ $.FE.PLUGINS.colors = function (editor) {
61
+ /*
62
+ * Show the colors popup.
63
+ */
64
+ function _showColorsPopup () {
65
+ var $btn = editor.$tb.find('.fr-command[data-cmd="color"]');
66
+
67
+ var $popup = editor.popups.get('colors.picker');
68
+ if (!$popup) $popup = _initColorsPopup();
69
+
70
+ if (!$popup.hasClass('fr-active')) {
71
+ // Colors popup
72
+ editor.popups.setContainer('colors.picker', editor.$tb);
73
+
74
+ // Refresh selected color.
75
+ _refreshColor($popup.find('.fr-selected-tab').attr('data-param1'));
76
+
77
+ // Colors popup left and top position.
78
+ if ($btn.is(':visible')) {
79
+ var left = $btn.offset().left + $btn.outerWidth() / 2;
80
+ var top = $btn.offset().top + (editor.opts.toolbarBottom ? 10 : $btn.outerHeight() - 10);
81
+ editor.popups.show('colors.picker', left, top, $btn.outerHeight());
82
+ }
83
+ else {
84
+ editor.position.forSelection($popup);
85
+ editor.popups.show('colors.picker');
86
+ }
87
+ }
88
+ }
89
+
90
+ /*
91
+ * Hide colors popup.
92
+ */
93
+ function _hideColorsPopup () {
94
+ // Hide popup.
95
+ editor.popups.hide('colors.picker');
96
+ }
97
+
98
+ /**
99
+ * Init the colors popup.
100
+ */
101
+ function _initColorsPopup () {
102
+ var colors_buttons = '<div class="fr-buttons fr-colors-buttons">';
103
+
104
+ if (editor.opts.toolbarInline) {
105
+ // Colors buttons.
106
+ if (editor.opts.colorsButtons.length > 0) {
107
+ colors_buttons += editor.button.buildList(editor.opts.colorsButtons)
108
+ }
109
+ }
110
+
111
+ colors_buttons += _colorsTabsHTML() + '</div>';
112
+
113
+ var template = {
114
+ buttons: colors_buttons,
115
+ text_colors: _colorPickerHTML('text'),
116
+ background_colors: _colorPickerHTML('background')
117
+ };
118
+
119
+ // Create popup.
120
+ var $popup = editor.popups.create('colors.picker', template);
121
+
122
+ return $popup;
123
+ }
124
+
125
+ /*
126
+ * HTML for the color picker text and background tabs.
127
+ */
128
+ function _colorsTabsHTML () {
129
+ var tabs_html = '<div class="fr-colors-tabs">';
130
+
131
+ // Text tab.
132
+ tabs_html += '<span class="fr-colors-tab ' + (editor.opts.colorsDefaultTab == 'background' ? '' : 'fr-selected-tab ') + 'fr-command" data-param1="text" data-cmd="colorChangeSet" title="' + editor.language.translate('Text') + '">' + editor.language.translate('Text') + '</span>';
133
+
134
+ // Background tab.
135
+ tabs_html += '<span class="fr-colors-tab ' + (editor.opts.colorsDefaultTab == 'background' ? 'fr-selected-tab ' : '') + 'fr-command" data-param1="background" data-cmd="colorChangeSet" title="' + editor.language.translate('Background') + '">' + editor.language.translate('Background') + '</span>';
136
+
137
+ return tabs_html + '</div>';
138
+ }
139
+
140
+ /*
141
+ * HTML for the color picker colors.
142
+ */
143
+ function _colorPickerHTML (tab) {
144
+ // Get colors according to tab name.
145
+ var colors = (tab == 'text' ? editor.opts.colorsText : editor.opts.colorsBackground);
146
+
147
+ // Create colors html.
148
+ var colors_html = '<div class="fr-color-set fr-' + tab + '-color' + ((editor.opts.colorsDefaultTab == tab || (editor.opts.colorsDefaultTab != 'text' && editor.opts.colorsDefaultTab != 'background' && tab == 'text')) ? ' fr-selected-set' : '') + '">';
149
+
150
+ // Add colors.
151
+ for (var i = 0; i < colors.length; i++) {
152
+ if (i !== 0 && i % editor.opts.colorsStep === 0) {
153
+ colors_html += '<br>';
154
+ }
155
+
156
+ if (colors[i] == 'REMOVE') {
157
+ colors_html += '<span class="fr-command fr-select-color" data-cmd="' + tab + 'Color" data-param1="REMOVE" title="' + editor.language.translate('Clear Formatting') + '">' + editor.icon.create('remove') + '</span>';
158
+ }
159
+ else if (colors[i] == 'PICKER') {
160
+ colors_html += '<span class="fr-command fr-select-color fr-color-picker-btn" data-cmd="' + tab + 'Color" data-param1="PICKER" title="' + editor.language.translate('Select Color') + '"><img src="assets/froala_editor/color_picker.png"></span>';
161
+ }
162
+ else {
163
+ colors_html += '<span class="fr-command fr-select-color" style="background: ' + colors[i] + ';" data-cmd="' + tab + 'Color" data-param1="' + colors[i] + '"></span>';
164
+ }
165
+ }
166
+
167
+ return colors_html + '</div>';
168
+ }
169
+
170
+ /*
171
+ * Show the current selected color.
172
+ */
173
+ function _refreshColor (tab) {
174
+ var $popup = editor.popups.get('colors.picker');
175
+ var $element = $(editor.selection.element());
176
+
177
+ // The color css property.
178
+ var color_type;
179
+ if (tab == 'background') {
180
+ color_type = 'background-color';
181
+ }
182
+ else {
183
+ color_type = 'color';
184
+ }
185
+
186
+ // Remove current color selection.
187
+ $popup.find('.fr-' + tab + '-color .fr-select-color').removeClass('fr-selected-color');
188
+
189
+ // Find the selected color.
190
+ while ($element.get(0) != editor.$el.get(0)) {
191
+ // Transparent or black.
192
+ if ($element.css(color_type) == 'transparent' || $element.css(color_type) == 'rgba(0, 0, 0, 0)') {
193
+ $element = $element.parent();
194
+ }
195
+
196
+ // Select the correct color.
197
+ else {
198
+ $popup.find('.fr-' + tab + '-color .fr-select-color[data-param1="' + editor.helpers.RGBToHex($element.css(color_type)) + '"]').addClass('fr-selected-color');
199
+ break;
200
+ }
201
+ }
202
+ }
203
+
204
+ /*
205
+ * Change the colors' tab.
206
+ */
207
+ function _changeSet ($tab, val) {
208
+ // Only on the tab that is not selected yet. On left click only.
209
+ if (!$tab.hasClass('fr-selected-tab')) {
210
+ // Switch selected tab.
211
+ $tab.siblings().removeClass('fr-selected-tab');
212
+ $tab.addClass('fr-selected-tab');
213
+
214
+ // Switch the color set.
215
+ $tab.parents('.fr-popup').find('.fr-color-set').removeClass('fr-selected-set');
216
+ $tab.parents('.fr-popup').find('.fr-color-set.fr-' + val + '-color').addClass('fr-selected-set');
217
+
218
+ // Refresh selected color.
219
+ _refreshColor(val);
220
+ }
221
+ }
222
+
223
+ /*
224
+ * Change background color.
225
+ */
226
+ function background (val) {
227
+ // Remove background color.
228
+ if (val == 'REMOVE') {
229
+ editor.format.removeStyle('background-color');
230
+ }
231
+ else if (val == 'PICKER') {
232
+ $('.fr-color-picker').val('');
233
+ $('.fr-color-picker')[0].click();
234
+ $('.fr-color-picker').change(function(){
235
+ editor.format.applyStyle('color', editor.helpers.HEXtoRGB($(this).val()));
236
+ });
237
+ }
238
+ // Set background color.
239
+ else {
240
+ editor.format.applyStyle('background-color', editor.helpers.HEXtoRGB(val));
241
+ }
242
+
243
+ _hideColorsPopup();
244
+ }
245
+
246
+ /*
247
+ * Change text color.
248
+ */
249
+ function text (val) {
250
+ // Remove text color.
251
+ if (val == 'REMOVE') {
252
+ editor.format.removeStyle('color');
253
+ }
254
+ else if (val == 'PICKER') {
255
+ $('.fr-color-picker').val('');
256
+ $('.fr-color-picker')[0].click();
257
+ $('.fr-color-picker').change(function(){
258
+ editor.format.applyStyle('color', editor.helpers.HEXtoRGB($(this).val()));
259
+ });
260
+ }
261
+ // Set text color.
262
+ else {
263
+ editor.format.applyStyle('color', editor.helpers.HEXtoRGB(val));
264
+ }
265
+
266
+ _hideColorsPopup();
267
+ }
268
+
269
+ /*
270
+ * Go back to the inline editor.
271
+ */
272
+ function back () {
273
+ editor.popups.hide('colors.picker');
274
+ editor.toolbar.showInline();
275
+ }
276
+
277
+ return {
278
+ showColorsPopup: _showColorsPopup,
279
+ hideColorsPopup: _hideColorsPopup,
280
+ changeSet: _changeSet,
281
+ background: background,
282
+ text: text,
283
+ back: back
284
+ }
285
+ }
286
+
287
+ // Toolbar colors button.
288
+ $.FE.DefineIcon('colors', { NAME: 'tint' });
289
+ $.FE.RegisterCommand('color', {
290
+ title: 'Colors',
291
+ undo: false,
292
+ focus: true,
293
+ refreshOnCallback: false,
294
+ popup: true,
295
+ callback: function () {
296
+ if (!this.popups.isVisible('colors.picker')) {
297
+ this.colors.showColorsPopup();
298
+ }
299
+ else {
300
+ if (this.$el.find('.fr-marker')) {
301
+ this.events.disableBlur();
302
+ this.selection.restore();
303
+ }
304
+ this.popups.hide('colors.picker');
305
+ }
306
+ },
307
+ plugin: 'colors'
308
+ });
309
+
310
+ // Select text color command.
311
+ $.FE.RegisterCommand('textColor', {
312
+ undo: true,
313
+ callback: function (cmd, val) {
314
+ this.colors.text(val);
315
+ }
316
+ });
317
+
318
+ // Select background color command.
319
+ $.FE.RegisterCommand('backgroundColor', {
320
+ undo: true,
321
+ callback: function (cmd, val) {
322
+ this.colors.background(val);
323
+ }
324
+ });
325
+
326
+ $.FE.RegisterCommand('colorChangeSet', {
327
+ undo: false,
328
+ focus: false,
329
+ callback: function (cmd, val) {
330
+ var $tab = this.popups.get('colors.picker').find('.fr-command[data-cmd="' + cmd + '"][data-param1="' + val + '"]');
331
+ this.colors.changeSet($tab, val);
332
+ }
333
+ });
334
+
335
+ // Colors back.
336
+ $.FE.DefineIcon('colorsBack', { NAME: 'arrow-left' });
337
+ $.FE.RegisterCommand('colorsBack', {
338
+ title: 'Back',
339
+ undo: false,
340
+ focus: false,
341
+ back: true,
342
+ refreshAfterCallback: false,
343
+ callback: function () {
344
+ this.colors.back();
345
+ }
346
+ });
347
+
348
+ $.FE.DefineIcon('remove', { NAME: 'eraser' });
349
+
350
+ }));