spotlight-frontend 3.5.0-beta.1

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 (153) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +114 -0
  3. package/app/assets/images/blacklight/arrow-alt-circle-left.svg +1 -0
  4. package/app/assets/images/blacklight/arrow-alt-circle-right.svg +1 -0
  5. package/app/assets/images/blacklight/arrow_back_ios.svg +1 -0
  6. package/app/assets/images/blacklight/arrow_forward_ios.svg +1 -0
  7. package/app/assets/images/blacklight/check.svg +1 -0
  8. package/app/assets/images/blacklight/check_circle.svg +1 -0
  9. package/app/assets/images/blacklight/chevron_right.svg +1 -0
  10. package/app/assets/images/blacklight/close.svg +1 -0
  11. package/app/assets/images/blacklight/edit.svg +1 -0
  12. package/app/assets/images/blacklight/error.svg +1 -0
  13. package/app/assets/images/blacklight/highlight_off.svg +1 -0
  14. package/app/assets/images/blacklight/info.svg +1 -0
  15. package/app/assets/images/blacklight/warning.svg +1 -0
  16. package/app/assets/images/blacklight/zoom_in.svg +1 -0
  17. package/app/assets/images/blacklight/zoom_out.svg +1 -0
  18. package/app/assets/images/spotlight/.keep +0 -0
  19. package/app/assets/images/spotlight/blocks/sir-trevor-icons.svg +320 -0
  20. package/app/assets/images/spotlight/default_browse_thumbnail.jpg +0 -0
  21. package/app/assets/images/spotlight/default_thumbnail.jpg +0 -0
  22. package/app/assets/images/spotlight/fallback/default.png +0 -0
  23. package/app/assets/javascripts/spotlight/admin/add_another.js +22 -0
  24. package/app/assets/javascripts/spotlight/admin/add_new_button.js +81 -0
  25. package/app/assets/javascripts/spotlight/admin/appearance.js +24 -0
  26. package/app/assets/javascripts/spotlight/admin/attachments.js +2 -0
  27. package/app/assets/javascripts/spotlight/admin/blacklight_configuration.js +63 -0
  28. package/app/assets/javascripts/spotlight/admin/block_mixins/autocompleteable.js +72 -0
  29. package/app/assets/javascripts/spotlight/admin/block_mixins/formable.js +78 -0
  30. package/app/assets/javascripts/spotlight/admin/block_mixins/plustextable.js +57 -0
  31. package/app/assets/javascripts/spotlight/admin/blocks/block.js +23 -0
  32. package/app/assets/javascripts/spotlight/admin/blocks/browse_block.js +87 -0
  33. package/app/assets/javascripts/spotlight/admin/blocks/browse_group_categories_block.js +88 -0
  34. package/app/assets/javascripts/spotlight/admin/blocks/iframe_block.js +34 -0
  35. package/app/assets/javascripts/spotlight/admin/blocks/link_to_search_block.js +16 -0
  36. package/app/assets/javascripts/spotlight/admin/blocks/oembed_block.js +40 -0
  37. package/app/assets/javascripts/spotlight/admin/blocks/pages_block.js +22 -0
  38. package/app/assets/javascripts/spotlight/admin/blocks/resources_block.js +145 -0
  39. package/app/assets/javascripts/spotlight/admin/blocks/rule_block.js +25 -0
  40. package/app/assets/javascripts/spotlight/admin/blocks/search_result_block.js +44 -0
  41. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_base_block.js +108 -0
  42. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_block.js +25 -0
  43. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_carousel_block.js +103 -0
  44. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_embed_block.js +17 -0
  45. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_features_block.js +41 -0
  46. package/app/assets/javascripts/spotlight/admin/blocks/solr_documents_grid_block.js +14 -0
  47. package/app/assets/javascripts/spotlight/admin/blocks/uploaded_items_block.js +145 -0
  48. package/app/assets/javascripts/spotlight/admin/catalog_edit.js +16 -0
  49. package/app/assets/javascripts/spotlight/admin/copy_email_addresses.js +9 -0
  50. package/app/assets/javascripts/spotlight/admin/crop.es6 +310 -0
  51. package/app/assets/javascripts/spotlight/admin/croppable.js +25 -0
  52. package/app/assets/javascripts/spotlight/admin/edit_in_place.js +54 -0
  53. package/app/assets/javascripts/spotlight/admin/exhibit_tag_autocomplete.js +37 -0
  54. package/app/assets/javascripts/spotlight/admin/exhibits.js +58 -0
  55. package/app/assets/javascripts/spotlight/admin/form_observer.js +86 -0
  56. package/app/assets/javascripts/spotlight/admin/iiif.es6 +54 -0
  57. package/app/assets/javascripts/spotlight/admin/index.js +16 -0
  58. package/app/assets/javascripts/spotlight/admin/locks.js +12 -0
  59. package/app/assets/javascripts/spotlight/admin/multi_image_selector.js +158 -0
  60. package/app/assets/javascripts/spotlight/admin/pages.js.erb +40 -0
  61. package/app/assets/javascripts/spotlight/admin/progress_monitor.js +148 -0
  62. package/app/assets/javascripts/spotlight/admin/readonly_checkbox.js +6 -0
  63. package/app/assets/javascripts/spotlight/admin/search_typeahead.js +108 -0
  64. package/app/assets/javascripts/spotlight/admin/select_related_input.js +34 -0
  65. package/app/assets/javascripts/spotlight/admin/sir-trevor/block_controls.js +120 -0
  66. package/app/assets/javascripts/spotlight/admin/sir-trevor/block_limits.js +37 -0
  67. package/app/assets/javascripts/spotlight/admin/sir-trevor/locales.js +120 -0
  68. package/app/assets/javascripts/spotlight/admin/spotlight_nestable.js +72 -0
  69. package/app/assets/javascripts/spotlight/admin/tabs.js +6 -0
  70. package/app/assets/javascripts/spotlight/admin/translation_progress.js +23 -0
  71. package/app/assets/javascripts/spotlight/admin/users.js +79 -0
  72. package/app/assets/javascripts/spotlight/application.js +14 -0
  73. package/app/assets/javascripts/spotlight/spotlight.js +23 -0
  74. package/app/assets/javascripts/spotlight/user/analytics.js +9 -0
  75. package/app/assets/javascripts/spotlight/user/browse_group_categories.js +59 -0
  76. package/app/assets/javascripts/spotlight/user/carousel.js +3 -0
  77. package/app/assets/javascripts/spotlight/user/clear_form_button.js +27 -0
  78. package/app/assets/javascripts/spotlight/user/index.js +8 -0
  79. package/app/assets/javascripts/spotlight/user/report_a_problem.js +39 -0
  80. package/app/assets/javascripts/spotlight/user/zpr_links.js.erb +45 -0
  81. package/app/assets/stylesheets/spotlight/_accessibility.scss +8 -0
  82. package/app/assets/stylesheets/spotlight/_attachments.css +4 -0
  83. package/app/assets/stylesheets/spotlight/_blacklight_configuration.scss +82 -0
  84. package/app/assets/stylesheets/spotlight/_blacklight_overrides.scss +21 -0
  85. package/app/assets/stylesheets/spotlight/_bootstrap_overrides.scss +105 -0
  86. package/app/assets/stylesheets/spotlight/_breadcrumbs.scss +6 -0
  87. package/app/assets/stylesheets/spotlight/_browse.scss +158 -0
  88. package/app/assets/stylesheets/spotlight/_catalog.scss +161 -0
  89. package/app/assets/stylesheets/spotlight/_collapse_toggle.scss +14 -0
  90. package/app/assets/stylesheets/spotlight/_croppable.scss +4 -0
  91. package/app/assets/stylesheets/spotlight/_curation.scss +224 -0
  92. package/app/assets/stylesheets/spotlight/_edit_in_place.scss +9 -0
  93. package/app/assets/stylesheets/spotlight/_exhibit_admin.scss +81 -0
  94. package/app/assets/stylesheets/spotlight/_exhibit_navbar.scss +10 -0
  95. package/app/assets/stylesheets/spotlight/_exhibits_index.scss +147 -0
  96. package/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +269 -0
  97. package/app/assets/stylesheets/spotlight/_footer.scss +12 -0
  98. package/app/assets/stylesheets/spotlight/_header.scss +155 -0
  99. package/app/assets/stylesheets/spotlight/_item_text_block.scss +50 -0
  100. package/app/assets/stylesheets/spotlight/_mixins.scss +17 -0
  101. package/app/assets/stylesheets/spotlight/_modals.scss +3 -0
  102. package/app/assets/stylesheets/spotlight/_multi_image_selector.scss +22 -0
  103. package/app/assets/stylesheets/spotlight/_multi_up_item_grid.scss +63 -0
  104. package/app/assets/stylesheets/spotlight/_nestable.scss +124 -0
  105. package/app/assets/stylesheets/spotlight/_pages.scss +282 -0
  106. package/app/assets/stylesheets/spotlight/_report_a_problem.scss +14 -0
  107. package/app/assets/stylesheets/spotlight/_sir-trevor_overrides.scss +87 -0
  108. package/app/assets/stylesheets/spotlight/_slideshow_block.scss +87 -0
  109. package/app/assets/stylesheets/spotlight/_spotlight.scss +49 -0
  110. package/app/assets/stylesheets/spotlight/_translations.scss +86 -0
  111. package/app/assets/stylesheets/spotlight/_upload.scss +0 -0
  112. package/app/assets/stylesheets/spotlight/_uploaded_items_block.scss +7 -0
  113. package/app/assets/stylesheets/spotlight/_utilities.scss +7 -0
  114. package/app/assets/stylesheets/spotlight/_variables.scss +42 -0
  115. package/app/assets/stylesheets/spotlight/_variables_bootstrap.scss +7 -0
  116. package/app/assets/stylesheets/spotlight/_view_larger.scss +22 -0
  117. package/app/assets/stylesheets/spotlight/browse_group_categories_block.scss +92 -0
  118. package/app/assets/stylesheets/spotlight/typeahead.css +77 -0
  119. package/package.json +29 -0
  120. package/vendor/assets/images/sir-trevor-icons.svg +263 -0
  121. package/vendor/assets/javascripts/Leaflet.Editable.js +1917 -0
  122. package/vendor/assets/javascripts/MutationObserver.js +625 -0
  123. package/vendor/assets/javascripts/Path.Drag.js +137 -0
  124. package/vendor/assets/javascripts/bootstrap-tagsinput.js +530 -0
  125. package/vendor/assets/javascripts/eventable.js +205 -0
  126. package/vendor/assets/javascripts/jquery.serializejson.js +234 -0
  127. package/vendor/assets/javascripts/jquery.waitforimages.min.js +2 -0
  128. package/vendor/assets/javascripts/leaflet-iiif.js +323 -0
  129. package/vendor/assets/javascripts/nestable.js +645 -0
  130. package/vendor/assets/javascripts/parameterize.js +137 -0
  131. package/vendor/assets/javascripts/polyfill.min.js +4 -0
  132. package/vendor/assets/javascripts/sir-trevor.js +21639 -0
  133. package/vendor/assets/javascripts/tiny-slider.js +3218 -0
  134. package/vendor/assets/javascripts/typeahead.bundle.min.js +7 -0
  135. package/vendor/assets/stylesheets/bootstrap-tagsinput.css +46 -0
  136. package/vendor/assets/stylesheets/leaflet-areaselect.css +15 -0
  137. package/vendor/assets/stylesheets/sir-trevor/_icons.scss +6 -0
  138. package/vendor/assets/stylesheets/sir-trevor/_variables.scss +22 -0
  139. package/vendor/assets/stylesheets/sir-trevor/base.scss +17 -0
  140. package/vendor/assets/stylesheets/sir-trevor/block-addition-top.scss +95 -0
  141. package/vendor/assets/stylesheets/sir-trevor/block-addition.scss +72 -0
  142. package/vendor/assets/stylesheets/sir-trevor/block-controls.scss +34 -0
  143. package/vendor/assets/stylesheets/sir-trevor/block-positioner.scss +34 -0
  144. package/vendor/assets/stylesheets/sir-trevor/block-replacer.scss +43 -0
  145. package/vendor/assets/stylesheets/sir-trevor/block-ui.scss +120 -0
  146. package/vendor/assets/stylesheets/sir-trevor/block.scss +300 -0
  147. package/vendor/assets/stylesheets/sir-trevor/errors.scss +21 -0
  148. package/vendor/assets/stylesheets/sir-trevor/format-bar.scss +65 -0
  149. package/vendor/assets/stylesheets/sir-trevor/inputs.scss +45 -0
  150. package/vendor/assets/stylesheets/sir-trevor/main.scss +24 -0
  151. package/vendor/assets/stylesheets/sir-trevor/patterns/ui-popup.scss +38 -0
  152. package/vendor/assets/stylesheets/sir-trevor/utils.scss +10 -0
  153. package/vendor/assets/stylesheets/tiny-slider.css +1 -0
@@ -0,0 +1,645 @@
1
+ /*!
2
+ * Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
3
+ * Dual-licensed under the BSD or MIT licenses
4
+ */
5
+ ;(function($, window, document, undefined)
6
+ {
7
+ var hasTouch = 'ontouchstart' in window;
8
+ var nestableCopy;
9
+
10
+ /**
11
+ * Detect CSS pointer-events property
12
+ * events are normally disabled on the dragging element to avoid conflicts
13
+ * https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
14
+ */
15
+ var hasPointerEvents = (function()
16
+ {
17
+ var el = document.createElement('div'),
18
+ docEl = document.documentElement;
19
+ if (!('pointerEvents' in el.style)) {
20
+ return false;
21
+ }
22
+ el.style.pointerEvents = 'auto';
23
+ el.style.pointerEvents = 'x';
24
+ docEl.appendChild(el);
25
+ var supports = window.getComputedStyle && window.getComputedStyle(el, '').pointerEvents === 'auto';
26
+ docEl.removeChild(el);
27
+ return !!supports;
28
+ })();
29
+
30
+ var eStart = hasTouch ? 'touchstart' : 'mousedown',
31
+ eMove = hasTouch ? 'touchmove' : 'mousemove',
32
+ eEnd = hasTouch ? 'touchend' : 'mouseup',
33
+ eCancel = hasTouch ? 'touchcancel' : 'mouseup';
34
+
35
+ var defaults = {
36
+ listNodeName : 'ol',
37
+ itemNodeName : 'li',
38
+ rootClass : 'dd',
39
+ listClass : 'dd-list',
40
+ itemClass : 'dd-item',
41
+ dragClass : 'dd-dragel',
42
+ handleClass : 'dd-handle',
43
+ collapsedClass : 'dd-collapsed',
44
+ placeClass : 'dd-placeholder',
45
+ noDragClass : 'dd-nodrag',
46
+ noChildrenClass : 'dd-nochildren',
47
+ emptyClass : 'dd-empty',
48
+ expandBtnHTML : '<button data-action="expand" type="button">Expand</button>',
49
+ collapseBtnHTML : '<button data-action="collapse" type="button">Collapse</button>',
50
+ group : 0,
51
+ maxDepth : 5,
52
+ threshold : 20,
53
+ reject : [],
54
+ //method for call when an item has been successfully dropped
55
+ //method has 1 argument in which sends an object containing all
56
+ //necessary details
57
+ dropCallback : null,
58
+ // When a node is dragged it is moved to its new location.
59
+ // You can set the next option to true to create a copy of the node that is dragged.
60
+ cloneNodeOnDrag : false,
61
+ // When the node is dragged and released outside its list delete it.
62
+ dragOutsideToDelete : false
63
+ };
64
+
65
+ function Plugin(element, options)
66
+ {
67
+ this.w = $(document);
68
+ this.el = $(element);
69
+ this.options = $.extend({}, defaults, options);
70
+ this.init();
71
+ }
72
+
73
+ Plugin.prototype = {
74
+
75
+ init: function()
76
+ {
77
+ var list = this;
78
+
79
+ list.reset();
80
+
81
+ list.el.data('nestable-group', this.options.group);
82
+
83
+ list.placeEl = $('<div class="' + list.options.placeClass + '"/>');
84
+
85
+ $.each(this.el.find(list.options.itemNodeName), function(k, el) {
86
+ list.setParent($(el));
87
+ });
88
+
89
+ list.el.on('click', 'button', function(e)
90
+ {
91
+ if (list.dragEl || (!hasTouch && e.button !== 0)) {
92
+ return;
93
+ }
94
+ var target = $(e.currentTarget),
95
+ action = target.data('action'),
96
+ item = target.parent(list.options.itemNodeName);
97
+ if (action === 'collapse') {
98
+ list.collapseItem(item);
99
+ }
100
+ if (action === 'expand') {
101
+ list.expandItem(item);
102
+ }
103
+ });
104
+
105
+ var onStartEvent = function(e)
106
+ {
107
+ var handle = $(e.target);
108
+
109
+ list.nestableCopy = handle.closest('.'+list.options.rootClass).clone(true);
110
+
111
+ if (!handle.hasClass(list.options.handleClass)) {
112
+ if (handle.closest('.' + list.options.noDragClass).length) {
113
+ return;
114
+ }
115
+ handle = handle.closest('.' + list.options.handleClass);
116
+ }
117
+ if (!handle.length || list.dragEl || (!hasTouch && e.which !== 1) || (hasTouch && e.touches.length !== 1)) {
118
+ return;
119
+ }
120
+ e.preventDefault();
121
+ list.dragStart(hasTouch ? e.touches[0] : e);
122
+ };
123
+
124
+ var onMoveEvent = function(e)
125
+ {
126
+ if (list.dragEl) {
127
+ e.preventDefault();
128
+ list.dragMove(hasTouch ? e.touches[0] : e);
129
+ }
130
+ };
131
+
132
+ var onEndEvent = function(e)
133
+ {
134
+ if (list.dragEl) {
135
+ e.preventDefault();
136
+ list.dragStop(hasTouch ? e.touches[0] : e);
137
+ }
138
+ };
139
+
140
+ if (hasTouch) {
141
+ list.el[0].addEventListener(eStart, onStartEvent, false);
142
+ window.addEventListener(eMove, onMoveEvent, false);
143
+ window.addEventListener(eEnd, onEndEvent, false);
144
+ window.addEventListener(eCancel, onEndEvent, false);
145
+ } else {
146
+ list.el.on(eStart, onStartEvent);
147
+ list.w.on(eMove, onMoveEvent);
148
+ list.w.on(eEnd, onEndEvent);
149
+ }
150
+
151
+ var destroyNestable = function()
152
+ {
153
+ if (hasTouch) {
154
+ list.el[0].removeEventListener(eStart, onStartEvent, false);
155
+ window.removeEventListener(eMove, onMoveEvent, false);
156
+ window.removeEventListener(eEnd, onEndEvent, false);
157
+ window.removeEventListener(eCancel, onEndEvent, false);
158
+ } else {
159
+ list.el.off(eStart, onStartEvent);
160
+ list.w.off(eMove, onMoveEvent);
161
+ list.w.off(eEnd, onEndEvent);
162
+ }
163
+
164
+ list.el.off('click');
165
+ list.el.unbind('destroy-nestable');
166
+
167
+ list.el.data("nestable", null);
168
+
169
+ var buttons = list.el[0].getElementsByTagName('button');
170
+
171
+ $(buttons).remove();
172
+ };
173
+
174
+ list.el.bind('destroy-nestable', destroyNestable);
175
+ },
176
+
177
+ destroy: function ()
178
+ {
179
+ this.expandAll();
180
+ this.el.trigger('destroy-nestable');
181
+ },
182
+
183
+ serialize: function()
184
+ {
185
+ var data,
186
+ depth = 0,
187
+ list = this;
188
+ step = function(level, depth)
189
+ {
190
+ var array = [ ],
191
+ items = level.children(list.options.itemNodeName);
192
+ items.each(function()
193
+ {
194
+ var li = $(this),
195
+ item = $.extend({}, li.data()),
196
+ sub = li.children(list.options.listNodeName);
197
+ if (sub.length) {
198
+ item.children = step(sub, depth + 1);
199
+ }
200
+ array.push(item);
201
+ });
202
+ return array;
203
+ };
204
+ var el;
205
+
206
+ if (list.el.is(list.options.listNodeName)) {
207
+ el = list.el;
208
+ } else {
209
+ el = list.el.find(list.options.listNodeName).first();
210
+ }
211
+ data = step(el, depth);
212
+ return data;
213
+ },
214
+
215
+ reset: function()
216
+ {
217
+ this.mouse = {
218
+ offsetX : 0,
219
+ offsetY : 0,
220
+ startX : 0,
221
+ startY : 0,
222
+ lastX : 0,
223
+ lastY : 0,
224
+ nowX : 0,
225
+ nowY : 0,
226
+ distX : 0,
227
+ distY : 0,
228
+ dirAx : 0,
229
+ dirX : 0,
230
+ dirY : 0,
231
+ lastDirX : 0,
232
+ lastDirY : 0,
233
+ distAxX : 0,
234
+ distAxY : 0
235
+ };
236
+ this.moving = false;
237
+ this.dragEl = null;
238
+ this.dragRootEl = null;
239
+ this.dragDepth = 0;
240
+ this.dragItem = null;
241
+ this.hasNewRoot = false;
242
+ this.pointEl = null;
243
+ this.sourceRoot = null;
244
+ this.isOutsideRoot = false;
245
+ },
246
+
247
+ expandItem: function(li)
248
+ {
249
+ li.removeClass(this.options.collapsedClass);
250
+ li.children('[data-action="expand"]').hide();
251
+ li.children('[data-action="collapse"]').show();
252
+ li.children(this.options.listNodeName).show();
253
+ this.el.trigger('expand', [li]);
254
+ li.trigger('expand');
255
+ },
256
+
257
+ collapseItem: function(li)
258
+ {
259
+ var lists = li.children(this.options.listNodeName);
260
+ if (lists.length) {
261
+ li.addClass(this.options.collapsedClass);
262
+ li.children('[data-action="collapse"]').hide();
263
+ li.children('[data-action="expand"]').show();
264
+ li.children(this.options.listNodeName).hide();
265
+ }
266
+ this.el.trigger('collapse', [li]);
267
+ li.trigger('collapse');
268
+ },
269
+
270
+ expandAll: function()
271
+ {
272
+ var list = this;
273
+ list.el.find(list.options.itemNodeName).each(function() {
274
+ list.expandItem($(this));
275
+ });
276
+ },
277
+
278
+ collapseAll: function()
279
+ {
280
+ var list = this;
281
+ list.el.find(list.options.itemNodeName).each(function() {
282
+ list.collapseItem($(this));
283
+ });
284
+ },
285
+
286
+ setParent: function(li)
287
+ {
288
+ if (li.children(this.options.listNodeName).length) {
289
+ li.prepend($(this.options.expandBtnHTML));
290
+ li.prepend($(this.options.collapseBtnHTML));
291
+ }
292
+ if( (' ' + li[0].className + ' ').indexOf(' ' + defaults.collapsedClass + ' ') > -1 )
293
+ {
294
+ li.children('[data-action="collapse"]').hide();
295
+ } else {
296
+ li.children('[data-action="expand"]').hide();
297
+ }
298
+ },
299
+
300
+ unsetParent: function(li)
301
+ {
302
+ li.removeClass(this.options.collapsedClass);
303
+ li.children('[data-action]').remove();
304
+ li.children(this.options.listNodeName).remove();
305
+ },
306
+
307
+ dragStart: function(e)
308
+ {
309
+ var mouse = this.mouse,
310
+ target = $(e.target),
311
+ dragItem = target.closest('.' + this.options.handleClass).closest(this.options.itemNodeName);
312
+
313
+ this.sourceRoot = target.closest('.' + this.options.rootClass);
314
+
315
+ this.dragItem = dragItem;
316
+
317
+ this.placeEl.css('height', dragItem.height());
318
+
319
+ mouse.offsetX = e.offsetX !== undefined ? e.offsetX : e.pageX - target.offset().left;
320
+ mouse.offsetY = e.offsetY !== undefined ? e.offsetY : e.pageY - target.offset().top;
321
+ mouse.startX = mouse.lastX = e.pageX;
322
+ mouse.startY = mouse.lastY = e.pageY;
323
+
324
+ this.dragRootEl = this.el;
325
+
326
+ this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);
327
+ this.dragEl.css('width', dragItem.width());
328
+
329
+ // fix for zepto.js
330
+ //dragItem.after(this.placeEl).detach().appendTo(this.dragEl);
331
+ if(this.options.cloneNodeOnDrag) {
332
+ dragItem.after(dragItem.clone());
333
+ } else {
334
+ dragItem.after(this.placeEl);
335
+ }
336
+ dragItem[0].parentNode.removeChild(dragItem[0]);
337
+ dragItem.appendTo(this.dragEl);
338
+
339
+ $(document.body).append(this.dragEl);
340
+ this.dragEl.css({
341
+ 'left' : e.pageX - mouse.offsetX,
342
+ 'top' : e.pageY - mouse.offsetY
343
+ });
344
+ // total depth of dragging item
345
+ var i, depth,
346
+ items = this.dragEl.find(this.options.itemNodeName);
347
+ for (i = 0; i < items.length; i++) {
348
+ depth = $(items[i]).parents(this.options.listNodeName).length;
349
+ if (depth > this.dragDepth) {
350
+ this.dragDepth = depth;
351
+ }
352
+ }
353
+ },
354
+
355
+ dragStop: function(e)
356
+ {
357
+ // fix for zepto.js
358
+ //this.placeEl.replaceWith(this.dragEl.children(this.options.itemNodeName + ':first').detach());
359
+ var el = this.dragEl.children(this.options.itemNodeName).first();
360
+ el[0].parentNode.removeChild(el[0]);
361
+
362
+ if(this.isOutsideRoot && this.options.dragOutsideToDelete)
363
+ {
364
+ var parent = this.placeEl.parent();
365
+ this.placeEl.remove();
366
+ if (!parent.children().length) {
367
+ this.unsetParent(parent.parent());
368
+ }
369
+ // If all nodes where deleted, create a placeholder element.
370
+ if (!this.dragRootEl.find(this.options.itemNodeName).length)
371
+ {
372
+ this.dragRootEl.append('<div class="' + this.options.emptyClass + '"/>');
373
+ }
374
+ }
375
+ else
376
+ {
377
+ this.placeEl.replaceWith(el);
378
+ }
379
+
380
+ if (!this.moving)
381
+ {
382
+ $(this.dragItem).trigger('click');
383
+ }
384
+
385
+ var i;
386
+ var isRejected = false;
387
+ for (i = 0; i < this.options.reject.length; i++)
388
+ {
389
+ var reject = this.options.reject[i];
390
+ if (reject.rule.apply(this.dragRootEl))
391
+ {
392
+ var nestableDragEl = el.clone(true);
393
+ this.dragRootEl.html(this.nestableCopy.children().clone(true));
394
+ if (reject.action) {
395
+ reject.action.apply(this.dragRootEl, [nestableDragEl]);
396
+ }
397
+
398
+ isRejected = true;
399
+ break;
400
+ }
401
+ }
402
+
403
+ if (!isRejected)
404
+ {
405
+ this.dragEl.remove();
406
+ this.el.trigger('change');
407
+
408
+ //Let's find out new parent id
409
+ var parentItem = el.parent().parent();
410
+ var parentId = null;
411
+ if(parentItem !== null && !parentItem.is('.' + this.options.rootClass))
412
+ parentId = parentItem.data('id');
413
+
414
+ if($.isFunction(this.options.dropCallback))
415
+ {
416
+ var details = {
417
+ sourceId : el.data('id'),
418
+ destId : parentId,
419
+ sourceEl : el,
420
+ destParent : parentItem,
421
+ destRoot : el.closest('.' + this.options.rootClass),
422
+ sourceRoot : this.sourceRoot
423
+ };
424
+ this.options.dropCallback.call(this, details);
425
+ }
426
+
427
+ if (this.hasNewRoot) {
428
+ this.dragRootEl.trigger('change');
429
+ }
430
+
431
+ this.reset();
432
+ }
433
+ },
434
+
435
+ dragMove: function(e)
436
+ {
437
+ var list, parent, prev, next, depth,
438
+ opt = this.options,
439
+ mouse = this.mouse;
440
+
441
+ this.dragEl.css({
442
+ 'left' : e.pageX - mouse.offsetX,
443
+ 'top' : e.pageY - mouse.offsetY
444
+ });
445
+
446
+ // mouse position last events
447
+ mouse.lastX = mouse.nowX;
448
+ mouse.lastY = mouse.nowY;
449
+ // mouse position this events
450
+ mouse.nowX = e.pageX;
451
+ mouse.nowY = e.pageY;
452
+ // distance mouse moved between events
453
+ mouse.distX = mouse.nowX - mouse.lastX;
454
+ mouse.distY = mouse.nowY - mouse.lastY;
455
+ // direction mouse was moving
456
+ mouse.lastDirX = mouse.dirX;
457
+ mouse.lastDirY = mouse.dirY;
458
+ // direction mouse is now moving (on both axis)
459
+ mouse.dirX = mouse.distX === 0 ? 0 : mouse.distX > 0 ? 1 : -1;
460
+ mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
461
+ // axis mouse is now moving on
462
+ var newAx = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;
463
+
464
+ // do nothing on first move
465
+ if (!this.moving) {
466
+ mouse.dirAx = newAx;
467
+ this.moving = true;
468
+ return;
469
+ }
470
+
471
+ // calc distance moved on this axis (and direction)
472
+ if (mouse.dirAx !== newAx) {
473
+ mouse.distAxX = 0;
474
+ mouse.distAxY = 0;
475
+ } else {
476
+ mouse.distAxX += Math.abs(mouse.distX);
477
+ if (mouse.dirX !== 0 && mouse.dirX !== mouse.lastDirX) {
478
+ mouse.distAxX = 0;
479
+ }
480
+ mouse.distAxY += Math.abs(mouse.distY);
481
+ if (mouse.dirY !== 0 && mouse.dirY !== mouse.lastDirY) {
482
+ mouse.distAxY = 0;
483
+ }
484
+ }
485
+ mouse.dirAx = newAx;
486
+
487
+ /**
488
+ * move horizontal
489
+ */
490
+ if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
491
+ // reset move distance on x-axis for new phase
492
+ mouse.distAxX = 0;
493
+ prev = this.placeEl.prev(opt.itemNodeName);
494
+ // increase horizontal level if previous sibling exists and is not collapsed
495
+ if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass) && !prev.hasClass(opt.noChildrenClass)) {
496
+ // cannot increase level when item above is collapsed
497
+ list = prev.find(opt.listNodeName).last();
498
+ // check if depth limit has reached
499
+ depth = this.placeEl.parents(opt.listNodeName).length;
500
+ if (depth + this.dragDepth <= opt.maxDepth) {
501
+ // create new sub-level if one doesn't exist
502
+ if (!list.length) {
503
+ list = $('<' + opt.listNodeName + '/>').addClass(opt.listClass);
504
+ list.append(this.placeEl);
505
+ prev.append(list);
506
+ this.setParent(prev);
507
+ } else {
508
+ // else append to next level up
509
+ list = prev.children(opt.listNodeName).last();
510
+ list.append(this.placeEl);
511
+ }
512
+ }
513
+ }
514
+ // decrease horizontal level
515
+ if (mouse.distX < 0) {
516
+ // we can't decrease a level if an item preceeds the current one
517
+ next = this.placeEl.next(opt.itemNodeName);
518
+ if (!next.length) {
519
+ parent = this.placeEl.parent();
520
+ this.placeEl.closest(opt.itemNodeName).after(this.placeEl);
521
+ if (!parent.children().length) {
522
+ this.unsetParent(parent.parent());
523
+ }
524
+ }
525
+ }
526
+ }
527
+
528
+ var isEmpty = false;
529
+
530
+ // find list item under cursor
531
+ if (!hasPointerEvents) {
532
+ this.dragEl[0].style.visibility = 'hidden';
533
+ }
534
+
535
+ this.pointEl = $(document.elementFromPoint(e.pageX - document.documentElement.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
536
+
537
+ // Check if the node is dragged outside of its list.
538
+ if(this.dragRootEl.has(this.pointEl).length) {
539
+ this.isOutsideRoot = false;
540
+ this.dragEl[0].style.opacity = 1;
541
+ } else {
542
+ this.isOutsideRoot = true;
543
+ this.dragEl[0].style.opacity = 0.5;
544
+ }
545
+
546
+ // find parent list of item under cursor
547
+ var pointElRoot = this.pointEl.closest('.' + opt.rootClass),
548
+ isNewRoot = this.dragRootEl.data('nestable-id') !== pointElRoot.data('nestable-id');
549
+
550
+ this.isOutsideRoot = !pointElRoot.length;
551
+
552
+ if (!hasPointerEvents) {
553
+ this.dragEl[0].style.visibility = 'visible';
554
+ }
555
+ if (this.pointEl.hasClass(opt.handleClass)) {
556
+ this.pointEl = this.pointEl.closest( opt.itemNodeName );
557
+ }
558
+
559
+ if (opt.maxDepth == 1 && !this.pointEl.hasClass(opt.itemClass)) {
560
+ this.pointEl = this.pointEl.closest("." + opt.itemClass);
561
+ }
562
+
563
+ if (this.pointEl.hasClass(opt.emptyClass)) {
564
+ isEmpty = true;
565
+ }
566
+ else if (!this.pointEl.length || !this.pointEl.hasClass(opt.itemClass)) {
567
+ return;
568
+ }
569
+
570
+ /**
571
+ * move vertical
572
+ */
573
+ if (!mouse.dirAx || isNewRoot || isEmpty) {
574
+ // check if groups match if dragging over new root
575
+ if (isNewRoot && opt.group !== pointElRoot.data('nestable-group')) {
576
+ return;
577
+ }
578
+ // check depth limit
579
+ depth = this.dragDepth - 1 + this.pointEl.parents(opt.listNodeName).length;
580
+ if (depth > opt.maxDepth) {
581
+ return;
582
+ }
583
+ var before = e.pageY < (this.pointEl.offset().top + this.pointEl.height() / 2);
584
+ parent = this.placeEl.parent();
585
+ // if empty create new list to replace empty placeholder
586
+ if (isEmpty) {
587
+ list = $(document.createElement(opt.listNodeName)).addClass(opt.listClass);
588
+ list.append(this.placeEl);
589
+ this.pointEl.replaceWith(list);
590
+ }
591
+ else if (before) {
592
+ this.pointEl.before(this.placeEl);
593
+ }
594
+ else {
595
+ this.pointEl.after(this.placeEl);
596
+ }
597
+ if (!parent.children().length) {
598
+ this.unsetParent(parent.parent());
599
+ }
600
+ if (!this.dragRootEl.find(opt.itemNodeName).length) {
601
+ this.dragRootEl.append('<div class="' + opt.emptyClass + '"/>');
602
+ }
603
+ // parent root list has changed
604
+ this.dragRootEl = pointElRoot;
605
+ if (isNewRoot) {
606
+ this.hasNewRoot = this.el[0] !== this.dragRootEl[0];
607
+ }
608
+ }
609
+ }
610
+
611
+ };
612
+
613
+ $.fn.nestable = function(params)
614
+ {
615
+ var lists = this,
616
+ retval = this;
617
+
618
+ var generateUid = function (separator) {
619
+ var delim = separator || "-";
620
+
621
+ function S4() {
622
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
623
+ }
624
+
625
+ return (S4() + S4() + delim + S4() + delim + S4() + delim + S4() + delim + S4() + S4() + S4());
626
+ };
627
+
628
+ lists.each(function()
629
+ {
630
+ var plugin = $(this).data("nestable");
631
+
632
+ if (!plugin) {
633
+ $(this).data("nestable", new Plugin(this, params));
634
+ $(this).data("nestable-id", generateUid());
635
+ } else {
636
+ if (typeof params === 'string' && typeof plugin[params] === 'function') {
637
+ retval = plugin[params]();
638
+ }
639
+ }
640
+ });
641
+
642
+ return retval || lists;
643
+ };
644
+
645
+ })(window.jQuery || window.Zepto, window, document);