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,178 @@
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
+ fontFamily: {
39
+ 'Arial,Helvetica,sans-serif': 'Arial',
40
+ 'Georgia,serif': 'Georgia',
41
+ 'Impact,Charcoal,sans-serif': 'Impact',
42
+ 'Tahoma,Geneva,sans-serif': 'Tahoma',
43
+ 'Times New Roman,Times,serif': 'Times New Roman',
44
+ 'Verdana,Geneva,sans-serif': 'Verdana'
45
+ },
46
+ fontFamilySelection: false,
47
+ fontFamilyDefaultSelection: 'Font Family'
48
+ })
49
+
50
+ $.FE.PLUGINS.fontFamily = function (editor) {
51
+ function apply (val) {
52
+ editor.format.applyStyle('font-family', val);
53
+ }
54
+
55
+ function refreshOnShow($btn, $dropdown) {
56
+ $dropdown.find('.fr-command.fr-active').removeClass('fr-active');
57
+ $dropdown.find('.fr-command[data-param1="' + _getSelection() + '"]').addClass('fr-active');
58
+
59
+ var $list = $dropdown.find('.fr-dropdown-list');
60
+ var $active = $dropdown.find('.fr-active').parent();
61
+ if ($active.length) {
62
+ $list.parent().scrollTop($active.offset().top - $list.offset().top - ($list.parent().outerHeight() / 2 - $active.outerHeight() / 2));
63
+ }
64
+ else {
65
+ $list.parent().scrollTop(0);
66
+ }
67
+ }
68
+
69
+ function _getArray (val) {
70
+ var font_array = val.replace(/(sans-serif|serif|monospace|cursive|fantasy)/gi, '').replace(/"|'| /g, '').split(',');
71
+
72
+ return $.grep(font_array, function (txt) { return txt.length > 0 });
73
+ }
74
+
75
+ /**
76
+ * Return first match position.
77
+ */
78
+ function _matches (array1, array2) {
79
+ for (var i = 0; i < array1.length; i++) {
80
+ for (var j = 0; j < array2.length; j++) {
81
+ if (array1[i] == array2[j]) {
82
+ return [i, j];
83
+ }
84
+ }
85
+ }
86
+
87
+ return null;
88
+ }
89
+
90
+ function _getSelection () {
91
+ var val = $(editor.selection.element()).css('font-family');
92
+ var font_array = _getArray(val);
93
+
94
+ var font_matches = [];
95
+ for (var key in editor.opts.fontFamily) {
96
+ if (editor.opts.fontFamily.hasOwnProperty(key)) {
97
+ var c_font_array = _getArray(key);
98
+
99
+ var match = _matches(font_array, c_font_array);
100
+ if (match) {
101
+ font_matches.push([key, match]);
102
+ }
103
+ }
104
+ }
105
+
106
+ if (font_matches.length === 0) return null;
107
+
108
+ // Sort matches by their position.
109
+ // Times,Arial should be detected as being Times, not Arial.
110
+ font_matches.sort(function (a, b) {
111
+ var f_diff = a[1][0] - b[1][0];
112
+ if (f_diff === 0) {
113
+ return a[1][1] - b[1][1];
114
+ }
115
+ else {
116
+ return f_diff;
117
+ }
118
+ });
119
+
120
+ return font_matches[0][0];
121
+ }
122
+
123
+ function refresh ($btn) {
124
+ if (editor.opts.fontFamilySelection) {
125
+ var val = $(editor.selection.element()).css('font-family').replace(/(sans-serif|serif|monospace|cursive|fantasy)/gi, '').replace(/"|'|/g, '').split(',');
126
+
127
+ $btn.find('> span').text(editor.opts.fontFamily[_getSelection()] || val[0] || editor.opts.fontFamilyDefaultSelection);
128
+ }
129
+ }
130
+
131
+ return {
132
+ apply: apply,
133
+ refreshOnShow: refreshOnShow,
134
+ refresh: refresh
135
+ }
136
+ }
137
+
138
+ // Register the font size command.
139
+ $.FE.RegisterCommand('fontFamily', {
140
+ type: 'dropdown',
141
+ displaySelection: function (editor) {
142
+ return editor.opts.fontFamilySelection;
143
+ },
144
+ defaultSelection: function (editor) {
145
+ return editor.opts.fontFamilyDefaultSelection;
146
+ },
147
+ displaySelectionWidth: 120,
148
+ html: function () {
149
+ var c = '<ul class="fr-dropdown-list">';
150
+ var options = this.opts.fontFamily;
151
+ for (var val in options) {
152
+ if (options.hasOwnProperty(val)) {
153
+ c += '<li><a class="fr-command" data-cmd="fontFamily" data-param1="' + val + '" style="font-family: ' + val + '" title="' + options[val] + '">' + options[val] + '</a></li>';
154
+ }
155
+ }
156
+ c += '</ul>';
157
+
158
+ return c;
159
+ },
160
+ title: 'Font Family',
161
+ callback: function (cmd, val) {
162
+ this.fontFamily.apply(val);
163
+ },
164
+ refresh: function ($btn) {
165
+ this.fontFamily.refresh($btn);
166
+ },
167
+ refreshOnShow: function ($btn, $dropdown) {
168
+ this.fontFamily.refreshOnShow($btn, $dropdown);
169
+ },
170
+ plugin: 'fontFamily'
171
+ })
172
+
173
+ // Add the font size icon.
174
+ $.FE.DefineIcon('fontFamily', {
175
+ NAME: 'font'
176
+ });
177
+
178
+ }));
@@ -0,0 +1,116 @@
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
+ fontSize: ['8', '9', '10', '11', '12', '14', '18', '24', '30', '36', '48', '60', '72', '96'],
39
+ fontSizeSelection: false,
40
+ fontSizeDefaultSelection: '12'
41
+ });
42
+
43
+ $.FE.PLUGINS.fontSize = function (editor) {
44
+ function apply (val) {
45
+ editor.format.applyStyle('font-size', val);
46
+ }
47
+
48
+ function refreshOnShow($btn, $dropdown) {
49
+ var val = $(editor.selection.element()).css('font-size');
50
+ $dropdown.find('.fr-command.fr-active').removeClass('fr-active');
51
+ $dropdown.find('.fr-command[data-param1="' + val + '"]').addClass('fr-active');
52
+
53
+ var $list = $dropdown.find('.fr-dropdown-list');
54
+ var $active = $dropdown.find('.fr-active').parent();
55
+ if ($active.length) {
56
+ $list.parent().scrollTop($active.offset().top - $list.offset().top - ($list.parent().outerHeight() / 2 - $active.outerHeight() / 2));
57
+ }
58
+ else {
59
+ $list.parent().scrollTop(0);
60
+ }
61
+ }
62
+
63
+ function refresh ($btn) {
64
+ if (editor.opts.fontSizeSelection) {
65
+ var val = editor.helpers.getPX($(editor.selection.element()).css('font-size'));
66
+ $btn.find('> span').text(val);
67
+ }
68
+ }
69
+
70
+ return {
71
+ apply: apply,
72
+ refreshOnShow: refreshOnShow,
73
+ refresh: refresh
74
+ }
75
+ }
76
+
77
+ // Register the font size command.
78
+ $.FE.RegisterCommand('fontSize', {
79
+ type: 'dropdown',
80
+ title: 'Font Size',
81
+ displaySelection: function (editor) {
82
+ return editor.opts.fontSizeSelection;
83
+ },
84
+ displaySelectionWidth: 30,
85
+ defaultSelection: function (editor) {
86
+ return editor.opts.fontSizeDefaultSelection;
87
+ },
88
+ html: function () {
89
+ var c = '<ul class="fr-dropdown-list">';
90
+ var options = this.opts.fontSize;
91
+ for (var i = 0; i < options.length; i++) {
92
+ var val = options[i];
93
+ c += '<li><a class="fr-command" data-cmd="fontSize" data-param1="' + val + 'px" title="' + val + '">' + val + '</a></li>';
94
+ }
95
+ c += '</ul>';
96
+
97
+ return c;
98
+ },
99
+ callback: function (cmd, val) {
100
+ this.fontSize.apply(val);
101
+ },
102
+ refresh: function ($btn) {
103
+ this.fontSize.refresh($btn);
104
+ },
105
+ refreshOnShow: function ($btn, $dropdown) {
106
+ this.fontSize.refreshOnShow($btn, $dropdown);
107
+ },
108
+ plugin: 'fontSize'
109
+ })
110
+
111
+ // Add the font size icon.
112
+ $.FE.DefineIcon('fontSize', {
113
+ NAME: 'text-height'
114
+ });
115
+
116
+ }));
@@ -0,0 +1,415 @@
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
+ 'forms.edit': '[_BUTTONS_]',
39
+ 'forms.update': '[_BUTTONS_][_TEXT_LAYER_]'
40
+ })
41
+
42
+ $.extend($.FE.DEFAULTS, {
43
+ formEditButtons: ['inputStyle', 'inputEdit'],
44
+ formStyles: {
45
+ 'fr-rounded': 'Rounded',
46
+ 'fr-large': 'Large'
47
+ },
48
+ formMultipleStyles: true,
49
+ formUpdateButtons: ['inputBack', '|']
50
+ })
51
+
52
+ $.FE.PLUGINS.forms = function (editor) {
53
+ var current_input;
54
+
55
+ /**
56
+ * Input mousedown.
57
+ */
58
+ function _inputMouseDown (e) {
59
+ e.preventDefault();
60
+ editor.selection.clear();
61
+ $(this).data('mousedown', true);
62
+ }
63
+
64
+ /**
65
+ * Mouseup on the input.
66
+ */
67
+ function _inputMouseUp (e) {
68
+ // Mousedown was made.
69
+ if ($(this).data('mousedown')) {
70
+ e.stopPropagation();
71
+ $(this).removeData('mousedown');
72
+
73
+ current_input = this;
74
+
75
+ showEditPopup(this);
76
+ }
77
+
78
+ e.preventDefault();
79
+ }
80
+
81
+ /**
82
+ * Cancel if mousedown was made on any input.
83
+ */
84
+ function _cancelSelection () {
85
+ editor.$el.find('input, textarea, button').removeData('mousedown');
86
+ }
87
+
88
+ /**
89
+ * Touch move.
90
+ */
91
+ function _inputTouchMove () {
92
+ $(this).removeData('mousedown');
93
+ }
94
+
95
+ /**
96
+ * Assign the input events.
97
+ */
98
+ function _bindEvents () {
99
+ editor.events.$on(editor.$el, editor._mousedown, 'input, textarea, button', _inputMouseDown);
100
+ editor.events.$on(editor.$el, editor._mouseup, 'input, textarea, button', _inputMouseUp);
101
+ editor.events.$on(editor.$el, 'touchmove', 'input, textarea, button', _inputTouchMove);
102
+ editor.events.$on(editor.$el, editor._mouseup, _cancelSelection);
103
+ editor.events.$on(editor.$win, editor._mouseup, _cancelSelection);
104
+
105
+ _initUpdatePopup(true);
106
+ }
107
+
108
+ /**
109
+ * Get the current button.
110
+ */
111
+ function getInput () {
112
+ if (current_input) return current_input;
113
+
114
+ return null;
115
+ }
116
+
117
+ /**
118
+ * Init the edit button popup.
119
+ */
120
+ function _initEditPopup () {
121
+ // Button edit buttons.
122
+ var buttons = '';
123
+ if (editor.opts.formEditButtons.length > 0) {
124
+ buttons = '<div class="fr-buttons">' + editor.button.buildList(editor.opts.formEditButtons) + '</div>';
125
+ }
126
+
127
+ var template = {
128
+ buttons: buttons
129
+ };
130
+
131
+ // Set the template in the popup.
132
+ var $popup = editor.popups.create('forms.edit', template);
133
+
134
+ if (editor.$wp) {
135
+ editor.events.$on(editor.$wp, 'scroll.link-edit', function () {
136
+ if (get() && editor.popups.isVisible('forms.edit')) {
137
+ showEditPopup(getInput());
138
+ }
139
+ });
140
+ }
141
+
142
+ return $popup;
143
+ }
144
+
145
+ /**
146
+ * Show the edit button popup.
147
+ */
148
+ function showEditPopup (input) {
149
+ var $popup = editor.popups.get('forms.edit');
150
+ if (!$popup) $popup = _initEditPopup();
151
+
152
+ current_input = input;
153
+ var $input = $(input);
154
+
155
+ editor.popups.refresh('forms.edit');
156
+
157
+ editor.popups.setContainer('forms.edit', $(editor.opts.scrollableContainer));
158
+ var left = $input.offset().left + $input.outerWidth() / 2;
159
+ var top = $input.offset().top + $input.outerHeight();
160
+
161
+ editor.popups.show('forms.edit', left, top, $input.outerHeight());
162
+ }
163
+
164
+ /**
165
+ * Refresh update button popup callback.
166
+ */
167
+ function _refreshUpdateCallback () {
168
+ var $popup = editor.popups.get('forms.update');
169
+
170
+ var input = getInput();
171
+ if (input) {
172
+ var $input = $(input);
173
+ if ($input.is('button')) {
174
+ $popup.find('input[type="text"][name="text"]').val($input.text());
175
+ }
176
+ else {
177
+ $popup.find('input[type="text"][name="text"]').val($input.attr('placeholder'));
178
+ }
179
+ }
180
+
181
+ $popup.find('input[type="text"][name="text"]').trigger('change');
182
+ }
183
+
184
+ /**
185
+ * Hide update button popup callback.
186
+ */
187
+ function _hideUpdateCallback () {
188
+ current_input = null;
189
+ }
190
+
191
+ /**
192
+ * Init update button popup.
193
+ */
194
+ function _initUpdatePopup (delayed) {
195
+ if (delayed) {
196
+ editor.popups.onRefresh('forms.update', _refreshUpdateCallback);
197
+ editor.popups.onHide('forms.update', _hideUpdateCallback);
198
+
199
+ return true;
200
+ }
201
+
202
+ // Button update buttons.
203
+ var buttons = '';
204
+ if (editor.opts.formUpdateButtons.length >= 1) {
205
+ buttons = '<div class="fr-buttons">' + editor.button.buildList(editor.opts.formUpdateButtons) + '</div>';
206
+ }
207
+
208
+ var text_layer = '';
209
+ var tab_idx = 0;
210
+ text_layer = '<div class="fr-forms-text-layer fr-layer fr-active">';
211
+ text_layer += '<div class="fr-input-line"><input name="text" type="text" placeholder="Text" tabIndex="' + (++tab_idx) + '"></div>';
212
+
213
+ text_layer += '<div class="fr-action-buttons"><button class="fr-command fr-submit" data-cmd="updateInput" href="#" tabIndex="' + (++tab_idx) + '" type="button">' + editor.language.translate('Update') + '</button></div></div>'
214
+
215
+ var template = {
216
+ buttons: buttons,
217
+ text_layer: text_layer
218
+ }
219
+
220
+ // Set the template in the popup.
221
+ var $popup = editor.popups.create('forms.update', template);
222
+
223
+ return $popup;
224
+ }
225
+
226
+ /**
227
+ * Show the button update popup.
228
+ */
229
+ function showUpdatePopup () {
230
+ var input = getInput();
231
+ if (input) {
232
+ var $input = $(input);
233
+
234
+ var $popup = editor.popups.get('forms.update');
235
+ if (!$popup) $popup = _initUpdatePopup();
236
+
237
+ if (!editor.popups.isVisible('forms.update')) {
238
+ editor.popups.refresh('forms.update');
239
+ }
240
+
241
+ editor.popups.setContainer('forms.update', $(editor.opts.scrollableContainer));
242
+ var left = $input.offset().left + $input.outerWidth() / 2;
243
+ var top = $input.offset().top + $input.outerHeight();
244
+
245
+ editor.popups.show('forms.update', left, top, $input.outerHeight());
246
+ }
247
+ }
248
+
249
+ /**
250
+ * Apply specific style.
251
+ */
252
+ function applyStyle (val, formStyles, multipleStyles) {
253
+ if (typeof formStyles == 'undefined') formStyles = editor.opts.formStyles;
254
+ if (typeof multipleStyles == 'undefined') multipleStyles = editor.opts.formMultipleStyles;
255
+
256
+ var input = getInput();
257
+ if (!input) return false;
258
+
259
+ // Remove multiple styles.
260
+ if (!multipleStyles) {
261
+ var styles = Object.keys(formStyles);
262
+ styles.splice(styles.indexOf(val), 1);
263
+ $(input).removeClass(styles.join(' '));
264
+ }
265
+
266
+ $(input).toggleClass(val);
267
+ }
268
+
269
+ /**
270
+ * Back button in update button popup.
271
+ */
272
+ function back () {
273
+ editor.events.disableBlur();
274
+ editor.selection.restore();
275
+ editor.events.enableBlur();
276
+
277
+ var input = getInput();
278
+
279
+ if (input && editor.$wp) {
280
+ if (input.tagName == 'BUTTON') editor.selection.restore();
281
+ showEditPopup(input);
282
+ }
283
+ }
284
+
285
+ /**
286
+ * Hit the update button in the input popup.
287
+ */
288
+ function updateInput () {
289
+ var $popup = editor.popups.get('forms.update');
290
+
291
+ var input = getInput();
292
+ if (input) {
293
+ var $input = $(input);
294
+ var val = $popup.find('input[type="text"][name="text"]').val() || '';
295
+
296
+ if (val.length) {
297
+ if ($input.is('button')) {
298
+ $input.text(val);
299
+ }
300
+ else {
301
+ $input.attr('placeholder', val);
302
+ }
303
+ }
304
+
305
+ editor.popups.hide('forms.update');
306
+ showEditPopup(input);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Initialize.
312
+ */
313
+ function _init () {
314
+ // Bind input events.
315
+ _bindEvents();
316
+
317
+ // Prevent form submit.
318
+ editor.events.$on(editor.$el, 'submit', 'form', function (e) {
319
+ e.preventDefault();
320
+ return false;
321
+ })
322
+ }
323
+
324
+ return {
325
+ _init: _init,
326
+ updateInput: updateInput,
327
+ getInput: getInput,
328
+ applyStyle: applyStyle,
329
+ showUpdatePopup: showUpdatePopup,
330
+ showEditPopup: showEditPopup,
331
+ back: back
332
+ }
333
+ }
334
+
335
+ // Register command to update input.
336
+ $.FE.RegisterCommand('updateInput', {
337
+ undo: false,
338
+ focus: false,
339
+ title: 'Update',
340
+ callback: function () {
341
+ this.forms.updateInput();
342
+ }
343
+ });
344
+
345
+ // Link styles.
346
+ $.FE.DefineIcon('inputStyle', { NAME: 'magic' })
347
+ $.FE.RegisterCommand('inputStyle', {
348
+ title: 'Style',
349
+ type: 'dropdown',
350
+ html: function () {
351
+ var c = '<ul class="fr-dropdown-list">';
352
+ var options = this.opts.formStyles;
353
+ for (var cls in options) {
354
+ if (options.hasOwnProperty(cls)) {
355
+ c += '<li><a class="fr-command" data-cmd="inputStyle" data-param1="' + cls + '">' + this.language.translate(options[cls]) + '</a></li>';
356
+ }
357
+ }
358
+ c += '</ul>';
359
+
360
+ return c;
361
+ },
362
+ callback: function (cmd, val) {
363
+ var input = this.forms.getInput();
364
+
365
+ if (input) {
366
+ this.forms.applyStyle(val);
367
+ this.forms.showEditPopup(input);
368
+ }
369
+ },
370
+ refreshOnShow: function ($btn, $dropdown) {
371
+ var input = this.forms.getInput();
372
+
373
+ if (input) {
374
+ var $input = $(input);
375
+ $dropdown.find('.fr-command').each (function () {
376
+ var cls = $(this).data('param1');
377
+ $(this).toggleClass('fr-active', $input.hasClass(cls));
378
+ })
379
+ }
380
+ }
381
+ });
382
+
383
+ $.FE.DefineIcon('inputEdit', { NAME: 'edit' });
384
+ $.FE.RegisterCommand('inputEdit', {
385
+ title: 'Edit Button',
386
+ undo: false,
387
+ refreshAfterCallback: false,
388
+ callback: function () {
389
+ this.forms.showUpdatePopup();
390
+ }
391
+ })
392
+
393
+ $.FE.DefineIcon('inputBack', { NAME: 'arrow-left' });
394
+ $.FE.RegisterCommand('inputBack', {
395
+ title: 'Back',
396
+ undo: false,
397
+ focus: false,
398
+ back: true,
399
+ refreshAfterCallback: false,
400
+ callback: function () {
401
+ this.forms.back();
402
+ }
403
+ });
404
+
405
+ // Register command to update button.
406
+ $.FE.RegisterCommand('updateInput', {
407
+ undo: false,
408
+ focus: false,
409
+ title: 'Update',
410
+ callback: function () {
411
+ this.forms.updateInput();
412
+ }
413
+ });
414
+
415
+ }));