spec/internal/tmp/cache/assets/development/sprockets/7bf9acc825022f0424cd4ccfb51a57b8 in blacklight-spotlight-0.0.1 vs spec/internal/tmp/cache/assets/development/sprockets/7bf9acc825022f0424cd4ccfb51a57b8 in blacklight-spotlight-0.0.2
- old
+ new
@@ -1,15 +1,16 @@
{I"
class:ETI"BundledAsset; FI"logical_path; TI"nestable.js; FI"
pathname; TI"R/Volumes/TempStorage/Projects/spotlight/vendor/assets/javascripts/nestable.js; FI"content_type; TI"application/javascript; TI"
-mtime; Tl+4YñRI"length; Ti/FI"digest; TI"%28cc3ef5ee1ef8cb4f2d296a07653998; FI"source; TI"/F/*!
+mtime; Tl+“úRI"length; Tiÿ\I"digest; TI"%d240efae60bc0ebf4b694b9fb367ab10; FI"source; TI"ÿ\/*!
* Nestable jQuery Plugin - Copyright (c) 2012 David Bushell - http://dbushell.com/
* Dual-licensed under the BSD or MIT licenses
*/
;(function($, window, document, undefined)
{
var hasTouch = 'ontouchstart' in window;
+ var nestableCopy;
/**
* Detect CSS pointer-events property
* events are normally disabled on the dragging element to avoid conflicts
* https://github.com/ausi/Feature-detection-technique-for-pointer-events/blob/master/modernizr-pointerevents.js
@@ -28,36 +29,47 @@
docEl.removeChild(el);
return !!supports;
})();
var eStart = hasTouch ? 'touchstart' : 'mousedown',
- eMove = hasTouch ? 'touchmove' : 'mousemove',
- eEnd = hasTouch ? 'touchend' : 'mouseup';
- eCancel = hasTouch ? 'touchcancel' : 'mouseup';
-
+ eMove = hasTouch ? 'touchmove' : 'mousemove',
+ eEnd = hasTouch ? 'touchend' : 'mouseup',
+ eCancel = hasTouch ? 'touchcancel' : 'mouseup';
+
var defaults = {
- listNodeName : 'ol',
- itemNodeName : 'li',
- rootClass : 'dd',
- listClass : 'dd-list',
- itemClass : 'dd-item',
- dragClass : 'dd-dragel',
- handleClass : 'dd-handle',
- collapsedClass : 'dd-collapsed',
- placeClass : 'dd-placeholder',
- noDragClass : 'dd-nodrag',
- emptyClass : 'dd-empty',
- expandBtnHTML : '<button data-action="expand" type="button">Expand</button>',
- collapseBtnHTML : '<button data-action="collapse" type="button">Collapse</button>',
- group : 0,
- maxDepth : 5,
- threshold : 20
- };
+ listNodeName : 'ol',
+ itemNodeName : 'li',
+ rootClass : 'dd',
+ listClass : 'dd-list',
+ itemClass : 'dd-item',
+ dragClass : 'dd-dragel',
+ handleClass : 'dd-handle',
+ collapsedClass : 'dd-collapsed',
+ placeClass : 'dd-placeholder',
+ noDragClass : 'dd-nodrag',
+ noChildrenClass : 'dd-nochildren',
+ emptyClass : 'dd-empty',
+ expandBtnHTML : '<button data-action="expand" type="button">Expand</button>',
+ collapseBtnHTML : '<button data-action="collapse" type="button">Collapse</button>',
+ group : 0,
+ maxDepth : 5,
+ threshold : 20,
+ reject : [],
+ //method for call when an item has been successfully dropped
+ //method has 1 argument in which sends an object containing all
+ //necessary details
+ dropCallback : null,
+ // When a node is dragged it is moved to its new location.
+ // You can set the next option to true to create a copy of the node that is dragged.
+ cloneNodeOnDrag : false,
+ // When the node is dragged and released outside its list delete it.
+ dragOutsideToDelete : false
+ };
function Plugin(element, options)
{
- this.w = $(window);
+ this.w = $(document);
this.el = $(element);
this.options = $.extend({}, defaults, options);
this.init();
}
@@ -75,11 +87,12 @@
$.each(this.el.find(list.options.itemNodeName), function(k, el) {
list.setParent($(el));
});
- list.el.on('click', 'button', function(e) {
+ list.el.on('click', 'button', function(e)
+ {
if (list.dragEl || (!hasTouch && e.button !== 0)) {
return;
}
var target = $(e.currentTarget),
action = target.data('action'),
@@ -93,17 +106,20 @@
});
var onStartEvent = function(e)
{
var handle = $(e.target);
+
+ list.nestableCopy = handle.closest('.'+list.options.rootClass).clone(true);
+
if (!handle.hasClass(list.options.handleClass)) {
if (handle.closest('.' + list.options.noDragClass).length) {
return;
}
handle = handle.closest('.' + list.options.handleClass);
}
- if (!handle.length || list.dragEl || (!hasTouch && e.button !== 0) || (hasTouch && e.touches.length !== 1)) {
+ if (!handle.length || list.dragEl || (!hasTouch && e.which !== 1) || (hasTouch && e.touches.length !== 1)) {
return;
}
e.preventDefault();
list.dragStart(hasTouch ? e.touches[0] : e);
};
@@ -133,12 +149,42 @@
list.el.on(eStart, onStartEvent);
list.w.on(eMove, onMoveEvent);
list.w.on(eEnd, onEndEvent);
}
+ var destroyNestable = function()
+ {
+ if (hasTouch) {
+ list.el[0].removeEventListener(eStart, onStartEvent, false);
+ window.removeEventListener(eMove, onMoveEvent, false);
+ window.removeEventListener(eEnd, onEndEvent, false);
+ window.removeEventListener(eCancel, onEndEvent, false);
+ } else {
+ list.el.off(eStart, onStartEvent);
+ list.w.off(eMove, onMoveEvent);
+ list.w.off(eEnd, onEndEvent);
+ }
+
+ list.el.off('click');
+ list.el.unbind('destroy-nestable');
+
+ list.el.data("nestable", null);
+
+ var buttons = list.el[0].getElementsByTagName('button');
+
+ $(buttons).remove();
+ };
+
+ list.el.bind('destroy-nestable', destroyNestable);
},
+ destroy: function ()
+ {
+ this.expandAll();
+ this.el.trigger('destroy-nestable');
+ },
+
serialize: function()
{
var data,
depth = 0,
list = this;
@@ -156,19 +202,21 @@
}
array.push(item);
});
return array;
};
- data = step(list.el.find(list.options.listNodeName).first(), depth);
+ var el;
+
+ if (list.el.is(list.options.listNodeName)) {
+ el = list.el;
+ } else {
+ el = list.el.find(list.options.listNodeName).first();
+ }
+ data = step(el, depth);
return data;
},
- serialise: function()
- {
- return this.serialize();
- },
-
reset: function()
{
this.mouse = {
offsetX : 0,
offsetY : 0,
@@ -190,20 +238,25 @@
};
this.moving = false;
this.dragEl = null;
this.dragRootEl = null;
this.dragDepth = 0;
+ this.dragItem = null;
this.hasNewRoot = false;
this.pointEl = null;
+ this.sourceRoot = null;
+ this.isOutsideRoot = false;
},
expandItem: function(li)
{
li.removeClass(this.options.collapsedClass);
li.children('[data-action="expand"]').hide();
li.children('[data-action="collapse"]').show();
li.children(this.options.listNodeName).show();
+ this.el.trigger('expand', [li]);
+ li.trigger('expand');
},
collapseItem: function(li)
{
var lists = li.children(this.options.listNodeName);
@@ -211,10 +264,12 @@
li.addClass(this.options.collapsedClass);
li.children('[data-action="collapse"]').hide();
li.children('[data-action="expand"]').show();
li.children(this.options.listNodeName).hide();
}
+ this.el.trigger('collapse', [li]);
+ li.trigger('collapse');
},
expandAll: function()
{
var list = this;
@@ -235,11 +290,16 @@
{
if (li.children(this.options.listNodeName).length) {
li.prepend($(this.options.expandBtnHTML));
li.prepend($(this.options.collapseBtnHTML));
}
- li.children('[data-action="expand"]').hide();
+ if( (' ' + li[0].className + ' ').indexOf(' ' + defaults.collapsedClass + ' ') > -1 )
+ {
+ li.children('[data-action="collapse"]').hide();
+ } else {
+ li.children('[data-action="expand"]').hide();
+ }
},
unsetParent: function(li)
{
li.removeClass(this.options.collapsedClass);
@@ -249,12 +309,16 @@
dragStart: function(e)
{
var mouse = this.mouse,
target = $(e.target),
- dragItem = target.closest(this.options.itemNodeName);
+ dragItem = target.closest('.' + this.options.handleClass).closest(this.options.itemNodeName);
+ this.sourceRoot = target.closest('.' + this.options.rootClass);
+
+ this.dragItem = dragItem;
+
this.placeEl.css('height', dragItem.height());
mouse.offsetX = e.offsetX !== undefined ? e.offsetX : e.pageX - target.offset().left;
mouse.offsetY = e.offsetY !== undefined ? e.offsetY : e.pageY - target.offset().top;
mouse.startX = mouse.lastX = e.pageX;
@@ -265,11 +329,15 @@
this.dragEl = $(document.createElement(this.options.listNodeName)).addClass(this.options.listClass + ' ' + this.options.dragClass);
this.dragEl.css('width', dragItem.width());
// fix for zepto.js
//dragItem.after(this.placeEl).detach().appendTo(this.dragEl);
- dragItem.after(this.placeEl);
+ if(this.options.cloneNodeOnDrag) {
+ dragItem.after(dragItem.clone());
+ } else {
+ dragItem.after(this.placeEl);
+ }
dragItem[0].parentNode.removeChild(dragItem[0]);
dragItem.appendTo(this.dragEl);
$(document.body).append(this.dragEl);
this.dragEl.css({
@@ -291,18 +359,82 @@
{
// fix for zepto.js
//this.placeEl.replaceWith(this.dragEl.children(this.options.itemNodeName + ':first').detach());
var el = this.dragEl.children(this.options.itemNodeName).first();
el[0].parentNode.removeChild(el[0]);
- this.placeEl.replaceWith(el);
- this.dragEl.remove();
- this.el.trigger('change');
- if (this.hasNewRoot) {
- this.dragRootEl.trigger('change');
+ if(this.isOutsideRoot && this.options.dragOutsideToDelete)
+ {
+ var parent = this.placeEl.parent();
+ this.placeEl.remove();
+ if (!parent.children().length) {
+ this.unsetParent(parent.parent());
+ }
+ // If all nodes where deleted, create a placeholder element.
+ if (!this.dragRootEl.find(this.options.itemNodeName).length)
+ {
+ this.dragRootEl.append('<div class="' + this.options.emptyClass + '"/>');
+ }
+ }
+ else
+ {
+ this.placeEl.replaceWith(el);
}
- this.reset();
+
+ if (!this.moving)
+ {
+ $(this.dragItem).trigger('click');
+ }
+
+ var i;
+ var isRejected = false;
+ for (i in this.options.reject)
+ {
+ var reject = this.options.reject[i];
+ if (reject.rule.apply(this.dragRootEl))
+ {
+ var nestableDragEl = el.clone(true);
+ this.dragRootEl.html(this.nestableCopy.children().clone(true));
+ if (reject.action) {
+ reject.action.apply(this.dragRootEl, [nestableDragEl]);
+ }
+
+ isRejected = true;
+ break;
+ }
+ }
+
+ if (!isRejected)
+ {
+ this.dragEl.remove();
+ this.el.trigger('change');
+
+ //Let's find out new parent id
+ var parentItem = el.parent().parent();
+ var parentId = null;
+ if(parentItem !== null && !parentItem.is('.' + this.options.rootClass))
+ parentId = parentItem.data('id');
+
+ if($.isFunction(this.options.dropCallback))
+ {
+ var details = {
+ sourceId : el.data('id'),
+ destId : parentId,
+ sourceEl : el,
+ destParent : parentItem,
+ destRoot : el.closest('.' + this.options.rootClass),
+ sourceRoot : this.sourceRoot
+ };
+ this.options.dropCallback.call(this, details);
+ }
+
+ if (this.hasNewRoot) {
+ this.dragRootEl.trigger('change');
+ }
+
+ this.reset();
+ }
},
dragMove: function(e)
{
var list, parent, prev, next, depth,
@@ -331,13 +463,13 @@
mouse.dirY = mouse.distY === 0 ? 0 : mouse.distY > 0 ? 1 : -1;
// axis mouse is now moving on
var newAx = Math.abs(mouse.distX) > Math.abs(mouse.distY) ? 1 : 0;
// do nothing on first move
- if (!mouse.moving) {
+ if (!this.moving) {
mouse.dirAx = newAx;
- mouse.moving = true;
+ this.moving = true;
return;
}
// calc distance moved on this axis (and direction)
if (mouse.dirAx !== newAx) {
@@ -361,11 +493,11 @@
if (mouse.dirAx && mouse.distAxX >= opt.threshold) {
// reset move distance on x-axis for new phase
mouse.distAxX = 0;
prev = this.placeEl.prev(opt.itemNodeName);
// increase horizontal level if previous sibling exists and is not collapsed
- if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass)) {
+ if (mouse.distX > 0 && prev.length && !prev.hasClass(opt.collapsedClass) && !prev.hasClass(opt.noChildrenClass)) {
// cannot increase level when item above is collapsed
list = prev.find(opt.listNodeName).last();
// check if depth limit has reached
depth = this.placeEl.parents(opt.listNodeName).length;
if (depth + this.dragDepth <= opt.maxDepth) {
@@ -400,28 +532,46 @@
// find list item under cursor
if (!hasPointerEvents) {
this.dragEl[0].style.visibility = 'hidden';
}
- this.pointEl = $(document.elementFromPoint(e.pageX - document.body.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
+
+ this.pointEl = $(document.elementFromPoint(e.pageX - document.documentElement.scrollLeft, e.pageY - (window.pageYOffset || document.documentElement.scrollTop)));
+
+ // Check if the node is dragged outside of its list.
+ if(this.dragRootEl.has(this.pointEl).length) {
+ this.isOutsideRoot = false;
+ this.dragEl[0].style.opacity = 1;
+ } else {
+ this.isOutsideRoot = true;
+ this.dragEl[0].style.opacity = 0.5;
+ }
+
+ // find parent list of item under cursor
+ var pointElRoot = this.pointEl.closest('.' + opt.rootClass),
+ isNewRoot = this.dragRootEl.data('nestable-id') !== pointElRoot.data('nestable-id');
+
+ this.isOutsideRoot = !pointElRoot.length;
+
if (!hasPointerEvents) {
this.dragEl[0].style.visibility = 'visible';
}
if (this.pointEl.hasClass(opt.handleClass)) {
- this.pointEl = this.pointEl.parent(opt.itemNodeName);
+ this.pointEl = this.pointEl.closest( opt.itemNodeName );
}
+
+ if (opt.maxDepth == 1 && !this.pointEl.hasClass(opt.itemClass)) {
+ this.pointEl = this.pointEl.closest("." + opt.itemClass);
+ }
+
if (this.pointEl.hasClass(opt.emptyClass)) {
isEmpty = true;
}
else if (!this.pointEl.length || !this.pointEl.hasClass(opt.itemClass)) {
return;
}
- // find parent list of item under cursor
- var pointElRoot = this.pointEl.closest('.' + opt.rootClass),
- isNewRoot = this.dragRootEl.data('nestable-id') !== pointElRoot.data('nestable-id');
-
/**
* move vertical
*/
if (!mouse.dirAx || isNewRoot || isEmpty) {
// check if groups match if dragging over new root
@@ -452,12 +602,12 @@
}
if (!this.dragRootEl.find(opt.itemNodeName).length) {
this.dragRootEl.append('<div class="' + opt.emptyClass + '"/>');
}
// parent root list has changed
+ this.dragRootEl = pointElRoot;
if (isNewRoot) {
- this.dragRootEl = pointElRoot;
this.hasNewRoot = this.el[0] !== this.dragRootEl[0];
}
}
}
@@ -466,17 +616,27 @@
$.fn.nestable = function(params)
{
var lists = this,
retval = this;
+ var generateUid = function (separator) {
+ var delim = separator || "-";
+
+ function S4() {
+ return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
+ }
+
+ return (S4() + S4() + delim + S4() + delim + S4() + delim + S4() + delim + S4() + S4() + S4());
+ };
+
lists.each(function()
{
var plugin = $(this).data("nestable");
if (!plugin) {
$(this).data("nestable", new Plugin(this, params));
- $(this).data("nestable-id", new Date().getTime());
+ $(this).data("nestable-id", generateUid());
} else {
if (typeof params === 'string' && typeof plugin[params] === 'function') {
retval = plugin[params]();
}
}
@@ -484,6 +644,6 @@
return retval || lists;
};
})(window.jQuery || window.Zepto, window, document);
-; TI"required_assets_digest; TI"%40cc35d603793a19ab43894280c8c22c; FI"
_version; TI"%01dc9d4cb5b0ece13ed47cc1cabfeb41; F
+; TI"required_assets_digest; TI"%a922d8c08948b73a3c04089360cf9ca0; FI"
_version; TI"%01dc9d4cb5b0ece13ed47cc1cabfeb41; F
\ No newline at end of file