aboutsummaryrefslogtreecommitdiffstats
path: root/public/assets/refinery/nestedsortables-f06a9d7e8817ff59ffcc30502aa2747b.js
blob: 33961e10f462bba03a31c3646af281c3634f70c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
/*
 * jQuery UI Nested Sortable
 * v 1.3.4 / 28 apr 2011
 * http://mjsarfatti.com/sandbox/nestedSortable
 *
 * Depends:
 *	 jquery.ui.sortable.js 1.8+
 *
 * License CC BY-SA 3.0
 * Copyright 2010-2011, Manuele J Sarfatti
 */
!function(c){c.widget("ui.nestedSortable",c.extend({},c.ui.sortable.prototype,{options:{tabSize:20,disableNesting:"ui-nestedSortable-no-nesting",errorClass:"ui-nestedSortable-error",listType:"ol",maxLevels:0,noJumpFix:0},_create:function(){return 0==this.noJumpFix&&this.element.height(this.element.height()),this.element.data("sortable",this.element.data("nestedSortable")),c.ui.sortable.prototype._create.apply(this,arguments)},_mouseDrag:function(t){if(this.position=this._generatePosition(t),this.positionAbs=this._convertPositionTo("absolute"),this.lastPositionAbs||(this.lastPositionAbs=this.positionAbs),this.options.scroll){var e=this.options,i=!1;this.scrollParent[0]!=document&&"HTML"!=this.scrollParent[0].tagName?(this.overflowOffset.top+this.scrollParent[0].offsetHeight-t.pageY<e.scrollSensitivity?this.scrollParent[0].scrollTop=i=this.scrollParent[0].scrollTop+e.scrollSpeed:t.pageY-this.overflowOffset.top<e.scrollSensitivity&&(this.scrollParent[0].scrollTop=i=this.scrollParent[0].scrollTop-e.scrollSpeed),this.overflowOffset.left+this.scrollParent[0].offsetWidth-t.pageX<e.scrollSensitivity?this.scrollParent[0].scrollLeft=i=this.scrollParent[0].scrollLeft+e.scrollSpeed:t.pageX-this.overflowOffset.left<e.scrollSensitivity&&(this.scrollParent[0].scrollLeft=i=this.scrollParent[0].scrollLeft-e.scrollSpeed)):(t.pageY-c(document).scrollTop()<e.scrollSensitivity?i=c(document).scrollTop(c(document).scrollTop()-e.scrollSpeed):c(window).height()-(t.pageY-c(document).scrollTop())<e.scrollSensitivity&&(i=c(document).scrollTop(c(document).scrollTop()+e.scrollSpeed)),t.pageX-c(document).scrollLeft()<e.scrollSensitivity?i=c(document).scrollLeft(c(document).scrollLeft()-e.scrollSpeed):c(window).width()-(t.pageX-c(document).scrollLeft())<e.scrollSensitivity&&(i=c(document).scrollLeft(c(document).scrollLeft()+e.scrollSpeed))),!1!==i&&c.ui.ddmanager&&!e.dropBehaviour&&c.ui.ddmanager.prepareOffsets(this,t)}this.positionAbs=this._convertPositionTo("absolute"),this.options.axis&&"y"==this.options.axis||(this.helper[0].style.left=this.position.left+"px"),this.options.axis&&"x"==this.options.axis||(this.helper[0].style.top=this.position.top+"px");for(var s=this.items.length-1;0<=s;s--){var o=this.items[s],l=o.item[0],r=this._intersectsWithPointer(o);if(r&&!(l==this.currentItem[0]||this.placeholder[1==r?"next":"prev"]()[0]==l||c.contains(this.placeholder[0],l)||"semi-dynamic"==this.options.type&&c.contains(this.element[0],l))){if(this.direction=1==r?"down":"up","pointer"!=this.options.tolerance&&!this._intersectsWithSides(o))break;this._rearrange(t,o),this._clearEmpty(l),this._trigger("change",t,this._uiHash());break}}var n=this.placeholder[0].parentNode.parentNode&&c(this.placeholder[0].parentNode.parentNode).closest(".ui-sortable").length?c(this.placeholder[0].parentNode.parentNode):null,h=this._getLevel(this.placeholder),a=this._getChildLevels(this.helper),p=this.placeholder[0].previousSibling?c(this.placeholder[0].previousSibling):null;if(null!=p)for(;"li"!=p[0].nodeName.toLowerCase()||p[0]==this.currentItem[0];){if(!p[0].previousSibling){p=null;break}p=c(p[0].previousSibling)}return newList=document.createElement(e.listType),this.beyondMaxLevels=0,null!=n&&this.positionAbs.left<n.offset().left?(n.after(this.placeholder[0]),this._clearEmpty(n[0]),this._trigger("change",t,this._uiHash())):null!=p&&this.positionAbs.left>p.offset().left+e.tabSize?(this._isAllowed(p,h+a+1),p.children(e.listType).length||p[0].appendChild(newList),p.children(e.listType)[0].appendChild(this.placeholder[0]),this._trigger("change",t,this._uiHash())):this._isAllowed(n,h+a),this._contactContainers(t),c.ui.ddmanager&&c.ui.ddmanager.drag(this,t),this._trigger("sort",t,this._uiHash()),this.lastPositionAbs=this.positionAbs,!1},_mouseStop:function(t){if(this.beyondMaxLevels){for(var e=this.placeholder.parent().closest(this.options.items),i=this.beyondMaxLevels-1;0<i;i--)e=e.parent().closest(this.options.items);this.placeholder.removeClass(this.options.errorClass),e.after(this.placeholder),this._trigger("change",t,this._uiHash())}c.ui.sortable.prototype._mouseStop.apply(this,arguments)},serialize:function(i){var t=this._getItemsAsjQuery(i&&i.connected),s=[];return i=i||{},c(t).each(function(){var t=(c(i.item||this).attr(i.attribute||"id")||"").match(i.expression||/(.+)[-=_](.+)/),e=(c(i.item||this).parent(i.listType).parent("li").attr(i.attribute||"id")||"").match(i.expression||/(.+)[-=_](.+)/);t&&s.push((i.key||t[1]+"["+(i.key&&i.expression?t[1]:t[2])+"]")+"="+(e?i.key&&i.expression?e[1]:e[2]:"root"))}),!s.length&&i.key&&s.push(i.key+"="),s.join("&")},toHierarchy:function(s){function o(t){var e=(c(t).attr(s.attribute||"id")||"").match(s.expression||/(.+)[-=_](.+)/);if(null!=e){var i={id:e[2]};return 0<c(t).children(s.listType).children("li").length&&(i.children=[],c(t).children(s.listType).children("li").each(function(){var t=o(c(this));i.children.push(t)})),i}}(s=s||{}).startDepthCount;var e=[];return c(this.element).children("li").each(function(){var t=o(c(this));e.push(t)}),e},toArray:function(s){function t(t,e){return t.left-e.left}function o(t,e,i){return right=i+1,0<c(t).children(s.listType).children("li").length&&(e++,c(t).children(s.listType).children("li").each(function(){right=o(c(this),e,right)}),e--),id=c(t).attr(s.attribute||"id").match(s.expression||/(.+)[-=_](.+)/),e===l+1?pid="root":(parentItem=c(t).parent(s.listType).parent("li").attr("id").match(s.expression||/(.+)[-=_](.+)/),pid=parentItem[2]),null!=id&&r.push({item_id:id[2],parent_id:pid,depth:e,left:i,right:right}),right+1}var l=(s=s||{}).startDepthCount||0,r=[],e=2;return r.push({item_id:"root",parent_id:"none",depth:l,left:"1",right:2*(c("li",this.element).length+1)}),c(this.element).children("li").each(function(){e=o(this,l+1,e)}),r=r.sort(t)},_clear:function(){c.ui.sortable.prototype._clear.apply(this,arguments);for(var t=this.items.length-1;0<=t;t--){var e=this.items[t].item[0];this._clearEmpty(e)}return!0},_clearEmpty:function(t){t.children[1]&&0==t.children[1].children.length&&t.removeChild(t.children[1])},_getLevel:function(t){var e=1;if(this.options.listType)for(var i=t.closest(this.options.listType);!i.is(".ui-sortable");)e++,i=i.parent().closest(this.options.listType);return e},_getChildLevels:function(t,i){var s=this,e=this.options,o=0;return i=i||0,c(t).children(e.listType).children(e.items).each(function(t,e){o=Math.max(s._getChildLevels(e,i+1),o)}),i?o+1:o},_isAllowed:function(t,e){var i=this.options;null!=t&&t.hasClass(i.disableNesting)?(this.placeholder.addClass(i.errorClass),i.maxLevels<e&&0!=i.maxLevels?this.beyondMaxLevels=e-i.maxLevels:this.beyondMaxLevels=1):i.maxLevels<e&&0!=i.maxLevels?(this.placeholder.addClass(i.errorClass),this.beyondMaxLevels=e-i.maxLevels):(this.placeholder.removeClass(i.errorClass),this.beyondMaxLevels=0)}})),c.ui.nestedSortable.prototype.options=c.extend({},c.ui.sortable.prototype.options,c.ui.nestedSortable.prototype.options)}(jQuery);