rails-uikit 2.8.0
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.
- data/lib/rails/uikit/engine.rb +6 -0
- data/lib/rails/uikit/version.rb +5 -0
- data/lib/rails/uikit.rb +8 -0
- data/public/fonts/FontAwesome.otf +0 -0
- data/public/fonts/fontawesome-webfont.eot +0 -0
- data/public/fonts/fontawesome-webfont.ttf +0 -0
- data/public/fonts/fontawesome-webfont.woff +0 -0
- data/vendor/assets/javascripts/addons/autocomplete.js +306 -0
- data/vendor/assets/javascripts/addons/autocomplete.min.js +3 -0
- data/vendor/assets/javascripts/addons/datepicker.js +365 -0
- data/vendor/assets/javascripts/addons/datepicker.min.js +3 -0
- data/vendor/assets/javascripts/addons/form-password.js +62 -0
- data/vendor/assets/javascripts/addons/form-password.min.js +3 -0
- data/vendor/assets/javascripts/addons/form-select.js +62 -0
- data/vendor/assets/javascripts/addons/form-select.min.js +3 -0
- data/vendor/assets/javascripts/addons/htmleditor.js +594 -0
- data/vendor/assets/javascripts/addons/htmleditor.min.js +3 -0
- data/vendor/assets/javascripts/addons/nestable.js +574 -0
- data/vendor/assets/javascripts/addons/nestable.min.js +3 -0
- data/vendor/assets/javascripts/addons/notify.js +177 -0
- data/vendor/assets/javascripts/addons/notify.min.js +3 -0
- data/vendor/assets/javascripts/addons/pagination.js +146 -0
- data/vendor/assets/javascripts/addons/pagination.min.js +3 -0
- data/vendor/assets/javascripts/addons/search.js +90 -0
- data/vendor/assets/javascripts/addons/search.min.js +3 -0
- data/vendor/assets/javascripts/addons/sortable.js +494 -0
- data/vendor/assets/javascripts/addons/sortable.min.js +3 -0
- data/vendor/assets/javascripts/addons/sticky.js +130 -0
- data/vendor/assets/javascripts/addons/sticky.min.js +3 -0
- data/vendor/assets/javascripts/addons/timepicker.js +163 -0
- data/vendor/assets/javascripts/addons/timepicker.min.js +3 -0
- data/vendor/assets/javascripts/addons/upload.js +239 -0
- data/vendor/assets/javascripts/addons/upload.min.js +3 -0
- data/vendor/assets/javascripts/uikit.js +2573 -0
- data/vendor/assets/javascripts/uikit.min.js +4 -0
- data/vendor/assets/stylesheets/addons/uikit.addons.css +1124 -0
- data/vendor/assets/stylesheets/addons/uikit.addons.min.css +3 -0
- data/vendor/assets/stylesheets/addons/uikit.almost-flat.addons.css +1205 -0
- data/vendor/assets/stylesheets/addons/uikit.almost-flat.addons.min.css +3 -0
- data/vendor/assets/stylesheets/addons/uikit.gradient.addons.css +1226 -0
- data/vendor/assets/stylesheets/addons/uikit.gradient.addons.min.css +3 -0
- data/vendor/assets/stylesheets/uikit.almost-flat.css +7022 -0
- data/vendor/assets/stylesheets/uikit.almost-flat.min.css +3 -0
- data/vendor/assets/stylesheets/uikit.css +6732 -0
- data/vendor/assets/stylesheets/uikit.gradient.css +7090 -0
- data/vendor/assets/stylesheets/uikit.gradient.min.css +3 -0
- data/vendor/assets/stylesheets/uikit.min.css +3 -0
- metadata +125 -0
@@ -0,0 +1,574 @@
|
|
1
|
+
/*! UIkit 2.8.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2
|
+
|
3
|
+
/*
|
4
|
+
* Based on Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
|
5
|
+
*/
|
6
|
+
(function(addon) {
|
7
|
+
|
8
|
+
var component;
|
9
|
+
|
10
|
+
if (jQuery && jQuery.UIkit) {
|
11
|
+
component = addon(jQuery, jQuery.UIkit);
|
12
|
+
}
|
13
|
+
|
14
|
+
if (typeof define == "function" && define.amd) {
|
15
|
+
define("uikit-nestable", ["uikit"], function(){
|
16
|
+
return component || addon(jQuery, jQuery.UIkit);
|
17
|
+
});
|
18
|
+
}
|
19
|
+
|
20
|
+
})(function($, UI) {
|
21
|
+
|
22
|
+
var hasTouch = 'ontouchstart' in window,
|
23
|
+
html = $("html"),
|
24
|
+
touchedlists = [],
|
25
|
+
$win = $(window);
|
26
|
+
|
27
|
+
/**
|
28
|
+
* Detect CSS pointer-events property
|
29
|
+
* events are normally disabled on the dragging element to avoid conflicts
|
30
|
+
* https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
|
31
|
+
*/
|
32
|
+
var hasPointerEvents = (function() {
|
33
|
+
|
34
|
+
var el = document.createElement('div'), docEl = document.documentElement;
|
35
|
+
|
36
|
+
if (!('pointerEvents' in el.style)) {
|
37
|
+
return false;
|
38
|
+
}
|
39
|
+
|
40
|
+
el.style.pointerEvents = 'auto';
|
41
|
+
el.style.pointerEvents = 'x';
|
42
|
+
|
43
|
+
docEl.appendChild(el);
|
44
|
+
|
45
|
+
var supports = window.getComputedStyle && window.getComputedStyle(el, '').pointerEvents === 'auto';
|
46
|
+
|
47
|
+
docEl.removeChild(el);
|
48
|
+
|
49
|
+
return !!supports;
|
50
|
+
})();
|
51
|
+
|
52
|
+
var eStart = hasTouch ? 'touchstart' : 'mousedown',
|
53
|
+
eMove = hasTouch ? 'touchmove' : 'mousemove',
|
54
|
+
eEnd = hasTouch ? 'touchend' : 'mouseup',
|
55
|
+
eCancel = hasTouch ? 'touchcancel' : 'mouseup';
|
56
|
+
|
57
|
+
|
58
|
+
UI.component('nestable', {
|
59
|
+
|
60
|
+
defaults: {
|
61
|
+
prefix : 'uk',
|
62
|
+
listNodeName : 'ul',
|
63
|
+
itemNodeName : 'li',
|
64
|
+
listBaseClass : '{prefix}-nestable',
|
65
|
+
listClass : '{prefix}-nestable-list',
|
66
|
+
listitemClass : '{prefix}-nestable-list-item',
|
67
|
+
itemClass : '{prefix}-nestable-item',
|
68
|
+
dragClass : '{prefix}-nestable-list-dragged',
|
69
|
+
movingClass : '{prefix}-nestable-moving',
|
70
|
+
handleClass : '{prefix}-nestable-handle',
|
71
|
+
collapsedClass : '{prefix}-collapsed',
|
72
|
+
placeClass : '{prefix}-nestable-placeholder',
|
73
|
+
noDragClass : '{prefix}-nestable-nodrag',
|
74
|
+
emptyClass : '{prefix}-nestable-empty',
|
75
|
+
group : 0,
|
76
|
+
maxDepth : 10,
|
77
|
+
threshold : 20
|
78
|
+
},
|
79
|
+
|
80
|
+
init: function()
|
81
|
+
{
|
82
|
+
var $this = this;
|
83
|
+
|
84
|
+
Object.keys(this.options).forEach(function(key){
|
85
|
+
|
86
|
+
if(String($this.options[key]).indexOf('{prefix}')!=-1) {
|
87
|
+
$this.options[key] = $this.options[key].replace('{prefix}', $this.options.prefix);
|
88
|
+
}
|
89
|
+
});
|
90
|
+
|
91
|
+
this.tplempty = '<div class="' + this.options.emptyClass + '"/>';
|
92
|
+
|
93
|
+
this.find(">"+this.options.itemNodeName).addClass(this.options.listitemClass)
|
94
|
+
.end()
|
95
|
+
.find("ul:not(.ignore-list)").addClass(this.options.listClass)
|
96
|
+
.find(">li").addClass(this.options.listitemClass);
|
97
|
+
|
98
|
+
if (!this.element.children(this.options.itemNodeName).length) {
|
99
|
+
this.element.append(this.tplempty);
|
100
|
+
}
|
101
|
+
|
102
|
+
this.element.data("nestable-id", "ID"+(new Date().getTime())+"RAND"+(Math.ceil(Math.random() *100000)));
|
103
|
+
this.reset();
|
104
|
+
this.element.data('nestable-group', this.options.group);
|
105
|
+
this.placeEl = $('<div class="' + this.options.placeClass + '"/>');
|
106
|
+
|
107
|
+
this.find(this.options.itemNodeName).each(function() {
|
108
|
+
$this.setParent($(this));
|
109
|
+
});
|
110
|
+
|
111
|
+
this.on('click', '[data-nestable-action]', function(e) {
|
112
|
+
|
113
|
+
if ($this.dragEl || (!hasTouch && e.button !== 0)) {
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
|
117
|
+
e.preventDefault();
|
118
|
+
|
119
|
+
var target = $(e.currentTarget),
|
120
|
+
action = target.data('nestableAction'),
|
121
|
+
item = target.closest($this.options.itemNodeName);
|
122
|
+
if (action === 'collapse') {
|
123
|
+
$this.collapseItem(item);
|
124
|
+
}
|
125
|
+
if (action === 'expand') {
|
126
|
+
$this.expandItem(item);
|
127
|
+
}
|
128
|
+
if (action === 'toggle') {
|
129
|
+
$this.toggleItem(item);
|
130
|
+
}
|
131
|
+
});
|
132
|
+
|
133
|
+
var onStartEvent = function(e) {
|
134
|
+
|
135
|
+
var handle = $(e.target);
|
136
|
+
|
137
|
+
if (!handle.hasClass($this.options.handleClass)) {
|
138
|
+
if (handle.closest('.' + $this.options.noDragClass).length) {
|
139
|
+
return;
|
140
|
+
}
|
141
|
+
handle = handle.closest('.' + $this.options.handleClass);
|
142
|
+
}
|
143
|
+
if (!handle.length || $this.dragEl || (!hasTouch && e.button !== 0) || (hasTouch && e.touches.length !== 1)) {
|
144
|
+
return;
|
145
|
+
}
|
146
|
+
e.preventDefault();
|
147
|
+
$this.dragStart(hasTouch ? e.touches[0] : e);
|
148
|
+
$this.trigger('nestable-start', [$this]);
|
149
|
+
};
|
150
|
+
|
151
|
+
var onMoveEvent = function(e) {
|
152
|
+
if ($this.dragEl) {
|
153
|
+
e.preventDefault();
|
154
|
+
$this.dragMove(hasTouch ? e.touches[0] : e);
|
155
|
+
$this.trigger('nestable-move', [$this]);
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
var onEndEvent = function(e) {
|
160
|
+
if ($this.dragEl) {
|
161
|
+
e.preventDefault();
|
162
|
+
$this.dragStop(hasTouch ? e.touches[0] : e);
|
163
|
+
$this.trigger('nestable-stop', [$this]);
|
164
|
+
}
|
165
|
+
};
|
166
|
+
|
167
|
+
if (hasTouch) {
|
168
|
+
this.element[0].addEventListener(eStart, onStartEvent, false);
|
169
|
+
window.addEventListener(eMove, onMoveEvent, false);
|
170
|
+
window.addEventListener(eEnd, onEndEvent, false);
|
171
|
+
window.addEventListener(eCancel, onEndEvent, false);
|
172
|
+
} else {
|
173
|
+
this.on(eStart, onStartEvent);
|
174
|
+
$win.on(eMove, onMoveEvent);
|
175
|
+
$win.on(eEnd, onEndEvent);
|
176
|
+
}
|
177
|
+
|
178
|
+
},
|
179
|
+
|
180
|
+
serialize: function() {
|
181
|
+
|
182
|
+
var data,
|
183
|
+
depth = 0,
|
184
|
+
list = this;
|
185
|
+
step = function(level, depth) {
|
186
|
+
|
187
|
+
var array = [ ], items = level.children(list.options.itemNodeName);
|
188
|
+
|
189
|
+
items.each(function() {
|
190
|
+
|
191
|
+
var li = $(this),
|
192
|
+
item = $.extend({}, li.data()),
|
193
|
+
sub = li.children(list.options.listNodeName);
|
194
|
+
|
195
|
+
if (sub.length) {
|
196
|
+
item.children = step(sub, depth + 1);
|
197
|
+
}
|
198
|
+
array.push(item);
|
199
|
+
});
|
200
|
+
return array;
|
201
|
+
};
|
202
|
+
|
203
|
+
data = step(list.element, depth);
|
204
|
+
|
205
|
+
return data;
|
206
|
+
},
|
207
|
+
|
208
|
+
list: function(options) {
|
209
|
+
|
210
|
+
var data = [],
|
211
|
+
list = this,
|
212
|
+
depth = 0,
|
213
|
+
options = $.extend({}, list.options, options),
|
214
|
+
step = function(level, depth, parent) {
|
215
|
+
|
216
|
+
var items = level.children(options.itemNodeName);
|
217
|
+
|
218
|
+
items.each(function(index) {
|
219
|
+
var li = $(this),
|
220
|
+
item = $.extend({parent_id: (parent ? parent : null), depth: depth, order: index}, li.data()),
|
221
|
+
sub = li.children(options.listNodeName);
|
222
|
+
|
223
|
+
data.push(item);
|
224
|
+
|
225
|
+
if (sub.length) {
|
226
|
+
step(sub, depth + 1, li.data(options.idProperty || 'id'));
|
227
|
+
}
|
228
|
+
});
|
229
|
+
};
|
230
|
+
|
231
|
+
step(list.element, depth);
|
232
|
+
|
233
|
+
return data;
|
234
|
+
},
|
235
|
+
|
236
|
+
reset: function() {
|
237
|
+
|
238
|
+
this.mouse = {
|
239
|
+
offsetX : 0,
|
240
|
+
offsetY : 0,
|
241
|
+
startX : 0,
|
242
|
+
startY : 0,
|
243
|
+
lastX : 0,
|
244
|
+
lastY : 0,
|
245
|
+
nowX : 0,
|
246
|
+
nowY : 0,
|
247
|
+
distX : 0,
|
248
|
+
distY : 0,
|
249
|
+
dirAx : 0,
|
250
|
+
dirX : 0,
|
251
|
+
dirY : 0,
|
252
|
+
lastDirX : 0,
|
253
|
+
lastDirY : 0,
|
254
|
+
distAxX : 0,
|
255
|
+
distAxY : 0
|
256
|
+
};
|
257
|
+
this.moving = false;
|
258
|
+
this.dragEl = null;
|
259
|
+
this.dragRootEl = null;
|
260
|
+
this.dragDepth = 0;
|
261
|
+
this.hasNewRoot = false;
|
262
|
+
this.pointEl = null;
|
263
|
+
|
264
|
+
for (var i=0; i<touchedlists.length; i++) {
|
265
|
+
if (!touchedlists[i].children().length) {
|
266
|
+
touchedlists[i].append(this.tplempty);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
touchedlists = [];
|
271
|
+
},
|
272
|
+
|
273
|
+
toggleItem: function(li) {
|
274
|
+
this[li.hasClass(this.options.collapsedClass) ? "expandItem":"collapseItem"](li);
|
275
|
+
},
|
276
|
+
|
277
|
+
expandItem: function(li) {
|
278
|
+
li.removeClass(this.options.collapsedClass);
|
279
|
+
},
|
280
|
+
|
281
|
+
collapseItem: function(li) {
|
282
|
+
var lists = li.children(this.options.listNodeName);
|
283
|
+
if (lists.length) {
|
284
|
+
li.addClass(this.options.collapsedClass);
|
285
|
+
}
|
286
|
+
},
|
287
|
+
|
288
|
+
expandAll: function() {
|
289
|
+
var list = this;
|
290
|
+
this.find(list.options.itemNodeName).each(function() {
|
291
|
+
list.expandItem($(this));
|
292
|
+
});
|
293
|
+
},
|
294
|
+
|
295
|
+
collapseAll: function() {
|
296
|
+
var list = this;
|
297
|
+
this.find(list.options.itemNodeName).each(function() {
|
298
|
+
list.collapseItem($(this));
|
299
|
+
});
|
300
|
+
},
|
301
|
+
|
302
|
+
setParent: function(li) {
|
303
|
+
if (li.children(this.options.listNodeName).length) {
|
304
|
+
li.addClass("uk-parent");
|
305
|
+
}
|
306
|
+
},
|
307
|
+
|
308
|
+
unsetParent: function(li) {
|
309
|
+
li.removeClass('uk-parent '+this.options.collapsedClass);
|
310
|
+
li.children(this.options.listNodeName).remove();
|
311
|
+
},
|
312
|
+
|
313
|
+
dragStart: function(e) {
|
314
|
+
var mouse = this.mouse,
|
315
|
+
target = $(e.target),
|
316
|
+
dragItem = target.closest(this.options.itemNodeName),
|
317
|
+
offset = dragItem.offset();
|
318
|
+
|
319
|
+
this.placeEl.css('height', dragItem.height());
|
320
|
+
|
321
|
+
mouse.offsetX = e.pageX - offset.left;
|
322
|
+
mouse.offsetY = e.pageY - offset.top;
|
323
|
+
|
324
|
+
mouse.startX = mouse.lastX = offset.left;
|
325
|
+
mouse.startY = mouse.lastY = offset.top;
|
326
|
+
|
327
|
+
this.dragRootEl = this.element;
|
328
|
+
|
329
|
+
this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);
|
330
|
+
this.dragEl.css('width', dragItem.width());
|
331
|
+
|
332
|
+
this.tmpDragOnSiblings = [dragItem[0].previousSibling, dragItem[0].nextSibling];
|
333
|
+
|
334
|
+
// fix for zepto.js
|
335
|
+
//dragItem.after(this.placeEl).detach().appendTo(this.dragEl);
|
336
|
+
dragItem.after(this.placeEl);
|
337
|
+
dragItem[0].parentNode.removeChild(dragItem[0]);
|
338
|
+
dragItem.appendTo(this.dragEl);
|
339
|
+
|
340
|
+
$(document.body).append(this.dragEl);
|
341
|
+
|
342
|
+
this.dragEl.css({
|
343
|
+
left : offset.left,
|
344
|
+
top : offset.top
|
345
|
+
});
|
346
|
+
|
347
|
+
// total depth of dragging item
|
348
|
+
var i, depth,
|
349
|
+
items = this.dragEl.find(this.options.itemNodeName);
|
350
|
+
for (i = 0; i < items.length; i++) {
|
351
|
+
depth = $(items[i]).parents(this.options.listNodeName).length;
|
352
|
+
if (depth > this.dragDepth) {
|
353
|
+
this.dragDepth = depth;
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
html.addClass(this.options.movingClass);
|
358
|
+
},
|
359
|
+
|
360
|
+
dragStop: function(e) {
|
361
|
+
// fix for zepto.js
|
362
|
+
//this.placeEl.replaceWith(this.dragEl.children(this.options.itemNodeName + ':first').detach());
|
363
|
+
var el = this.dragEl.children(this.options.itemNodeName).first();
|
364
|
+
el[0].parentNode.removeChild(el[0]);
|
365
|
+
this.placeEl.replaceWith(el);
|
366
|
+
|
367
|
+
this.dragEl.remove();
|
368
|
+
|
369
|
+
if (this.tmpDragOnSiblings[0]!=el[0].previousSibling || this.tmpDragOnSiblings[0]!=el[0].previousSibling) {
|
370
|
+
|
371
|
+
this.element.trigger('nestable-change',[el, this.hasNewRoot ? "added":"moved"]);
|
372
|
+
|
373
|
+
if (this.hasNewRoot) {
|
374
|
+
this.dragRootEl.trigger('nestable-change', [el, "removed"]);
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
this.reset();
|
379
|
+
|
380
|
+
html.removeClass(this.options.movingClass);
|
381
|
+
},
|
382
|
+
|
383
|
+
dragMove: function(e) {
|
384
|
+
var list, parent, prev, next, depth,
|
385
|
+
opt = this.options,
|
386
|
+
mouse = this.mouse;
|
387
|
+
|
388
|
+
this.dragEl.css({
|
389
|
+
left : e.pageX - mouse.offsetX,
|
390
|
+
top : e.pageY - mouse.offsetY
|
391
|
+
});
|
392
|
+
|
393
|
+
// mouse position last events
|
394
|
+
mouse.lastX = mouse.nowX;
|
395
|
+
mouse.lastY = mouse.nowY;
|
396
|
+
// mouse position this events
|
397
|
+
mouse.nowX = e.pageX;
|
398
|
+
mouse.nowY = e.pageY;
|
399
|
+
// distance mouse moved between events
|
400
|
+
mouse.distX = mouse.nowX - mouse.lastX;
|
401
|
+
mouse.distY = mouse.nowY - mouse.lastY;
|
402
|
+
// direction mouse was moving
|
403
|
+
mouse.lastDirX = mouse.dirX;
|
404
|
+
mouse.lastDirY = mouse.dirY;
|
405
|
+
// direction mouse is now moving (on both axis)
|
406
|
+
mouse.dirX = mouse.distX === 0 ? 0 : mouse.distX > 0 ? 1 : -1;
|
407
|
+
mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
|
408
|
+
// axis mouse is now moving on
|
409
|
+
var newAx = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;
|
410
|
+
|
411
|
+
// do nothing on first move
|
412
|
+
if (!mouse.moving) {
|
413
|
+
mouse.dirAx = newAx;
|
414
|
+
mouse.moving = true;
|
415
|
+
return;
|
416
|
+
}
|
417
|
+
|
418
|
+
// calc distance moved on this axis (and direction)
|
419
|
+
if (mouse.dirAx !== newAx) {
|
420
|
+
mouse.distAxX = 0;
|
421
|
+
mouse.distAxY = 0;
|
422
|
+
} else {
|
423
|
+
mouse.distAxX += Math.abs(mouse.distX);
|
424
|
+
if (mouse.dirX !== 0 && mouse.dirX !== mouse.lastDirX) {
|
425
|
+
mouse.distAxX = 0;
|
426
|
+
}
|
427
|
+
mouse.distAxY += Math.abs(mouse.distY);
|
428
|
+
if (mouse.dirY !== 0 && mouse.dirY !== mouse.lastDirY) {
|
429
|
+
mouse.distAxY = 0;
|
430
|
+
}
|
431
|
+
}
|
432
|
+
mouse.dirAx = newAx;
|
433
|
+
|
434
|
+
/**
|
435
|
+
* move horizontal
|
436
|
+
*/
|
437
|
+
if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
|
438
|
+
// reset move distance on x-axis for new phase
|
439
|
+
mouse.distAxX = 0;
|
440
|
+
prev = this.placeEl.prev(opt.itemNodeName);
|
441
|
+
// increase horizontal level if previous sibling exists and is not collapsed
|
442
|
+
if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass)) {
|
443
|
+
// cannot increase level when item above is collapsed
|
444
|
+
list = prev.find(opt.listNodeName).last();
|
445
|
+
// check if depth limit has reached
|
446
|
+
depth = this.placeEl.parents(opt.listNodeName).length;
|
447
|
+
if (depth + this.dragDepth <= opt.maxDepth) {
|
448
|
+
// create new sub-level if one doesn't exist
|
449
|
+
if (!list.length) {
|
450
|
+
list = $('<' + opt.listNodeName + '/>').addClass(opt.listClass);
|
451
|
+
list.append(this.placeEl);
|
452
|
+
prev.append(list);
|
453
|
+
this.setParent(prev);
|
454
|
+
} else {
|
455
|
+
// else append to next level up
|
456
|
+
list = prev.children(opt.listNodeName).last();
|
457
|
+
list.append(this.placeEl);
|
458
|
+
}
|
459
|
+
}
|
460
|
+
}
|
461
|
+
// decrease horizontal level
|
462
|
+
if (mouse.distX < 0) {
|
463
|
+
// we can't decrease a level if an item preceeds the current one
|
464
|
+
next = this.placeEl.next(opt.itemNodeName);
|
465
|
+
if (!next.length) {
|
466
|
+
parent = this.placeEl.parent();
|
467
|
+
this.placeEl.closest(opt.itemNodeName).after(this.placeEl);
|
468
|
+
if (!parent.children().length) {
|
469
|
+
this.unsetParent(parent.parent());
|
470
|
+
}
|
471
|
+
}
|
472
|
+
}
|
473
|
+
}
|
474
|
+
|
475
|
+
var isEmpty = false;
|
476
|
+
|
477
|
+
// find list item under cursor
|
478
|
+
if (!hasPointerEvents) {
|
479
|
+
this.dragEl[0].style.visibility = 'hidden';
|
480
|
+
}
|
481
|
+
this.pointEl = $(document.elementFromPoint(e.pageX - document.body.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
|
482
|
+
if (!hasPointerEvents) {
|
483
|
+
this.dragEl[0].style.visibility = 'visible';
|
484
|
+
}
|
485
|
+
|
486
|
+
if (this.pointEl.hasClass(opt.handleClass)) {
|
487
|
+
this.pointEl = this.pointEl.closest(opt.itemNodeName);
|
488
|
+
} else {
|
489
|
+
|
490
|
+
var nestableitem = this.pointEl.closest('.'+opt.itemClass);
|
491
|
+
|
492
|
+
if(nestableitem.length) {
|
493
|
+
this.pointEl = nestableitem.closest(opt.itemNodeName);
|
494
|
+
}
|
495
|
+
}
|
496
|
+
|
497
|
+
if (this.pointEl.hasClass(opt.emptyClass)) {
|
498
|
+
isEmpty = true;
|
499
|
+
} else if (this.pointEl.data('nestable') && !this.pointEl.children().length) {
|
500
|
+
isEmpty = true;
|
501
|
+
this.pointEl = $(this.tplempty).appendTo(this.pointEl);
|
502
|
+
} else if (!this.pointEl.length || !this.pointEl.hasClass(opt.listitemClass)) {
|
503
|
+
return;
|
504
|
+
}
|
505
|
+
|
506
|
+
// find parent list of item under cursor
|
507
|
+
var pointElRoot = this.element,
|
508
|
+
tmpRoot = this.pointEl.closest('.'+this.options.listBaseClass),
|
509
|
+
isNewRoot = pointElRoot[0] !== this.pointEl.closest('.'+this.options.listBaseClass)[0],
|
510
|
+
$newRoot = tmpRoot;
|
511
|
+
|
512
|
+
/**
|
513
|
+
* move vertical
|
514
|
+
*/
|
515
|
+
if (!mouse.dirAx || isNewRoot || isEmpty) {
|
516
|
+
// check if groups match if dragging over new root
|
517
|
+
if (isNewRoot && opt.group !== $newRoot.data('nestable-group')) {
|
518
|
+
return;
|
519
|
+
} else {
|
520
|
+
touchedlists.push(pointElRoot);
|
521
|
+
}
|
522
|
+
|
523
|
+
// check depth limit
|
524
|
+
depth = this.dragDepth - 1 + this.pointEl.parents(opt.listNodeName).length;
|
525
|
+
|
526
|
+
if (depth > opt.maxDepth) {
|
527
|
+
return;
|
528
|
+
}
|
529
|
+
|
530
|
+
var before = e.pageY < (this.pointEl.offset().top + this.pointEl.height() / 2);
|
531
|
+
|
532
|
+
parent = this.placeEl.parent();
|
533
|
+
|
534
|
+
// if empty create new list to replace empty placeholder
|
535
|
+
if (isEmpty) {
|
536
|
+
this.pointEl.replaceWith(this.placeEl);
|
537
|
+
} else if (before) {
|
538
|
+
this.pointEl.before(this.placeEl);
|
539
|
+
} else {
|
540
|
+
this.pointEl.after(this.placeEl);
|
541
|
+
}
|
542
|
+
|
543
|
+
if (!parent.children().length) {
|
544
|
+
if(!parent.data("nestable")) this.unsetParent(parent.parent());
|
545
|
+
}
|
546
|
+
|
547
|
+
if (!this.dragRootEl.find(opt.itemNodeName).length && !this.dragRootEl.children().length) {
|
548
|
+
this.dragRootEl.append(this.tplempty);
|
549
|
+
}
|
550
|
+
|
551
|
+
// parent root list has changed
|
552
|
+
if (isNewRoot) {
|
553
|
+
this.dragRootEl = tmpRoot;
|
554
|
+
this.hasNewRoot = this.element[0] !== this.dragRootEl[0];
|
555
|
+
}
|
556
|
+
}
|
557
|
+
}
|
558
|
+
|
559
|
+
});
|
560
|
+
|
561
|
+
$(document).on("uk-domready", function(e) {
|
562
|
+
|
563
|
+
$("[data-uk-nestable]").each(function(){
|
564
|
+
|
565
|
+
var ele = $(this);
|
566
|
+
|
567
|
+
if(!ele.data("nestable")) {
|
568
|
+
var plugin = UI.nestable(ele, UI.Utils.options(ele.attr("data-uk-nestable")));
|
569
|
+
}
|
570
|
+
});
|
571
|
+
});
|
572
|
+
|
573
|
+
return UI.nestable;
|
574
|
+
});
|
@@ -0,0 +1,3 @@
|
|
1
|
+
/*! UIkit 2.8.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
2
|
+
|
3
|
+
!function(a){var b;jQuery&&jQuery.UIkit&&(b=a(jQuery,jQuery.UIkit)),"function"==typeof define&&define.amd&&define("uikit-nestable",["uikit"],function(){return b||a(jQuery,jQuery.UIkit)})}(function(a,b){var c="ontouchstart"in window,d=a("html"),e=[],f=a(window),g=function(){var a=document.createElement("div"),b=document.documentElement;if(!("pointerEvents"in a.style))return!1;a.style.pointerEvents="auto",a.style.pointerEvents="x",b.appendChild(a);var c=window.getComputedStyle&&"auto"===window.getComputedStyle(a,"").pointerEvents;return b.removeChild(a),!!c}(),h=c?"touchstart":"mousedown",i=c?"touchmove":"mousemove",j=c?"touchend":"mouseup",k=c?"touchcancel":"mouseup";return b.component("nestable",{defaults:{prefix:"uk",listNodeName:"ul",itemNodeName:"li",listBaseClass:"{prefix}-nestable",listClass:"{prefix}-nestable-list",listitemClass:"{prefix}-nestable-list-item",itemClass:"{prefix}-nestable-item",dragClass:"{prefix}-nestable-list-dragged",movingClass:"{prefix}-nestable-moving",handleClass:"{prefix}-nestable-handle",collapsedClass:"{prefix}-collapsed",placeClass:"{prefix}-nestable-placeholder",noDragClass:"{prefix}-nestable-nodrag",emptyClass:"{prefix}-nestable-empty",group:0,maxDepth:10,threshold:20},init:function(){var b=this;Object.keys(this.options).forEach(function(a){-1!=String(b.options[a]).indexOf("{prefix}")&&(b.options[a]=b.options[a].replace("{prefix}",b.options.prefix))}),this.tplempty='<div class="'+this.options.emptyClass+'"/>',this.find(">"+this.options.itemNodeName).addClass(this.options.listitemClass).end().find("ul:not(.ignore-list)").addClass(this.options.listClass).find(">li").addClass(this.options.listitemClass),this.element.children(this.options.itemNodeName).length||this.element.append(this.tplempty),this.element.data("nestable-id","ID"+(new Date).getTime()+"RAND"+Math.ceil(1e5*Math.random())),this.reset(),this.element.data("nestable-group",this.options.group),this.placeEl=a('<div class="'+this.options.placeClass+'"/>'),this.find(this.options.itemNodeName).each(function(){b.setParent(a(this))}),this.on("click","[data-nestable-action]",function(d){if(!b.dragEl&&(c||0===d.button)){d.preventDefault();var e=a(d.currentTarget),f=e.data("nestableAction"),g=e.closest(b.options.itemNodeName);"collapse"===f&&b.collapseItem(g),"expand"===f&&b.expandItem(g),"toggle"===f&&b.toggleItem(g)}});var d=function(d){var e=a(d.target);if(!e.hasClass(b.options.handleClass)){if(e.closest("."+b.options.noDragClass).length)return;e=e.closest("."+b.options.handleClass)}!e.length||b.dragEl||!c&&0!==d.button||c&&1!==d.touches.length||(d.preventDefault(),b.dragStart(c?d.touches[0]:d),b.trigger("nestable-start",[b]))},e=function(a){b.dragEl&&(a.preventDefault(),b.dragMove(c?a.touches[0]:a),b.trigger("nestable-move",[b]))},g=function(a){b.dragEl&&(a.preventDefault(),b.dragStop(c?a.touches[0]:a),b.trigger("nestable-stop",[b]))};c?(this.element[0].addEventListener(h,d,!1),window.addEventListener(i,e,!1),window.addEventListener(j,g,!1),window.addEventListener(k,g,!1)):(this.on(h,d),f.on(i,e),f.on(j,g))},serialize:function(){var b,c=0,d=this;return step=function(b,c){var e=[],f=b.children(d.options.itemNodeName);return f.each(function(){var b=a(this),f=a.extend({},b.data()),g=b.children(d.options.listNodeName);g.length&&(f.children=step(g,c+1)),e.push(f)}),e},b=step(d.element,c)},list:function(b){var c=[],d=this,e=0,b=a.extend({},d.options,b),f=function(d,e,g){var h=d.children(b.itemNodeName);h.each(function(d){var h=a(this),i=a.extend({parent_id:g?g:null,depth:e,order:d},h.data()),j=h.children(b.listNodeName);c.push(i),j.length&&f(j,e+1,h.data(b.idProperty||"id"))})};return f(d.element,e),c},reset:function(){this.mouse={offsetX:0,offsetY:0,startX:0,startY:0,lastX:0,lastY:0,nowX:0,nowY:0,distX:0,distY:0,dirAx:0,dirX:0,dirY:0,lastDirX:0,lastDirY:0,distAxX:0,distAxY:0},this.moving=!1,this.dragEl=null,this.dragRootEl=null,this.dragDepth=0,this.hasNewRoot=!1,this.pointEl=null;for(var a=0;a<e.length;a++)e[a].children().length||e[a].append(this.tplempty);e=[]},toggleItem:function(a){this[a.hasClass(this.options.collapsedClass)?"expandItem":"collapseItem"](a)},expandItem:function(a){a.removeClass(this.options.collapsedClass)},collapseItem:function(a){var b=a.children(this.options.listNodeName);b.length&&a.addClass(this.options.collapsedClass)},expandAll:function(){var b=this;this.find(b.options.itemNodeName).each(function(){b.expandItem(a(this))})},collapseAll:function(){var b=this;this.find(b.options.itemNodeName).each(function(){b.collapseItem(a(this))})},setParent:function(a){a.children(this.options.listNodeName).length&&a.addClass("uk-parent")},unsetParent:function(a){a.removeClass("uk-parent "+this.options.collapsedClass),a.children(this.options.listNodeName).remove()},dragStart:function(b){var c=this.mouse,e=a(b.target),f=e.closest(this.options.itemNodeName),g=f.offset();this.placeEl.css("height",f.height()),c.offsetX=b.pageX-g.left,c.offsetY=b.pageY-g.top,c.startX=c.lastX=g.left,c.startY=c.lastY=g.top,this.dragRootEl=this.element,this.dragEl=a(document.createElement(this.options.listNodeName)).addClass(this.options.listClass+" "+this.options.dragClass),this.dragEl.css("width",f.width()),this.tmpDragOnSiblings=[f[0].previousSibling,f[0].nextSibling],f.after(this.placeEl),f[0].parentNode.removeChild(f[0]),f.appendTo(this.dragEl),a(document.body).append(this.dragEl),this.dragEl.css({left:g.left,top:g.top});var h,i,j=this.dragEl.find(this.options.itemNodeName);for(h=0;h<j.length;h++)i=a(j[h]).parents(this.options.listNodeName).length,i>this.dragDepth&&(this.dragDepth=i);d.addClass(this.options.movingClass)},dragStop:function(){var a=this.dragEl.children(this.options.itemNodeName).first();a[0].parentNode.removeChild(a[0]),this.placeEl.replaceWith(a),this.dragEl.remove(),(this.tmpDragOnSiblings[0]!=a[0].previousSibling||this.tmpDragOnSiblings[0]!=a[0].previousSibling)&&(this.element.trigger("nestable-change",[a,this.hasNewRoot?"added":"moved"]),this.hasNewRoot&&this.dragRootEl.trigger("nestable-change",[a,"removed"])),this.reset(),d.removeClass(this.options.movingClass)},dragMove:function(b){var c,d,f,h,i,j=this.options,k=this.mouse;this.dragEl.css({left:b.pageX-k.offsetX,top:b.pageY-k.offsetY}),k.lastX=k.nowX,k.lastY=k.nowY,k.nowX=b.pageX,k.nowY=b.pageY,k.distX=k.nowX-k.lastX,k.distY=k.nowY-k.lastY,k.lastDirX=k.dirX,k.lastDirY=k.dirY,k.dirX=0===k.distX?0:k.distX>0?1:-1,k.dirY=0===k.distY?0:k.distY>0?1:-1;var l=Math.abs(k.distX)>Math.abs(k.distY)?1:0;if(!k.moving)return k.dirAx=l,void(k.moving=!0);k.dirAx!==l?(k.distAxX=0,k.distAxY=0):(k.distAxX+=Math.abs(k.distX),0!==k.dirX&&k.dirX!==k.lastDirX&&(k.distAxX=0),k.distAxY+=Math.abs(k.distY),0!==k.dirY&&k.dirY!==k.lastDirY&&(k.distAxY=0)),k.dirAx=l,k.dirAx&&k.distAxX>=j.threshold&&(k.distAxX=0,f=this.placeEl.prev(j.itemNodeName),k.distX>0&&f.length&&!f.hasClass(j.collapsedClass)&&(c=f.find(j.listNodeName).last(),i=this.placeEl.parents(j.listNodeName).length,i+this.dragDepth<=j.maxDepth&&(c.length?(c=f.children(j.listNodeName).last(),c.append(this.placeEl)):(c=a("<"+j.listNodeName+"/>").addClass(j.listClass),c.append(this.placeEl),f.append(c),this.setParent(f)))),k.distX<0&&(h=this.placeEl.next(j.itemNodeName),h.length||(d=this.placeEl.parent(),this.placeEl.closest(j.itemNodeName).after(this.placeEl),d.children().length||this.unsetParent(d.parent()))));var m=!1;if(g||(this.dragEl[0].style.visibility="hidden"),this.pointEl=a(document.elementFromPoint(b.pageX-document.body.scrollLeft,b.pageY-(window.pageYOffset||document.documentElement.scrollTop))),g||(this.dragEl[0].style.visibility="visible"),this.pointEl.hasClass(j.handleClass))this.pointEl=this.pointEl.closest(j.itemNodeName);else{var n=this.pointEl.closest("."+j.itemClass);n.length&&(this.pointEl=n.closest(j.itemNodeName))}if(this.pointEl.hasClass(j.emptyClass))m=!0;else if(this.pointEl.data("nestable")&&!this.pointEl.children().length)m=!0,this.pointEl=a(this.tplempty).appendTo(this.pointEl);else if(!this.pointEl.length||!this.pointEl.hasClass(j.listitemClass))return;var o=this.element,p=this.pointEl.closest("."+this.options.listBaseClass),q=o[0]!==this.pointEl.closest("."+this.options.listBaseClass)[0],r=p;if(!k.dirAx||q||m){if(q&&j.group!==r.data("nestable-group"))return;if(e.push(o),i=this.dragDepth-1+this.pointEl.parents(j.listNodeName).length,i>j.maxDepth)return;var s=b.pageY<this.pointEl.offset().top+this.pointEl.height()/2;d=this.placeEl.parent(),m?this.pointEl.replaceWith(this.placeEl):s?this.pointEl.before(this.placeEl):this.pointEl.after(this.placeEl),d.children().length||d.data("nestable")||this.unsetParent(d.parent()),this.dragRootEl.find(j.itemNodeName).length||this.dragRootEl.children().length||this.dragRootEl.append(this.tplempty),q&&(this.dragRootEl=p,this.hasNewRoot=this.element[0]!==this.dragRootEl[0])}}}),a(document).on("uk-domready",function(){a("[data-uk-nestable]").each(function(){var c=a(this);if(!c.data("nestable")){b.nestable(c,b.Utils.options(c.attr("data-uk-nestable")))}})}),b.nestable});
|