blacklight-spotlight 4.7.1 → 5.0.0.pre.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -12
- data/Rakefile +8 -1
- data/app/assets/javascripts/spotlight/application.js +0 -1
- data/app/assets/javascripts/spotlight/spotlight.esm.js +3620 -3847
- data/app/assets/javascripts/spotlight/spotlight.esm.js.map +1 -1
- data/app/assets/javascripts/spotlight/spotlight.js +3620 -3852
- data/app/assets/javascripts/spotlight/spotlight.js.map +1 -1
- data/app/assets/stylesheets/spotlight/_accessibility.scss +0 -9
- data/app/assets/stylesheets/spotlight/_autocomplete.scss +49 -0
- data/app/assets/stylesheets/spotlight/_blacklight_configuration.scss +0 -1
- data/app/assets/stylesheets/spotlight/_blacklight_overrides.scss +1 -6
- data/app/assets/stylesheets/spotlight/_browse.scss +2 -2
- data/app/assets/stylesheets/spotlight/_catalog.scss +40 -41
- data/app/assets/stylesheets/spotlight/_curation.scss +1 -1
- data/app/assets/stylesheets/spotlight/_exhibit_admin.scss +7 -0
- data/app/assets/stylesheets/spotlight/_exhibits_index.scss +8 -5
- data/app/assets/stylesheets/spotlight/_featured_browse_categories_block.scss +3 -3
- data/app/assets/stylesheets/spotlight/_header.scss +13 -0
- data/app/assets/stylesheets/spotlight/_mixins.scss +3 -4
- data/app/assets/stylesheets/spotlight/_nestable.scss +2 -12
- data/app/assets/stylesheets/spotlight/_pages.scss +11 -9
- data/app/assets/stylesheets/spotlight/_report_a_problem.scss +1 -3
- data/app/assets/stylesheets/spotlight/_sir-trevor_overrides.scss +2 -2
- data/app/assets/stylesheets/spotlight/_spotlight.scss +2 -1
- data/app/assets/stylesheets/spotlight/_tag_selector.scss +34 -0
- data/app/assets/stylesheets/spotlight/_variables.scss +0 -8
- data/app/components/spotlight/analytics/dashboard_component.html.erb +3 -3
- data/app/components/spotlight/breadcrumbs_component.html.erb +13 -19
- data/app/components/spotlight/bulk_action_component.rb +1 -1
- data/app/components/spotlight/document_component.rb +1 -1
- data/app/components/spotlight/save_search_component.rb +1 -1
- data/app/components/spotlight/select_image_component.html.erb +17 -0
- data/app/components/spotlight/select_image_component.rb +24 -0
- data/app/components/spotlight/skip_link_component.rb +16 -0
- data/app/components/spotlight/tag_selector_component.html.erb +40 -0
- data/app/components/spotlight/tag_selector_component.rb +41 -0
- data/app/components/spotlight/tag_selector_component.yml +6 -0
- data/app/components/spotlight/title_component.html.erb +8 -0
- data/app/components/spotlight/title_component.rb +22 -0
- data/app/controllers/spotlight/accessibility_controller.rb +2 -2
- data/app/controllers/spotlight/catalog_controller.rb +7 -2
- data/app/controllers/spotlight/contact_email_controller.rb +8 -2
- data/app/controllers/spotlight/languages_controller.rb +9 -4
- data/app/helpers/spotlight/application_helper.rb +7 -0
- data/app/helpers/spotlight/crop_helper.rb +4 -0
- data/app/helpers/spotlight/meta_helper.rb +59 -36
- data/app/javascript/spotlight/admin/blacklight_configuration.js +1 -1
- data/app/javascript/spotlight/admin/block_mixins/autocompleteable.js +70 -34
- data/app/javascript/spotlight/admin/blocks/block.js +1 -0
- data/app/javascript/spotlight/admin/blocks/browse_block.js +8 -12
- data/app/javascript/spotlight/admin/blocks/browse_group_categories_block.js +14 -18
- data/app/javascript/spotlight/admin/blocks/pages_block.js +6 -10
- data/app/javascript/spotlight/admin/blocks/resources_block.js +33 -15
- data/app/javascript/spotlight/admin/blocks/solr_documents_base_block.js +11 -6
- data/app/javascript/spotlight/admin/blocks/solr_documents_embed_block.js +1 -0
- data/app/javascript/spotlight/admin/blocks/uploaded_items_block.js +4 -3
- data/app/javascript/spotlight/admin/copy_email_addresses.js +2 -0
- data/app/javascript/spotlight/admin/crop.js +45 -17
- data/app/javascript/spotlight/admin/croppable.js +8 -1
- data/app/javascript/spotlight/admin/croppable_modal.js +68 -0
- data/app/javascript/spotlight/admin/exhibits.js +15 -10
- data/app/javascript/spotlight/admin/form_observer.js +1 -1
- data/app/javascript/spotlight/admin/index.js +0 -10
- data/app/javascript/spotlight/admin/locks.js +15 -5
- data/app/javascript/spotlight/admin/pages.js +1 -1
- data/app/javascript/spotlight/admin/search_typeahead.js +62 -55
- data/app/javascript/spotlight/admin/spotlight_nestable.js +173 -50
- data/app/javascript/spotlight/admin/visibility_toggle.js +1 -11
- data/app/javascript/spotlight/controllers/index.js +8 -0
- data/app/javascript/spotlight/controllers/tag_selector_controller.js +203 -0
- data/app/javascript/spotlight/core.js +4 -6
- data/app/javascript/spotlight/index.js +2 -0
- data/app/javascript/spotlight/user/browse_group_categories.js +2 -0
- data/app/javascript/spotlight/user/carousel.js +3 -1
- data/app/javascript/spotlight/user/index.js +0 -2
- data/app/models/sir_trevor_rails/block.rb +5 -4
- data/app/models/sir_trevor_rails/blocks/solr_documents_block.rb +1 -1
- data/app/models/sir_trevor_rails/blocks/solr_documents_embed_block.rb +1 -1
- data/app/models/sir_trevor_rails/blocks/uploaded_items_block.rb +1 -1
- data/app/models/spotlight/page_configurations.rb +1 -1
- data/app/views/catalog/_add_tags.html.erb +2 -2
- data/app/views/catalog/_change_visibility.html.erb +1 -1
- data/app/views/catalog/_remove_tags.html.erb +2 -2
- data/app/views/layouts/spotlight/base.html.erb +24 -13
- data/app/views/layouts/spotlight/spotlight.html.erb +6 -6
- data/app/views/shared/_masthead.html.erb +4 -31
- data/app/views/shared/_site_sidebar.html.erb +1 -1
- data/app/views/shared/_user_util_links.html.erb +3 -1
- data/app/views/spotlight/accessibility/alt_text.html.erb +2 -2
- data/app/views/spotlight/admin_users/index.html.erb +3 -3
- data/app/views/spotlight/appearances/edit.html.erb +1 -1
- data/app/views/spotlight/browse/_search_box.html.erb +8 -8
- data/app/views/spotlight/browse/show.html.erb +1 -1
- data/app/views/spotlight/bulk_updates/_download.html.erb +1 -1
- data/app/views/spotlight/bulk_updates/_upload.html.erb +1 -1
- data/app/views/spotlight/catalog/_admin_header.html.erb +1 -1
- data/app/views/spotlight/catalog/_edit_default.html.erb +2 -1
- data/app/views/spotlight/catalog/select_image.html.erb +1 -0
- data/app/views/spotlight/contacts/_form.html.erb +1 -1
- data/app/views/spotlight/exhibits/_contact.html.erb +5 -6
- data/app/views/spotlight/exhibits/_delete.html.erb +1 -1
- data/app/views/spotlight/exhibits/_languages.html.erb +3 -2
- data/app/views/spotlight/featured_images/_form.html.erb +6 -2
- data/app/views/spotlight/featured_images/_upload_form.html.erb +1 -1
- data/app/views/spotlight/metadata_configurations/_metadata_field.html.erb +1 -1
- data/app/views/spotlight/metadata_configurations/edit.html.erb +6 -6
- data/app/views/spotlight/pages/show.html.erb +1 -1
- data/app/views/spotlight/resources/csv_upload/_form.html.erb +1 -1
- data/app/views/spotlight/resources/upload/_form.html.erb +1 -1
- data/app/views/spotlight/roles/index.html.erb +1 -1
- data/app/views/spotlight/searches/_form.html.erb +1 -1
- data/app/views/spotlight/shared/_dd3_item.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_browse_group_categories_block.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_block.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_solr_documents_carousel_block.html.erb +1 -1
- data/app/views/spotlight/sir_trevor/blocks/_uploaded_items_block.html.erb +1 -1
- data/app/views/spotlight/tags/index.html.erb +2 -3
- data/app/views/spotlight/translations/_import.html.erb +2 -2
- data/config/importmap.rb +5 -0
- data/config/locales/spotlight.en.yml +2 -0
- data/config/routes.rb +5 -3
- data/lib/generators/spotlight/assets/generator_common_utilities.rb +36 -0
- data/lib/generators/spotlight/assets/importmap_generator.rb +87 -0
- data/lib/generators/spotlight/assets/propshaft_generator.rb +96 -0
- data/lib/generators/spotlight/assets_generator.rb +22 -0
- data/lib/generators/spotlight/install_generator.rb +8 -36
- data/lib/generators/spotlight/scaffold_resource_generator.rb +1 -1
- data/lib/generators/spotlight/templates/assets/spotlight.scss +6 -0
- data/lib/generators/spotlight/templates/javascript/jquery-shim.js +1 -0
- data/lib/spotlight/engine.rb +7 -6
- data/lib/spotlight/version.rb +1 -1
- data/spec/support/features/capybara_wait_metadata_helper.rb +13 -0
- data/spec/support/features/test_features_helpers.rb +16 -30
- data/vendor/assets/javascripts/tiny-slider.js +3 -0
- metadata +35 -87
- data/app/assets/stylesheets/spotlight/#_accessibility.scss# +0 -12
- data/app/javascript/spotlight/admin/checkbox_submit.js +0 -75
- data/app/javascript/spotlight/admin/exhibit_tag_autocomplete.js +0 -39
- data/app/javascript/spotlight/user/report_a_problem.js +0 -30
- data/app/views/spotlight/browse/_tophat.html.erb +0 -1
- data/app/views/spotlight/catalog/_tophat_default.html.erb +0 -1
- data/app/views/spotlight/home_pages/_tophat.html.erb +0 -2
- data/app/views/spotlight/pages/_tophat.html.erb +0 -1
- data/lib/generators/spotlight/templates/spotlight.js +0 -1
- data/lib/generators/spotlight/templates/spotlight.scss +0 -5
- data/spec/support/features/capybara_default_max_wait_metadata_helper.rb +0 -20
- data/vendor/assets/javascripts/bootstrap-tagsinput.js +0 -530
- data/vendor/assets/javascripts/jquery.serializejson.js +0 -234
- data/vendor/assets/javascripts/nestable.js +0 -645
- data/vendor/assets/javascripts/sir-trevor.js +0 -23508
- data/vendor/assets/javascripts/typeahead.bundle.min.js +0 -7
- data/vendor/assets/stylesheets/bootstrap-tagsinput.css +0 -46
@@ -1,645 +0,0 @@
|
|
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
|
-
const 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);
|