| 12 |
- //knockout-sortable 0.7.3 | (c) 2012 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
- (function(e){typeof define=="function"&&define.amd?define(["knockout","jquery","jquery.ui.sortable"],e):e(window.ko,jQuery)})(function(e,t,n){var r="ko_sortItem",i="ko_sortList",s="ko_parentList",o="ko_dragItem",u=e.utils.unwrapObservable,a=function(t,n){e.utils.arrayForEach(t,function(t){t.nodeType===1&&(e.utils.domData.set(t,r,n),e.utils.domData.set(t,s,e.utils.domData.get(t.parentNode,i)))})},f=function(t,n){var r={},i=u(t()),s;return i.data?(r[n]=i.data,r.name=i.template):r[n]=t(),e.utils.arrayForEach(["afterAdd","afterRender","as","beforeRemove","includeDestroyed","templateEngine","templateOptions"],function(t){r[t]=i[t]||e.bindingHandlers.sortable[t]}),n==="foreach"&&(r.afterRender?(s=r.afterRender,r.afterRender=function(e,t){a.call(t,e,t),s.call(t,e,t)}):r.afterRender=a),r};e.bindingHandlers.sortable={init:function(a,l,c,h,p){var d=t(a),v=u(l())||{},m=f(l,"foreach"),g={},y,b;e.utils.arrayForEach(a.childNodes,function(e){e&&e.nodeType===3&&e.parentNode.removeChild(e)}),t.extend(!0,g,e.bindingHandlers.sortable),v.options&&g.options&&(e.utils.extend(g.options,v.options),delete v.options),e.utils.extend(g,v),g.connectClass&&(e.isObservable(g.allowDrop)||typeof g.allowDrop=="function")?e.computed({read:function(){var t=u(g.allowDrop),n=typeof t=="function"?t.call(this,m.foreach):t;e.utils.toggleDomNodeCssClass(a,g.connectClass,n)},disposeWhenNodeIsRemoved:a},this):e.utils.toggleDomNodeCssClass(a,g.connectClass,g.allowDrop),e.bindingHandlers.template.init(a,function(){return m},c,h,p),y=g.options.start,b=g.options.update;var w=setTimeout(function(){var f;d.sortable(e.utils.extend(g.options,{start:function(e,t){t.item.find("input:focus").change(),y&&y.apply(this,arguments)},receive:function(t,n){f=e.utils.domData.get(n.item[0],o),f&&(f.clone&&(f=f.clone()),g.dragged&&(f=g.dragged.call(this,f,t,n)||f))},update:function(n,o){var a,l,c,h,p,d,v=o.item[0],y=o.item.parent()[0],w=e.utils.domData.get(v,r)||f;f=null;if(w&&(this===y||t.contains(this,y))){a=e.utils.domData.get(v,s),l=e.utils.domData.get(v.parentNode,i),c=e.utils.arrayIndexOf(o.item.parent().children(),v);if(!m.includeDestroyed){p=l();for(h=0;h<c;h++)p[h]&&u(p[h]._destroy)&&c++}if(g.beforeMove||g.afterMove)d={item:w,sourceParent:a,sourceParentNode:a&&o.sender||v.parentNode,sourceIndex:a&&a.indexOf(w),targetParent:l,targetIndex:c,cancelDrop:!1};if(g.beforeMove){g.beforeMove.call(this,d,n,o);if(d.cancelDrop){d.sourceParent?t(d.sourceParent===d.targetParent?this:o.sender).sortable("cancel"):t(v).remove();return}}c>=0&&(a&&(a.remove(w),e.processAllDeferredBindingUpdates&&e.processAllDeferredBindingUpdates()),l.splice(c,0,w)),e.utils.domData.set(v,r,null),o.item.remove(),e.processAllDeferredBindingUpdates&&e.processAllDeferredBindingUpdates(),g.afterMove&&g.afterMove.call(this,d,n,o)}b&&b.apply(this,arguments)},connectWith:g.connectClass?"."+g.connectClass:!1})),g.isEnabled!==n&&e.computed({read:function(){d.sortable(u(g.isEnabled)?"enable":"disable")},disposeWhenNodeIsRemoved:a})},0);return e.utils.domNodeDisposal.addDisposeCallback(a,function(){d.data("sortable")&&d.sortable("destroy"),clearTimeout(w)}),{controlsDescendantBindings:!0}},update:function(t,n,r,s,o){var u=f(n,"foreach");e.utils.domData.set(t,i,u.foreach),e.bindingHandlers.template.update(t,function(){return u},r,s,o)},connectClass:"ko_container",allowDrop:!0,afterMove:null,beforeMove:null,options:{}},e.bindingHandlers.draggable={init:function(r,i,s,a,l){var c=u(i())||{},h=c.options||{},p=e.utils.extend({},e.bindingHandlers.draggable.options),d=f(i,"data"),v=c.connectClass||e.bindingHandlers.draggable.connectClass,m=c.isEnabled!==n?c.isEnabled:e.bindingHandlers.draggable.isEnabled;return c=c.data||c,e.utils.domData.set(r,o,c),e.utils.extend(p,h),p.connectToSortable=v?"."+v:!1,t(r).draggable(p),m!==n&&e.computed({read:function(){t(r).draggable(u(m)?"enable":"disable")},disposeWhenNodeIsRemoved:r}),e.bindingHandlers.template.init(r,function(){return d},s,a,l)},update:function(t,n,r,i,s){var o=f(n,"data");return e.bindingHandlers.template.update(t,function(){return o},r,i,s)},connectClass:e.bindingHandlers.sortable.connectClass,options:{helper:"clone"}}})
|