binda 0.1.5 → 0.1.6

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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -26
  3. data/Rakefile +4 -0
  4. data/app/assets/javascripts/binda/application.js +3 -0
  5. data/app/assets/javascripts/binda/components/field_setting_choices.js +5 -5
  6. data/app/assets/javascripts/binda/components/fileupload.js +1 -1
  7. data/app/assets/javascripts/binda/components/form_item_collapsable.js +245 -0
  8. data/app/assets/javascripts/binda/components/form_item_image.js +1 -1
  9. data/app/assets/javascripts/binda/components/login-shader.js +1 -1
  10. data/app/assets/javascripts/binda/components/login_form.js +1 -1
  11. data/app/assets/javascripts/binda/components/sortable.js +21 -30
  12. data/app/assets/javascripts/binda/dist/binda.bundle.js +299 -377
  13. data/app/assets/javascripts/binda/index.js +9 -17
  14. data/app/assets/stylesheets/binda/components/field_setting_choices.scss +5 -3
  15. data/app/assets/stylesheets/binda/components/form_item.scss +23 -70
  16. data/app/assets/stylesheets/binda/components/standard-form.scss +56 -1
  17. data/app/assets/stylesheets/binda/settings/tiny_mce_overrides.scss +8 -0
  18. data/app/controllers/binda/application_controller.rb +6 -0
  19. data/app/controllers/binda/boards_controller.rb +18 -12
  20. data/app/controllers/binda/components_controller.rb +21 -16
  21. data/app/controllers/binda/field_groups_controller.rb +57 -16
  22. data/app/controllers/binda/field_settings_controller.rb +14 -2
  23. data/app/controllers/binda/repeaters_controller.rb +2 -2
  24. data/app/controllers/binda/structures_controller.rb +32 -16
  25. data/app/controllers/concerns/binda/fieldable_helpers.rb +2 -2
  26. data/app/helpers/binda/components_helper.rb +16 -4
  27. data/app/helpers/binda/field_groups_helper.rb +4 -1
  28. data/app/models/binda/asset.rb +1 -3
  29. data/app/models/binda/component.rb +17 -10
  30. data/app/models/binda/date.rb +2 -6
  31. data/app/models/binda/field_group.rb +7 -5
  32. data/app/models/binda/field_setting.rb +69 -8
  33. data/app/models/binda/gallery.rb +2 -3
  34. data/app/models/binda/image.rb +7 -1
  35. data/app/models/binda/relation.rb +2 -5
  36. data/app/models/binda/repeater.rb +10 -14
  37. data/app/models/binda/selection.rb +3 -3
  38. data/app/models/binda/structure.rb +9 -5
  39. data/app/models/binda/text.rb +2 -6
  40. data/app/models/binda/user.rb +10 -0
  41. data/app/models/concerns/binda/field_uniqueness.rb +31 -0
  42. data/app/models/concerns/binda/fieldable_association_helpers.rb +31 -11
  43. data/app/models/concerns/binda/fieldable_associations.rb +2 -3
  44. data/app/models/concerns/binda/fields.rb +21 -0
  45. data/app/views/binda/boards/edit.html.erb +2 -1
  46. data/app/views/binda/components/edit.html.erb +2 -1
  47. data/app/views/binda/field_groups/_form_body.html.erb +4 -42
  48. data/app/views/binda/field_groups/_form_header.html.erb +11 -0
  49. data/app/views/binda/field_groups/_form_item.html.erb +4 -6
  50. data/app/views/binda/field_groups/_form_new_item.html.erb +8 -0
  51. data/app/views/binda/field_groups/_form_section.html.erb +17 -27
  52. data/app/views/binda/field_groups/_form_section_repeater.html.erb +17 -18
  53. data/app/views/binda/field_groups/_form_sidebar.html.erb +13 -0
  54. data/app/views/binda/field_groups/form_item/_form_item_editor.html.erb +9 -5
  55. data/app/views/binda/field_groups/form_item/{_form_item_persisted_editor.html.erb → _form_item_editor_existing_item.html.erb} +1 -4
  56. data/app/views/binda/field_groups/form_item/_form_item_editor_new_item.html.erb +3 -0
  57. data/app/views/binda/field_groups/form_item/_form_item_header.html.erb +23 -24
  58. data/app/views/binda/field_groups/form_section/_form_section_header.html.erb +45 -0
  59. data/app/views/binda/field_groups/form_section/_form_section_list.html.erb +9 -0
  60. data/app/views/binda/fieldable/_form_body.html.erb +6 -1
  61. data/app/views/binda/fieldable/_form_item_date.html.erb +1 -1
  62. data/app/views/binda/fieldable/_form_item_image.html.erb +1 -1
  63. data/app/views/binda/fieldable/_form_item_new_repeater.html.erb +7 -21
  64. data/app/views/binda/fieldable/_form_item_relation.html.erb +7 -7
  65. data/app/views/binda/fieldable/_form_item_repeater.html.erb +9 -99
  66. data/app/views/binda/fieldable/_form_item_selections.html.erb +1 -1
  67. data/app/views/binda/fieldable/_form_item_string.html.erb +5 -12
  68. data/app/views/binda/fieldable/_form_item_text.html.erb +5 -13
  69. data/app/views/binda/fieldable/_form_item_video.html.erb +1 -1
  70. data/app/views/binda/fieldable/_form_section.html.erb +11 -10
  71. data/app/views/binda/fieldable/_form_section_repeater.html.erb +2 -3
  72. data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_header.html.erb +32 -0
  73. data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_list.html.erb +19 -0
  74. data/app/views/binda/fieldable/form_item_repeater/_form_item_repeater_list_item.html.erb +42 -0
  75. data/app/views/binda/structures/_form_field_group_item.html.erb +5 -0
  76. data/app/views/binda/structures/_form_new_field_group_item.html.erb +8 -0
  77. data/app/views/binda/structures/_form_section.html.erb +16 -78
  78. data/app/views/binda/structures/_form_sidebar.html.erb +9 -8
  79. data/app/views/binda/structures/form_field_group_item/_form_field_group_item_editor.html.erb +18 -0
  80. data/app/views/binda/structures/form_field_group_item/_form_field_group_item_field_setting_form.html.erb +12 -0
  81. data/app/views/binda/structures/form_field_group_item/_form_field_group_item_field_settings.html.erb +18 -0
  82. data/app/views/binda/structures/form_field_group_item/_form_field_group_item_header.html.erb +29 -0
  83. data/app/views/binda/structures/form_section/_form_section_header.html.erb +26 -0
  84. data/app/views/binda/structures/form_section/_form_section_list.html.erb +8 -0
  85. data/config/initializers/simple_form__fileupload.rb +3 -4
  86. data/config/locales/en.yml +9 -4
  87. data/config/routes.rb +4 -0
  88. data/lib/binda/version.rb +1 -1
  89. data/lib/generators/binda/install/install_generator.rb +17 -6
  90. data/lib/generators/binda/maintenance/maintenance_generator.rb +12 -8
  91. data/lib/generators/binda/setup/setup_generator.rb +23 -27
  92. data/lib/tasks/create_missing_field_instances_task.rake +10 -0
  93. data/lib/tasks/remove_orphan_fields_task.rake +1 -7
  94. data/lib/tasks/user_tasks.rake +1 -7
  95. data/vendor/assets/javascripts/lodash.js +17097 -0
  96. metadata +39 -7
  97. data/app/assets/javascripts/binda/components/form_item.js +0 -113
  98. data/app/assets/javascripts/binda/components/form_item_editor.js +0 -39
  99. data/app/assets/javascripts/binda/components/form_item_repeater.js +0 -127
  100. data/app/views/binda/field_groups/form_item/_form_item_new_editor.html.erb +0 -8
@@ -2,6 +2,8 @@
2
2
  * SORTABLE
3
3
  */
4
4
 
5
+ import { openCollapsableStacks, closeCollapsableStacks } from './form_item_collapsable';
6
+
5
7
  var sortableOptions = {
6
8
  stop: function(event, ui) {
7
9
  ui.item.css("z-index", 0);
@@ -10,6 +12,14 @@ var sortableOptions = {
10
12
  update: updateSortable
11
13
  };
12
14
 
15
+ /* Initialize jQuery Sortable
16
+ *
17
+ * This function handles several things:
18
+ * - it sets Sortable for each ".sortable" element
19
+ * - it adds handles only if required
20
+ * - it disable itself if it finds ".sortable--disabled" class
21
+ * - it sets up a toggle button and behaviour if required
22
+ */
13
23
  export default function() {
14
24
  if ($(".sortable").length > 0) {
15
25
  // Initialize sortable item
@@ -31,50 +41,31 @@ export default function() {
31
41
  if ($(".sortable--toggle").length > 0) {
32
42
  setupSortableToggle();
33
43
  }
34
-
35
- // Add event to any sortable toggle button
36
- // TODO: make this event available to element which aren't standard form repeaters
37
- $(document).on(
38
- "click",
39
- ".standard-form--repeater .sortable--toggle",
40
- toggleSortable
41
- );
42
44
  }
43
45
 
46
+ /* Setup Sortable Toggle
47
+ *
48
+ * It sets up each toggle button and add the events needed to enable or disable Sortable.
49
+ */
44
50
  function setupSortableToggle() {
45
51
  $(".sortable--toggle").each(function() {
46
- let id = "#" + $(this).data("repeater-id");
47
- $(id)
48
- .find(".form-item--collapsable")
49
- .addClass("form-item--collapsed");
50
- $(id)
51
- .find(".form-item--repeater-fields")
52
- .each(close);
52
+ let id = "#" + $(this).data("sortable-target-id");
53
+ closeCollapsableStacks(id);
53
54
  });
54
- }
55
-
56
- function close() {
57
- this.style.maxHeight = "0px";
58
- }
59
-
60
- function open() {
61
- this.style.maxHeight = this.scrollHeight + "px";
55
+ // Add event to any sortable toggle button
56
+ $(document).on("click", ".sortable--toggle", toggleSortable);
62
57
  }
63
58
 
64
59
  function toggleSortable(event) {
65
60
  event.preventDefault();
66
- let id = "#" + $(this).data("repeater-id");
61
+ let id = "#" + $(this).data("sortable-target-id");
67
62
 
68
63
  if ($(id).hasClass("sortable--disabled")) {
69
64
  $(id).sortable("enable");
70
- $(id)
71
- .find(".form-item--repeater-fields")
72
- .each(close);
73
- $(id)
74
- .find(".form-item--collapsable")
75
- .addClass("form-item--collapsed");
65
+ closeCollapsableStacks(id);
76
66
  } else {
77
67
  $(id).sortable("disable");
68
+ openCollapsableStacks(id);
78
69
  }
79
70
 
80
71
  $(id).toggleClass("sortable--disabled");
@@ -68,26 +68,33 @@
68
68
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
69
69
 
70
70
  "use strict";
71
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemEditor; });
71
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemCollapsable; });
72
+ /* harmony export (immutable) */ __webpack_exports__["b"] = closeCollapsableStacks;
73
+ /* harmony export (immutable) */ __webpack_exports__["c"] = openCollapsableStacks;
74
+ /* harmony export (immutable) */ __webpack_exports__["d"] = resizeCollapsableStacks;
75
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__select2__ = __webpack_require__(1);
72
76
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
73
77
 
74
78
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
75
79
 
76
80
  /**
77
- * FORM ITEM EDITOR
81
+ * FORM ITEM
78
82
  */
79
83
 
80
- var FormItemEditor = function () {
81
- function FormItemEditor() {
82
- _classCallCheck(this, FormItemEditor);
83
84
 
84
- this.target = ".form-item--editor";
85
+
86
+ // Component Global Variables
87
+ var newFormItemId = 1;
88
+
89
+ var FormItemCollapsable = function () {
90
+ function FormItemCollapsable() {
91
+ _classCallCheck(this, FormItemCollapsable);
85
92
  }
86
93
 
87
- _createClass(FormItemEditor, [{
88
- key: "isSet",
89
- value: function isSet() {
90
- if ($(this.target).length > 0) {
94
+ _createClass(FormItemCollapsable, [{
95
+ key: "isPresent",
96
+ value: function isPresent() {
97
+ if ($(".form--list").length > 0) {
91
98
  return true;
92
99
  } else {
93
100
  return false;
@@ -96,33 +103,218 @@ var FormItemEditor = function () {
96
103
  }, {
97
104
  key: "setEvents",
98
105
  value: function setEvents() {
99
- var _this = this;
100
-
101
- // run resize to set initial size
102
- this.resize();
103
- // run resize on each of these events
104
- $(window).resize(function () {
105
- _this.resize();
106
- });
107
- }
108
- }, {
109
- key: "resize",
110
- value: function resize() {
111
- $(this.target).each(function () {
112
- // If the form item editor is closed don't go any further
113
- if ($(this).height() === 0) return;
114
- // otherwise update the max-height which is needed for the CSS transition
115
- // NOTE you need to remove the max-height (inside 'style' attribute) to get the real height
116
- $(this).get(0).style.height = "auto";
117
- $(this).get(0).style.maxHeight = $(this).get(0).scrollHeight + "px";
118
- });
106
+ $(document).on("click", ".form--add-list-item", addNewItem);
107
+ $(document).on("click", ".form--delete-list-item", deleteItem);
108
+ $(document).on("click", ".form-item--collapse-btn", collapseToggle);
109
+ $(window).resize(resizeCollapsableStacks);
110
+ // Make sure all collapsable items are resized already at every page load
111
+ resizeCollapsableStacks();
119
112
  }
120
113
  }]);
121
114
 
122
- return FormItemEditor;
115
+ return FormItemCollapsable;
123
116
  }();
124
117
 
125
- var _FormItemEditor = new FormItemEditor();
118
+ var _FormItemCollapsable = new FormItemCollapsable();
119
+
120
+ /**
121
+ * COMPONENT HELPER FUNCTIONS
122
+ */
123
+
124
+ /**
125
+ * Adds a new item.
126
+ *
127
+ * @param {event} event The event
128
+ */
129
+ function addNewItem(event) {
130
+ // Stop default behaviour
131
+ event.preventDefault();
132
+ // Get the child to clone
133
+ var id = $(this).data("id");
134
+ var $list = $("#form--list-" + id);
135
+ var url = $(this).data("url");
136
+ var data = $list.sortable("serialize");
137
+ var params = $(this).data("params");
138
+ if (params) {
139
+ data = data.concat("&" + params);
140
+ }
141
+ $.ajax({
142
+ url: url,
143
+ data: data,
144
+ method: "POST"
145
+ }).done(function (data) {
146
+ // Get repaeter code from Rails
147
+ // Due to the Rails way of creating nested forms it's necessary to
148
+ // create the nested item inside a different new form, then get just
149
+ // the code contained between the two SPLIT comments
150
+ var parts = data.split("<!-- SPLIT -->");
151
+ var newItem = parts[1];
152
+ setupAndAppend(newItem, $list);
153
+ });
154
+ }
155
+
156
+ /**
157
+ * Setup and append new item
158
+ *
159
+ * @param {string} newItem The new item
160
+ * @param {object} $list The list
161
+ */
162
+ function setupAndAppend(newItem, $list) {
163
+ // Append the item
164
+ $list.prepend(newItem);
165
+ var collapsable = $list.find(".form-item--collapsable").get(0);
166
+
167
+ // Update select input for Select2 plugin
168
+ Object(__WEBPACK_IMPORTED_MODULE_0__select2__["b" /* setupSelect2 */])($list.find("select"));
169
+
170
+ setupTinyMCE($list.find("textarea"));
171
+
172
+ // Prepare collapsable animation
173
+ collapsable.style.maxHeight = "0px";
174
+
175
+ // Prepare collapsable stack animation
176
+ openCollapsableStacks(collapsable);
177
+
178
+ // Refresh Sortable to update the added item with Sortable features
179
+ $list.sortable("refresh");
180
+
181
+ // Run animation 500ms after previous style declaration (see above) otherwise animation doesn't get triggered
182
+ setTimeout(function () {
183
+ collapsable.style.maxHeight = collapsable.scrollHeight + "px";
184
+ }, 50);
185
+ }
186
+
187
+ /**
188
+ * Close collapsable stacks
189
+ *
190
+ * It closes all collapsable stacks inside the collapsable item passed as argument
191
+ *
192
+ * @param {object, string} target The target
193
+ */
194
+ function closeCollapsableStacks(obj) {
195
+ $(obj).addClass("form-item--collapsed").find(".form-item--collapsable-stack").each(function () {
196
+ this.style.maxHeight = "0px";
197
+ this.style.pointerEvents = "none";
198
+ });
199
+ }
200
+
201
+ /**
202
+ * Open collapsable stacks
203
+ *
204
+ * It opens all collapsable stacks inside the collapsable item passed as argument
205
+ *
206
+ * @param {object, string} target The target
207
+ */
208
+ function openCollapsableStacks(obj) {
209
+ // Don't execute this if sortable is enabled
210
+ if ($(obj).closest(".sortable").hasClass("sortable--enabled")) {
211
+ return;
212
+ }
213
+ $(obj).removeClass("form-item--collapsed").find(".form-item--collapsable-stack").each(function () {
214
+ this.style.maxHeight = this.scrollHeight + "px";
215
+ this.style.pointerEvents = "auto";
216
+ });
217
+ }
218
+
219
+ /**
220
+ * Toggle a collapsable item
221
+ *
222
+ * Basically it opens it or closes it based on its state
223
+ *
224
+ * @param {event} event The event
225
+ */
226
+ function collapseToggle(event) {
227
+ // Stop default behaviour
228
+ event.preventDefault();
229
+ var $collapsable = $(this).closest(".form-item--collapsable");
230
+ if ($collapsable.hasClass("form-item--collapsed")) {
231
+ $collapsable.each(function () {
232
+ openCollapsableStacks(this);
233
+ });
234
+ } else {
235
+ $collapsable.each(function () {
236
+ closeCollapsableStacks(this);
237
+ });
238
+ }
239
+ }
240
+
241
+ /**
242
+ * Delete collapsable item and hide it
243
+ *
244
+ * @param {event} event The event
245
+ */
246
+ function deleteItem(event) {
247
+ // Stop default behaviour
248
+ event.preventDefault();
249
+ var record_id = $(this).data("id");
250
+ var targetId = "#form--list-item-" + record_id;
251
+ var target = $(targetId).get(0);
252
+ // As max-height isn't set you need to set it manually before changing it,
253
+ // otherwise the animation doesn't get triggered
254
+ target.style.maxHeight = target.scrollHeight + "px";
255
+ // Change max-height after 50ms to trigger css animation
256
+ setTimeout(function () {
257
+ target.style.maxHeight = "0px";
258
+ target.style.pointerEvents = "none";
259
+ }, 50);
260
+ $.ajax({
261
+ url: $(this).attr("href"),
262
+ data: { id: record_id, target_id: targetId, isAjax: true },
263
+ method: "DELETE"
264
+ }).done(function (data) {
265
+ // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
266
+ setTimeout(function () {
267
+ $(data.target_id).remove();
268
+ }, 700);
269
+ });
270
+ // TODO add a fallback if request fails
271
+ }
272
+
273
+ /**
274
+ * Resize all collapsable item
275
+ *
276
+ * If a target is passed as a argument the function will resize only that target and its children.
277
+ *
278
+ * @param {object, string} target The target.
279
+ */
280
+ function resizeCollapsableStacks(target) {
281
+ target = _.isUndefined(target) ? document.getElementsByClassName("form-item--collapsable-stack") : target;
282
+ // target CANNOT BE a jquery object because it leads to the following error
283
+ // TypeError: undefined is not an object (evaluating 't.ownerDocument.defaultView')
284
+ $(target).each(function () {
285
+ // If the collapsable item is closed don't go any further
286
+ if ($(this).height() === 0 || $(this).closest(".form-item--collapsable").hasClass("form-item--collapsed")) {
287
+ this.style.maxHeight = "0px";
288
+ this.style.pointerEvents = "none";
289
+ } else {
290
+ // otherwise update the max-height which is needed for the CSS transition
291
+ // NOTE you need to remove the max-height (inside 'style' attribute) to get the real height
292
+ this.style.height = "auto";
293
+ this.style.maxHeight = this.scrollHeight + "px";
294
+ this.style.pointerEvents = "auto";
295
+ }
296
+ });
297
+ }
298
+
299
+ /**
300
+ * Setup TinyMCE
301
+ *
302
+ * @param {jQuery object} $textareas The textareas
303
+ */
304
+ function setupTinyMCE($textareas) {
305
+ var editor_ids = _.map(tinyMCE.editors, function (editor) {
306
+ return editor.id;
307
+ });
308
+ // console.log({editors});
309
+ $textareas.each(function () {
310
+ if (_.includes(editor_ids, this.getAttribute('id'))) {
311
+ return;
312
+ }
313
+ tinyMCE.init({
314
+ selector: "#" + this.getAttribute("id")
315
+ });
316
+ });
317
+ }
126
318
 
127
319
  /***/ }),
128
320
  /* 1 */
@@ -164,19 +356,17 @@ function setupSelect2(target) {
164
356
 
165
357
  "use strict";
166
358
  Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
167
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__components_form_item__ = __webpack_require__(3);
168
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__components_form_item_repeater__ = __webpack_require__(4);
169
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__components_form_item_image__ = __webpack_require__(5);
170
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__components_field_setting_choices__ = __webpack_require__(6);
171
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__components_form_item_editor__ = __webpack_require__(0);
172
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__components_fileupload__ = __webpack_require__(7);
173
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__components_login_shader__ = __webpack_require__(8);
174
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__components_login_form__ = __webpack_require__(9);
175
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__components_sortable__ = __webpack_require__(10);
176
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__components_field_group_editor__ = __webpack_require__(11);
177
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__components_bootstrap__ = __webpack_require__(12);
178
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_11__components_select2__ = __webpack_require__(1);
179
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_12__components_radio_toggle__ = __webpack_require__(13);
359
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__components_form_item_collapsable__ = __webpack_require__(0);
360
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__components_form_item_image__ = __webpack_require__(3);
361
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_2__components_field_setting_choices__ = __webpack_require__(4);
362
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_3__components_fileupload__ = __webpack_require__(5);
363
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_4__components_login_shader__ = __webpack_require__(6);
364
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_5__components_login_form__ = __webpack_require__(7);
365
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_6__components_sortable__ = __webpack_require__(8);
366
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_7__components_field_group_editor__ = __webpack_require__(9);
367
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_8__components_bootstrap__ = __webpack_require__(10);
368
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_9__components_select2__ = __webpack_require__(1);
369
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_10__components_radio_toggle__ = __webpack_require__(11);
180
370
  ///- - - - - - - - - - - - - - - - - - - -
181
371
  /// INDEX OF BINDA'S SCRIPTS
182
372
  ///- - - - - - - - - - - - - - - - - - - -
@@ -193,45 +383,37 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
193
383
 
194
384
 
195
385
 
196
-
197
-
198
386
  $(document).ready(function () {
199
- if (__WEBPACK_IMPORTED_MODULE_0__components_form_item__["a" /* _FormItem */].isSet()) {
200
- __WEBPACK_IMPORTED_MODULE_0__components_form_item__["a" /* _FormItem */].setEvents();
201
- }
202
- if (__WEBPACK_IMPORTED_MODULE_1__components_form_item_repeater__["a" /* _FormItemRepeater */].isSet()) {
203
- __WEBPACK_IMPORTED_MODULE_1__components_form_item_repeater__["a" /* _FormItemRepeater */].setEvents();
204
- }
205
- if (__WEBPACK_IMPORTED_MODULE_2__components_form_item_image__["a" /* _FormItemImage */].isSet()) {
206
- __WEBPACK_IMPORTED_MODULE_2__components_form_item_image__["a" /* _FormItemImage */].setEvents();
387
+ if (__WEBPACK_IMPORTED_MODULE_0__components_form_item_collapsable__["a" /* _FormItemCollapsable */].isPresent()) {
388
+ __WEBPACK_IMPORTED_MODULE_0__components_form_item_collapsable__["a" /* _FormItemCollapsable */].setEvents();
207
389
  }
208
- if (__WEBPACK_IMPORTED_MODULE_3__components_field_setting_choices__["a" /* _FieldSettingChoices */].isSet()) {
209
- __WEBPACK_IMPORTED_MODULE_3__components_field_setting_choices__["a" /* _FieldSettingChoices */].setEvents();
390
+ if (__WEBPACK_IMPORTED_MODULE_1__components_form_item_image__["a" /* _FormItemImage */].isPresent()) {
391
+ __WEBPACK_IMPORTED_MODULE_1__components_form_item_image__["a" /* _FormItemImage */].setEvents();
210
392
  }
211
- if (__WEBPACK_IMPORTED_MODULE_4__components_form_item_editor__["a" /* _FormItemEditor */].isSet()) {
212
- __WEBPACK_IMPORTED_MODULE_4__components_form_item_editor__["a" /* _FormItemEditor */].setEvents();
393
+ if (__WEBPACK_IMPORTED_MODULE_2__components_field_setting_choices__["a" /* _FieldSettingChoices */].isPresent()) {
394
+ __WEBPACK_IMPORTED_MODULE_2__components_field_setting_choices__["a" /* _FieldSettingChoices */].setEvents();
213
395
  }
214
- if (__WEBPACK_IMPORTED_MODULE_5__components_fileupload__["a" /* _FileUpload */].isSet()) {
215
- __WEBPACK_IMPORTED_MODULE_5__components_fileupload__["a" /* _FileUpload */].setEvents();
396
+ if (__WEBPACK_IMPORTED_MODULE_3__components_fileupload__["a" /* _FileUpload */].isPresent()) {
397
+ __WEBPACK_IMPORTED_MODULE_3__components_fileupload__["a" /* _FileUpload */].setEvents();
216
398
  }
217
- if (__WEBPACK_IMPORTED_MODULE_7__components_login_form__["a" /* _LoginForm */].isSet()) {
218
- __WEBPACK_IMPORTED_MODULE_7__components_login_form__["a" /* _LoginForm */].init();
399
+ if (__WEBPACK_IMPORTED_MODULE_5__components_login_form__["a" /* _LoginForm */].isPresent()) {
400
+ __WEBPACK_IMPORTED_MODULE_5__components_login_form__["a" /* _LoginForm */].init();
219
401
  }
220
- if (__WEBPACK_IMPORTED_MODULE_6__components_login_shader__["a" /* _Shader */].isSet()) {
221
- __WEBPACK_IMPORTED_MODULE_6__components_login_shader__["a" /* _Shader */].setup();
222
- __WEBPACK_IMPORTED_MODULE_6__components_login_shader__["a" /* _Shader */].start();
402
+ if (__WEBPACK_IMPORTED_MODULE_4__components_login_shader__["a" /* _Shader */].isPresent()) {
403
+ __WEBPACK_IMPORTED_MODULE_4__components_login_shader__["a" /* _Shader */].setup();
404
+ __WEBPACK_IMPORTED_MODULE_4__components_login_shader__["a" /* _Shader */].start();
223
405
  }
224
- Object(__WEBPACK_IMPORTED_MODULE_12__components_radio_toggle__["a" /* default */])();
225
- Object(__WEBPACK_IMPORTED_MODULE_8__components_sortable__["a" /* default */])();
226
- Object(__WEBPACK_IMPORTED_MODULE_9__components_field_group_editor__["a" /* default */])();
227
- Object(__WEBPACK_IMPORTED_MODULE_10__components_bootstrap__["a" /* default */])();
228
- Object(__WEBPACK_IMPORTED_MODULE_11__components_select2__["a" /* default */])();
406
+ Object(__WEBPACK_IMPORTED_MODULE_10__components_radio_toggle__["a" /* default */])();
407
+ Object(__WEBPACK_IMPORTED_MODULE_6__components_sortable__["a" /* default */])();
408
+ Object(__WEBPACK_IMPORTED_MODULE_7__components_field_group_editor__["a" /* default */])();
409
+ Object(__WEBPACK_IMPORTED_MODULE_8__components_bootstrap__["a" /* default */])();
410
+ Object(__WEBPACK_IMPORTED_MODULE_9__components_select2__["a" /* default */])();
229
411
  });
230
412
 
231
413
  // handle event
232
414
  window.addEventListener("optimizedResize", function () {
233
- if (__WEBPACK_IMPORTED_MODULE_6__components_login_shader__["a" /* _Shader */].isSet()) {
234
- __WEBPACK_IMPORTED_MODULE_6__components_login_shader__["a" /* _Shader */].resize();
415
+ if (__WEBPACK_IMPORTED_MODULE_4__components_login_shader__["a" /* _Shader */].isPresent()) {
416
+ __WEBPACK_IMPORTED_MODULE_4__components_login_shader__["a" /* _Shader */].resize();
235
417
  }
236
418
  });
237
419
 
@@ -239,270 +421,6 @@ window.addEventListener("optimizedResize", function () {
239
421
  /* 3 */
240
422
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
241
423
 
242
- "use strict";
243
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItem; });
244
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
245
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__select2__ = __webpack_require__(1);
246
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
247
-
248
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
249
-
250
- /**
251
- * FORM ITEM
252
- */
253
-
254
-
255
-
256
-
257
- // Component Global Variables
258
- var newFormItemId = 1;
259
-
260
- var FormItem = function () {
261
- function FormItem() {
262
- _classCallCheck(this, FormItem);
263
- }
264
-
265
- _createClass(FormItem, [{
266
- key: "isSet",
267
- value: function isSet() {
268
- if ($(".form-item").length > 0) {
269
- return true;
270
- } else {
271
- return false;
272
- }
273
- }
274
- }, {
275
- key: "setEvents",
276
- value: function setEvents() {
277
- $(document).on("click", ".form-item--add-new", addNewItem);
278
-
279
- $(document).on("click", ".form-item--remove-item-with-js", function (event) {
280
- // Stop default behaviour
281
- event.preventDefault();
282
- $(this).closest(".form-item").remove();
283
- });
284
-
285
- $(document).on("click", ".form-item--collapse-btn", collapseToggle);
286
- }
287
- }]);
288
-
289
- return FormItem;
290
- }();
291
-
292
- var _FormItem = new FormItem();
293
-
294
- ///- - - - - - - - - - - - - - - - - - - -
295
- /// COMPONENT HELPER FUNCTIONS
296
- ///- - - - - - - - - - - - - - - - - - - -
297
-
298
- // This function could be improved as it generates an issue with
299
- // input ids which are duplicated after the entire target has been cloned
300
- function addNewItem(event) {
301
- // Stop default behaviour
302
- event.preventDefault();
303
- // Get the child to clone
304
- // (`this` always refers to the second argument of the $(document).on() method, in this case '.form-item--add-new')
305
- var id = $(this).data("new-form-item-id");
306
- var $newChild = $("#" + id);
307
- // Clone child and remove id and styles from cloned child
308
- $newChild.clone().insertAfter($newChild);
309
- // Remove class in order to remove styles, and change id so it's reachable when testing
310
- $newChild.removeClass("form-item--new").attr("id", "new-form-item-" + newFormItemId);
311
-
312
- // // Update all ids to avoid duplication
313
- $newChild.find("[id]").each(function () {
314
- var oldId = $(this).attr("id");
315
- var newId = oldId + "-" + newFormItemId;
316
- $(this).attr("id", newId);
317
- var $forId = $newChild.find("[for=" + oldId + "]");
318
- if ($forId.length > 0) {
319
- $forId.attr("for", newId);
320
- }
321
- });
322
-
323
- // Update height (max-height) of the new element
324
- var $formItemEditor = $("#new-form-item-" + newFormItemId).find(".form-item--editor");
325
-
326
- // override current max-height which is set to 0
327
- $formItemEditor.get(0).style.maxHeight = $formItemEditor.get(0).scrollHeight + "px";
328
-
329
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
330
-
331
- // Increment global id variable `newFormItemId` in case needs to be used again
332
- newFormItemId++;
333
-
334
- Object(__WEBPACK_IMPORTED_MODULE_1__select2__["b" /* setupSelect2 */])($formItemEditor.find("select"));
335
- }
336
-
337
- function close() {
338
- this.style.maxHeight = "0px";
339
- }
340
-
341
- function open() {
342
- this.style.maxHeight = this.scrollHeight + "px";
343
- }
344
-
345
- function collapseToggle(event) {
346
- // This function is temporarely just set for repeaters.
347
- // TODO: Need refactoring in order to be available also for generic form items
348
-
349
- // Stop default behaviour
350
- event.preventDefault();
351
-
352
- var $collapsable = $(this).closest(".form-item--collapsable");
353
-
354
- if ($collapsable.hasClass("form-item--collapsed")) {
355
- $collapsable.find(".form-item--repeater-fields").each(open);
356
- $collapsable.find(".form-item--editor").each(open);
357
- $collapsable.removeClass("form-item--collapsed");
358
- } else {
359
- $collapsable.find(".form-item--repeater-fields").each(close);
360
- $collapsable.find(".form-item--editor").each(close);
361
- $collapsable.addClass("form-item--collapsed");
362
- }
363
- }
364
-
365
- /***/ }),
366
- /* 4 */
367
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
368
-
369
- "use strict";
370
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemRepeater; });
371
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
372
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1__select2__ = __webpack_require__(1);
373
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
374
-
375
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
376
-
377
- /**
378
- * FORM ITEM REPEATER
379
- */
380
-
381
-
382
-
383
-
384
- var FormItemRepeater = function () {
385
- function FormItemRepeater() {
386
- _classCallCheck(this, FormItemRepeater);
387
- }
388
-
389
- _createClass(FormItemRepeater, [{
390
- key: "isSet",
391
- value: function isSet() {
392
- if ($(".form-item--repeater-section").length > 0) {
393
- return true;
394
- } else {
395
- return false;
396
- }
397
- }
398
- }, {
399
- key: "setEvents",
400
- value: function setEvents() {
401
- $(document).on("click", ".form-item--repeater-section--add-new", addNewItem);
402
-
403
- $(document).on("click", ".form-item--remove-item-with-js", function (event) {
404
- // Stop default behaviour
405
- event.preventDefault();
406
- $(this).parent(".form-item--repeater-section").remove();
407
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
408
- });
409
-
410
- $(document).on("click", ".form-item--delete-repeater-item", deleteRepeter);
411
- }
412
- }]);
413
-
414
- return FormItemRepeater;
415
- }();
416
-
417
- var _FormItemRepeater = new FormItemRepeater();
418
-
419
- /**
420
- * COMPONENT HELPER FUNCTIONS
421
- */
422
-
423
- function addNewItem(event) {
424
- // Stop default behaviour
425
- event.preventDefault();
426
- // Get the child to clone
427
- var id = $(this).data("id");
428
- var $list = $("#form-item--repeater-setting-" + id);
429
- var url = $(this).data("url");
430
- $.post(url, { repeater_setting_id: id }, function (data) {
431
- // Get repaeter code from Rails
432
- // Due to the Rails way of creating nested forms it's necessary to
433
- // create the nested item inside a different new form, then get just
434
- // the code contained between the two SPLIT comments
435
- var parts = data.split("<!-- SPLIT -->");
436
- var newRepeater = parts[1];
437
- setupAndAppend(newRepeater, $list);
438
- });
439
- }
440
-
441
- function setupAndAppend(newRepeater, $list) {
442
- // Append the item
443
- $list.prepend(newRepeater);
444
- var new_repeater_item = $list.find(".form-item--repeater").get(0);
445
-
446
- // Prepare animation
447
- new_repeater_item.style.maxHeight = 0;
448
-
449
- // Group fields if sotrable is enabled
450
- if ($list.hasClass("sortable--enabled")) {
451
- $(new_repeater_item).find(".form-item--repeater-fields").each(function () {
452
- this.style.maxHeight = 0 + "px";
453
- });
454
- }
455
-
456
- // Setup TinyMCE for the newly created item
457
- var textarea_editor_id = $list.find("textarea").last("textarea").attr("id");
458
- tinyMCE.EditorManager.execCommand("mceAddEditor", true, textarea_editor_id);
459
-
460
- // Resize the editor (is it needed with the new configuration?)
461
- // _FormItemEditor.resize()
462
-
463
- // Update select input for Select2 plugin
464
- Object(__WEBPACK_IMPORTED_MODULE_1__select2__["b" /* setupSelect2 */])($list.find("select"));
465
-
466
- // Refresh Sortable to update the added item with Sortable features
467
- $list.sortable("refresh");
468
-
469
- // Run animation 50ms after previous style declaration (see above) otherwise animation doesn't get triggered
470
- setTimeout(function () {
471
- new_repeater_item.style.maxHeight = new_repeater_item.scrollHeight + "px";
472
- }, 50);
473
- }
474
-
475
- function deleteRepeter(event) {
476
- // Stop default behaviour
477
- event.preventDefault();
478
-
479
- var record_id = $(this).data("id");
480
- var target = $("#repeater_" + record_id).get(0);
481
- // As max-height isn't set you need to set it manually before changing it,
482
- // otherwise the animation doesn't get triggered
483
- target.style.maxHeight = target.scrollHeight + "px";
484
- // Change max-height after 50ms to trigger css animation
485
- setTimeout(function () {
486
- target.style.maxHeight = 0 + "px";
487
- }, 50);
488
-
489
- $.ajax({
490
- url: $(this).attr("href"),
491
- data: { id: record_id, isAjax: true },
492
- method: "DELETE"
493
- }).done(function () {
494
- // Make sure the animation completes before removing the item (it should last 600ms + 50ms)
495
- setTimeout(function () {
496
- $(target).remove();
497
- }, 700);
498
- // _FormItemEditor.resize()
499
- });
500
- }
501
-
502
- /***/ }),
503
- /* 5 */
504
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
505
-
506
424
  "use strict";
507
425
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FormItemImage; });
508
426
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
@@ -521,8 +439,8 @@ var FormItemImage = function () {
521
439
  }
522
440
 
523
441
  _createClass(FormItemImage, [{
524
- key: "isSet",
525
- value: function isSet() {
442
+ key: "isPresent",
443
+ value: function isPresent() {
526
444
  if ($(this.target).length > 0) {
527
445
  return true;
528
446
  } else {
@@ -540,12 +458,12 @@ var FormItemImage = function () {
540
458
  var _FormItemImage = new FormItemImage();
541
459
 
542
460
  /***/ }),
543
- /* 6 */
461
+ /* 4 */
544
462
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
545
463
 
546
464
  "use strict";
547
465
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return _FieldSettingChoices; });
548
- /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_editor__ = __webpack_require__(0);
466
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__ = __webpack_require__(0);
549
467
  var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
550
468
 
551
469
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
@@ -564,8 +482,8 @@ var FieldSettingChoices = function () {
564
482
  }
565
483
 
566
484
  _createClass(FieldSettingChoices, [{
567
- key: "isSet",
568
- value: function isSet() {
485
+ key: "isPresent",
486
+ value: function isPresent() {
569
487
  if ($(this.target).length > 0) {
570
488
  return true;
571
489
  } else {
@@ -583,7 +501,7 @@ var FieldSettingChoices = function () {
583
501
  event.preventDefault();
584
502
  $(this).closest(".field-setting-choices--choice").remove();
585
503
  // Update form item editor size
586
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
504
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["d" /* resizeCollapsableStacks */])();
587
505
  });
588
506
  }
589
507
  }]);
@@ -608,7 +526,7 @@ function addChoice(event) {
608
526
  // Append the clone right after
609
527
  choices.prepend(clone);
610
528
  // Update form item editor size
611
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
529
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["d" /* resizeCollapsableStacks */])();
612
530
  }
613
531
 
614
532
  function deleteChoice(event) {
@@ -624,14 +542,14 @@ function deleteChoice(event) {
624
542
  }).done(function () {
625
543
  choice.remove();
626
544
  // Update form item editor size
627
- __WEBPACK_IMPORTED_MODULE_0__form_item_editor__["a" /* _FormItemEditor */].resize();
545
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["d" /* resizeCollapsableStacks */])();
628
546
  }).fail(function (data) {
629
547
  alert(data.responseJSON.errors);
630
548
  });
631
549
  }
632
550
 
633
551
  /***/ }),
634
- /* 7 */
552
+ /* 5 */
635
553
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
636
554
 
637
555
  "use strict";
@@ -657,8 +575,8 @@ var FileUpload = function () {
657
575
  }
658
576
 
659
577
  _createClass(FileUpload, [{
660
- key: "isSet",
661
- value: function isSet() {
578
+ key: "isPresent",
579
+ value: function isPresent() {
662
580
  if ($(this.target).length > 0) {
663
581
  return true;
664
582
  } else {
@@ -840,7 +758,7 @@ function setup_video_preview(data, id) {
840
758
  }
841
759
 
842
760
  /***/ }),
843
- /* 8 */
761
+ /* 6 */
844
762
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
845
763
 
846
764
  "use strict";
@@ -868,8 +786,8 @@ var Shader = function () {
868
786
  }
869
787
 
870
788
  _createClass(Shader, [{
871
- key: "isSet",
872
- value: function isSet() {
789
+ key: "isPresent",
790
+ value: function isPresent() {
873
791
  if ($("#background-shader").length > 0) {
874
792
  return true;
875
793
  } else {
@@ -1057,7 +975,7 @@ function hexToShaderRgb(hex) {
1057
975
  })();
1058
976
 
1059
977
  /***/ }),
1060
- /* 9 */
978
+ /* 7 */
1061
979
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1062
980
 
1063
981
  "use strict";
@@ -1082,8 +1000,8 @@ var LoginForm = function () {
1082
1000
  }
1083
1001
 
1084
1002
  _createClass(LoginForm, [{
1085
- key: "isSet",
1086
- value: function isSet() {
1003
+ key: "isPresent",
1004
+ value: function isPresent() {
1087
1005
  if ($(".login--form").length > 0) {
1088
1006
  return true;
1089
1007
  } else {
@@ -1186,14 +1104,17 @@ var LoginForm = function () {
1186
1104
  var _LoginForm = new LoginForm();
1187
1105
 
1188
1106
  /***/ }),
1189
- /* 10 */
1107
+ /* 8 */
1190
1108
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1191
1109
 
1192
1110
  "use strict";
1111
+ /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__ = __webpack_require__(0);
1193
1112
  /**
1194
1113
  * SORTABLE
1195
1114
  */
1196
1115
 
1116
+
1117
+
1197
1118
  var sortableOptions = {
1198
1119
  stop: function stop(event, ui) {
1199
1120
  ui.item.css("z-index", 0);
@@ -1202,6 +1123,14 @@ var sortableOptions = {
1202
1123
  update: updateSortable
1203
1124
  };
1204
1125
 
1126
+ /* Initialize jQuery Sortable
1127
+ *
1128
+ * This function handles several things:
1129
+ * - it sets Sortable for each ".sortable" element
1130
+ * - it adds handles only if required
1131
+ * - it disable itself if it finds ".sortable--disabled" class
1132
+ * - it sets up a toggle button and behaviour if required
1133
+ */
1205
1134
  /* harmony default export */ __webpack_exports__["a"] = (function () {
1206
1135
  if ($(".sortable").length > 0) {
1207
1136
  // Initialize sortable item
@@ -1223,38 +1152,31 @@ var sortableOptions = {
1223
1152
  if ($(".sortable--toggle").length > 0) {
1224
1153
  setupSortableToggle();
1225
1154
  }
1226
-
1227
- // Add event to any sortable toggle button
1228
- // TODO: make this event available to element which aren't standard form repeaters
1229
- $(document).on("click", ".standard-form--repeater .sortable--toggle", toggleSortable);
1230
1155
  });
1231
1156
 
1157
+ /* Setup Sortable Toggle
1158
+ *
1159
+ * It sets up each toggle button and add the events needed to enable or disable Sortable.
1160
+ */
1232
1161
  function setupSortableToggle() {
1233
1162
  $(".sortable--toggle").each(function () {
1234
- var id = "#" + $(this).data("repeater-id");
1235
- $(id).find(".form-item--collapsable").addClass("form-item--collapsed");
1236
- $(id).find(".form-item--repeater-fields").each(close);
1163
+ var id = "#" + $(this).data("sortable-target-id");
1164
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["b" /* closeCollapsableStacks */])(id);
1237
1165
  });
1238
- }
1239
-
1240
- function close() {
1241
- this.style.maxHeight = "0px";
1242
- }
1243
-
1244
- function open() {
1245
- this.style.maxHeight = this.scrollHeight + "px";
1166
+ // Add event to any sortable toggle button
1167
+ $(document).on("click", ".sortable--toggle", toggleSortable);
1246
1168
  }
1247
1169
 
1248
1170
  function toggleSortable(event) {
1249
1171
  event.preventDefault();
1250
- var id = "#" + $(this).data("repeater-id");
1172
+ var id = "#" + $(this).data("sortable-target-id");
1251
1173
 
1252
1174
  if ($(id).hasClass("sortable--disabled")) {
1253
1175
  $(id).sortable("enable");
1254
- $(id).find(".form-item--repeater-fields").each(close);
1255
- $(id).find(".form-item--collapsable").addClass("form-item--collapsed");
1176
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["b" /* closeCollapsableStacks */])(id);
1256
1177
  } else {
1257
1178
  $(id).sortable("disable");
1179
+ Object(__WEBPACK_IMPORTED_MODULE_0__form_item_collapsable__["c" /* openCollapsableStacks */])(id);
1258
1180
  }
1259
1181
 
1260
1182
  $(id).toggleClass("sortable--disabled");
@@ -1284,7 +1206,7 @@ function updateSortable() {
1284
1206
  }
1285
1207
 
1286
1208
  /***/ }),
1287
- /* 11 */
1209
+ /* 9 */
1288
1210
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1289
1211
 
1290
1212
  "use strict";
@@ -1306,7 +1228,7 @@ function updateSortable() {
1306
1228
  });
1307
1229
 
1308
1230
  /***/ }),
1309
- /* 12 */
1231
+ /* 10 */
1310
1232
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1311
1233
 
1312
1234
  "use strict";
@@ -1320,7 +1242,7 @@ function updateSortable() {
1320
1242
  });
1321
1243
 
1322
1244
  /***/ }),
1323
- /* 13 */
1245
+ /* 11 */
1324
1246
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
1325
1247
 
1326
1248
  "use strict";