From 0ffa616f100fb340944ccb38e8b6f85020e10c51 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 26 Dec 2014 09:20:11 +0300 Subject: [PATCH 001/594] #199: + check 'dataTransfer' exists --- Sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 5d104758a..44a02e59f 100644 --- a/Sortable.js +++ b/Sortable.js @@ -372,8 +372,10 @@ this._loopId = setInterval(this._emulateDragOver, 150); } else { - dataTransfer.effectAllowed = 'move'; - options.setData && options.setData.call(this, dataTransfer, dragEl); + if (dataTransfer) { + dataTransfer.effectAllowed = 'move'; + options.setData && options.setData.call(this, dataTransfer, dragEl); + } _on(document, 'drop', this); } From bb09bb423a47bea27e23e9e5b1bea44197dfd9ac Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 26 Dec 2014 09:30:37 +0300 Subject: [PATCH 002/594] #195: + amd --- ng-sortable.js | 212 ++++++++++++++++++++++++++----------------------- 1 file changed, 111 insertions(+), 101 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 12b93888e..ce4083f9b 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -2,119 +2,129 @@ * @author RubaXa * @licence MIT */ -angular.module('ng-sortable', []) - .constant('$version', '0.3.2') - .directive('ngSortable', ['$parse', function ($parse) { - 'use strict'; - - var removed; - - function getSource(el) { - var scope = angular.element(el).scope(); - var ngRepeat = [].filter.call(el.childNodes, function (node) { - return ( - (node.nodeType === 8) && - (node.nodeValue.indexOf('ngRepeat:') !== -1) - ); - })[0]; - ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([^\s]+)\s+in\s+([^\s|]+)/); - - var itemExpr = $parse(ngRepeat[1]); - var itemsExpr = $parse(ngRepeat[2]); - - return { - item: function (el) { - return itemExpr(angular.element(el).scope()); - }, - items: function () { - return itemsExpr(scope); - } - }; - } - +(function (factory) { + 'use strict'; + + if (window.angular && window.Sortable) { + factory(angular, Sortable); + } + else if (typeof define === 'function' && define.amd) { + define(['angular', 'sortable'], factory); + } +})(function (angular, Sortable) { + 'use strict'; + + angular.module('ng-sortable', []) + .constant('$version', '0.3.2') + .directive('ngSortable', ['$parse', function ($parse) { + var removed; + + function getSource(el) { + var scope = angular.element(el).scope(); + var ngRepeat = [].filter.call(el.childNodes, function (node) { + return ( + (node.nodeType === 8) && + (node.nodeValue.indexOf('ngRepeat:') !== -1) + ); + })[0]; + ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*([^\s]+)\s+in\s+([^\s|]+)/); + + var itemExpr = $parse(ngRepeat[1]); + var itemsExpr = $parse(ngRepeat[2]); + + return { + item: function (el) { + return itemExpr(angular.element(el).scope()); + }, + items: function () { + return itemsExpr(scope); + } + }; + } - // Export - return { - restrict: 'AC', - link: function (scope, $el, attrs) { - var el = $el[0], - ngSortable = attrs.ngSortable, - options = scope.$eval(ngSortable) || {}, - source = getSource(el), - sortable - ; + // Export + return { + restrict: 'AC', + link: function (scope, $el, attrs) { + var el = $el[0], + ngSortable = attrs.ngSortable, + options = scope.$eval(ngSortable) || {}, + source = getSource(el), + sortable + ; + + + 'Start End Add Update Remove Sort'.split(' ').forEach(function (name) { + options['on' + name] = options['on' + name] || function () {}; + }); - 'Start End Add Update Remove Sort'.split(' ').forEach(function (name) { - options['on' + name] = options['on' + name] || function () {}; - }); + function _sync(evt) { + var oldIndex = evt.oldIndex, + newIndex = evt.newIndex, + items = source.items(); - function _sync(evt) { - var oldIndex = evt.oldIndex, - newIndex = evt.newIndex, - items = source.items(); + if (el !== evt.from) { + var prevSource = getSource(evt.from), + prevItems = prevSource.items(); - if (el !== evt.from) { - var prevSource = getSource(evt.from), - prevItems = prevSource.items(); + oldIndex = prevItems.indexOf(prevSource.item(evt.item)); + removed = prevItems.splice(oldIndex, 1)[0]; - oldIndex = prevItems.indexOf(prevSource.item(evt.item)); - removed = prevItems.splice(oldIndex, 1)[0]; + items.splice(newIndex, 0, removed); - items.splice(newIndex, 0, removed); + evt.from.appendChild(evt.item); // revert element + } else { + items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); + } - evt.from.appendChild(evt.item); // revert element - } else { - items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); + scope.$apply(); } - scope.$apply(); - } + sortable = Sortable.create(el, Object.keys(options).reduce(function (opts, name) { + opts[name] = opts[name] || options[name]; + return opts; + }, { + onStart: function () { + options.onStart(source.items()); + }, + onEnd: function () { + options.onEnd(source.items()); + }, + onAdd: function (evt) { + _sync(evt); + options.onAdd(source.items(), removed); + }, + onUpdate: function (evt) { + _sync(evt); + options.onUpdate(source.items(), source.item(evt.item)); + }, + onRemove: function () { + options.onRemove(source.items(), removed); + }, + onSort: function () { + options.onSort(source.items()); + } + })); + + $el.on('$destroy', function () { + sortable.destroy(); + sortable = null; + }); - sortable = Sortable.create(el, Object.keys(options).reduce(function (opts, name) { - opts[name] = opts[name] || options[name]; - return opts; - }, { - onStart: function () { - options.onStart(source.items()); - }, - onEnd: function () { - options.onEnd(source.items()); - }, - onAdd: function (evt) { - _sync(evt); - options.onAdd(source.items(), removed); - }, - onUpdate: function (evt) { - _sync(evt); - options.onUpdate(source.items(), source.item(evt.item)); - }, - onRemove: function () { - options.onRemove(source.items(), removed); - }, - onSort: function () { - options.onSort(source.items()); - } - })); - - $el.on('$destroy', function () { - sortable.destroy(); - sortable = null; - }); - - if (!/{|}/.test(ngSortable)) { // todo: ugly - angular.forEach(['sort', 'disabled', 'draggable', 'handle', 'animation'], function (name) { - scope.$watch(ngSortable + '.' + name, function (value) { - if (value !== void 0) { - options[name] = value; - sortable.option(name, value); - } + if (!/{|}/.test(ngSortable)) { // todo: ugly + angular.forEach(['sort', 'disabled', 'draggable', 'handle', 'animation'], function (name) { + scope.$watch(ngSortable + '.' + name, function (value) { + if (value !== void 0) { + options[name] = value; + sortable.option(name, value); + } + }); }); - }); + } } - } - }; - }]) -; + }; + }]); +}); From ed5a636238a48d9297d54db523257733e46dd660 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 31 Dec 2014 14:47:25 +0300 Subject: [PATCH 003/594] * code style --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index ce4083f9b..3c3a8958e 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -126,5 +126,5 @@ } } }; - }]); + }]); }); From 0d162a016a1ead5af3edd6efdd0305809812ede7 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 31 Dec 2014 14:48:11 +0300 Subject: [PATCH 004/594] #151: + jquery binding --- .gitignore | 1 + Gruntfile.js | 20 ++++++++++++++++- README.md | 31 ++++++++++++++++++++++++-- Sortable.min.js | 2 +- jquery.binding.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 jquery.binding.js diff --git a/.gitignore b/.gitignore index 115f20ffc..883687b7e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules mock.png .*.sw* .build* +jquery.fn.sortable.js diff --git a/Gruntfile.js b/Gruntfile.js index 64cfc702f..f7ac7e62b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -34,8 +34,26 @@ module.exports = function (grunt) { 'meteor-publish': { command: 'meteor/publish.sh' } - } + }, + + jquery: {} + }); + + + grunt.registerTask('jquery', function () { + var fs = require('fs'), + filename = 'jquery.fn.sortable.js'; + + grunt.log.oklns(filename); + fs.writeFileSync( + filename, + (fs.readFileSync('jquery.binding.js') + '') + .replace('/* CODE */', + (fs.readFileSync('Sortable.js') + '') + .replace(/^[\s\S]*?function[\s\S]*?(var[\s\S]+)\/\/\s+Export[\s\S]+/, '$1') + ) + ); }); diff --git a/README.md b/README.md index c84cfc56d..99694437a 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Demo: http://rubaxa.github.io/Sortable/ * Supports [Meteor](meteor/README.md) and [AngularJS](#ng) * Supports any CSS library, e.g. [Bootstrap](#bs) * Simple API - * No jQuery + * No jQuery (but there is [support](#jq)) ### Usage @@ -428,9 +428,36 @@ Link to the active instance. --- + +### jQuery compatibility +To assemble plugin for jQuery, perform the following steps: + +```bash + cd Sortable + npm install + grunt jquery +``` + +Now you can use `jquery.fn.sortable.js`: + +```js + $("#list").sortable({ /* options */ }); // init + + $("#list").sortable("widget"); // get Sortable instance + + $("#list").sortable("destroy"); // destroy Sortable instance + + $("#list").sortable("{method-name}"); // call an instance method + + $("#list").sortable("{method-name}", "foo", "bar"); // call an instance method with parameters +``` + + +--- + ## MIT LICENSE -Copyright 2013-2014 Lebedev Konstantin +Copyright 2013-2015 Lebedev Konstantin http://rubaxa.github.io/Sortable/ Permission is hereby granted, free of charge, to any person obtaining diff --git a/Sortable.min.js b/Sortable.min.js index eec3f1dc9..9b1248744 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.0.0 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)}};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),K.forEach(function(d){b[d]=c(this,b[d]||L),f(a,d.substr(2).toLowerCase(),b[d])},this),a[D]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),H&&f(a,"selectstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),O.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,q),t.state=a)}function c(a,b){var c=N.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(N.call(arguments)))}}function d(a,b,c){if(a){c=c||F,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return F.defaultView&&F.defaultView.getComputedStyle?c=F.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){I=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling)&&"TEMPLATE"!==a.nodeName;)b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C={},D="Sortable"+(new Date).getTime(),E=window,F=E.document,G=E.parseInt,H=!!F.createElement("div").dragDrop,I=!1,J=function(a,b,c,d,e,f){var g=F.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},K="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),L=function(){},M=Math.abs,N=[].slice,O=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,J(u,"start",q,u,r)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,l=this.el,m=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,l)),e=d(e,h.draggable,l),r=o(e),"function"==typeof m){if(m.call(this,a,e,this))return J(g,"filter",e,l,r),a.preventDefault(),void 0}else if(m&&(m=m.split(",").some(function(a){return a=d(g,a.trim(),l),a?(J(a,"filter",e,l,r),!0):void 0})))return a.preventDefault(),void 0;if(e&&!q&&e.parentNode===l){"selectstart"===b&&e.dragDrop(),A=a,u=this.el,q=e,w=q.nextSibling,z=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(A={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(A,!0),a.preventDefault()),f(F,"mouseup",this._onDrop),f(F,"touchend",this._onDrop),f(F,"touchcancel",this._onDrop),f(q,"dragend",this),f(u,"dragstart",this._onDragStart),f(F,"dragover",this);try{F.selection?F.selection.empty():window.getSelection().removeAllRanges()}catch(n){}"clone"==z.pull&&(t=q.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,q))}}},_emulateDragOver:function(){if(B){i(s,"display","none");var a=F.elementFromPoint(B.clientX,B.clientY),b=a,c=this.options.group.name,d=O.length;if(b)do{if((" "+b[D]+" ").indexOf(c)>-1){for(;d--;)O[d]({clientX:B.clientX,clientY:B.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(A){var b=a.touches[0],c=b.clientX-A.clientX,d=b.clientY-A.clientY,e="translate3d("+c+"px,"+d+"px,0)";B=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),b){var e,g=q.getBoundingClientRect(),h=i(q);s=q.cloneNode(!0),i(s,"top",g.top-G(h.marginTop,10)),i(s,"left",g.left-G(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),f(F,"touchmove",this._onTouchMove),f(F,"touchend",this._onDrop),f(F,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c.effectAllowed="move",d.setData&&d.setData.call(this,c,q),f(F,"drop",this);if(v=d.scroll,v===!0){v=u;do if(v.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=E:v&&(b=v,c=v.getBoundingClientRect(),k=(M(c.right-g)<=e)-(M(c.left-g)<=e),l=(M(c.bottom-h)<=e)-(M(c.top-h)<=e)),(C.vx!==k||C.vy!==l||C.el!==b)&&(C.el=b,C.vx=k,C.vy=l,clearInterval(C.pid),b&&(C.pid=setInterval(function(){b===E?E.scrollTo(E.scrollX+k*f,E.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=z===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),a.stopPropagation()),!I&&z&&(n?o||(f=!u.contains(q)):z.pull&&k&&(z.name===j.name||k.indexOf&&~k.indexOf(z.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),t||w?u.insertBefore(q,t||w):o||u.appendChild(q),void 0;if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;r=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(r,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[D]){x!==c&&(x=c,y=i(c));var p,r=c.getBoundingClientRect(),v=r.right-r.left,A=r.bottom-r.top,B=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,E=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-r.left)/v:(a.clientY-r.top)/A)>.5,G=c.nextElementSibling;I=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!E||F&&E,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(r,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(F,"mouseup",this._onDrop),g(F,"touchmove",this._onTouchMove),g(F,"touchend",this._onDrop),g(F,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el;if(clearInterval(this._loopId),clearInterval(C.pid),g(F,"drop",this),g(F,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b){if(b.preventDefault(),b.stopPropagation(),s&&s.parentNode.removeChild(s),q){g(q,"dragend",this);var d=o(q);k(q),h(q,this.options.ghostClass,!1),u!==q.parentNode?(J(q.parentNode,"sort",q,u,r,d),J(u,"sort",q,u,r,d),J(q,"add",q,u,r,d),J(u,"remove",q,u,r,d)):q.nextSibling!==w&&(J(u,"update",q,u,r,d),J(u,"sort",q,u,r,d),t&&t.parentNode.removeChild(t)),a.active&&J(u,"end",q,u,r,d)}u=q=s=w=t=A=B=x=y=z=a.active=null,this.save()}},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void 0)},destroy:function(){var a=this.el,b=this.options;K.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"selectstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),O.splice(O.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:J,index:o},a.version="1.0.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)}};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),K.forEach(function(d){b[d]=c(this,b[d]||L),f(a,d.substr(2).toLowerCase(),b[d])},this),a[D]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),H&&f(a,"selectstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),O.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,q),t.state=a)}function c(a,b){var c=N.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(N.call(arguments)))}}function d(a,b,c){if(a){c=c||F,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return F.defaultView&&F.defaultView.getComputedStyle?c=F.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){I=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling)&&"TEMPLATE"!==a.nodeName;)b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C={},D="Sortable"+(new Date).getTime(),E=window,F=E.document,G=E.parseInt,H=!!F.createElement("div").dragDrop,I=!1,J=function(a,b,c,d,e,f){var g=F.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},K="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),L=function(){},M=Math.abs,N=[].slice,O=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,J(u,"start",q,u,r)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,l=this.el,m=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,l)),e=d(e,h.draggable,l),r=o(e),"function"==typeof m){if(m.call(this,a,e,this))return J(g,"filter",e,l,r),void a.preventDefault()}else if(m&&(m=m.split(",").some(function(a){return a=d(g,a.trim(),l),a?(J(a,"filter",e,l,r),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===l){"selectstart"===b&&e.dragDrop(),A=a,u=this.el,q=e,w=q.nextSibling,z=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(A={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(A,!0),a.preventDefault()),f(F,"mouseup",this._onDrop),f(F,"touchend",this._onDrop),f(F,"touchcancel",this._onDrop),f(q,"dragend",this),f(u,"dragstart",this._onDragStart),f(F,"dragover",this);try{F.selection?F.selection.empty():window.getSelection().removeAllRanges()}catch(n){}"clone"==z.pull&&(t=q.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,q))}}},_emulateDragOver:function(){if(B){i(s,"display","none");var a=F.elementFromPoint(B.clientX,B.clientY),b=a,c=this.options.group.name,d=O.length;if(b)do{if((" "+b[D]+" ").indexOf(c)>-1){for(;d--;)O[d]({clientX:B.clientX,clientY:B.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(A){var b=a.touches[0],c=b.clientX-A.clientX,d=b.clientY-A.clientY,e="translate3d("+c+"px,"+d+"px,0)";B=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),b){var e,g=q.getBoundingClientRect(),h=i(q);s=q.cloneNode(!0),i(s,"top",g.top-G(h.marginTop,10)),i(s,"left",g.left-G(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),f(F,"touchmove",this._onTouchMove),f(F,"touchend",this._onDrop),f(F,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(F,"drop",this);if(v=d.scroll,v===!0){v=u;do if(v.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=E:v&&(b=v,c=v.getBoundingClientRect(),k=(M(c.right-g)<=e)-(M(c.left-g)<=e),l=(M(c.bottom-h)<=e)-(M(c.top-h)<=e)),(C.vx!==k||C.vy!==l||C.el!==b)&&(C.el=b,C.vx=k,C.vy=l,clearInterval(C.pid),b&&(C.pid=setInterval(function(){b===E?E.scrollTo(E.scrollX+k*f,E.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=z===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),a.stopPropagation()),!I&&z&&(n?o||(f=!u.contains(q)):z.pull&&k&&(z.name===j.name||k.indexOf&&~k.indexOf(z.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(t||w?u.insertBefore(q,t||w):o||u.appendChild(q));if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;r=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(r,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[D]){x!==c&&(x=c,y=i(c));var p,r=c.getBoundingClientRect(),v=r.right-r.left,A=r.bottom-r.top,B=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,E=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-r.left)/v:(a.clientY-r.top)/A)>.5,G=c.nextElementSibling;I=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!E||F&&E,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(r,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(F,"mouseup",this._onDrop),g(F,"touchmove",this._onTouchMove),g(F,"touchend",this._onDrop),g(F,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el;if(clearInterval(this._loopId),clearInterval(C.pid),g(F,"drop",this),g(F,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b){if(b.preventDefault(),b.stopPropagation(),s&&s.parentNode.removeChild(s),q){g(q,"dragend",this);var d=o(q);k(q),h(q,this.options.ghostClass,!1),u!==q.parentNode?(J(q.parentNode,"sort",q,u,r,d),J(u,"sort",q,u,r,d),J(q,"add",q,u,r,d),J(u,"remove",q,u,r,d)):q.nextSibling!==w&&(J(u,"update",q,u,r,d),J(u,"sort",q,u,r,d),t&&t.parentNode.removeChild(t)),a.active&&J(u,"end",q,u,r,d)}u=q=s=w=t=A=B=x=y=z=a.active=null,this.save()}},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;K.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"selectstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),O.splice(O.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:J,index:o},a.version="1.0.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/jquery.binding.js b/jquery.binding.js new file mode 100644 index 000000000..16d7729b4 --- /dev/null +++ b/jquery.binding.js @@ -0,0 +1,57 @@ +/** + * jQuery plugin for Sortable + * @author RubaXa + * @license MIT + */ +(function (factory) { + "use strict"; + + if (typeof define === "function" && define.amd) { + define(["jquery"], factory); + } + else { + /* jshint sub:true */ + factory(jQuery); + } +})(function ($) { + "use strict"; + + + /* CODE */ + + + /** + * jQuery plugin for Sortable + * @param {Object|String} options + * @param {..*} [args] + * @returns {jQuery|*} + */ + $.fn.sortable = function (options) { + var retVal; + + this.each(function () { + var $el = $(this), + sortable = $el.data('sortable'); + + if (!sortable && (options instanceof Object || !options)) { + sortable = new Sortable(this, options); + $el.data('sortable', sortable); + } + + if (sortable) { + if (options === 'widget') { + return sortable; + } + else if (options === 'destroy') { + sortable.destroy(); + $el.removeData('sortable'); + } + else if (options in sortable) { + retVal = sortable[sortable].apply(sortable, [].slice.call(arguments, 1)); + } + } + }); + + return (retVal === void 0) ? this : retVal; + }; +}); From 1e499042bd24eb8b00048011372868cd2689c8ed Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 31 Dec 2014 16:55:12 +0300 Subject: [PATCH 005/594] #151: + grunt jquery:min --- .gitignore | 2 +- Gruntfile.js | 13 +++++++++++-- README.md | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 883687b7e..434cfa9b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ node_modules mock.png .*.sw* .build* -jquery.fn.sortable.js +jquery.fn.* diff --git a/Gruntfile.js b/Gruntfile.js index f7ac7e62b..0f1db6c34 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -24,6 +24,11 @@ module.exports = function (grunt) { files: { '<%= pkg.exportName %>.min.js': ['<%= pkg.exportName %>.js'] } + }, + jquery: { + files: { + 'jquery.fn.sortable.min.js': 'jquery.fn.sortable.js' + } } }, @@ -40,7 +45,7 @@ module.exports = function (grunt) { }); - grunt.registerTask('jquery', function () { + grunt.registerTask('jquery', function (arg) { var fs = require('fs'), filename = 'jquery.fn.sortable.js'; @@ -54,6 +59,10 @@ module.exports = function (grunt) { .replace(/^[\s\S]*?function[\s\S]*?(var[\s\S]+)\/\/\s+Export[\s\S]+/, '$1') ) ); + + if (arg === 'min') { + grunt.task.run('uglify:jquery'); + } }); @@ -68,5 +77,5 @@ module.exports = function (grunt) { grunt.registerTask('meteor', ['meteor-test', 'meteor-publish']); grunt.registerTask('tests', ['jshint']); - grunt.registerTask('default', ['tests', 'version', 'uglify']); + grunt.registerTask('default', ['tests', 'version', 'uglify:dist']); }; diff --git a/README.md b/README.md index 99694437a..46b68c879 100644 --- a/README.md +++ b/README.md @@ -438,7 +438,7 @@ To assemble plugin for jQuery, perform the following steps: grunt jquery ``` -Now you can use `jquery.fn.sortable.js`: +Now you can use `jquery.fn.sortable.js` (or `jquery.fn.sortable.min.js` if you run `grunt jquery:min`): ```js $("#list").sortable({ /* options */ }); // init From dabcb26cc12bb6a42091b7e985b8fe3c55394db9 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 31 Dec 2014 17:00:59 +0300 Subject: [PATCH 006/594] + br --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 46b68c879..c109fef22 100644 --- a/README.md +++ b/README.md @@ -438,7 +438,8 @@ To assemble plugin for jQuery, perform the following steps: grunt jquery ``` -Now you can use `jquery.fn.sortable.js` (or `jquery.fn.sortable.min.js` if you run `grunt jquery:min`): +Now you can use `jquery.fn.sortable.js`:
+(or `jquery.fn.sortable.min.js` if you run `grunt jquery:min`) ```js $("#list").sortable({ /* options */ }); // init From 75d95c4439c5131f0023ef32ae590abbe1a446f4 Mon Sep 17 00:00:00 2001 From: David Burles Date: Thu, 8 Jan 2015 16:33:04 +1100 Subject: [PATCH 007/594] fixes conflict with collection-helpers package update mongo-collection-instances to 0.2.6 --- meteor/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/package.js b/meteor/package.js index 823a0ac2a..148561aea 100644 --- a/meteor/package.js +++ b/meteor/package.js @@ -16,7 +16,7 @@ Package.describe({ Package.onUse(function (api) { api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.use('templating', 'client'); - api.use('dburles:mongo-collection-instances@0.2.5'); // to watch collections getting created + api.use('dburles:mongo-collection-instances@0.2.6'); // to watch collections getting created api.export('Sortable'); api.addFiles([ 'Sortable.js', From a5532380f9956b13b969ede386c85e568ba26a30 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 10 Jan 2015 20:19:41 +0300 Subject: [PATCH 008/594] #205: * support 'clone' for angular --- Sortable.js | 1 + ng-sortable.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 44a02e59f..0360f400c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -57,6 +57,7 @@ evt.item = targetEl || rootEl; evt.from = fromEl || rootEl; + evt.clone = cloneEl; evt.oldIndex = startIndex; evt.newIndex = newIndex; diff --git a/ng-sortable.js b/ng-sortable.js index 3c3a8958e..f7f3c8d27 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -74,6 +74,13 @@ items.splice(newIndex, 0, removed); + if (evt.clone) { + newIndex = Sortable.utils.index(evt.clone); + prevItems.splice(newIndex, 0, removed); + + evt.from.removeChild(evt.clone); + } + evt.from.appendChild(evt.item); // revert element } else { items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); @@ -114,7 +121,7 @@ sortable = null; }); - if (!/{|}/.test(ngSortable)) { // todo: ugly + if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly angular.forEach(['sort', 'disabled', 'draggable', 'handle', 'animation'], function (name) { scope.$watch(ngSortable + '.' + name, function (value) { if (value !== void 0) { From 3f909d84df4dcbc5e82367d7cde65536117f4660 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 10 Jan 2015 21:15:37 +0300 Subject: [PATCH 009/594] #207: * newIndex --- Sortable.js | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/Sortable.js b/Sortable.js index 0360f400c..b59986d04 100644 --- a/Sortable.js +++ b/Sortable.js @@ -25,7 +25,6 @@ "use strict"; var dragEl, - startIndex, ghostEl, cloneEl, rootEl, @@ -35,6 +34,9 @@ lastEl, lastCSS, + oldIndex, + newIndex, + activeGroup, autoScroll = {}, @@ -173,7 +175,7 @@ Sortable.active = this; // Drag start event - _dispatchEvent(rootEl, 'start', dragEl, rootEl, startIndex); + _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); }, @@ -197,12 +199,12 @@ target = _closest(target, options.draggable, el); // get the index of the dragged element within its parent - startIndex = _index(target); + oldIndex = _index(target); // Check filter if (typeof filter === 'function') { if (filter.call(this, evt, target, this)) { - _dispatchEvent(originalTarget, 'filter', target, el, startIndex); + _dispatchEvent(originalTarget, 'filter', target, el, oldIndex); evt.preventDefault(); return; // cancel dnd } @@ -212,7 +214,7 @@ criteria = _closest(originalTarget, criteria.trim(), el); if (criteria) { - _dispatchEvent(criteria, 'filter', target, el, startIndex); + _dispatchEvent(criteria, 'filter', target, el, oldIndex); return true; } }); @@ -606,33 +608,36 @@ if (dragEl) { _off(dragEl, 'dragend', this); - // get the index of the dragged element within its parent - var newIndex = _index(dragEl); - _disableDraggable(dragEl); _toggleClass(dragEl, this.options.ghostClass, false); if (rootEl !== dragEl.parentNode) { + newIndex = _index(dragEl); + // drag from one list and drop into another - _dispatchEvent(dragEl.parentNode, 'sort', dragEl, rootEl, startIndex, newIndex); - _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex); + _dispatchEvent(dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); // Add event - _dispatchEvent(dragEl, 'add', dragEl, rootEl, startIndex, newIndex); + _dispatchEvent(dragEl, 'add', dragEl, rootEl, oldIndex, newIndex); // Remove event - _dispatchEvent(rootEl, 'remove', dragEl, rootEl, startIndex, newIndex); + _dispatchEvent(rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); } else if (dragEl.nextSibling !== nextEl) { - // drag & drop within the same list - _dispatchEvent(rootEl, 'update', dragEl, rootEl, startIndex, newIndex); - _dispatchEvent(rootEl, 'sort', dragEl, rootEl, startIndex, newIndex); - + // (1) Remove clone cloneEl && cloneEl.parentNode.removeChild(cloneEl); + + // (2) Get the index of the dragged element within its parent + newIndex = _index(dragEl); + + // drag & drop within the same list + _dispatchEvent(rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); } // Drag end event - Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, startIndex, newIndex); + Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); } // Set NULL From 1812232e6a1b206839d97b540aedc7cd67d2616a Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 12 Jan 2015 18:50:21 +0300 Subject: [PATCH 010/594] + app.js; + comments --- index.html | 201 ++++------------------------------------------------- st/app.css | 6 ++ st/app.js | 186 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 205 insertions(+), 188 deletions(-) create mode 100644 st/app.js diff --git a/index.html b/index.html index 0f056b694..15f14c210 100644 --- a/index.html +++ b/index.html @@ -28,6 +28,7 @@

The JavaScript library for modern browser +
List A
@@ -55,6 +56,7 @@

The JavaScript library for modern browser

+
@@ -91,6 +93,7 @@

The JavaScript library for modern browser

+
@@ -109,6 +112,7 @@

The JavaScript library for modern browser

+
@@ -146,6 +150,7 @@

The JavaScript library for modern browser

+
@@ -164,6 +169,7 @@

The JavaScript library for modern browser

+
@@ -204,27 +210,27 @@

The JavaScript library for modern browser

- +
Code example
// Simple list
 var list = document.getElementById("my-ui-list");
-new Sortable(list); // That's all.
+Sortable.create(list); // That's all.
 
 
 // Grouping
 var foo = document.getElementById("foo");
-new Sortable(foo, { group: "omega" });
+Sortable.create(foo, { group: "omega" });
 
 var bar = document.getElementById("bar");
-new Sortable(bar, { group: "omega" });
+Sortable.create(bar, { group: "omega" });
 
 
 // Or
 var container = document.getElementById("multi");
-var sort = new Sortable(container, {
+var sort = Sortable.create(container, {
   animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
   handle: ".tile__title", // Restricts sort start click/touch to the specified element
   draggable: ".tile", // Specifies which items inside the element should be sortable
@@ -238,7 +244,7 @@ 

The JavaScript library for modern browser // Editable list -var editableList = new Sortable(editable, { +var editableList = Sortable.create(editable, { filter: '.js-remove', onFilter: function (evt) { var el = editableList.closest(evt.item); // get dragged item @@ -265,188 +271,7 @@

The JavaScript library for modern browser - + diff --git a/st/app.css b/st/app.css index 4dbbb8bdc..51cfbc1da 100644 --- a/st/app.css +++ b/st/app.css @@ -230,3 +230,9 @@ img { font-family: 'Roboto', sans-serif; font-weight: 300; } + + + +#nested ul li { + background-color: rgba(0,0,0,.05); +} diff --git a/st/app.js b/st/app.js new file mode 100644 index 000000000..109c70b3f --- /dev/null +++ b/st/app.js @@ -0,0 +1,186 @@ +(function () { + var byId = function (id) { return document.getElementById(id); }, + console = window.console; + + + if (!console.log) { + console.log = function () { + alert([].join.apply(arguments, ' ')); + }; + } + + + Sortable.create(byId('foo'), { + group: "words", + animation: 150, + store: { + get: function (sortable) { + var order = localStorage.getItem(sortable.options.group); + return order ? order.split('|') : []; + }, + set: function (sortable) { + var order = sortable.toArray(); + localStorage.setItem(sortable.options.group, order.join('|')); + } + }, + onAdd: function (evt){ console.log('onAdd.foo:', [evt.item, evt.from]); }, + onUpdate: function (evt){ console.log('onUpdate.foo:', [evt.item, evt.from]); }, + onRemove: function (evt){ console.log('onRemove.foo:', [evt.item, evt.from]); }, + onStart:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);}, + onSort:function(evt){ console.log('onStart.foo:', [evt.item, evt.from]);}, + onEnd: function(evt){ console.log('onEnd.foo:', [evt.item, evt.from]);} + }); + + + Sortable.create(byId('bar'), { + group: "words", + animation: 150, + onAdd: function (evt){ console.log('onAdd.bar:', evt.item); }, + onUpdate: function (evt){ console.log('onUpdate.bar:', evt.item); }, + onRemove: function (evt){ console.log('onRemove.bar:', evt.item); }, + onStart:function(evt){ console.log('onStart.foo:', evt.item);}, + onEnd: function(evt){ console.log('onEnd.foo:', evt.item);} + }); + + + // Multi groups + Sortable.create(byId('multi'), { + animation: 150, + draggable: '.tile', + handle: '.tile__name' + }); + + [].forEach.call(byId('multi').getElementsByClassName('tile__list'), function (el){ + Sortable.create(el, { + group: 'photo', + animation: 150 + }); + }); + + + // Editable list + var editableList = Sortable.create(byId('editable'), { + animation: 150, + filter: '.js-remove', + onFilter: function (evt) { + evt.item.parentNode.removeChild(evt.item); + } + }); + + + byId('addUser').onclick = function () { + Ply.dialog('prompt', { + title: 'Add', + form: { name: 'name' } + }).done(function (ui) { + var el = document.createElement('li'); + el.innerHTML = ui.data.name + ''; + editableList.el.appendChild(el); + }); + }; + + + // Advanced groups + [{ + name: 'advanced', + pull: true, + put: true + }, + { + name: 'advanced', + pull: 'clone', + put: false + }, { + name: 'advanced', + pull: false, + put: true + }].forEach(function (groupOpts, i) { + Sortable.create(byId('advanced-' + (i + 1)), { + sort: (i != 1), + group: groupOpts, + animation: 150 + }); + }); + + + // 'handle' option + Sortable.create(byId('handle-1'), { + handle: '.drag-handle', + animation: 150 + }); + + + // Angular example + angular.module('todoApp', ['ng-sortable']) + .controller('TodoController', ['$scope', function ($scope) { + $scope.todos = [ + {text: 'learn angular', done: true}, + {text: 'build an angular app', done: false} + ]; + + $scope.addTodo = function () { + $scope.todos.push({text: $scope.todoText, done: false}); + $scope.todoText = ''; + }; + + $scope.remaining = function () { + var count = 0; + angular.forEach($scope.todos, function (todo) { + count += todo.done ? 0 : 1; + }); + return count; + }; + + $scope.archive = function () { + var oldTodos = $scope.todos; + $scope.todos = []; + angular.forEach(oldTodos, function (todo) { + if (!todo.done) $scope.todos.push(todo); + }); + }; + }]) + .controller('TodoControllerNext', ['$scope', function ($scope) { + $scope.todos = [ + {text: 'learn Sortable', done: true}, + {text: 'use ng-sortable', done: false}, + {text: 'Enjoy', done: false} + ]; + + $scope.remaining = function () { + var count = 0; + angular.forEach($scope.todos, function (todo) { + count += todo.done ? 0 : 1; + }); + return count; + }; + + $scope.sortableConfig = { group: 'todo', animation: 150 }; + 'Start End Add Update Remove Sort'.split(' ').forEach(function (name) { + $scope.sortableConfig['on' + name] = console.log.bind(console, name); + }); + }]); +})(); + + +// Background +document.addEventListener("DOMContentLoaded", function () { + function setNoiseBackground(el, width, height, opacity) { + var canvas = document.createElement("canvas"); + var context = canvas.getContext("2d"); + + canvas.width = width; + canvas.height = height; + + for (var i = 0; i < width; i++) { + for (var j = 0; j < height; j++) { + var val = Math.floor(Math.random() * 255); + context.fillStyle = "rgba(" + val + "," + val + "," + val + "," + opacity + ")"; + context.fillRect(i, j, 1, 1); + } + } + + el.style.background = "url(" + canvas.toDataURL("image/png") + ")"; + } + + setNoiseBackground(document.getElementsByTagName('body')[0], 50, 50, 0.02); +}, false); From 06aac74871f3fd25a454df2fd7709ae5494e48ab Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 12 Jan 2015 18:56:35 +0300 Subject: [PATCH 011/594] #210: + 'dropBubble: false' & 'dragoverBubble: false' options --- Sortable.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index b59986d04..31386d34c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -106,7 +106,9 @@ animation: 0, setData: function (dataTransfer, dragEl) { dataTransfer.setData('Text', dragEl.textContent); - } + }, + dropBubble: false, + dragoverBubble: false }; @@ -465,7 +467,7 @@ if (evt.preventDefault !== void 0) { evt.preventDefault(); - evt.stopPropagation(); + !options.dragoverBubble && evt.stopPropagation(); } if (!_silent && activeGroup && @@ -586,7 +588,8 @@ }, _onDrop: function (/**Event*/evt) { - var el = this.el; + var el = this.el, + options = this.options; clearInterval(this._loopId); clearInterval(autoScroll.pid); @@ -601,7 +604,7 @@ if (evt) { evt.preventDefault(); - evt.stopPropagation(); + !options.dropBubble && evt.stopPropagation(); ghostEl && ghostEl.parentNode.removeChild(ghostEl); From 7ebf8ae093ce9c2689424efc44c8c3f6c0068a66 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 14 Jan 2015 15:04:23 +0300 Subject: [PATCH 012/594] #217: + inited commit --- react-sortable-mixin.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 react-sortable-mixin.js diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js new file mode 100644 index 000000000..4f4696801 --- /dev/null +++ b/react-sortable-mixin.js @@ -0,0 +1,36 @@ +/** + * @author RubaXa + * @licence MIT + */ + +(function (factory) { + 'use strict'; + + if (typeof define === 'function' && define.amd) { + define(['sortable'], factory); + } + else if (typeof module != 'undefined' && typeof module.exports != 'undefined') { + module.exports = factory(require('Sortable')); + } + else { + /* jshint sub:true */ + window['SortableMixin'] = factory(Sortable); + } +})(function (/** Sortable */Sortable) { + 'use strict'; + + + /** + * Simple and easy mixin-wrapper for rubaxa/Sortable library, in order to + * make reorderable drag-and-drop lists on modern browsers and touch devices. + * + * @mixin + */ + var SortableMixin = { + sortableMixinVersion: '0.0.0' + }; + + + // Export + return SortableMixin; +}); From dc2b05d8f2c8b59d7229a2353afcc57cb1007298 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 14 Jan 2015 23:29:46 +0300 Subject: [PATCH 013/594] #217: + base react mixin without 'linked lists' --- README.md | 34 ++++++++++++++- index.html | 12 +++++- package.json | 6 ++- react-sortable-mixin.js | 94 ++++++++++++++++++++++++++++++++++++++++- st/app.js | 74 ++++++++++++++++++++++++++++++++ 5 files changed, 215 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c109fef22..94fc435c1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Demo: http://rubaxa.github.io/Sortable/ * Supports drag handles *and selectable text* (better than voidberg's html5sortable) * Smart auto-scrolling * Built using native HTML5 drag and drop API - * Supports [Meteor](meteor/README.md) and [AngularJS](#ng) + * Supports [Meteor](meteor/README.md), [AngularJS](#ng) and [React](#react) * Supports any CSS library, e.g. [Bootstrap](#bs) * Simple API * No jQuery (but there is [support](#jq)) @@ -282,6 +282,38 @@ angular.module('myApp', ['ng-sortable']) --- + +### Support React +Include [react-sortable-mixin.js](react-sortable-mixin.js). +See more [here](react-sortable-mixin.js#L37). + + +```jsx +var SortableList = React.createClass({ + mixins: [SortableMixin], + + getInitialState: function() { + return { + items: ['Mixin', 'Sortable'] + }; + }, + + render: function() { + return
    { + this.state.items.map(function (text) { + return
  • {text}
  • + }) + }
+ } +}); + +React.render(, document.body); +``` + + +--- + + ### Method diff --git a/index.html b/index.html index 15f14c210..c9119f2f7 100644 --- a/index.html +++ b/index.html @@ -7,8 +7,8 @@ Sortable. No jQuery. - - + + @@ -210,6 +210,14 @@

The JavaScript library for modern browser

+ + +
+
+
+
+ +
diff --git a/package.json b/package.json index cade1dbee..da4c293ea 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,11 @@ "keywords": [ "sortable", "reorder", - "drag" + "drag", + "meteor", + "angular", + "react", + "mixin" ], "author": "Konstantin Lebedev ", "license": "MIT" diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 4f4696801..5415a13d5 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -27,7 +27,99 @@ * @mixin */ var SortableMixin = { - sortableMixinVersion: '0.0.0' + sortableMixinVersion: '0.0.0', + + /** + * @type {Sortable} + * @private + */ + _sortableInstance: null, + + + /** + * Sortable options + * @returns {object} + */ + getDefaultProps: function () { + return { + sortable: { + ref: 'list', + model: 'items', + + animation: 100, + onStart: 'handleStart', + onEnd: 'handleEnd', + onAdd: 'handleAdd', + onUpdate: 'handleUpdate', + onRemove: 'handleRemove', + onSort: 'handleSort', + onFilter: 'handleFilter' + } + }; + }, + + + componentDidMount: function () { + var nextSibling, + sortableProps = this.props.sortable, + sortableOptions = {}, + + callMethod = function (/** string */type, /** Event */evt) { + var method = this[sortableProps[type]]; + method && method.call(this, evt, this._sortableInstance); + }.bind(this); + + + // Pass through unrecognized options + for (var key in sortableProps) { + sortableOptions[key] = sortableProps[key]; + } + + + // Bind callbacks so that "this" refers to the component + 'onEnd onAdd onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { + if (sortableProps[name]) { + sortableOptions[name] = callMethod.bind(this, name); + } + }.bind(this)); + + + sortableOptions.onStart = function (/** Event */evt) { + nextSibling = evt.item.nextSibling; + callMethod('onStart', evt); + }.bind(this); + + + sortableOptions.onSort = function (/** Event */evt) { + evt.from.insertBefore(evt.item, nextSibling || null); + + var modelName = sortableProps.model, + newState = {}, + items = this.state[modelName]; + + if (items) { + items = items.slice(); // clone + items.splice(evt.newIndex, 0, items.splice(evt.oldIndex, 1)[0]); + + newState[modelName] = items; + this.setState(newState); + } + + callMethod('onSort', evt); + }.bind(this); + + + /** @namespace this.refs — http://facebook.github.io/react/docs/more-about-refs.html */ + if (!sortableProps.ref || this.refs[sortableProps.ref]) { + this._sortableInstance = Sortable.create((this.refs[sortableProps.ref] || this).getDOMNode(), sortableOptions); + } + }, + + + componentWillUnmount: function () { + this._sortableInstance.destroy(); + this._sortableInstance = null; + } }; diff --git a/st/app.js b/st/app.js index 109c70b3f..f6e121dde 100644 --- a/st/app.js +++ b/st/app.js @@ -1,5 +1,41 @@ (function () { + 'use strict'; + var byId = function (id) { return document.getElementById(id); }, + + loadScripts = function (desc, callback) { + var deps = [], key, idx = 0; + + for (key in desc) { + deps.push(key); + } + + (function _next() { + var pid, + name = deps[idx], + script = document.createElement('script'); + + script.type = 'text/javascript'; + script.src = desc[deps[idx]]; + + pid = setInterval(function () { + if (window[name]) { + clearTimeout(pid); + + deps[idx++] = window[name]; + + if (deps[idx]) { + _next(); + } else { + callback.apply(null, deps); + } + } + }, 30); + + document.getElementsByTagName('head')[0].appendChild(script); + })() + }, + console = window.console; @@ -159,9 +195,47 @@ $scope.sortableConfig['on' + name] = console.log.bind(console, name); }); }]); + + + + // React + loadScripts({ + 'React': '//fb.me/react-0.12.2.js', + 'SortableMixin': 'react-sortable-mixin.js' + }, function (React, SortableMixin) { + var SortableList = React.createClass({ + mixins: [SortableMixin], + + getInitialState: function() { + return { + items: [ + 'Mixin', + 'Sortable' + ] + }; + }, + + render: function() { + return React.DOM.div(null, + React.DOM.h4({ children: 'React mixin', className: 'layer title title_xl', style: { marginBottom: 0 } }), + React.DOM.div({ style: { width: '30%', marginLeft: '10px', cursor: 'move' }, className: 'block__list_words' }, + React.DOM.ul({ + ref: 'list', + children: this.state.items.map(function (v) { + return React.DOM.li(null, v); + }) + }) + ) + ); + } + }); + + React.render(React.createElement(SortableList, {}), byId('react-box')); + }); })(); + // Background document.addEventListener("DOMContentLoaded", function () { function setNoiseBackground(el, width, height, opacity) { From 34bbbcb5a19b1ae762de80a271e1b256abd82429 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Sun, 18 Jan 2015 21:34:37 +0300 Subject: [PATCH 014/594] #229: * ghostClass example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b67881a47..2d202b8ab 100644 --- a/README.md +++ b/README.md @@ -202,7 +202,7 @@ Sortable.create(list, { #### `ghostClass` option Class name for the drop placeholder. -Demo: http://jsbin.com/boqugumiqi/1/edit?css,js,output +Demo: http://jsbin.com/hunifu/1/edit?css,js,output ```css .ghost { From e08f065adaec1f47e056f0228da53cb986974637 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sun, 18 Jan 2015 21:55:53 +0300 Subject: [PATCH 015/594] #209: * drag-handle --- st/app.css | 1 + 1 file changed, 1 insertion(+) diff --git a/st/app.css b/st/app.css index 4dbbb8bdc..2059294f8 100644 --- a/st/app.css +++ b/st/app.css @@ -220,6 +220,7 @@ img { margin-right: 10px; font: bold 20px Sans-Serif; color: #5F9EDF; + display: inline-block; cursor: move; cursor: -webkit-grabbing; /* overrides 'move' */ } From 3dc8cae4fc0831f717e3c721df89794e3a30b485 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:18:39 +0300 Subject: [PATCH 016/594] #231: save order --- ng-sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index f7f3c8d27..827acdc82 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -15,7 +15,7 @@ 'use strict'; angular.module('ng-sortable', []) - .constant('$version', '0.3.2') + .constant('$version', '0.3.3') .directive('ngSortable', ['$parse', function ($parse) { var removed; @@ -76,7 +76,7 @@ if (evt.clone) { newIndex = Sortable.utils.index(evt.clone); - prevItems.splice(newIndex, 0, removed); + prevItems.splice(oldIndex, 0, removed); evt.from.removeChild(evt.clone); } From d823817419dbab417a64027ee8f7d177af4b7808 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:30:42 +0300 Subject: [PATCH 017/594] #231: correct 'clone' workaround --- ng-sortable.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 827acdc82..263ec3402 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -17,7 +17,8 @@ angular.module('ng-sortable', []) .constant('$version', '0.3.3') .directive('ngSortable', ['$parse', function ($parse) { - var removed; + var removed, + nextSibling; function getSource(el) { var scope = angular.element(el).scope(); @@ -70,19 +71,20 @@ prevItems = prevSource.items(); oldIndex = prevItems.indexOf(prevSource.item(evt.item)); - removed = prevItems.splice(oldIndex, 1)[0]; - - items.splice(newIndex, 0, removed); + removed = prevItems[oldIndex]; if (evt.clone) { - newIndex = Sortable.utils.index(evt.clone); - prevItems.splice(oldIndex, 0, removed); - evt.from.removeChild(evt.clone); } + else { + prevItems.splice(oldIndex, 1); + } - evt.from.appendChild(evt.item); // revert element - } else { + items.splice(newIndex, 0, removed); + + evt.from.insertBefore(evt.item, nextSibling); // revert element + } + else { items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); } @@ -94,17 +96,18 @@ opts[name] = opts[name] || options[name]; return opts; }, { - onStart: function () { + onStart: function (/**Event*/) { + nextSibling = evt.item.nextSibling; options.onStart(source.items()); }, onEnd: function () { options.onEnd(source.items()); }, - onAdd: function (evt) { + onAdd: function (/**Event*/evt) { _sync(evt); options.onAdd(source.items(), removed); }, - onUpdate: function (evt) { + onUpdate: function (/**Event*/evt) { _sync(evt); options.onUpdate(source.items(), source.item(evt.item)); }, @@ -119,6 +122,7 @@ $el.on('$destroy', function () { sortable.destroy(); sortable = null; + nextSibling = null; }); if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly From e370723822e2114e2acd6cb2f1c9d1bc614de08a Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 20 Jan 2015 00:32:37 +0300 Subject: [PATCH 018/594] * evt --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 263ec3402..3e7c24fff 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -96,7 +96,7 @@ opts[name] = opts[name] || options[name]; return opts; }, { - onStart: function (/**Event*/) { + onStart: function (/**Event*/evt) { nextSibling = evt.item.nextSibling; options.onStart(source.items()); }, From 8f2aa5eb68f5f31fc1cd0db7a5a3d76c06878803 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 26 Jan 2015 16:02:31 +0300 Subject: [PATCH 019/594] + create 'cloneEl' on dragStart --- Sortable.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Sortable.js b/Sortable.js index 31386d34c..38dbb7728 100644 --- a/Sortable.js +++ b/Sortable.js @@ -276,13 +276,6 @@ } } catch (err) { } - - - if (activeGroup.pull == 'clone') { - cloneEl = dragEl.cloneNode(true); - _css(cloneEl, 'display', 'none'); - rootEl.insertBefore(cloneEl, dragEl); - } } }, @@ -347,6 +340,12 @@ this._offUpEvents(); + if (activeGroup.pull == 'clone') { + cloneEl = dragEl.cloneNode(true); + _css(cloneEl, 'display', 'none'); + rootEl.insertBefore(cloneEl, dragEl); + } + if (isTouch) { var rect = dragEl.getBoundingClientRect(), css = _css(dragEl), From 5325c8a84224f231578f092ca56382480652cc91 Mon Sep 17 00:00:00 2001 From: Markus Ast Date: Tue, 27 Jan 2015 16:41:11 +0100 Subject: [PATCH 020/594] fix index calculation to skip templates --- Sortable.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 60cd0bd9f..153cf1b10 100644 --- a/Sortable.js +++ b/Sortable.js @@ -949,8 +949,10 @@ */ function _index(/**HTMLElement*/el) { var index = 0; - while (el && (el = el.previousElementSibling) && (el.nodeName.toUpperCase() !== 'TEMPLATE')) { - index++; + while (el && (el = el.previousElementSibling)) { + if (el.nodeName.toUpperCase() !== 'TEMPLATE') { + index++; + } } return index; } From f500b679f22b5aadf794a522751d5bb13ba881a0 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 27 Jan 2015 23:47:16 +0300 Subject: [PATCH 021/594] #238: * disabled --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 60cd0bd9f..63952150c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -469,7 +469,7 @@ !options.dragoverBubble && evt.stopPropagation(); } - if (!_silent && activeGroup && + if (!_silent && activeGroup && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) : activeGroup.pull && groupPut && ( From 705b3ed1aef454a897c433468e046d1ddd9f0cfb Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 27 Jan 2015 23:47:48 +0300 Subject: [PATCH 022/594] #238: * scope after event --- ng-sortable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 8d310c410..ecbf23b10 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -15,7 +15,7 @@ 'use strict'; angular.module('ng-sortable', []) - .constant('$version', '0.3.4') + .constant('$version', '0.3.5') .directive('ngSortable', ['$parse', function ($parse) { var removed, nextSibling; @@ -101,13 +101,16 @@ onStart: function (/**Event*/evt) { nextSibling = evt.item.nextSibling; options.onStart(source.items()); + scope.$apply(); }, onEnd: function () { options.onEnd(source.items()); + scope.$apply(); }, onAdd: function (/**Event*/evt) { _sync(evt); options.onAdd(source.items(), removed); + scope.$apply(); }, onUpdate: function (/**Event*/evt) { _sync(evt); From 778ee0b202f7d2396f945420896b312c01219725 Mon Sep 17 00:00:00 2001 From: "E.T.Cook" Date: Wed, 28 Jan 2015 00:06:55 -0600 Subject: [PATCH 023/594] Deep copy object to avoid unwanted referencing In relation to https://github.com/RubaXa/Sortable/issues/237 --- ng-sortable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/ng-sortable.js b/ng-sortable.js index 8d310c410..3a2162f0b 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -77,6 +77,7 @@ if (evt.clone) { evt.from.removeChild(evt.clone); + removed = angular.copy(removed); } else { prevItems.splice(oldIndex, 1); From 2843550ac8c57c306edfe9ff6856727cf1a324e3 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 28 Jan 2015 12:58:53 +0300 Subject: [PATCH 024/594] - comments --- .jshintrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.jshintrc b/.jshintrc index e870dcc84..3f67a098b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,9 +1,9 @@ { "strict": true, - "newcap": false, // "Tolerate uncapitalized constructors" + "newcap": false, "node": true, - "expr": true, // - true && call() "Expected an assignment or function call and instead saw an expression." - "supernew": true, // - "Missing '()' invoking a constructor." + "expr": true, + "supernew": true, "laxbreak": true, "white": true, "globals": { From c9051c24e18269ad13ce5ba4ddcf5ac7406f4e0a Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 2 Feb 2015 14:20:04 +0300 Subject: [PATCH 025/594] + support IE9 --- Sortable.js | 37 ++++++++++++++++++++++--------------- Sortable.min.js | 2 +- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Sortable.js b/Sortable.js index 3176f3aab..be35fe79c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -48,7 +48,9 @@ win = window, document = win.document, parseInt = win.parseInt, - supportIEdnd = !!document.createElement('div').dragDrop, + + supportDraggable = !!('draggable' in document.createElement('div')), + _silent = false, @@ -154,7 +156,6 @@ // Bind events _on(el, 'mousedown', this._onTapStart); _on(el, 'touchstart', this._onTapStart); - supportIEdnd && _on(el, 'selectstart', this._onTapStart); _on(el, 'dragover', this._onDragOver); _on(el, 'dragenter', this._onDragOver); @@ -229,9 +230,6 @@ // Prepare `dragstart` if (target && !dragEl && (target.parentNode === el)) { - // IE 9 Support - (type === 'selectstart') && target.dragDrop(); - tapEvt = evt; rootEl = this.el; @@ -254,7 +252,7 @@ clientY: touch.clientY }; - this._onDragStart(tapEvt, true); + this._onDragStart(tapEvt, 'touch'); evt.preventDefault(); } @@ -267,6 +265,10 @@ _on(document, 'dragover', this); + if (!supportDraggable) { + _on(document, 'mousemove', this); + this._onDragStart(tapEvt, true); + } try { if (document.selection) { @@ -316,10 +318,10 @@ _onTouchMove: function (/**TouchEvent*/evt) { if (tapEvt) { - var touch = evt.touches[0], + var touch = evt.touches ? evt.touches[0] : evt, dx = touch.clientX - tapEvt.clientX, dy = touch.clientY - tapEvt.clientY, - translate3d = 'translate3d(' + dx + 'px,' + dy + 'px,0)'; + translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)'; touchEvt = touch; @@ -334,7 +336,7 @@ }, - _onDragStart: function (/**Event*/evt, /**boolean*/isTouch) { + _onDragStart: function (/**Event*/evt, /**boolean*/useFallback) { var dataTransfer = evt.dataTransfer, options = this.options; @@ -346,7 +348,7 @@ rootEl.insertBefore(cloneEl, dragEl); } - if (isTouch) { + if (useFallback) { var rect = dragEl.getBoundingClientRect(), css = _css(dragEl), ghostRect; @@ -368,10 +370,16 @@ _css(ghostEl, 'width', rect.width * 2 - ghostRect.width); _css(ghostEl, 'height', rect.height * 2 - ghostRect.height); - // Bind touch events - _on(document, 'touchmove', this._onTouchMove); - _on(document, 'touchend', this._onDrop); - _on(document, 'touchcancel', this._onDrop); + if (useFallback === 'touch') { + // Bind touch events + _on(document, 'touchmove', this._onTouchMove); + _on(document, 'touchend', this._onDrop); + _on(document, 'touchcancel', this._onDrop); + } else { + // Old brwoser + _on(document, 'mousemove', this._onTouchMove); + _on(document, 'mouseup', this._onDrop); + } this._loopId = setInterval(this._emulateDragOver, 150); } @@ -774,7 +782,6 @@ _off(el, 'mousedown', this._onTapStart); _off(el, 'touchstart', this._onTapStart); - _off(el, 'selectstart', this._onTapStart); _off(el, 'dragover', this._onDragOver); _off(el, 'dragenter', this._onDragOver); diff --git a/Sortable.min.js b/Sortable.min.js index 56d114ba9..05f846821 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.0.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),L.forEach(function(d){b[d]=c(this,b[d]||M),f(a,d.substr(2).toLowerCase(),b[d])},this),a[E]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),I&&f(a,"selectstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),P.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=O.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(O.call(arguments)))}}function d(a,b,c){if(a){c=c||G,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return G.defaultView&&G.defaultView.getComputedStyle?c=G.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){J=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling)&&"TEMPLATE"!==a.nodeName.toUpperCase();)b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D={},E="Sortable"+(new Date).getTime(),F=window,G=F.document,H=F.parseInt,I=!!G.createElement("div").dragDrop,J=!1,K=function(a,b,c,d,e,f){var g=G.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},L="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),M=function(){},N=Math.abs,O=[].slice,P=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,K(t,"start",q,t,y)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),y=o(e),"function"==typeof l){if(l.call(this,a,e,this))return K(g,"filter",e,i,y),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(K(a,"filter",e,i,y),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){"selectstart"===b&&e.dragDrop(),B=a,t=this.el,q=e,v=q.nextSibling,A=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(B={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(B,!0),a.preventDefault()),f(G,"mouseup",this._onDrop),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),f(G,"dragover",this);try{G.selection?G.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(C){i(r,"display","none");var a=G.elementFromPoint(C.clientX,C.clientY),b=a,c=this.options.group.name,d=P.length;if(b)do{if((" "+b[E]+" ").indexOf(c)>-1){for(;d--;)P[d]({clientX:C.clientX,clientY:C.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(B){var b=a.touches[0],c=b.clientX-B.clientX,d=b.clientY-B.clientY,e="translate3d("+c+"px,"+d+"px,0)";C=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==A.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-H(h.marginTop,10)),i(r,"left",g.left-H(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),f(G,"touchmove",this._onTouchMove),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(G,"drop",this);if(u=d.scroll,u===!0){u=t;do if(u.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=F:u&&(b=u,c=u.getBoundingClientRect(),k=(N(c.right-g)<=e)-(N(c.left-g)<=e),l=(N(c.bottom-h)<=e)-(N(c.top-h)<=e)),(D.vx!==k||D.vy!==l||D.el!==b)&&(D.el=b,D.vx=k,D.vy=l,clearInterval(D.pid),b&&(D.pid=setInterval(function(){b===F?F.scrollTo(F.scrollX+k*f,F.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=A===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!J&&A&&(n?o||(f=!t.contains(q)):A.pull&&k&&(A.name===j.name||k.indexOf&&~k.indexOf(A.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||v?t.insertBefore(q,s||v):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;u=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(u,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[E]){w!==c&&(w=c,x=i(c));var p,u=c.getBoundingClientRect(),y=u.right-u.left,z=u.bottom-u.top,B=/left|right|inline/.test(x.cssFloat+x.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-u.left)/y:(a.clientY-u.top)/z)>.5,G=c.nextElementSibling;J=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!D||F&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(u,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(G,"mouseup",this._onDrop),g(G,"touchmove",this._onTouchMove),g(G,"touchend",this._onDrop),g(G,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(D.pid),g(G,"drop",this),g(G,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(z=o(q),K(q.parentNode,"sort",q,t,y,z),K(t,"sort",q,t,y,z),K(q,"add",q,t,y,z),K(t,"remove",q,t,y,z)):(s&&s.parentNode.removeChild(s),q.nextSibling!==v&&(z=o(q),K(t,"update",q,t,y,z),K(t,"sort",q,t,y,z))),a.active&&K(t,"end",q,t,y,z)),t=q=r=v=s=B=C=w=x=A=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;L.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"selectstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),P.splice(P.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:K,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),L.forEach(function(d){b[d]=c(this,b[d]||M),f(a,d.substr(2).toLowerCase(),b[d])},this),a[E]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),P.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=O.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(O.call(arguments)))}}function d(a,b,c){if(a){c=c||G,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return G.defaultView&&G.defaultView.getComputedStyle?c=G.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){J=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D={},E="Sortable"+(new Date).getTime(),F=window,G=F.document,H=F.parseInt,I=!!("draggable"in G.createElement("div")),J=!1,K=function(a,b,c,d,e,f){var g=G.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},L="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),M=function(){},N=Math.abs,O=[].slice,P=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,K(t,"start",q,t,y)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),y=o(e),"function"==typeof l){if(l.call(this,a,e,this))return K(g,"filter",e,i,y),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(K(a,"filter",e,i,y),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){B=a,t=this.el,q=e,v=q.nextSibling,A=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(B={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(B,"touch"),a.preventDefault()),f(G,"mouseup",this._onDrop),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),f(G,"dragover",this),I||(f(G,"mousemove",this),this._onDragStart(B,!0));try{G.selection?G.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(C){i(r,"display","none");var a=G.elementFromPoint(C.clientX,C.clientY),b=a,c=this.options.group.name,d=P.length;if(b)do{if((" "+b[E]+" ").indexOf(c)>-1){for(;d--;)P[d]({clientX:C.clientX,clientY:C.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(B){var b=a.touches?a.touches[0]:a,c=b.clientX-B.clientX,d=b.clientY-B.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";C=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==A.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-H(h.marginTop,10)),i(r,"left",g.left-H(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(G,"touchmove",this._onTouchMove),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop)):(f(G,"mousemove",this._onTouchMove),f(G,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(G,"drop",this);if(u=d.scroll,u===!0){u=t;do if(u.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=F:u&&(b=u,c=u.getBoundingClientRect(),k=(N(c.right-g)<=e)-(N(c.left-g)<=e),l=(N(c.bottom-h)<=e)-(N(c.top-h)<=e)),(D.vx!==k||D.vy!==l||D.el!==b)&&(D.el=b,D.vx=k,D.vy=l,clearInterval(D.pid),b&&(D.pid=setInterval(function(){b===F?F.scrollTo(F.scrollX+k*f,F.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=A===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!J&&A&&!h.disabled&&(n?o||(f=!t.contains(q)):A.pull&&k&&(A.name===j.name||k.indexOf&&~k.indexOf(A.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||v?t.insertBefore(q,s||v):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;u=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(u,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[E]){w!==c&&(w=c,x=i(c));var p,u=c.getBoundingClientRect(),y=u.right-u.left,z=u.bottom-u.top,B=/left|right|inline/.test(x.cssFloat+x.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-u.left)/y:(a.clientY-u.top)/z)>.5,G=c.nextElementSibling;J=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!D||F&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(u,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(G,"mouseup",this._onDrop),g(G,"touchmove",this._onTouchMove),g(G,"touchend",this._onDrop),g(G,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(D.pid),g(G,"drop",this),g(G,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(z=o(q),K(q.parentNode,"sort",q,t,y,z),K(t,"sort",q,t,y,z),K(q,"add",q,t,y,z),K(t,"remove",q,t,y,z)):(s&&s.parentNode.removeChild(s),q.nextSibling!==v&&(z=o(q),K(t,"update",q,t,y,z),K(t,"sort",q,t,y,z))),a.active&&K(t,"end",q,t,y,z)),t=q=r=v=s=B=C=w=x=A=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;L.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),P.splice(P.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:K,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file From 5475f8854dd83c1fccc15152ba03aa5309b04d9e Mon Sep 17 00:00:00 2001 From: Dan Dascalescu Date: Thu, 5 Feb 2015 18:10:33 -0800 Subject: [PATCH 026/594] Clone with https to avoid errors for noobs like #262 --- meteor/example/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meteor/example/README.md b/meteor/example/README.md index e18ca52ce..5e48aca4b 100644 --- a/meteor/example/README.md +++ b/meteor/example/README.md @@ -17,7 +17,7 @@ run script: ### Windows - git clone git@github.com:RubaXa/Sortable.git + git clone https://github.com/RubaXa/Sortable.git cd Sortable git checkout dev cd meteor\example @@ -25,7 +25,7 @@ run script: ### Elsewhere - git clone git@github.com:RubaXa/Sortable.git + git clone https://github.com/RubaXa/Sortable.git cd Sortable git checkout dev meteor/example./run.sh From c71b88f0756a3cafe62eec4a93ddf82b8798d120 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 6 Feb 2015 11:38:35 +0300 Subject: [PATCH 027/594] #251: + 'mousemove' unbind --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index be35fe79c..baee3e509 100644 --- a/Sortable.js +++ b/Sortable.js @@ -266,7 +266,6 @@ _on(document, 'dragover', this); if (!supportDraggable) { - _on(document, 'mousemove', this); this._onDragStart(tapEvt, true); } @@ -604,6 +603,7 @@ // Unbind events _off(document, 'drop', this); _off(document, 'dragover', this); + _off(document, 'mousemove', this._onTouchMove); _off(el, 'dragstart', this._onDragStart); From 7bff4352d60cc1991f245777bfa858e663a8faaa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 6 Feb 2015 12:24:01 +0300 Subject: [PATCH 028/594] #250: + additional check --- Sortable.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index 3176f3aab..bcc6b131a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -171,13 +171,15 @@ _dragStarted: function () { - // Apply effect - _toggleClass(dragEl, this.options.ghostClass, true); + if (rootEl && dragEl) { + // Apply effect + _toggleClass(dragEl, this.options.ghostClass, true); - Sortable.active = this; + Sortable.active = this; - // Drag start event - _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + // Drag start event + _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + } }, From 7bad7a3c1e7a2ee4612109928ecf7f6505d294aa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 7 Feb 2015 12:12:52 +0300 Subject: [PATCH 029/594] =?UTF-8?q?#317:=20+=20=D0=BE=D0=B1=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=B8=D1=82=D1=8C=20=D0=B4=D0=B0=D1=82=D1=83=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8=D1=86=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 8 --- react-sortable-mixin.js | 153 ++++++++++++++++++++++------------------ st/app.js | 37 ---------- 3 files changed, 85 insertions(+), 113 deletions(-) diff --git a/index.html b/index.html index 6b7a46dec..3e8334644 100644 --- a/index.html +++ b/index.html @@ -210,14 +210,6 @@

The JavaScript library for modern browser

- - -
-
-
-
- -
diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 5415a13d5..72a215deb 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -19,6 +19,46 @@ })(function (/** Sortable */Sortable) { 'use strict'; + var _nextSibling; + + var _activeComponent; + + + var _defaultOptions = { + ref: 'list', + model: 'items', + + animation: 100, + onStart: 'handleStart', + onEnd: 'handleEnd', + onAdd: 'handleAdd', + onUpdate: 'handleUpdate', + onRemove: 'handleRemove', + onSort: 'handleSort', + onFilter: 'handleFilter' + }; + + + function _getModelName(component) { + return component.sortableOptions && component.sortableOptions.model || _defaultOptions.model; + } + + + function _getModelItems(component) { + return component.state[_getModelName(component)].slice(); + } + + + function _extend(dst, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) { + dst[key] = src[key]; + } + } + + return dst; + } + /** * Simple and easy mixin-wrapper for rubaxa/Sortable library, in order to @@ -27,7 +67,8 @@ * @mixin */ var SortableMixin = { - sortableMixinVersion: '0.0.0', + sortableMixinVersion: '0.1.0', + /** * @type {Sortable} @@ -36,83 +77,59 @@ _sortableInstance: null, - /** - * Sortable options - * @returns {object} - */ - getDefaultProps: function () { - return { - sortable: { - ref: 'list', - model: 'items', - - animation: 100, - onStart: 'handleStart', - onEnd: 'handleEnd', - onAdd: 'handleAdd', - onUpdate: 'handleUpdate', - onRemove: 'handleRemove', - onSort: 'handleSort', - onFilter: 'handleFilter' - } - }; - }, - - componentDidMount: function () { - var nextSibling, - sortableProps = this.props.sortable, - sortableOptions = {}, + var options = _extend(_extend({}, _defaultOptions), this.sortableOptions || {}), + copyOptions = _extend({}, options), - callMethod = function (/** string */type, /** Event */evt) { - var method = this[sortableProps[type]]; + emitEvent = function (/** string */type, /** Event */evt) { + var method = this[options[type]]; method && method.call(this, evt, this._sortableInstance); }.bind(this); - // Pass through unrecognized options - for (var key in sortableProps) { - sortableOptions[key] = sortableProps[key]; - } - - // Bind callbacks so that "this" refers to the component - 'onEnd onAdd onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { - if (sortableProps[name]) { - sortableOptions[name] = callMethod.bind(this, name); - } - }.bind(this)); - - - sortableOptions.onStart = function (/** Event */evt) { - nextSibling = evt.item.nextSibling; - callMethod('onStart', evt); - }.bind(this); - - - sortableOptions.onSort = function (/** Event */evt) { - evt.from.insertBefore(evt.item, nextSibling || null); - - var modelName = sortableProps.model, - newState = {}, - items = this.state[modelName]; - - if (items) { - items = items.slice(); // clone - items.splice(evt.newIndex, 0, items.splice(evt.oldIndex, 1)[0]); - - newState[modelName] = items; - this.setState(newState); - } - - callMethod('onSort', evt); - }.bind(this); + 'onStart onEnd onAdd onSort onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { + copyOptions[name] = function (evt) { + if (name === 'onStart') { + _nextSibling = evt.item.nextElementSibling; + _activeComponent = this; + } + else if (name === 'onAdd' || name === 'onUpdate') { + evt.from.insertBefore(evt.item, _nextSibling); + + var newState = {}, + remoteState = {}, + oldIndex = evt.oldIndex, + newIndex = evt.newIndex, + items = _getModelItems(this), + remoteItems, + item; + + if (name === 'onAdd') { + remoteItems = _getModelItems(_activeComponent); + item = remoteItems.splice(oldIndex, 1)[0]; + items.splice(newIndex, 0, item); + + remoteState[_getModelName(_activeComponent)] = remoteItems; + } + else { + items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); + } + + newState[_getModelName(this)] = items; + this.setState(newState); + (this !== _activeComponent) && _activeComponent.setState(remoteState); + } + + setTimeout(function () { + emitEvent(name, evt); + }, 0); + }.bind(this); + }, this); /** @namespace this.refs — http://facebook.github.io/react/docs/more-about-refs.html */ - if (!sortableProps.ref || this.refs[sortableProps.ref]) { - this._sortableInstance = Sortable.create((this.refs[sortableProps.ref] || this).getDOMNode(), sortableOptions); - } + this._sortableInstance = Sortable.create((this.refs[options.ref] || this).getDOMNode(), copyOptions); }, diff --git a/st/app.js b/st/app.js index f6e121dde..fe50fe9d7 100644 --- a/st/app.js +++ b/st/app.js @@ -195,43 +195,6 @@ $scope.sortableConfig['on' + name] = console.log.bind(console, name); }); }]); - - - - // React - loadScripts({ - 'React': '//fb.me/react-0.12.2.js', - 'SortableMixin': 'react-sortable-mixin.js' - }, function (React, SortableMixin) { - var SortableList = React.createClass({ - mixins: [SortableMixin], - - getInitialState: function() { - return { - items: [ - 'Mixin', - 'Sortable' - ] - }; - }, - - render: function() { - return React.DOM.div(null, - React.DOM.h4({ children: 'React mixin', className: 'layer title title_xl', style: { marginBottom: 0 } }), - React.DOM.div({ style: { width: '30%', marginLeft: '10px', cursor: 'move' }, className: 'block__list_words' }, - React.DOM.ul({ - ref: 'list', - children: this.state.items.map(function (v) { - return React.DOM.li(null, v); - }) - }) - ) - ); - } - }); - - React.render(React.createElement(SortableList, {}), byId('react-box')); - }); })(); From accec9b001c459901a47de8fe035c0699bf21258 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 7 Feb 2015 12:12:52 +0300 Subject: [PATCH 030/594] #217: + linked lists --- index.html | 8 --- react-sortable-mixin.js | 153 ++++++++++++++++++++++------------------ st/app.js | 37 ---------- 3 files changed, 85 insertions(+), 113 deletions(-) diff --git a/index.html b/index.html index 6b7a46dec..3e8334644 100644 --- a/index.html +++ b/index.html @@ -210,14 +210,6 @@

The JavaScript library for modern browser

- - -
-
-
-
- -
diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 5415a13d5..72a215deb 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -19,6 +19,46 @@ })(function (/** Sortable */Sortable) { 'use strict'; + var _nextSibling; + + var _activeComponent; + + + var _defaultOptions = { + ref: 'list', + model: 'items', + + animation: 100, + onStart: 'handleStart', + onEnd: 'handleEnd', + onAdd: 'handleAdd', + onUpdate: 'handleUpdate', + onRemove: 'handleRemove', + onSort: 'handleSort', + onFilter: 'handleFilter' + }; + + + function _getModelName(component) { + return component.sortableOptions && component.sortableOptions.model || _defaultOptions.model; + } + + + function _getModelItems(component) { + return component.state[_getModelName(component)].slice(); + } + + + function _extend(dst, src) { + for (var key in src) { + if (src.hasOwnProperty(key)) { + dst[key] = src[key]; + } + } + + return dst; + } + /** * Simple and easy mixin-wrapper for rubaxa/Sortable library, in order to @@ -27,7 +67,8 @@ * @mixin */ var SortableMixin = { - sortableMixinVersion: '0.0.0', + sortableMixinVersion: '0.1.0', + /** * @type {Sortable} @@ -36,83 +77,59 @@ _sortableInstance: null, - /** - * Sortable options - * @returns {object} - */ - getDefaultProps: function () { - return { - sortable: { - ref: 'list', - model: 'items', - - animation: 100, - onStart: 'handleStart', - onEnd: 'handleEnd', - onAdd: 'handleAdd', - onUpdate: 'handleUpdate', - onRemove: 'handleRemove', - onSort: 'handleSort', - onFilter: 'handleFilter' - } - }; - }, - - componentDidMount: function () { - var nextSibling, - sortableProps = this.props.sortable, - sortableOptions = {}, + var options = _extend(_extend({}, _defaultOptions), this.sortableOptions || {}), + copyOptions = _extend({}, options), - callMethod = function (/** string */type, /** Event */evt) { - var method = this[sortableProps[type]]; + emitEvent = function (/** string */type, /** Event */evt) { + var method = this[options[type]]; method && method.call(this, evt, this._sortableInstance); }.bind(this); - // Pass through unrecognized options - for (var key in sortableProps) { - sortableOptions[key] = sortableProps[key]; - } - - // Bind callbacks so that "this" refers to the component - 'onEnd onAdd onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { - if (sortableProps[name]) { - sortableOptions[name] = callMethod.bind(this, name); - } - }.bind(this)); - - - sortableOptions.onStart = function (/** Event */evt) { - nextSibling = evt.item.nextSibling; - callMethod('onStart', evt); - }.bind(this); - - - sortableOptions.onSort = function (/** Event */evt) { - evt.from.insertBefore(evt.item, nextSibling || null); - - var modelName = sortableProps.model, - newState = {}, - items = this.state[modelName]; - - if (items) { - items = items.slice(); // clone - items.splice(evt.newIndex, 0, items.splice(evt.oldIndex, 1)[0]); - - newState[modelName] = items; - this.setState(newState); - } - - callMethod('onSort', evt); - }.bind(this); + 'onStart onEnd onAdd onSort onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { + copyOptions[name] = function (evt) { + if (name === 'onStart') { + _nextSibling = evt.item.nextElementSibling; + _activeComponent = this; + } + else if (name === 'onAdd' || name === 'onUpdate') { + evt.from.insertBefore(evt.item, _nextSibling); + + var newState = {}, + remoteState = {}, + oldIndex = evt.oldIndex, + newIndex = evt.newIndex, + items = _getModelItems(this), + remoteItems, + item; + + if (name === 'onAdd') { + remoteItems = _getModelItems(_activeComponent); + item = remoteItems.splice(oldIndex, 1)[0]; + items.splice(newIndex, 0, item); + + remoteState[_getModelName(_activeComponent)] = remoteItems; + } + else { + items.splice(newIndex, 0, items.splice(oldIndex, 1)[0]); + } + + newState[_getModelName(this)] = items; + this.setState(newState); + (this !== _activeComponent) && _activeComponent.setState(remoteState); + } + + setTimeout(function () { + emitEvent(name, evt); + }, 0); + }.bind(this); + }, this); /** @namespace this.refs — http://facebook.github.io/react/docs/more-about-refs.html */ - if (!sortableProps.ref || this.refs[sortableProps.ref]) { - this._sortableInstance = Sortable.create((this.refs[sortableProps.ref] || this).getDOMNode(), sortableOptions); - } + this._sortableInstance = Sortable.create((this.refs[options.ref] || this).getDOMNode(), copyOptions); }, diff --git a/st/app.js b/st/app.js index f6e121dde..fe50fe9d7 100644 --- a/st/app.js +++ b/st/app.js @@ -195,43 +195,6 @@ $scope.sortableConfig['on' + name] = console.log.bind(console, name); }); }]); - - - - // React - loadScripts({ - 'React': '//fb.me/react-0.12.2.js', - 'SortableMixin': 'react-sortable-mixin.js' - }, function (React, SortableMixin) { - var SortableList = React.createClass({ - mixins: [SortableMixin], - - getInitialState: function() { - return { - items: [ - 'Mixin', - 'Sortable' - ] - }; - }, - - render: function() { - return React.DOM.div(null, - React.DOM.h4({ children: 'React mixin', className: 'layer title title_xl', style: { marginBottom: 0 } }), - React.DOM.div({ style: { width: '30%', marginLeft: '10px', cursor: 'move' }, className: 'block__list_words' }, - React.DOM.ul({ - ref: 'list', - children: this.state.items.map(function (v) { - return React.DOM.li(null, v); - }) - }) - ) - ); - } - }); - - React.render(React.createElement(SortableList, {}), byId('react-box')); - }); })(); From 5551a9ba3e4c8f77c2c724b03dab54cceb96a1b5 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 7 Feb 2015 13:02:31 +0300 Subject: [PATCH 031/594] #217: + react examples --- README.md | 56 ++++++++++++++++++++++++++++++++++++++++- react-sortable-mixin.js | 1 - 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2d6417f96..4bbe34fc7 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ angular.module('myApp', ['ng-sortable']) ### Support React Include [react-sortable-mixin.js](react-sortable-mixin.js). -See more [here](react-sortable-mixin.js#L37). +See [more options](react-sortable-mixin.js#L26). ```jsx @@ -298,6 +298,8 @@ var SortableList = React.createClass({ }; }, + onSort: function (/** Event */evt) { /*..*/ }, + render: function() { return
    { this.state.items.map(function (text) { @@ -308,6 +310,58 @@ var SortableList = React.createClass({ }); React.render(, document.body); + + +// +// Groups +// +var AllUsers = React.createClass({ + mixins: [SortableMixin], + + sortableOptions: { + ref: "user", + group: "shared", + model: "users" + }, + + getInitialState: function() { + return { users: ['Abbi', 'Adela', 'Bud', 'Cate', 'Davis', 'Eric']; }; + }, + + render: function() { + return ( +

    Users

    +
      { + this.state.users.map(function (text) { + return
    • {text}
    • + }) + }
    + ); + } +}); + +var ApprovedUsers = React.createClass({ + mixins: [SortableMixin], + sortableOptions: { group: "shared" }, + + getInitialState: function() { + return { items: ['Hal', 'Judy']; }; + }, + + render: function() { + return
      { + this.state.items.map(function (text) { + return
    • {text}
    • + }) + }
    + } +}); + +React.render(
    + +
    + +
    , document.body); ``` diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 72a215deb..fb99379e0 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -23,7 +23,6 @@ var _activeComponent; - var _defaultOptions = { ref: 'list', model: 'items', From fbf4f8b65feed6d6d81da28d6ee15ece93dd1ac2 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 7 Feb 2015 15:52:24 +0300 Subject: [PATCH 032/594] #217: onSort -> handleSort --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4bbe34fc7..de5636377 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,7 @@ var SortableList = React.createClass({ }; }, - onSort: function (/** Event */evt) { /*..*/ }, + handleSort: function (/** Event */evt) { /*..*/ }, render: function() { return
      { From 15d6f07a01f299bc1aa2f4240ae6713414e797ad Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 7 Feb 2015 23:06:01 +0300 Subject: [PATCH 033/594] #254: + check 'effectAllowed' on 'dragover' --- Sortable.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sortable.js b/Sortable.js index bcc6b131a..be83ad393 100644 --- a/Sortable.js +++ b/Sortable.js @@ -466,6 +466,10 @@ isOwner = (activeGroup === group), canSort = options.sort; + if (evt.dataTransfer && evt.dataTransfer.effectAllowed !== 'move') { + return; + } + if (evt.preventDefault !== void 0) { evt.preventDefault(); !options.dragoverBubble && evt.stopPropagation(); From bfddd35dd4244f32f70433f9594f205abe31e2b7 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 9 Feb 2015 16:48:41 +0300 Subject: [PATCH 034/594] + choice between 'state' or 'props' --- react-sortable-mixin.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index fb99379e0..6f25acc4b 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -44,7 +44,10 @@ function _getModelItems(component) { - return component.state[_getModelName(component)].slice(); + var name = _getModelName(component), + items = component.state && component.state[name] || component.props[name]; + + return items.slice(); } From 21bf07a93fe0ec9a997a6d81b117ce64198e2837 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 9 Feb 2015 17:16:40 +0300 Subject: [PATCH 035/594] #256: * fixed auto-scrolling --- Sortable.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/Sortable.js b/Sortable.js index bcc6b131a..4a0e8fa1d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -156,8 +156,8 @@ _on(el, 'touchstart', this._onTapStart); supportIEdnd && _on(el, 'selectstart', this._onTapStart); - _on(el, 'dragover', this._onDragOver); - _on(el, 'dragenter', this._onDragOver); + _on(el, 'dragover', this); + _on(el, 'dragenter', this); touchDragOverListeners.push(this._onDragOver); @@ -267,9 +267,6 @@ _on(dragEl, 'dragend', this); _on(rootEl, 'dragstart', this._onDragStart); - _on(document, 'dragover', this); - - try { if (document.selection) { document.selection.empty(); @@ -597,8 +594,6 @@ // Unbind events _off(document, 'drop', this); - _off(document, 'dragover', this); - _off(el, 'dragstart', this._onDragStart); this._offUpEvents(); @@ -671,8 +666,9 @@ handleEvent: function (/**Event*/evt) { var type = evt.type; - if (type === 'dragover') { + if (type === 'dragover' || type === 'dragenter') { this._onDrag(evt); + this._onDragOver(evt); _globalDragOver(evt); } else if (type === 'drop' || type === 'dragend') { @@ -778,8 +774,8 @@ _off(el, 'touchstart', this._onTapStart); _off(el, 'selectstart', this._onTapStart); - _off(el, 'dragover', this._onDragOver); - _off(el, 'dragenter', this._onDragOver); + _off(el, 'dragover', this); + _off(el, 'dragenter', this); //remove draggable attributes Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) { From 85292d9558472686321ff12d973cdb5c65f823ff Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 9 Feb 2015 18:10:20 +0300 Subject: [PATCH 036/594] #236: + ngSortEvent --- README.md | 8 +++++++- ng-sortable.js | 44 +++++++++++++++++++++++++++++++------------- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index d548c23c8..132d3852b 100644 --- a/README.md +++ b/README.md @@ -274,7 +274,13 @@ angular.module('myApp', ['ng-sortable']) $scope.items = ['item 1', 'item 2']; $scope.foo = ['foo 1', '..']; $scope.bar = ['bar 1', '..']; - $scope.barConfig = { group: 'foobar', animation: 150 }; + $scope.barConfig = { + group: 'foobar', + animation: 150, + onSort: function (/** ngSortEvent */evt){ + // @see https://github.com/RubaXa/Sortable/blob/master/ng-sortable.js#L18-L24 + } + }; }]); ``` diff --git a/ng-sortable.js b/ng-sortable.js index d4fe47fe2..ec4aba6df 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -14,6 +14,16 @@ })(function (angular, Sortable) { 'use strict'; + + /** + * @typedef {Object} ngSortEvent + * @property {*} model List item + * @property {Object|Array} models List of items + * @property {number} oldIndex before sort + * @property {number} newIndex after sort + */ + + angular.module('ng-sortable', []) .constant('$version', '0.3.5') .directive('ngSortable', ['$parse', function ($parse) { @@ -58,12 +68,20 @@ ; - 'Start End Add Update Remove Sort'.split(' ').forEach(function (name) { - options['on' + name] = options['on' + name] || function () {}; - }); + function _emitEvent(/**Event*/evt, /*Mixed*/item) { + var name = 'on' + evt.type.charAt(0).toUpperCase() + evt.type.substr(1); + + /* jshint expr:true */ + options[name] && options[name]({ + model: item, + models: source.items(), + oldIndex: evt.oldIndex, + newIndex: evt.newIndex + }); + } - function _sync(evt) { + function _sync(/**Event*/evt) { var oldIndex = evt.oldIndex, newIndex = evt.newIndex, items = source.items(); @@ -101,27 +119,27 @@ }, { onStart: function (/**Event*/evt) { nextSibling = evt.item.nextSibling; - options.onStart(source.items()); + _emitEvent(evt); scope.$apply(); }, - onEnd: function () { - options.onEnd(source.items()); + onEnd: function (/**Event*/evt) { + _emitEvent(evt, removed); scope.$apply(); }, onAdd: function (/**Event*/evt) { _sync(evt); - options.onAdd(source.items(), removed); + _emitEvent(evt, removed); scope.$apply(); }, onUpdate: function (/**Event*/evt) { _sync(evt); - options.onUpdate(source.items(), source.item(evt.item)); + _emitEvent(evt, source.item(evt.item)); }, - onRemove: function () { - options.onRemove(source.items(), removed); + onRemove: function (/**Event*/evt) { + _emitEvent(evt, removed); }, - onSort: function () { - options.onSort(source.items()); + onSort: function (/**Event*/evt) { + _emitEvent(evt, source.item(evt.item)); } })); From 55ae4457ca7bd8de31b0a98d527f8a0cb3204212 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 9 Feb 2015 18:27:02 +0300 Subject: [PATCH 037/594] #267: + support without ng-repeat --- ng-sortable.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index ec4aba6df..bef396c7f 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -39,6 +39,11 @@ ); })[0]; + if (!ngRepeat) { + // Without ng-repeat + return null; + } + // tests: http://jsbin.com/kosubutilo/1/edit?js,output ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); @@ -74,7 +79,7 @@ /* jshint expr:true */ options[name] && options[name]({ model: item, - models: source.items(), + models: source && source.items(), oldIndex: evt.oldIndex, newIndex: evt.newIndex }); @@ -82,6 +87,11 @@ function _sync(/**Event*/evt) { + if (!source) { + // Without ng-repeat + return; + } + var oldIndex = evt.oldIndex, newIndex = evt.newIndex, items = source.items(); @@ -133,13 +143,13 @@ }, onUpdate: function (/**Event*/evt) { _sync(evt); - _emitEvent(evt, source.item(evt.item)); + _emitEvent(evt, source && source.item(evt.item)); }, onRemove: function (/**Event*/evt) { _emitEvent(evt, removed); }, onSort: function (/**Event*/evt) { - _emitEvent(evt, source.item(evt.item)); + _emitEvent(evt, source && source.item(evt.item)); } })); From 879282da6ffff5d8aef7e9383bde0e7645987c66 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 10 Feb 2015 12:36:40 +0300 Subject: [PATCH 038/594] #269: + CDN --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index d548c23c8..d9225a2eb 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Demo: http://rubaxa.github.io/Sortable/ * Supports [Meteor](meteor/README.md) and [AngularJS](#ng) * Supports any CSS library, e.g. [Bootstrap](#bs) * Simple API + * [CDN](#cdn) * No jQuery (but there is [support](#jq)) @@ -424,6 +425,25 @@ Link to the active instance. * toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element +--- + + + +### CDN + +```html + + + + + + + + + + +``` + --- From 161efcdb53b3c7b1711fe8aa2407a9cc7a6c65b4 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Tue, 10 Feb 2015 21:33:38 +0300 Subject: [PATCH 039/594] + Articles --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d9225a2eb..213e4db5f 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,17 @@ Demo: http://rubaxa.github.io/Sortable/ * No jQuery (but there is [support](#jq)) +--- + + +### Articles + * [Sortable v1.0 — New capabilities](wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014) + * [Sorting with the help of HTML5 Drag'n'Drop API](wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013) + + +--- + + ### Usage ```html
        From 450370e5865924040c39511cd619672c7d02ee09 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Tue, 10 Feb 2015 21:35:10 +0300 Subject: [PATCH 040/594] * wiki inks --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 213e4db5f..b2056c7bd 100644 --- a/README.md +++ b/README.md @@ -19,15 +19,15 @@ Demo: http://rubaxa.github.io/Sortable/ * No jQuery (but there is [support](#jq)) ---- +
        ### Articles - * [Sortable v1.0 — New capabilities](wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014) - * [Sorting with the help of HTML5 Drag'n'Drop API](wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013) + * [Sortable v1.0 — New capabilities](https://github.com/RubaXa/Sortable/wiki/Sortable-v1.0-—-New-capabilities/) (December 22, 2014) + * [Sorting with the help of HTML5 Drag'n'Drop API](https://github.com/RubaXa/Sortable/wiki/Sorting-with-the-help-of-HTML5-Drag'n'Drop-API/) (December 23, 2013) ---- +
        ### Usage From 64ec81ab6d6032afa52da9f74f82aa8fef3bbce1 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 10 Feb 2015 22:35:41 +0300 Subject: [PATCH 041/594] + IE9 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b2056c7bd..b532cdc6c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Demo: http://rubaxa.github.io/Sortable/ ## Features - * Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers + * Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers (including IE9) * Can drag from one list to another or within the same list * CSS animation when moving items * Supports drag handles *and selectable text* (better than voidberg's html5sortable) From ab52c138509968f1c85dd2c3d5205a85e54ef797 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 10 Feb 2015 23:20:37 +0300 Subject: [PATCH 042/594] #271: * logic of auto-scrolling --- Sortable.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Sortable.js b/Sortable.js index 19c504aee..ac34a5b0c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -424,20 +424,28 @@ winWidth = window.innerWidth, winHeight = window.innerHeight, - vx = (winWidth - x <= sens) - (x <= sens), - vy = (winHeight - y <= sens) - (y <= sens) + vx, + vy ; - if (vx || vy) { - el = win; - } - else if (scrollEl) { + + if (scrollEl) { el = scrollEl; rect = scrollEl.getBoundingClientRect(); vx = (abs(rect.right - x) <= sens) - (abs(rect.left - x) <= sens); vy = (abs(rect.bottom - y) <= sens) - (abs(rect.top - y) <= sens); } + + if (!(vx || vy)) { + vx = (winWidth - x <= sens) - (x <= sens); + vy = (winHeight - y <= sens) - (y <= sens); + + /* jshint expr:true */ + (vx || vy) && (el = win); + } + + if (autoScroll.vx !== vx || autoScroll.vy !== vy || autoScroll.el !== el) { autoScroll.el = el; autoScroll.vx = vx; From 9e3f6f1e2b94b7d990ce20c44e7fbba63712f782 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Feb 2015 13:50:54 +0300 Subject: [PATCH 043/594] + CONTRIBUTING --- CONTRIBUTING.md | 18 ++++++++++++++++++ README.md | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..b7dd18912 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,18 @@ +# Contribution Guidelines + + +### Issue + + 1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved; + 2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer; + 3. If not found, create example to [jsbin.com](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. + + +--- + + +### Pull Request + + 1. Before PR run `grunt`; + 2. Only into [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch. + diff --git a/README.md b/README.md index b2056c7bd..0105c90cb 100644 --- a/README.md +++ b/README.md @@ -488,6 +488,14 @@ Now you can use `jquery.fn.sortable.js`:
        --- +### Contributing (Issue/PR) + +Please, [read this](CONTRIBUTING.md). + + +--- + + ## MIT LICENSE Copyright 2013-2015 Lebedev Konstantin http://rubaxa.github.io/Sortable/ From 4b367b5b9832854073316bca426f641cee146c09 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Wed, 11 Feb 2015 13:52:04 +0300 Subject: [PATCH 044/594] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b7dd18912..ef9d5d18d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ 1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved; 2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer; - 3. If not found, create example to [jsbin.com](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. + 3. If not found, create example on [jsbin.com](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. --- From e97970b303af821d517ecc42a5f97c8a5fd77e28 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Feb 2015 18:12:28 +0300 Subject: [PATCH 045/594] #256: uber-autoscroll, support drag between lists --- Sortable.js | 172 +++++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 82 deletions(-) diff --git a/Sortable.js b/Sortable.js index b50378b40..050e74254 100644 --- a/Sortable.js +++ b/Sortable.js @@ -28,9 +28,11 @@ ghostEl, cloneEl, rootEl, - scrollEl, nextEl, + scrollEl, + scrollParentEl, + lastEl, lastCSS, @@ -76,7 +78,82 @@ abs = Math.abs, slice = [].slice, - touchDragOverListeners = [] + touchDragOverListeners = [], + + _autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) { + // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 + if (rootEl && options.scroll) { + var el, + rect, + sens = options.scrollSensitivity, + speed = options.scrollSpeed, + + x = evt.clientX, + y = evt.clientY, + + winWidth = window.innerWidth, + winHeight = window.innerHeight, + + vx, + vy + ; + + // Delect scrollEl + if (scrollParentEl !== rootEl) { + scrollEl = options.scroll; + scrollParentEl = rootEl; + + if (scrollEl === true) { + scrollEl = rootEl; + + do { + if ((scrollEl.offsetWidth < scrollEl.scrollWidth) || + (scrollEl.offsetHeight < scrollEl.scrollHeight) + ) { + break; + } + /* jshint boss:true */ + } while (scrollEl = scrollEl.parentNode); + } + } + + if (scrollEl) { + el = scrollEl; + rect = scrollEl.getBoundingClientRect(); + vx = (abs(rect.right - x) <= sens) - (abs(rect.left - x) <= sens); + vy = (abs(rect.bottom - y) <= sens) - (abs(rect.top - y) <= sens); + } + + + if (!(vx || vy)) { + vx = (winWidth - x <= sens) - (x <= sens); + vy = (winHeight - y <= sens) - (y <= sens); + + /* jshint expr:true */ + (vx || vy) && (el = win); + } + + + if (autoScroll.vx !== vx || autoScroll.vy !== vy || autoScroll.el !== el) { + autoScroll.el = el; + autoScroll.vx = vx; + autoScroll.vy = vy; + + clearInterval(autoScroll.pid); + + if (el) { + autoScroll.pid = setInterval(function () { + if (el === win) { + win.scrollTo(win.scrollX + vx * speed, win.scrollY + vy * speed); + } else { + vy && (el.scrollTop += vy * speed); + vx && (el.scrollLeft += vx * speed); + } + }, 24); + } + } + } + }, 30) ; @@ -141,8 +218,9 @@ }, this); - // Export group name - el[expando] = group.name + ' ' + (group.put.join ? group.put.join(' ') : ''); + // Export options + options.groups = ' ' + group.name + (group.put.join ? ' ' + group.put.join(' ') : '') + ' '; + el[expando] = options; // Bind all private methods @@ -286,12 +364,12 @@ var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY), parent = target, - groupName = this.options.group.name, + groupName = ' ' + this.options.group.name + '', i = touchDragOverListeners.length; if (parent) { do { - if ((' ' + parent[expando] + ' ').indexOf(groupName) > -1) { + if (parent[expando] && parent[expando].groups.indexOf(groupName) > -1) { while (i--) { touchDragOverListeners[i]({ clientX: touchEvt.clientX, @@ -391,83 +469,9 @@ _on(document, 'drop', this); } - scrollEl = options.scroll; - - if (scrollEl === true) { - scrollEl = rootEl; - - do { - if ((scrollEl.offsetWidth < scrollEl.scrollWidth) || - (scrollEl.offsetHeight < scrollEl.scrollHeight) - ) { - break; - } - /* jshint boss:true */ - } while (scrollEl = scrollEl.parentNode); - } - setTimeout(this._dragStarted, 0); }, - _onDrag: _throttle(function (/**Event*/evt) { - // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 - if (rootEl && this.options.scroll) { - var el, - rect, - options = this.options, - sens = options.scrollSensitivity, - speed = options.scrollSpeed, - - x = evt.clientX, - y = evt.clientY, - - winWidth = window.innerWidth, - winHeight = window.innerHeight, - - vx, - vy - ; - - - if (scrollEl) { - el = scrollEl; - rect = scrollEl.getBoundingClientRect(); - vx = (abs(rect.right - x) <= sens) - (abs(rect.left - x) <= sens); - vy = (abs(rect.bottom - y) <= sens) - (abs(rect.top - y) <= sens); - } - - - if (!(vx || vy)) { - vx = (winWidth - x <= sens) - (x <= sens); - vy = (winHeight - y <= sens) - (y <= sens); - - /* jshint expr:true */ - (vx || vy) && (el = win); - } - - - if (autoScroll.vx !== vx || autoScroll.vy !== vy || autoScroll.el !== el) { - autoScroll.el = el; - autoScroll.vx = vx; - autoScroll.vy = vy; - - clearInterval(autoScroll.pid); - - if (el) { - autoScroll.pid = setInterval(function () { - if (el === win) { - win.scrollTo(win.scrollX + vx * speed, win.scrollY + vy * speed); - } else { - vy && (el.scrollTop += vy * speed); - vx && (el.scrollLeft += vx * speed); - } - }, 24); - } - } - } - }, 30), - - _onDragOver: function (/**Event*/evt) { var el = this.el, target, @@ -488,6 +492,8 @@ !options.dragoverBubble && evt.stopPropagation(); } + _autoScroll(evt, options, this.el); + if (!_silent && activeGroup && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) @@ -662,13 +668,16 @@ Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); } - // Set NULL + // Nulling rootEl = dragEl = ghostEl = nextEl = cloneEl = + scrollEl = + scrollParentEl = + tapEvt = touchEvt = @@ -688,7 +697,6 @@ var type = evt.type; if (type === 'dragover' || type === 'dragenter') { - this._onDrag(evt); this._onDragOver(evt); _globalDragOver(evt); } From 4c0f1afd324e8b598782a8fa62bfa5b8a21401ef Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Feb 2015 19:12:00 +0300 Subject: [PATCH 046/594] #256: - _onDrag --- Sortable.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index 050e74254..0e16a7dfe 100644 --- a/Sortable.js +++ b/Sortable.js @@ -407,7 +407,6 @@ _css(ghostEl, 'msTransform', translate3d); _css(ghostEl, 'transform', translate3d); - this._onDrag(touch); evt.preventDefault(); } }, @@ -492,9 +491,7 @@ !options.dragoverBubble && evt.stopPropagation(); } - _autoScroll(evt, options, this.el); - - if (!_silent && activeGroup && !options.disabled && + if (activeGroup && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) : activeGroup.pull && groupPut && ( @@ -504,6 +501,13 @@ ) && (evt.rootEl === void 0 || evt.rootEl === this.el) ) { + // Smart auto-scrolling + _autoScroll(evt, options, this.el); + + if (_silent) { + return; + } + target = _closest(evt.target, options.draggable, el); dragRect = dragEl.getBoundingClientRect(); From 563311f25eddbeb7b0276593f5a7d787504c7026 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Feb 2015 23:16:46 +0300 Subject: [PATCH 047/594] #271: + remove 'transform' (#issuecomment-73954644) --- Sortable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sortable.js b/Sortable.js index 0e16a7dfe..5c4672c64 100644 --- a/Sortable.js +++ b/Sortable.js @@ -603,6 +603,7 @@ clearTimeout(target.animated); target.animated = setTimeout(function () { _css(target, 'transition', ''); + _css(target, 'transform', ''); target.animated = false; }, ms); } From a89c2d5dc27001de87f967157e321339c1b337fc Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 12 Feb 2015 13:21:30 +0300 Subject: [PATCH 048/594] #217: * modularizing --- react-sortable-mixin.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 6f25acc4b..2cb2cb4ef 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -6,12 +6,12 @@ (function (factory) { 'use strict'; - if (typeof define === 'function' && define.amd) { - define(['sortable'], factory); - } - else if (typeof module != 'undefined' && typeof module.exports != 'undefined') { + if (typeof module != 'undefined' && typeof module.exports != 'undefined') { module.exports = factory(require('Sortable')); } + else if (typeof define === 'function' && define.amd) { + define(['sortable'], factory); + } else { /* jshint sub:true */ window['SortableMixin'] = factory(Sortable); From ef76066cc5df2bc41468ec1511b309eabf9b368f Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 12 Feb 2015 18:36:45 +0300 Subject: [PATCH 049/594] * relative path --- ng-sortable.js | 2 +- react-sortable-mixin.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index bef396c7f..a87256137 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -9,7 +9,7 @@ factory(angular, Sortable); } else if (typeof define === 'function' && define.amd) { - define(['angular', 'sortable'], factory); + define(['angular', './Sortable'], factory); } })(function (angular, Sortable) { 'use strict'; diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 2cb2cb4ef..47d1c3656 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -7,10 +7,10 @@ 'use strict'; if (typeof module != 'undefined' && typeof module.exports != 'undefined') { - module.exports = factory(require('Sortable')); + module.exports = factory(require('./Sortable')); } else if (typeof define === 'function' && define.amd) { - define(['sortable'], factory); + define(['./Sortable'], factory); } else { /* jshint sub:true */ From 52a49f36ed9faa92b5782e95e894edb56be01343 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 12 Feb 2015 22:34:02 +0300 Subject: [PATCH 050/594] * version-task --- Gruntfile.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 0f1db6c34..26e165684 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,7 +5,16 @@ module.exports = function (grunt) { pkg: grunt.file.readJSON('package.json'), version: { - src: ['<%= pkg.exportName %>.js', '*.json'] + js: { + src: ['<%= pkg.exportName %>.js', '*.json'] + }, + cdn: { + options: { + prefix: '(cdnjs\\.cloudflare\\.com\\/ajax\\/libs\\/Sortable|cdn\\.jsdelivr\\.net\\/sortable)\\/', + replace: '[0-9\\.]+' + }, + src: ['README.md'] + } }, jshint: { From 070a5715084c860dc8ddd5bedd17be09ccf7a102 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 13 Feb 2015 22:01:00 +0300 Subject: [PATCH 051/594] v1.1.0: Support IE9, CDN, enhancement auto-scrolling, React-mixin and more. --- README.md | 4 ++-- Sortable.js | 2 +- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- package.json | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 798651f85..720c880f6 100644 --- a/README.md +++ b/README.md @@ -536,11 +536,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index 5c4672c64..fbd588acb 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1028,7 +1028,7 @@ }; - Sortable.version = '1.0.1'; + Sortable.version = '1.1.0'; /** diff --git a/Sortable.min.js b/Sortable.min.js index 05f846821..f607599ac 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.0.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),L.forEach(function(d){b[d]=c(this,b[d]||M),f(a,d.substr(2).toLowerCase(),b[d])},this),a[E]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),P.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=O.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(O.call(arguments)))}}function d(a,b,c){if(a){c=c||G,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return G.defaultView&&G.defaultView.getComputedStyle?c=G.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){J=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D={},E="Sortable"+(new Date).getTime(),F=window,G=F.document,H=F.parseInt,I=!!("draggable"in G.createElement("div")),J=!1,K=function(a,b,c,d,e,f){var g=G.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},L="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),M=function(){},N=Math.abs,O=[].slice,P=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,K(t,"start",q,t,y)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),y=o(e),"function"==typeof l){if(l.call(this,a,e,this))return K(g,"filter",e,i,y),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(K(a,"filter",e,i,y),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){B=a,t=this.el,q=e,v=q.nextSibling,A=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(B={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(B,"touch"),a.preventDefault()),f(G,"mouseup",this._onDrop),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),f(G,"dragover",this),I||(f(G,"mousemove",this),this._onDragStart(B,!0));try{G.selection?G.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(C){i(r,"display","none");var a=G.elementFromPoint(C.clientX,C.clientY),b=a,c=this.options.group.name,d=P.length;if(b)do{if((" "+b[E]+" ").indexOf(c)>-1){for(;d--;)P[d]({clientX:C.clientX,clientY:C.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(B){var b=a.touches?a.touches[0]:a,c=b.clientX-B.clientX,d=b.clientY-B.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";C=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==A.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-H(h.marginTop,10)),i(r,"left",g.left-H(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(G,"touchmove",this._onTouchMove),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop)):(f(G,"mousemove",this._onTouchMove),f(G,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(G,"drop",this);if(u=d.scroll,u===!0){u=t;do if(u.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=F:u&&(b=u,c=u.getBoundingClientRect(),k=(N(c.right-g)<=e)-(N(c.left-g)<=e),l=(N(c.bottom-h)<=e)-(N(c.top-h)<=e)),(D.vx!==k||D.vy!==l||D.el!==b)&&(D.el=b,D.vx=k,D.vy=l,clearInterval(D.pid),b&&(D.pid=setInterval(function(){b===F?F.scrollTo(F.scrollX+k*f,F.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=A===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!J&&A&&!h.disabled&&(n?o||(f=!t.contains(q)):A.pull&&k&&(A.name===j.name||k.indexOf&&~k.indexOf(A.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||v?t.insertBefore(q,s||v):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;u=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(u,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[E]){w!==c&&(w=c,x=i(c));var p,u=c.getBoundingClientRect(),y=u.right-u.left,z=u.bottom-u.top,B=/left|right|inline/.test(x.cssFloat+x.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-u.left)/y:(a.clientY-u.top)/z)>.5,G=c.nextElementSibling;J=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!D||F&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(u,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(G,"mouseup",this._onDrop),g(G,"touchmove",this._onTouchMove),g(G,"touchend",this._onDrop),g(G,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(D.pid),g(G,"drop",this),g(G,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(z=o(q),K(q.parentNode,"sort",q,t,y,z),K(t,"sort",q,t,y,z),K(q,"add",q,t,y,z),K(t,"remove",q,t,y,z)):(s&&s.parentNode.removeChild(s),q.nextSibling!==v&&(z=o(q),K(t,"update",q,t,y,z),K(t,"sort",q,t,y,z))),a.active&&K(t,"end",q,t,y,z)),t=q=r=v=s=B=C=w=x=A=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;L.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),P.splice(P.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:K,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.1.0 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.scrollX+f*i,G.scrollY+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(!(a.dataTransfer&&"move"!==a.dataTransfer.effectAllowed||(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!B||h.disabled||!(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))||void 0!==a.rootEl&&a.rootEl!==this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.1.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index cb0e811ed..a5ffef41a 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.0.1", + "version": "1.1.0", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index e9fc86ea4..4eb1e0d1a 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.0.1", + "version": "1.1.0", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/package.json b/package.json index 6173c85b4..52009c261 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.0.1", + "version": "1.1.0", "devDependencies": { "grunt": "*", "grunt-version": "*", From 1c8839f08fdbe5399a216cfa4872df97eda794a6 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 16 Feb 2015 08:57:02 +0300 Subject: [PATCH 052/594] #277: * fixed handle & filter --- Sortable.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index 5c4672c64..6f1d4f049 100644 --- a/Sortable.js +++ b/Sortable.js @@ -275,12 +275,12 @@ return; // only left button or enabled } - if (options.handle) { - target = _closest(target, options.handle, el); - } - target = _closest(target, options.draggable, el); + if (!target) { + return; + } + // get the index of the dragged element within its parent oldIndex = _index(target); @@ -308,6 +308,12 @@ } } + + if (options.handle && !_closest(originalTarget, options.handle, el)) { + return; + } + + // Prepare `dragstart` if (target && !dragEl && (target.parentNode === el)) { tapEvt = evt; From 7dc8be57559534d5a93cf5aff1306a0f83daf56d Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 16 Feb 2015 17:55:24 +0300 Subject: [PATCH 053/594] #279: + dataIdAttr --- README.md | 3 ++- Sortable.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 70560084f..1c1867dbb 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ var sortable = new Sortable(el, { filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) draggable: ".item", // Specifies which items inside the element should be sortable ghostClass: "sortable-ghost", // Class name for the drop placeholder + dataIdAttr: 'data-id', scroll: true, // or HTMLElement scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. @@ -399,7 +400,7 @@ For each element in the set, get the first element that matches the selector by ##### toArray():`String[]` -Serializes the sortable's item `data-id`'s into an array of string. +Serializes the sortable's item `data-id`'s (`dataIdAttr` option) into an array of string. ##### sort(order:`String[]`) diff --git a/Sortable.js b/Sortable.js index 6f1d4f049..c6295b59d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -187,7 +187,8 @@ dataTransfer.setData('Text', dragEl.textContent); }, dropBubble: false, - dragoverBubble: false + dragoverBubble: false, + dataIdAttr: 'data-id' }; @@ -726,12 +727,13 @@ el, children = this.el.children, i = 0, - n = children.length; + n = children.length, + options = this.options; for (; i < n; i++) { el = children[i]; - if (_closest(el, this.options.draggable, this.el)) { - order.push(el.getAttribute('data-id') || _generateId(el)); + if (_closest(el, options.draggable, this.el)) { + order.push(el.getAttribute(options.dataAttr) || _generateId(el)); } } From 8b3e8f949710d3360c92b8fdc2d9f3fcd58d7e30 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 16 Feb 2015 18:06:58 +0300 Subject: [PATCH 054/594] #279: * dataAttr -> dataIdAttr --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index c6295b59d..1b054f77a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -733,7 +733,7 @@ for (; i < n; i++) { el = children[i]; if (_closest(el, options.draggable, this.el)) { - order.push(el.getAttribute(options.dataAttr) || _generateId(el)); + order.push(el.getAttribute(options.dataIdAttr) || _generateId(el)); } } From 1482449b1816b7bdce9f96be51c47000b9a73453 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 19 Feb 2015 21:20:16 +0300 Subject: [PATCH 055/594] #285: * fixed dragover handler --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 1b054f77a..a3cb20e4e 100644 --- a/Sortable.js +++ b/Sortable.js @@ -489,7 +489,7 @@ isOwner = (activeGroup === group), canSort = options.sort; - if (evt.dataTransfer && evt.dataTransfer.effectAllowed !== 'move') { + if (!dragEl) { return; } From 87e336a175ec4d0e593df685fe1f9ced612395fd Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 16 Feb 2015 08:57:02 +0300 Subject: [PATCH 056/594] #277: * fixed handle & filter --- Sortable.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index fbd588acb..2b6f6fcff 100644 --- a/Sortable.js +++ b/Sortable.js @@ -275,12 +275,12 @@ return; // only left button or enabled } - if (options.handle) { - target = _closest(target, options.handle, el); - } - target = _closest(target, options.draggable, el); + if (!target) { + return; + } + // get the index of the dragged element within its parent oldIndex = _index(target); @@ -308,6 +308,12 @@ } } + + if (options.handle && !_closest(originalTarget, options.handle, el)) { + return; + } + + // Prepare `dragstart` if (target && !dragEl && (target.parentNode === el)) { tapEvt = evt; From 0b909aa59d24e90220f549e4d4106b6e0b760f05 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 19 Feb 2015 21:20:16 +0300 Subject: [PATCH 057/594] #285: * fixed dragover handler --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 2b6f6fcff..5bcfee073 100644 --- a/Sortable.js +++ b/Sortable.js @@ -488,7 +488,7 @@ isOwner = (activeGroup === group), canSort = options.sort; - if (evt.dataTransfer && evt.dataTransfer.effectAllowed !== 'move') { + if (!dragEl) { return; } From c6a536aa3f999b2c556f301527fa1e7186a67d65 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 20 Feb 2015 08:49:33 +0300 Subject: [PATCH 058/594] v1.1.1: #227, #285 --- README.md | 4 ++-- Sortable.js | 2 +- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- package.json | 2 +- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 720c880f6..44a1f946a 100644 --- a/README.md +++ b/README.md @@ -536,11 +536,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index 5bcfee073..2be6baee9 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1034,7 +1034,7 @@ }; - Sortable.version = '1.1.0'; + Sortable.version = '1.1.1'; /** diff --git a/Sortable.min.js b/Sortable.min.js index f607599ac..909ab3ef4 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.1.0 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.scrollX+f*i,G.scrollY+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(!(a.dataTransfer&&"move"!==a.dataTransfer.effectAllowed||(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!B||h.disabled||!(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))||void 0!==a.rootEl&&a.rootEl!==this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.1.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.1.1 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.scrollX+f*i,G.scrollY+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)&&(e=d(e,h.draggable,i))){if(z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if((!h.handle||d(g,h.handle,i))&&e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(q&&(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),B&&!h.disabled&&(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))&&(void 0===a.rootEl||a.rootEl===this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.1.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index a5ffef41a..c5e42aac3 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.1.0", + "version": "1.1.1", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index 4eb1e0d1a..de414f10e 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.1.0", + "version": "1.1.1", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/package.json b/package.json index 52009c261..44367c223 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.1.0", + "version": "1.1.1", "devDependencies": { "grunt": "*", "grunt-version": "*", From c7257ae198ba136ebec55b9cfae760f9e89c4e9a Mon Sep 17 00:00:00 2001 From: Bogdan Mustiata Date: Tue, 3 Mar 2015 14:53:15 +0100 Subject: [PATCH 059/594] Don't join class names when removing classes after additions. --- Sortable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index a3cb20e4e..e7bb2fee0 100644 --- a/Sortable.js +++ b/Sortable.js @@ -896,7 +896,10 @@ el.classList[state ? 'add' : 'remove'](name); } else { - var className = (' ' + el.className + ' ').replace(/\s+/g, ' ').replace(' ' + name + ' ', ''); + var className = (' ' + el.className + ' ') + .replace(/\s+/g, ' ') + .replace(' ' + name + ' ', ' ') + .replace(/ /, ' '); el.className = className + (state ? ' ' + name : ''); } } From 3738fa8db47daa74ea14aad564dc5796664b4721 Mon Sep 17 00:00:00 2001 From: srosengren Date: Wed, 4 Mar 2015 14:59:58 +0100 Subject: [PATCH 060/594] Added bindinghandlers for KnockoutJS --- knockout-sortable.js | 158 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) create mode 100644 knockout-sortable.js diff --git a/knockout-sortable.js b/knockout-sortable.js new file mode 100644 index 000000000..0a97d0a75 --- /dev/null +++ b/knockout-sortable.js @@ -0,0 +1,158 @@ +(function () { + + var init = function (element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) { + var options = buildOptions(valueAccessor, sortableOptions); + + //It's seems that we cannot update the eventhandlers after we've created the sortable, so define them in init instead of update + ['onStart', 'onEnd', 'onRemove', 'onAdd', 'onUpdate', 'onSort', 'onFilter'].forEach(function (e) { + if (options[e] || eventHandlers[e]) + options[e] = function (eventType, parentVM, parentBindings, handler, e) { + var itemVM = ko.dataFor(e.item), + //All of the bindings on the parent element + bindings = ko.utils.peekObservable(parentBindings()), + //The binding options for the draggable/sortable binding of the parent element + bindingHandlerBinding = bindings.sortable || bindings.draggable, + //The collection that we should modify + collection = bindingHandlerBinding.collection || bindingHandlerBinding.foreach; + if (handler) + handler(e, itemVM, parentVM, collection, bindings); + if (eventHandlers[eventType]) + eventHandlers[eventType](e, itemVM, parentVM, collection, bindings); + }.bind(undefined, e, viewModel, allBindings, options[e]); + }); + + viewModel._sortable = Sortable.create(element, options); + + //Destroy the sortable if knockout disposes the element it's connected to + ko.utils.domNodeDisposal.addDisposeCallback(element, function () { + viewModel._sortable.destroy(); + }); + return ko.bindingHandlers['template']['init'](element, valueAccessor); + }, + update = function (element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) { + + //There seems to be some problems with updating the options of a sortable + //Tested to change eventhandlers and the group options without any luck + + return ko.bindingHandlers['template']['update'](element, valueAccessor, allBindings, viewModel, bindingContext); + }, + eventHandlers = (function (handlers) { + + var moveOperations = [], + tryMoveOperation = function (e, itemVM, parentVM, collection, parentBindings) { + //A move operation is the combination of a add and remove event, this is to make sure that we have both the target and origin collections + var currentOperation = { event: e, itemVM: itemVM, parentVM: parentVM, collection: collection, parentBindings: parentBindings }, + existingOperation = moveOperations.filter(function (op) { + return op.itemVM === currentOperation.itemVM; + })[0]; + + if (!existingOperation) { + moveOperations.push(currentOperation); + } + else { + //We're finishing the operation and already have a handle on the operation item meaning that it's safe to remove it + moveOperations.splice(moveOperations.indexOf(existingOperation), 1); + + var removeOperation = currentOperation.event.type === 'remove' ? currentOperation : existingOperation, + addOperation = currentOperation.event.type === 'add' ? currentOperation : existingOperation; + + moveItem(itemVM, removeOperation.collection, addOperation.collection, addOperation.event.clone, addOperation.event); + } + }, + //Moves an item from the to (collection to from (collection), these can be references to the same collection which means it's a sort, + //clone indicates if we should move or copy the item into the new collection + moveItem = function (itemVM, from, to, clone, e) { + //Unwrapping this allows us to manipulate the actual array + var fromArray = from(), + //It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc. + originalIndex = fromArray.indexOf(itemVM); + + //Remove sortables "unbound" element + e.item.parentNode.removeChild(e.item); + + //This splice is necessary for both clone and move/sort + //In sort/move since it shouldn't be at this index/in this array anymore + //In clone since we have to work around knockouts valuHasMutated when manipulating arrays and avoid a "unbound" item added by sortable + fromArray.splice(originalIndex, 1); + //Update the array, this will also remove sortables "unbound" clone + from.valueHasMutated(); + if (clone && from !== to) { + //Readd the item + fromArray.splice(originalIndex, 0, itemVM); + //Force knockout to update + from.valueHasMutated(); + } + //Insert the item on its new position + to().splice(e.newIndex, 0, itemVM); + //Make sure to tell knockout that we've modified the actual array. + to.valueHasMutated(); + }; + + handlers.onRemove = tryMoveOperation; + handlers.onAdd = tryMoveOperation; + handlers.onUpdate = function (e, itemVM, parentVM, collection, parentBindings) { + //This will be performed as a sort since the to/from collections reference the same collection and clone is set to false + moveItem(itemVM, collection, collection, false, e); + } + + return handlers; + })({}), + //bindingOptions are the options set in the "data-bind" attribute in the ui. + //options are custom options, for instance draggable/sortable specific options + buildOptions = function (bindingOptions, options) { + //deep clone/copy of properties from the "from" argument onto the "into" argument and returns the modified "into" + var merge = function (into, from) { + for (var prop in from) { + if (Object.prototype.toString.call(from[prop]) === '[object Object]') { + if (Object.prototype.toString.call(into[prop]) !== '[object Object]') { + into[prop] = {}; + } + into[prop] = merge(into[prop], from[prop]); + } + else + into[prop] = from[prop]; + } + + return into; + }, + //unwrap the supplied options + unwrappedOptions = ko.utils.peekObservable(bindingOptions()).options || {}, + //Make sure that we don't modify the provided settings object + options = merge({}, options); + + //group is handled differently since we should both allow to change a draggable to a sortable (and vice versa), + //but still be able to set a name on a draggable without it becoming a drop target. + if (unwrappedOptions.group && Object.prototype.toString.call(unwrappedOptions.group) !== '[object Object]') { + //group property is a name string declaration, convert to object. + unwrappedOptions.group = { name: unwrappedOptions.group }; + } + + return merge(options, unwrappedOptions); + }; + + ko.bindingHandlers.draggable = { + sortableOptions: { + group: { pull: 'clone', put: false }, + sort: false + }, + init: function (element, valueAccessor, allBindings, viewModel, bindingContext) { + return init(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.draggable.sortableOptions); + }, + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { + return update(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.draggable.sortableOptions); + } + }; + + ko.bindingHandlers.sortable = { + sortableOptions: { + group: { pull: true, put: true } + }, + init: function (element, valueAccessor, allBindings, viewModel, bindingContext) { + return init(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.sortable.sortableOptions); + }, + update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { + return update(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.sortable.sortableOptions); + } + } + +})(); \ No newline at end of file From 2920836d5c2ff372a03869c1c449a2621f1fa83c Mon Sep 17 00:00:00 2001 From: srosengren Date: Wed, 4 Mar 2015 15:12:00 +0100 Subject: [PATCH 061/594] Ran grunt after adding knockoutjs bindinghandlers --- Sortable.min.js | 2 +- knockout-sortable.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Sortable.min.js b/Sortable.min.js index 05f846821..4a75c2c94 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.0.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),L.forEach(function(d){b[d]=c(this,b[d]||M),f(a,d.substr(2).toLowerCase(),b[d])},this),a[E]=g.name+" "+(g.put.join?g.put.join(" "):"");for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),P.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=O.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(O.call(arguments)))}}function d(a,b,c){if(a){c=c||G,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return G.defaultView&&G.defaultView.getComputedStyle?c=G.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){J=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D={},E="Sortable"+(new Date).getTime(),F=window,G=F.document,H=F.parseInt,I=!!("draggable"in G.createElement("div")),J=!1,K=function(a,b,c,d,e,f){var g=G.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},L="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),M=function(){},N=Math.abs,O=[].slice,P=[];return a.prototype={constructor:a,_dragStarted:function(){h(q,this.options.ghostClass,!0),a.active=this,K(t,"start",q,t,y)},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)){if(h.handle&&(e=d(e,h.handle,i)),e=d(e,h.draggable,i),y=o(e),"function"==typeof l){if(l.call(this,a,e,this))return K(g,"filter",e,i,y),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(K(a,"filter",e,i,y),!0):void 0})))return void a.preventDefault();if(e&&!q&&e.parentNode===i){B=a,t=this.el,q=e,v=q.nextSibling,A=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(B={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(B,"touch"),a.preventDefault()),f(G,"mouseup",this._onDrop),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),f(G,"dragover",this),I||(f(G,"mousemove",this),this._onDragStart(B,!0));try{G.selection?G.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(C){i(r,"display","none");var a=G.elementFromPoint(C.clientX,C.clientY),b=a,c=this.options.group.name,d=P.length;if(b)do{if((" "+b[E]+" ").indexOf(c)>-1){for(;d--;)P[d]({clientX:C.clientX,clientY:C.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(B){var b=a.touches?a.touches[0]:a,c=b.clientX-B.clientX,d=b.clientY-B.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";C=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==A.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-H(h.marginTop,10)),i(r,"left",g.left-H(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(G,"touchmove",this._onTouchMove),f(G,"touchend",this._onDrop),f(G,"touchcancel",this._onDrop)):(f(G,"mousemove",this._onTouchMove),f(G,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(G,"drop",this);if(u=d.scroll,u===!0){u=t;do if(u.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=F:u&&(b=u,c=u.getBoundingClientRect(),k=(N(c.right-g)<=e)-(N(c.left-g)<=e),l=(N(c.bottom-h)<=e)-(N(c.top-h)<=e)),(D.vx!==k||D.vy!==l||D.el!==b)&&(D.el=b,D.vx=k,D.vy=l,clearInterval(D.pid),b&&(D.pid=setInterval(function(){b===F?F.scrollTo(F.scrollX+k*f,F.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=A===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),!J&&A&&!h.disabled&&(n?o||(f=!t.contains(q)):A.pull&&k&&(A.name===j.name||k.indexOf&&~k.indexOf(A.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||v?t.insertBefore(q,s||v):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;u=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(u,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[E]){w!==c&&(w=c,x=i(c));var p,u=c.getBoundingClientRect(),y=u.right-u.left,z=u.bottom-u.top,B=/left|right|inline/.test(x.cssFloat+x.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,F=(B?(a.clientX-u.left)/y:(a.clientY-u.top)/z)>.5,G=c.nextElementSibling;J=!0,setTimeout(l,30),b(n),p=B?c.previousElementSibling===q&&!C||F&&C:G!==q&&!D||F&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(u,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),b.animated=!1},c)}},_offUpEvents:function(){g(G,"mouseup",this._onDrop),g(G,"touchmove",this._onTouchMove),g(G,"touchend",this._onDrop),g(G,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(D.pid),g(G,"drop",this),g(G,"dragover",this),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(z=o(q),K(q.parentNode,"sort",q,t,y,z),K(t,"sort",q,t,y,z),K(q,"add",q,t,y,z),K(t,"remove",q,t,y,z)):(s&&s.parentNode.removeChild(s),q.nextSibling!==v&&(z=o(q),K(t,"update",q,t,y,z),K(t,"sort",q,t,y,z))),a.active&&K(t,"end",q,t,y,z)),t=q=r=v=s=B=C=w=x=A=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length;f>e;e++)a=c[e],d(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;L.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this._onDragOver),g(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),P.splice(P.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:K,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id"};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.scrollX+f*i,G.scrollY+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)&&(e=d(e,h.draggable,i))){if(z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if((!h.handle||d(g,h.handle,i))&&e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(q&&(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),B&&!h.disabled&&(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))&&(void 0===a.rootEl||a.rootEl===this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/knockout-sortable.js b/knockout-sortable.js index 0a97d0a75..6a7f70137 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -1,6 +1,8 @@ (function () { + "use strict"; var init = function (element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) { + var options = buildOptions(valueAccessor, sortableOptions); //It's seems that we cannot update the eventhandlers after we've created the sortable, so define them in init instead of update @@ -27,14 +29,14 @@ ko.utils.domNodeDisposal.addDisposeCallback(element, function () { viewModel._sortable.destroy(); }); - return ko.bindingHandlers['template']['init'](element, valueAccessor); + return ko.bindingHandlers.template.init(element, valueAccessor); }, update = function (element, valueAccessor, allBindings, viewModel, bindingContext, sortableOptions) { //There seems to be some problems with updating the options of a sortable //Tested to change eventhandlers and the group options without any luck - return ko.bindingHandlers['template']['update'](element, valueAccessor, allBindings, viewModel, bindingContext); + return ko.bindingHandlers.template.update(element, valueAccessor, allBindings, viewModel, bindingContext); }, eventHandlers = (function (handlers) { @@ -93,7 +95,7 @@ handlers.onUpdate = function (e, itemVM, parentVM, collection, parentBindings) { //This will be performed as a sort since the to/from collections reference the same collection and clone is set to false moveItem(itemVM, collection, collection, false, e); - } + }; return handlers; })({}), @@ -116,7 +118,8 @@ return into; }, //unwrap the supplied options - unwrappedOptions = ko.utils.peekObservable(bindingOptions()).options || {}, + unwrappedOptions = ko.utils.peekObservable(bindingOptions()).options || {}; + //Make sure that we don't modify the provided settings object options = merge({}, options); @@ -153,6 +156,6 @@ update: function (element, valueAccessor, allBindings, viewModel, bindingContext) { return update(element, valueAccessor, allBindings, viewModel, bindingContext, ko.bindingHandlers.sortable.sortableOptions); } - } + }; })(); \ No newline at end of file From 6928b193ab9d571c78a34550e71b9c4712f9dae6 Mon Sep 17 00:00:00 2001 From: Sebastian Rosengren Date: Wed, 4 Mar 2015 21:35:34 +0100 Subject: [PATCH 062/594] Added KnockoutJS description to README --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index 1c1867dbb..0e949de21 100644 --- a/README.md +++ b/README.md @@ -387,6 +387,32 @@ React.render(
        --- + +### Support KnockoutJS +Include [knockout-sortable.js](knockout-sortable.js) + +```html +
        + +
        + +
        + +
        +``` + +Using this bindingHandler sorts the observableArray when the user sorts the HTMLElements. + +The sortable/draggable bindingHandlers supports the same syntax as Knockouts built in [template](http://knockoutjs.com/documentation/template-binding.html) binding except for the `data` option, meaning that you could supply the name of a template or specify a separate templateEngine. The difference between the sortable and draggable handlers is that the draggable has the sortable `group` option set to `{pull:'clone',put: false}` and the `sort` option set to false by default (overridable). + +Other attributes are: +* options: an object that contains settings for the underlaying sortable, ie `group`,`handle`, events etc. +* collection: if your `foreach` array is a computed then you would supply the underlaying observableArray that you would like to sort here. + + +--- + + ### Method From f802c84d05f49adcbf8627dedb689225a27afba9 Mon Sep 17 00:00:00 2001 From: Bogdan Mustiata Date: Thu, 5 Mar 2015 12:13:56 +0100 Subject: [PATCH 063/594] Use precompiled RegExp. --- Sortable.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index e7bb2fee0..c20e3be9c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -889,6 +889,8 @@ el.removeEventListener(event, fn, false); } + /** @const */ + var RSPACE = /\s+/g; function _toggleClass(el, name, state) { if (el) { @@ -896,11 +898,8 @@ el.classList[state ? 'add' : 'remove'](name); } else { - var className = (' ' + el.className + ' ') - .replace(/\s+/g, ' ') - .replace(' ' + name + ' ', ' ') - .replace(/ /, ' '); - el.className = className + (state ? ' ' + name : ''); + var className = (' ' + el.className + ' ').replace(RSPACE, ' ').replace(' ' + name + ' ', ' '); + el.className = (className + (state ? ' ' + name : '')).replace(RSPACE, ' '); } } } From a6f86320ce298aa9ec46b8cd62ca6717bd7d7395 Mon Sep 17 00:00:00 2001 From: srosengren Date: Sat, 7 Mar 2015 21:35:52 +0100 Subject: [PATCH 064/594] Fixed issue with computed foreach's Fixed how we find correct indexes for items if the sortable is bound to a filtered collection. --- knockout-sortable.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index 6a7f70137..59d424d08 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -67,7 +67,13 @@ //Unwrapping this allows us to manipulate the actual array var fromArray = from(), //It's not certain that the items actual index is the same as the index reported by sortable due to filtering etc. - originalIndex = fromArray.indexOf(itemVM); + originalIndex = fromArray.indexOf(itemVM), + newIndex = e.newIndex; + + if (e.item.previousElementSibling) + newIndex = fromArray.indexOf(ko.dataFor(e.item.previousElementSibling)); + if (originalIndex > newIndex) + newIndex = newIndex + 1; //Remove sortables "unbound" element e.item.parentNode.removeChild(e.item); @@ -85,7 +91,7 @@ from.valueHasMutated(); } //Insert the item on its new position - to().splice(e.newIndex, 0, itemVM); + to().splice(newIndex, 0, itemVM); //Make sure to tell knockout that we've modified the actual array. to.valueHasMutated(); }; From 1f58b1b10b7eca676654e0989c7831ae8e9f9fdd Mon Sep 17 00:00:00 2001 From: Noah Chase Date: Tue, 10 Mar 2015 12:38:43 -0400 Subject: [PATCH 065/594] use `page{d}Offset` instead of `scroll{d}` All modern browsers seem to support `window.pageXOffset` and `window.pageYOffset`, which are aliases for `window.scrollX` and `window.scrollY`. IE doesn't seem to have `window.scrollX` and `window.scrollY`. fixes #302 --- Sortable.js | 2 +- Sortable.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index a3cb20e4e..9bdc895bb 100644 --- a/Sortable.js +++ b/Sortable.js @@ -144,7 +144,7 @@ if (el) { autoScroll.pid = setInterval(function () { if (el === win) { - win.scrollTo(win.scrollX + vx * speed, win.scrollY + vy * speed); + win.scrollTo(win.pageXOffset + vx * speed, win.pageYOffset + vy * speed); } else { vy && (el.scrollTop += vy * speed); vx && (el.scrollLeft += vx * speed); diff --git a/Sortable.min.js b/Sortable.min.js index 4a75c2c94..3dc5f5d77 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.0.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id"};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.scrollX+f*i,G.scrollY+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)&&(e=d(e,h.draggable,i))){if(z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if((!h.handle||d(g,h.handle,i))&&e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(q&&(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),B&&!h.disabled&&(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))&&(void 0===a.rootEl||a.rootEl===this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=b||{};var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id"};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),M.forEach(function(d){b[d]=c(this,b[d]||N),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[F]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){s&&s.state!==a&&(i(s,"display",a?"none":""),!a&&s.state&&t.insertBefore(s,q),s.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||H,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return H.defaultView&&H.defaultView.getComputedStyle?c=H.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){K=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}var q,r,s,t,u,v,w,x,y,z,A,B,C,D,E={},F="Sortable"+(new Date).getTime(),G=window,H=G.document,I=G.parseInt,J=!!("draggable"in H.createElement("div")),K=!1,L=function(a,b,c,d,e,f){var g=H.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=s,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},M="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),N=function(){},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(w!==c&&(v=b.scroll,w=c,v===!0)){v=c;do if(v.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=G)),(E.vx!==f||E.vy!==g||E.el!==d)&&(E.el=d,E.vx=f,E.vy=g,clearInterval(E.pid),d&&(E.pid=setInterval(function(){d===G?G.scrollTo(G.pageXOffset+f*i,G.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_dragStarted:function(){t&&q&&(h(q,this.options.ghostClass,!0),a.active=this,L(t,"start",q,t,z))},_onTapStart:function(a){var b=a.type,c=a.touches&&a.touches[0],e=(c||a).target,g=e,h=this.options,i=this.el,l=h.filter;if(!("mousedown"===b&&0!==a.button||h.disabled)&&(e=d(e,h.draggable,i))){if(z=o(e),"function"==typeof l){if(l.call(this,a,e,this))return L(g,"filter",e,i,z),void a.preventDefault()}else if(l&&(l=l.split(",").some(function(a){return a=d(g,a.trim(),i),a?(L(a,"filter",e,i,z),!0):void 0})))return void a.preventDefault();if((!h.handle||d(g,h.handle,i))&&e&&!q&&e.parentNode===i){C=a,t=this.el,q=e,u=q.nextSibling,B=this.options.group,q.draggable=!0,h.ignore.split(",").forEach(function(a){j(e,a.trim(),k)}),c&&(C={target:e,clientX:c.clientX,clientY:c.clientY},this._onDragStart(C,"touch"),a.preventDefault()),f(H,"mouseup",this._onDrop),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop),f(q,"dragend",this),f(t,"dragstart",this._onDragStart),J||this._onDragStart(C,!0);try{H.selection?H.selection.empty():window.getSelection().removeAllRanges()}catch(m){}}}},_emulateDragOver:function(){if(D){i(r,"display","none");var a=H.elementFromPoint(D.clientX,D.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[F]&&b[F].groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:D.clientX,clientY:D.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(r,"display","")}},_onTouchMove:function(a){if(C){var b=a.touches?a.touches[0]:a,c=b.clientX-C.clientX,d=b.clientY-C.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";D=b,i(r,"webkitTransform",e),i(r,"mozTransform",e),i(r,"msTransform",e),i(r,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==B.pull&&(s=q.cloneNode(!0),i(s,"display","none"),t.insertBefore(s,q)),b){var e,g=q.getBoundingClientRect(),h=i(q);r=q.cloneNode(!0),i(r,"top",g.top-I(h.marginTop,10)),i(r,"left",g.left-I(h.marginLeft,10)),i(r,"width",g.width),i(r,"height",g.height),i(r,"opacity","0.8"),i(r,"position","fixed"),i(r,"zIndex","100000"),t.appendChild(r),e=r.getBoundingClientRect(),i(r,"width",2*g.width-e.width),i(r,"height",2*g.height-e.height),"touch"===b?(f(H,"touchmove",this._onTouchMove),f(H,"touchend",this._onDrop),f(H,"touchcancel",this._onDrop)):(f(H,"mousemove",this._onTouchMove),f(H,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,q)),f(H,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=B===j,o=h.sort;if(q&&(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),B&&!h.disabled&&(n?o||(f=!t.contains(q)):B.pull&&k&&(B.name===j.name||k.indexOf&&~k.indexOf(B.name)))&&(void 0===a.rootEl||a.rootEl===this.el))){if(R(a,h,this.el),K)return;if(c=d(a.target,h.draggable,g),e=q.getBoundingClientRect(),f)return b(!0),void(s||u?t.insertBefore(q,s||u):o||t.appendChild(q));if(0===g.children.length||g.children[0]===r||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;v=c.getBoundingClientRect()}b(n),g.appendChild(q),this._animate(e,q),c&&this._animate(v,c)}else if(c&&!c.animated&&c!==q&&void 0!==c.parentNode[F]){x!==c&&(x=c,y=i(c));var p,v=c.getBoundingClientRect(),w=v.right-v.left,z=v.bottom-v.top,A=/left|right|inline/.test(y.cssFloat+y.display),C=c.offsetWidth>q.offsetWidth,D=c.offsetHeight>q.offsetHeight,E=(A?(a.clientX-v.left)/w:(a.clientY-v.top)/z)>.5,G=c.nextElementSibling;K=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===q&&!C||E&&C:G!==q&&!D||E&&D,p&&!G?g.appendChild(q):c.parentNode.insertBefore(q,p?G:c),this._animate(e,q),this._animate(v,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){g(H,"mouseup",this._onDrop),g(H,"touchmove",this._onTouchMove),g(H,"touchend",this._onDrop),g(H,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(E.pid),g(H,"drop",this),g(H,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),r&&r.parentNode.removeChild(r),q&&(g(q,"dragend",this),k(q),h(q,this.options.ghostClass,!1),t!==q.parentNode?(A=o(q),L(q.parentNode,"sort",q,t,z,A),L(t,"sort",q,t,z,A),L(q,"add",q,t,z,A),L(t,"remove",q,t,z,A)):(s&&s.parentNode.removeChild(s),q.nextSibling!==u&&(A=o(q),L(t,"update",q,t,z,A),L(t,"sort",q,t,z,A))),a.active&&L(t,"end",q,t,z,A)),t=q=r=u=s=v=w=C=D=x=y=B=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;M.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},throttle:p,closest:d,toggleClass:h,dispatchEvent:L,index:o},a.version="1.0.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file From 7309734dbf52e0e9d9682ad563660a5d0acb51de Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Mar 2015 18:06:34 +0300 Subject: [PATCH 066/594] #290: + clone simple 'option' and 'extend' method --- Sortable.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 9bdc895bb..db894b64f 100644 --- a/Sortable.js +++ b/Sortable.js @@ -165,7 +165,7 @@ */ function Sortable(el, options) { this.el = el; // root element - this.options = options = (options || {}); + this.options = options = _extend({}, options); // Default options @@ -1017,6 +1017,18 @@ }; } + function _extend(dst, src) { + if (dst && src) { + for (var key in src) { + if (src.hasOwnProperty(key)) { + dst[key] = src[key]; + } + } + } + + return dst; + } + // Export utils Sortable.utils = { @@ -1028,6 +1040,7 @@ is: function (el, selector) { return !!_closest(el, selector, el); }, + extend: _extend, throttle: _throttle, closest: _closest, toggleClass: _toggleClass, From 8b818ed280bfe54e4e51d5ff375f751eb590239f Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Mar 2015 18:33:36 +0300 Subject: [PATCH 067/594] #288: + use 'ownerDocument' for correct working with/into iframe --- Sortable.js | 17 ++++++++------- st/iframe/frame.html | 32 +++++++++++++++++++++++++++++ st/iframe/index.html | 49 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 st/iframe/frame.html create mode 100644 st/iframe/index.html diff --git a/Sortable.js b/Sortable.js index db894b64f..82e1525c3 100644 --- a/Sortable.js +++ b/Sortable.js @@ -269,8 +269,9 @@ target = (touch || evt).target, originalTarget = target, options = this.options, + filter = options.filter, el = this.el, - filter = options.filter; + ownerDocument = el.ownerDocument; // for correct working with/into iframe if (type === 'mousedown' && evt.button !== 0 || options.disabled) { return; // only left button or enabled @@ -343,9 +344,9 @@ evt.preventDefault(); } - _on(document, 'mouseup', this._onDrop); - _on(document, 'touchend', this._onDrop); - _on(document, 'touchcancel', this._onDrop); + _on(ownerDocument, 'mouseup', this._onDrop); + _on(ownerDocument, 'touchend', this._onDrop); + _on(ownerDocument, 'touchcancel', this._onDrop); _on(dragEl, 'dragend', this); _on(rootEl, 'dragstart', this._onDragStart); @@ -617,10 +618,12 @@ }, _offUpEvents: function () { - _off(document, 'mouseup', this._onDrop); + var ownerDocument = this.el.ownerDocument; + _off(document, 'touchmove', this._onTouchMove); - _off(document, 'touchend', this._onDrop); - _off(document, 'touchcancel', this._onDrop); + _off(ownerDocument, 'mouseup', this._onDrop); + _off(ownerDocument, 'touchend', this._onDrop); + _off(ownerDocument, 'touchcancel', this._onDrop); }, _onDrop: function (/**Event*/evt) { diff --git a/st/iframe/frame.html b/st/iframe/frame.html new file mode 100644 index 000000000..677eeef64 --- /dev/null +++ b/st/iframe/frame.html @@ -0,0 +1,32 @@ + + + + + + + + + + + + +
        +
        + 14 + + Drag me by the handle +
        +
        + 2 + + You can also select text +
        +
        + 1 + + Best of both worlds! +
        +
        + + + diff --git a/st/iframe/index.html b/st/iframe/index.html new file mode 100644 index 000000000..fcd089857 --- /dev/null +++ b/st/iframe/index.html @@ -0,0 +1,49 @@ + + + + + IFrame playground + + + + + + + + + + + + + +
        +
        This is Sortable
        +
        It works with Bootstrap...
        +
        ...out of the box.
        +
        It has support for touch devices.
        +
        Just drag some elements around.
        +
        + + + + + From 5fd36b19b18ef81148ae38078a159fbd281120aa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Mar 2015 18:36:32 +0300 Subject: [PATCH 068/594] * RSPACE --- Sortable.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index ec0875012..c64980f15 100644 --- a/Sortable.js +++ b/Sortable.js @@ -45,6 +45,9 @@ tapEvt, touchEvt, + /** @const */ + RSPACE = /\s+/g, + expando = 'Sortable' + (new Date).getTime(), win = window, @@ -53,7 +56,6 @@ supportDraggable = !!('draggable' in document.createElement('div')), - _silent = false, _dispatchEvent = function (rootEl, name, targetEl, fromEl, startIndex, newIndex) { @@ -892,8 +894,6 @@ el.removeEventListener(event, fn, false); } - /** @const */ - var RSPACE = /\s+/g; function _toggleClass(el, name, state) { if (el) { From 6209024019951f6250540d3fb1a8adc4d28faa33 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 11 Mar 2015 19:27:47 +0300 Subject: [PATCH 069/594] #284: -> version --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index a87256137..26df499c1 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -25,7 +25,7 @@ angular.module('ng-sortable', []) - .constant('$version', '0.3.5') + .constant('version', '0.3.6') .directive('ngSortable', ['$parse', function ($parse) { var removed, nextSibling; From b7749c4576af790cdd3620336dea69729cf35b57 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 12 Mar 2015 08:46:36 +0300 Subject: [PATCH 070/594] #298: + watchers of events --- ng-sortable.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 26df499c1..4d40d3dc6 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -160,7 +160,10 @@ }); if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly - angular.forEach(['sort', 'disabled', 'draggable', 'handle', 'animation'], function (name) { + angular.forEach([ + 'sort', 'disabled', 'draggable', 'handle', 'animation', + 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' + ], function (name) { scope.$watch(ngSortable + '.' + name, function (value) { if (value !== void 0) { options[name] = value; From 78c53ba5e19c6616893183e655cf9d28cb1ec77d Mon Sep 17 00:00:00 2001 From: jboulouloubi Date: Wed, 1 Apr 2015 18:35:36 -0400 Subject: [PATCH 071/594] Add delay between touchstart and dragstart --- Sortable.js | 135 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 49 deletions(-) diff --git a/Sortable.js b/Sortable.js index c64980f15..962c6e9a2 100644 --- a/Sortable.js +++ b/Sortable.js @@ -190,7 +190,8 @@ }, dropBubble: false, dragoverBubble: false, - dataIdAttr: 'data-id' + dataIdAttr: 'data-id', + delay: 0 }; @@ -264,6 +265,87 @@ } }, + _triggerDragStart: function (evt, target, touch) { + evt.preventDefault(); + + if (touch) { + // Touch device support + tapEvt = { + target: target, + clientX: touch.clientX, + clientY: touch.clientY + }; + + this._onDragStart(tapEvt, 'touch'); + } else if (!supportDraggable) { + this._onDragStart(tapEvt, true); + } else { + _on(dragEl, 'dragend', this); + _on(rootEl, 'dragstart', this._onDragStart); + } + + try { + if (document.selection) { + document.selection.empty(); + } else { + window.getSelection().removeAllRanges(); + } + } catch (err) { + } + }, + + _enableDragStart: function (dragEl, target) { + dragEl.draggable = true; + + // Disable "draggable" + this.options.ignore.split(',').forEach(function (criteria) { + _find(target, criteria.trim(), _disableDraggable); + }); + }, + + _disableDelayedDrag: function () { + clearTimeout(this.dragStartTimer); + + _off(document, 'mousemove', this._disableDelayedDrag); + _off(document, 'touchmove', this._disableDelayedDrag); + }, + + _prepareDragStart: function (evt, target, el, touch) { + var _this = this; + + if (target && !dragEl && (target.parentNode === el)) { + tapEvt = evt; + + rootEl = this.el; + dragEl = target; + nextEl = dragEl.nextSibling; + activeGroup = this.options.group; + + this.options.delay = this.options.delay || 1; + if (this.options.delay) { + _on(document, 'mouseup', this._onDrop); + _on(document, 'touchend', this._onDrop); + _on(document, 'touchcancel', this._onDrop); + + // If the user moves the pointer before the delay has been reached: + // disable the delayed drag + _on(document, 'mousemove', this._disableDelayedDrag); + _on(document, 'touchmove', this._disableDelayedDrag); + + this.dragStartTimer = setTimeout(function () { + // Delayed drag has been triggered + // we can re-enable the events: touchmove/mousemove + _off(document, 'mousemove', _this._disableDelayedDrag); + _off(document, 'touchmove', _this._disableDelayedDrag); + + // Make the element draggable + _this._enableDragStart(dragEl, target); + // Bind the events: dragstart/dragend + _this._triggerDragStart(evt, target, touch); + }, this.options.delay); + } + } + }, _onTapStart: function (/**Event|TouchEvent*/evt) { var type = evt.type, @@ -317,55 +399,8 @@ return; } - // Prepare `dragstart` - if (target && !dragEl && (target.parentNode === el)) { - tapEvt = evt; - - rootEl = this.el; - dragEl = target; - nextEl = dragEl.nextSibling; - activeGroup = this.options.group; - - dragEl.draggable = true; - - // Disable "draggable" - options.ignore.split(',').forEach(function (criteria) { - _find(target, criteria.trim(), _disableDraggable); - }); - - if (touch) { - // Touch device support - tapEvt = { - target: target, - clientX: touch.clientX, - clientY: touch.clientY - }; - - this._onDragStart(tapEvt, 'touch'); - evt.preventDefault(); - } - - _on(ownerDocument, 'mouseup', this._onDrop); - _on(ownerDocument, 'touchend', this._onDrop); - _on(ownerDocument, 'touchcancel', this._onDrop); - - _on(dragEl, 'dragend', this); - _on(rootEl, 'dragstart', this._onDragStart); - - if (!supportDraggable) { - this._onDragStart(tapEvt, true); - } - - try { - if (document.selection) { - document.selection.empty(); - } else { - window.getSelection().removeAllRanges(); - } - } catch (err) { - } - } + this._prepareDragStart(evt, target, el, touch); }, _emulateDragOver: function () { @@ -635,6 +670,8 @@ clearInterval(this._loopId); clearInterval(autoScroll.pid); + clearTimeout(this.dragStartTimer); + // Unbind events _off(document, 'drop', this); _off(document, 'mousemove', this._onTouchMove); From 723bc1e605de32555fa9e5fd5d531832cfc9848e Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sun, 5 Apr 2015 23:57:39 +0300 Subject: [PATCH 072/594] #325: PR refactoring: - _enableDragStart & revert lost fixes --- Sortable.js | 103 +++++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 49 deletions(-) diff --git a/Sortable.js b/Sortable.js index 962c6e9a2..ea26139d2 100644 --- a/Sortable.js +++ b/Sortable.js @@ -252,7 +252,6 @@ Sortable.prototype = /** @lends Sortable.prototype */ { constructor: Sortable, - _dragStarted: function () { if (rootEl && dragEl) { // Apply effect @@ -265,21 +264,21 @@ } }, - _triggerDragStart: function (evt, target, touch) { - evt.preventDefault(); - + _triggerDragStart: function (/** Touch */touch) { if (touch) { // Touch device support tapEvt = { - target: target, + target: dragEl, clientX: touch.clientX, clientY: touch.clientY }; this._onDragStart(tapEvt, 'touch'); - } else if (!supportDraggable) { + } + else if (!supportDraggable) { this._onDragStart(tapEvt, true); - } else { + } + else { _on(dragEl, 'dragend', this); _on(rootEl, 'dragstart', this._onDragStart); } @@ -294,68 +293,73 @@ } }, - _enableDragStart: function (dragEl, target) { - dragEl.draggable = true; - - // Disable "draggable" - this.options.ignore.split(',').forEach(function (criteria) { - _find(target, criteria.trim(), _disableDraggable); - }); - }, - _disableDelayedDrag: function () { - clearTimeout(this.dragStartTimer); + var ownerDocument = this.el.ownerDocument; + + clearTimeout(this._dragStartTimer); - _off(document, 'mousemove', this._disableDelayedDrag); - _off(document, 'touchmove', this._disableDelayedDrag); + _off(ownerDocument, 'mousemove', this._disableDelayedDrag); + _off(ownerDocument, 'touchmove', this._disableDelayedDrag); }, - _prepareDragStart: function (evt, target, el, touch) { - var _this = this; + _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) { + var _this = this, + el = _this.el, + options = _this.options, + ownerDocument = el.ownerDocument, + dragStartFn; if (target && !dragEl && (target.parentNode === el)) { tapEvt = evt; - rootEl = this.el; + rootEl = el; dragEl = target; nextEl = dragEl.nextSibling; - activeGroup = this.options.group; + activeGroup = options.group; - this.options.delay = this.options.delay || 1; - if (this.options.delay) { - _on(document, 'mouseup', this._onDrop); - _on(document, 'touchend', this._onDrop); - _on(document, 'touchcancel', this._onDrop); + dragStartFn = function () { + // Delayed drag has been triggered + // we can re-enable the events: touchmove/mousemove + _this._disableDelayedDrag(); + + // Make the element draggable + dragEl.draggable = true; + + // Disable "draggable" + options.ignore.split(',').forEach(function (criteria) { + _find(dragEl, criteria.trim(), _disableDraggable); + }); + + // Bind the events: dragstart/dragend + _this._triggerDragStart(touch); + }; + + _on(ownerDocument, 'mouseup', _this._onDrop); + _on(ownerDocument, 'touchend', _this._onDrop); + _on(ownerDocument, 'touchcancel', _this._onDrop); + if (options.delay) { // If the user moves the pointer before the delay has been reached: // disable the delayed drag - _on(document, 'mousemove', this._disableDelayedDrag); - _on(document, 'touchmove', this._disableDelayedDrag); - - this.dragStartTimer = setTimeout(function () { - // Delayed drag has been triggered - // we can re-enable the events: touchmove/mousemove - _off(document, 'mousemove', _this._disableDelayedDrag); - _off(document, 'touchmove', _this._disableDelayedDrag); - - // Make the element draggable - _this._enableDragStart(dragEl, target); - // Bind the events: dragstart/dragend - _this._triggerDragStart(evt, target, touch); - }, this.options.delay); + _on(ownerDocument, 'mousemove', _this._disableDelayedDrag); + _on(ownerDocument, 'touchmove', _this._disableDelayedDrag); + + _this._dragStartTimer = setTimeout(dragStartFn, options.delay); + } else { + dragStartFn(); } } }, - _onTapStart: function (/**Event|TouchEvent*/evt) { - var type = evt.type, + _onTapStart: function (/** Event|TouchEvent */evt) { + var el = this.el, + options = this.options, + type = evt.type, touch = evt.touches && evt.touches[0], target = (touch || evt).target, originalTarget = target, - options = this.options, - filter = options.filter, - el = this.el, - ownerDocument = el.ownerDocument; // for correct working with/into iframe + filter = options.filter; + if (type === 'mousedown' && evt.button !== 0 || options.disabled) { return; // only left button or enabled @@ -399,8 +403,9 @@ return; } + // Prepare `dragstart` - this._prepareDragStart(evt, target, el, touch); + this._prepareDragStart(evt, touch, target); }, _emulateDragOver: function () { From 40af728d53c8ed6ca41dead85ceb08d71b8a77fa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 6 Apr 2015 00:00:55 +0300 Subject: [PATCH 073/594] #325: * changed the order of the methods (code style) --- Sortable.js | 156 ++++++++++++++++++++++++++-------------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/Sortable.js b/Sortable.js index ea26139d2..a3b82fea1 100644 --- a/Sortable.js +++ b/Sortable.js @@ -252,54 +252,61 @@ Sortable.prototype = /** @lends Sortable.prototype */ { constructor: Sortable, - _dragStarted: function () { - if (rootEl && dragEl) { - // Apply effect - _toggleClass(dragEl, this.options.ghostClass, true); + _onTapStart: function (/** Event|TouchEvent */evt) { + var el = this.el, + options = this.options, + type = evt.type, + touch = evt.touches && evt.touches[0], + target = (touch || evt).target, + originalTarget = target, + filter = options.filter; - Sortable.active = this; - // Drag start event - _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + if (type === 'mousedown' && evt.button !== 0 || options.disabled) { + return; // only left button or enabled } - }, - _triggerDragStart: function (/** Touch */touch) { - if (touch) { - // Touch device support - tapEvt = { - target: dragEl, - clientX: touch.clientX, - clientY: touch.clientY - }; + target = _closest(target, options.draggable, el); - this._onDragStart(tapEvt, 'touch'); - } - else if (!supportDraggable) { - this._onDragStart(tapEvt, true); + if (!target) { + return; } - else { - _on(dragEl, 'dragend', this); - _on(rootEl, 'dragstart', this._onDragStart); + + // get the index of the dragged element within its parent + oldIndex = _index(target); + + // Check filter + if (typeof filter === 'function') { + if (filter.call(this, evt, target, this)) { + _dispatchEvent(originalTarget, 'filter', target, el, oldIndex); + evt.preventDefault(); + return; // cancel dnd + } } + else if (filter) { + filter = filter.split(',').some(function (criteria) { + criteria = _closest(originalTarget, criteria.trim(), el); - try { - if (document.selection) { - document.selection.empty(); - } else { - window.getSelection().removeAllRanges(); + if (criteria) { + _dispatchEvent(criteria, 'filter', target, el, oldIndex); + return true; + } + }); + + if (filter) { + evt.preventDefault(); + return; // cancel dnd } - } catch (err) { } - }, - _disableDelayedDrag: function () { - var ownerDocument = this.el.ownerDocument; - clearTimeout(this._dragStartTimer); + if (options.handle && !_closest(originalTarget, options.handle, el)) { + return; + } - _off(ownerDocument, 'mousemove', this._disableDelayedDrag); - _off(ownerDocument, 'touchmove', this._disableDelayedDrag); + + // Prepare `dragstart` + this._prepareDragStart(evt, touch, target); }, _prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) { @@ -351,61 +358,54 @@ } }, - _onTapStart: function (/** Event|TouchEvent */evt) { - var el = this.el, - options = this.options, - type = evt.type, - touch = evt.touches && evt.touches[0], - target = (touch || evt).target, - originalTarget = target, - filter = options.filter; + _disableDelayedDrag: function () { + var ownerDocument = this.el.ownerDocument; + clearTimeout(this._dragStartTimer); - if (type === 'mousedown' && evt.button !== 0 || options.disabled) { - return; // only left button or enabled - } + _off(ownerDocument, 'mousemove', this._disableDelayedDrag); + _off(ownerDocument, 'touchmove', this._disableDelayedDrag); + }, - target = _closest(target, options.draggable, el); + _triggerDragStart: function (/** Touch */touch) { + if (touch) { + // Touch device support + tapEvt = { + target: dragEl, + clientX: touch.clientX, + clientY: touch.clientY + }; - if (!target) { - return; + this._onDragStart(tapEvt, 'touch'); } - - // get the index of the dragged element within its parent - oldIndex = _index(target); - - // Check filter - if (typeof filter === 'function') { - if (filter.call(this, evt, target, this)) { - _dispatchEvent(originalTarget, 'filter', target, el, oldIndex); - evt.preventDefault(); - return; // cancel dnd - } + else if (!supportDraggable) { + this._onDragStart(tapEvt, true); + } + else { + _on(dragEl, 'dragend', this); + _on(rootEl, 'dragstart', this._onDragStart); } - else if (filter) { - filter = filter.split(',').some(function (criteria) { - criteria = _closest(originalTarget, criteria.trim(), el); - - if (criteria) { - _dispatchEvent(criteria, 'filter', target, el, oldIndex); - return true; - } - }); - if (filter) { - evt.preventDefault(); - return; // cancel dnd + try { + if (document.selection) { + document.selection.empty(); + } else { + window.getSelection().removeAllRanges(); } + } catch (err) { } + }, + _dragStarted: function () { + if (rootEl && dragEl) { + // Apply effect + _toggleClass(dragEl, this.options.ghostClass, true); - if (options.handle && !_closest(originalTarget, options.handle, el)) { - return; - } - + Sortable.active = this; - // Prepare `dragstart` - this._prepareDragStart(evt, touch, target); + // Drag start event + _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + } }, _emulateDragOver: function () { From 5c4e3dce2a8b0b28c0e7d7235377d13cc71a9bbd Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 9 Apr 2015 11:42:14 +0300 Subject: [PATCH 074/594] #318, #328: + Improved work with events transmitted through the options --- Sortable.js | 63 +++++++++++++++++++++++--------------------------- ng-sortable.js | 5 +++- 2 files changed, 33 insertions(+), 35 deletions(-) diff --git a/Sortable.js b/Sortable.js index cfdd8afff..71f5a328b 100644 --- a/Sortable.js +++ b/Sortable.js @@ -58,8 +58,10 @@ _silent = false, - _dispatchEvent = function (rootEl, name, targetEl, fromEl, startIndex, newIndex) { - var evt = document.createEvent('Event'); + _dispatchEvent = function (sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) { + var evt = document.createEvent('Event'), + options = (sortable || rootEl[expando]).options, + onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1); evt.initEvent(name, true, true); @@ -70,13 +72,13 @@ evt.oldIndex = startIndex; evt.newIndex = newIndex; + if (options[onName]) { + options[onName].call(sortable, evt); + } + rootEl.dispatchEvent(evt); }, - _customEvents = 'onAdd onUpdate onRemove onStart onEnd onFilter onSort'.split(' '), - - noop = function () {}, - abs = Math.abs, slice = [].slice, @@ -170,6 +172,10 @@ this.options = options = _extend({}, options); + // Export instance + el[expando] = this; + + // Default options var defaults = { group: Math.random(), @@ -215,16 +221,7 @@ }); - // Define events - _customEvents.forEach(function (name) { - options[name] = _bind(this, options[name] || noop); - _on(el, name.substr(2).toLowerCase(), options[name]); - }, this); - - - // Export options options.groups = ' ' + group.name + (group.put.join ? ' ' + group.put.join(' ') : '') + ' '; - el[expando] = options; // Bind all private methods @@ -253,7 +250,8 @@ constructor: Sortable, _onTapStart: function (/** Event|TouchEvent */evt) { - var el = this.el, + var _this = this, + el = this.el, options = this.options, type = evt.type, touch = evt.touches && evt.touches[0], @@ -278,7 +276,7 @@ // Check filter if (typeof filter === 'function') { if (filter.call(this, evt, target, this)) { - _dispatchEvent(originalTarget, 'filter', target, el, oldIndex); + _dispatchEvent(_this, originalTarget, 'filter', target, el, oldIndex); evt.preventDefault(); return; // cancel dnd } @@ -288,7 +286,7 @@ criteria = _closest(originalTarget, criteria.trim(), el); if (criteria) { - _dispatchEvent(criteria, 'filter', target, el, oldIndex); + _dispatchEvent(_this, criteria, 'filter', target, el, oldIndex); return true; } }); @@ -404,7 +402,7 @@ Sortable.active = this; // Drag start event - _dispatchEvent(rootEl, 'start', dragEl, rootEl, oldIndex); + _dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex); } }, @@ -419,7 +417,7 @@ if (parent) { do { - if (parent[expando] && parent[expando].groups.indexOf(groupName) > -1) { + if (parent[expando] && parent[expando].options.groups.indexOf(groupName) > -1) { while (i--) { touchDragOverListeners[i]({ clientX: touchEvt.clientX, @@ -700,14 +698,14 @@ newIndex = _index(dragEl); // drag from one list and drop into another - _dispatchEvent(dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(null, dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); // Add event - _dispatchEvent(dragEl, 'add', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(null, dragEl.parentNode, 'add', dragEl, rootEl, oldIndex, newIndex); // Remove event - _dispatchEvent(rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); } else { // Remove clone @@ -718,13 +716,13 @@ newIndex = _index(dragEl); // drag & drop within the same list - _dispatchEvent(rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); } } // Drag end event - Sortable.active && _dispatchEvent(rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); + Sortable.active && _dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); } // Nulling @@ -853,11 +851,9 @@ * Destroy */ destroy: function () { - var el = this.el, options = this.options; + var el = this.el; - _customEvents.forEach(function (name) { - _off(el, name.substr(2).toLowerCase(), options[name]); - }); + el[expando] = null; _off(el, 'mousedown', this._onTapStart); _off(el, 'touchstart', this._onTapStart); @@ -865,7 +861,7 @@ _off(el, 'dragover', this); _off(el, 'dragenter', this); - //remove draggable attributes + // Remove draggable attributes Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) { el.removeAttribute('draggable'); }); @@ -874,7 +870,7 @@ this._onDrop(); - this.el = null; + this.el = el = null; } }; @@ -1091,7 +1087,6 @@ throttle: _throttle, closest: _closest, toggleClass: _toggleClass, - dispatchEvent: _dispatchEvent, index: _index }; diff --git a/ng-sortable.js b/ng-sortable.js index 4d40d3dc6..a34c756d3 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -167,7 +167,10 @@ scope.$watch(ngSortable + '.' + name, function (value) { if (value !== void 0) { options[name] = value; - sortable.option(name, value); + + if (!/^on[A-Z]/.test(name)) { + sortable.option(name, value); + } } }); }); From c1f6cf50c4fc6fa16d12c0c804fe8464bbda0c0f Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 11 Apr 2015 11:13:32 +0300 Subject: [PATCH 075/594] #308: * allow drop text --- Sortable.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sortable.js b/Sortable.js index 71f5a328b..8fbb61af4 100644 --- a/Sortable.js +++ b/Sortable.js @@ -530,10 +530,6 @@ isOwner = (activeGroup === group), canSort = options.sort; - if (!dragEl) { - return; - } - if (evt.preventDefault !== void 0) { evt.preventDefault(); !options.dragoverBubble && evt.stopPropagation(); @@ -754,8 +750,10 @@ var type = evt.type; if (type === 'dragover' || type === 'dragenter') { - this._onDragOver(evt); - _globalDragOver(evt); + if (dragEl) { + this._onDragOver(evt); + _globalDragOver(evt); + } } else if (type === 'drop' || type === 'dragend') { this._onDrop(evt); From ae8f76f19d392138484e61c6605d8864972908cb Mon Sep 17 00:00:00 2001 From: Dan Dascalescu Date: Sun, 12 Apr 2015 18:20:38 -0700 Subject: [PATCH 076/594] {{#sortable}}, not {{sortable}} in README --- meteor/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/meteor/README.md b/meteor/README.md index 163223bbe..0faf2b244 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -20,13 +20,13 @@ development framework. Read more at [Why Meteor](http://www.meteorpedia.com/read Simplest invocation - order will be lost when the page is refreshed: ```handlebars -{{sortable }} +{{#sortable }} ``` Persist the sort order in the 'order' field of each document in the collection: ```handlebars -{{sortable items= sortField="order"}} +{{#sortable items= sortField="order"}} ``` Along with `items`, `sortField` is the only Meteor-specific option. If it's missing, the package will @@ -39,8 +39,8 @@ reorderings, unlike with [naive solutions](http://programmers.stackexchange.com/ ## Passing options to the Sortable library - {{sortable items= option1=value1 option2=value2...}} - {{sortable items= options=myOptions}} + {{#sortable items= option1=value1 option2=value2...}} + {{#sortable items= options=myOptions}} For available options, please refer to [the main README](../README.md#options). You can pass them directly or under the `options` object. Direct options (`key=value`) override those in `options`. It is best @@ -49,7 +49,7 @@ object, as this will enable designers to work without needing to inspect the Jav Define the options in a helper for the template that calls Sortable: @@ -76,7 +76,7 @@ All the original Sortable events are supported. In addition, they will receive the data context in `event.data`. You can access `event.data.order` this way: ```handlebars -{{sortable items=players options=playersOptions}} +{{#sortable items=players options=playersOptions}} ``` ```js @@ -104,3 +104,4 @@ If you encounter an issue while using this package, please CC @dandv when you fi * Array support * Tests * Misc. - see reactivize.js +* [GitHub issues](https://github.com/RubaXa/Sortable/labels/%E2%98%84%20meteor) From 12df12c2b57c48831a728100a4bab5bda26ec896 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 13 Apr 2015 22:52:02 +0300 Subject: [PATCH 077/594] * correct ng-events --- ng-sortable.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index a34c756d3..d340a59a9 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -25,7 +25,7 @@ angular.module('ng-sortable', []) - .constant('version', '0.3.6') + .constant('version', '0.3.7') .directive('ngSortable', ['$parse', function ($parse) { var removed, nextSibling; @@ -78,7 +78,7 @@ /* jshint expr:true */ options[name] && options[name]({ - model: item, + model: item || source && source.item(evt.item), models: source && source.items(), oldIndex: evt.oldIndex, newIndex: evt.newIndex @@ -143,13 +143,13 @@ }, onUpdate: function (/**Event*/evt) { _sync(evt); - _emitEvent(evt, source && source.item(evt.item)); + _emitEvent(evt); }, onRemove: function (/**Event*/evt) { _emitEvent(evt, removed); }, onSort: function (/**Event*/evt) { - _emitEvent(evt, source && source.item(evt.item)); + _emitEvent(evt); } })); From 8db2fd26ecf3919e8fb78f697075e24fdce0bdc1 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 14 Apr 2015 21:36:49 +0300 Subject: [PATCH 078/594] v1.2.0: Events, Nested, Drop text, IE11, iframe and etc --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 44367c223..6b40d2a69 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.1.1", + "version": "1.2.0", "devDependencies": { "grunt": "*", "grunt-version": "*", From b30ece99c5c87752db61b452e04467e0a3cf5f79 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 14 Apr 2015 21:37:41 +0300 Subject: [PATCH 079/594] v1.2.0: Events, Nested, Drop text, IE11, iframe and etc --- README.md | 4 ++-- Sortable.js | 2 +- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 4474bfe07..c68502587 100644 --- a/README.md +++ b/README.md @@ -563,11 +563,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index 8fbb61af4..4527f6c19 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1089,7 +1089,7 @@ }; - Sortable.version = '1.1.1'; + Sortable.version = '1.2.0'; /** diff --git a/Sortable.min.js b/Sortable.min.js index 43a4fd74b..6b3c9428f 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.1.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=q({},b);var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),O.forEach(function(d){b[d]=c(this,b[d]||P),f(a,d.substr(2).toLowerCase(),b[d])},this),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ",a[H]=b;for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),S.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,r),t.state=a)}function c(a,b){var c=R.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(R.call(arguments)))}}function d(a,b,c){if(a){c=c||J,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(G," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(G," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return J.defaultView&&J.defaultView.getComputedStyle?c=J.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){M=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function q(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var r,s,t,u,v,w,x,y,z,A,B,C,D,E,F={},G=/\s+/g,H="Sortable"+(new Date).getTime(),I=window,J=I.document,K=I.parseInt,L=!!("draggable"in J.createElement("div")),M=!1,N=function(a,b,c,d,e,f){var g=J.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.clone=t,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},O="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),P=function(){},Q=Math.abs,R=[].slice,S=[],T=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(x!==c&&(w=b.scroll,x=c,w===!0)){w=c;do if(w.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=I)),(F.vx!==f||F.vy!==g||F.el!==d)&&(F.el=d,F.vx=f,F.vy=g,clearInterval(F.pid),d&&(F.pid=setInterval(function(){d===I?I.scrollTo(I.pageXOffset+f*i,I.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this.el,c=this.options,e=a.type,f=a.touches&&a.touches[0],g=(f||a).target,h=g,i=c.filter;if(!("mousedown"===e&&0!==a.button||c.disabled)&&(g=d(g,c.draggable,b))){if(A=o(g),"function"==typeof i){if(i.call(this,a,g,this))return N(h,"filter",g,b,A),void a.preventDefault()}else if(i&&(i=i.split(",").some(function(a){return a=d(h,a.trim(),b),a?(N(a,"filter",g,b,A),!0):void 0})))return void a.preventDefault();(!c.handle||d(h,c.handle,b))&&this._prepareDragStart(a,f,g)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!r&&c.parentNode===g&&(D=a,u=g,r=c,v=r.nextSibling,C=h.group,d=function(){e._disableDelayedDrag(),r.draggable=!0,h.ignore.split(",").forEach(function(a){j(r,a.trim(),k)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(D={target:r,clientX:a.clientX,clientY:a.clientY},this._onDragStart(D,"touch")):L?(f(r,"dragend",this),f(u,"dragstart",this._onDragStart)):this._onDragStart(D,!0);try{J.selection?J.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){u&&r&&(h(r,this.options.ghostClass,!0),a.active=this,N(u,"start",r,u,A))},_emulateDragOver:function(){if(E){i(s,"display","none");var a=J.elementFromPoint(E.clientX,E.clientY),b=a,c=" "+this.options.group.name,d=S.length;if(b)do{if(b[H]&&b[H].groups.indexOf(c)>-1){for(;d--;)S[d]({clientX:E.clientX,clientY:E.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(D){var b=a.touches?a.touches[0]:a,c=b.clientX-D.clientX,d=b.clientY-D.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";E=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==C.pull&&(t=r.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,r)),b){var e,g=r.getBoundingClientRect(),h=i(r);s=r.cloneNode(!0),i(s,"top",g.top-K(h.marginTop,10)),i(s,"left",g.left-K(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),"touch"===b?(f(J,"touchmove",this._onTouchMove),f(J,"touchend",this._onDrop),f(J,"touchcancel",this._onDrop)):(f(J,"mousemove",this._onTouchMove),f(J,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,r)),f(J,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=C===j,o=h.sort;if(r&&(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),C&&!h.disabled&&(n?o||(f=!u.contains(r)):C.pull&&k&&(C.name===j.name||k.indexOf&&~k.indexOf(C.name)))&&(void 0===a.rootEl||a.rootEl===this.el))){if(T(a,h,this.el),M)return;if(c=d(a.target,h.draggable,g),e=r.getBoundingClientRect(),f)return b(!0),void(t||v?u.insertBefore(r,t||v):o||u.appendChild(r));if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;q=c.getBoundingClientRect()}b(n),g.appendChild(r),this._animate(e,r),c&&this._animate(q,c)}else if(c&&!c.animated&&c!==r&&void 0!==c.parentNode[H]){y!==c&&(y=c,z=i(c));var p,q=c.getBoundingClientRect(),w=q.right-q.left,x=q.bottom-q.top,A=/left|right|inline/.test(z.cssFloat+z.display),B=c.offsetWidth>r.offsetWidth,D=c.offsetHeight>r.offsetHeight,E=(A?(a.clientX-q.left)/w:(a.clientY-q.top)/x)>.5,F=c.nextElementSibling;M=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===r&&!B||E&&B:F!==r&&!D||E&&D,p&&!F?g.appendChild(r):c.parentNode.insertBefore(r,p?F:c),this._animate(e,r),this._animate(q,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(J,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(F.pid),clearTimeout(this.dragStartTimer),g(J,"drop",this),g(J,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),s&&s.parentNode.removeChild(s),r&&(g(r,"dragend",this),k(r),h(r,this.options.ghostClass,!1),u!==r.parentNode?(B=o(r),N(r.parentNode,"sort",r,u,A,B),N(u,"sort",r,u,A,B),N(r,"add",r,u,A,B),N(u,"remove",r,u,A,B)):(t&&t.parentNode.removeChild(t),r.nextSibling!==v&&(B=o(r),N(u,"update",r,u,A,B),N(u,"sort",r,u,A,B))),a.active&&N(u,"end",r,u,A,B)),u=r=s=v=t=w=x=D=E=y=z=C=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el,b=this.options;O.forEach(function(c){g(a,c.substr(2).toLowerCase(),b[c])}),g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),S.splice(S.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:q,throttle:p,closest:d,toggleClass:h,dispatchEvent:N,index:o},a.version="1.1.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.2.0 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=q({},b),a[H]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,r),t.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||J,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(G," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(G," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return J.defaultView&&J.defaultView.getComputedStyle?c=J.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){M=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function q(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var r,s,t,u,v,w,x,y,z,A,B,C,D,E,F={},G=/\s+/g,H="Sortable"+(new Date).getTime(),I=window,J=I.document,K=I.parseInt,L=!!("draggable"in J.createElement("div")),M=!1,N=function(a,b,c,d,e,f,g){var h=J.createEvent("Event"),i=(a||b[H]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.item=d||b,h.from=e||b,h.clone=t,h.oldIndex=f,h.newIndex=g,i[j]&&i[j].call(a,h),b.dispatchEvent(h)},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(x!==c&&(w=b.scroll,x=c,w===!0)){w=c;do if(w.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=I)),(F.vx!==f||F.vy!==g||F.el!==d)&&(F.el=d,F.vx=f,F.vy=g,clearInterval(F.pid),d&&(F.pid=setInterval(function(){d===I?I.scrollTo(I.pageXOffset+f*i,I.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(A=o(h),"function"==typeof j){if(j.call(this,a,h,this))return N(b,i,"filter",h,c,A),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(N(b,a,"filter",h,c,A),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!r&&c.parentNode===g&&(D=a,u=g,r=c,v=r.nextSibling,C=h.group,d=function(){e._disableDelayedDrag(),r.draggable=!0,h.ignore.split(",").forEach(function(a){j(r,a.trim(),k)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(D={target:r,clientX:a.clientX,clientY:a.clientY},this._onDragStart(D,"touch")):L?(f(r,"dragend",this),f(u,"dragstart",this._onDragStart)):this._onDragStart(D,!0);try{J.selection?J.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){u&&r&&(h(r,this.options.ghostClass,!0),a.active=this,N(this,u,"start",r,u,A))},_emulateDragOver:function(){if(E){i(s,"display","none");var a=J.elementFromPoint(E.clientX,E.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[H]&&b[H].options.groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:E.clientX,clientY:E.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(D){var b=a.touches?a.touches[0]:a,c=b.clientX-D.clientX,d=b.clientY-D.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";E=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==C.pull&&(t=r.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,r)),b){var e,g=r.getBoundingClientRect(),h=i(r);s=r.cloneNode(!0),i(s,"top",g.top-K(h.marginTop,10)),i(s,"left",g.left-K(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),"touch"===b?(f(J,"touchmove",this._onTouchMove),f(J,"touchend",this._onDrop),f(J,"touchcancel",this._onDrop)):(f(J,"mousemove",this._onTouchMove),f(J,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,r)),f(J,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=C===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),C&&!h.disabled&&(n?o||(f=!u.contains(r)):C.pull&&k&&(C.name===j.name||k.indexOf&&~k.indexOf(C.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(R(a,h,this.el),M)return;if(c=d(a.target,h.draggable,g),e=r.getBoundingClientRect(),f)return b(!0),void(t||v?u.insertBefore(r,t||v):o||u.appendChild(r));if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;q=c.getBoundingClientRect()}b(n),g.appendChild(r),this._animate(e,r),c&&this._animate(q,c)}else if(c&&!c.animated&&c!==r&&void 0!==c.parentNode[H]){y!==c&&(y=c,z=i(c));var p,q=c.getBoundingClientRect(),w=q.right-q.left,x=q.bottom-q.top,A=/left|right|inline/.test(z.cssFloat+z.display),B=c.offsetWidth>r.offsetWidth,D=c.offsetHeight>r.offsetHeight,E=(A?(a.clientX-q.left)/w:(a.clientY-q.top)/x)>.5,F=c.nextElementSibling;M=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===r&&!B||E&&B:F!==r&&!D||E&&D,p&&!F?g.appendChild(r):c.parentNode.insertBefore(r,p?F:c),this._animate(e,r),this._animate(q,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(J,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(F.pid),clearTimeout(this.dragStartTimer),g(J,"drop",this),g(J,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),s&&s.parentNode.removeChild(s),r&&(g(r,"dragend",this),k(r),h(r,this.options.ghostClass,!1),u!==r.parentNode?(B=o(r),N(null,r.parentNode,"sort",r,u,A,B),N(this,u,"sort",r,u,A,B),N(null,r.parentNode,"add",r,u,A,B),N(this,u,"remove",r,u,A,B)):(t&&t.parentNode.removeChild(t),r.nextSibling!==v&&(B=o(r),N(this,u,"update",r,u,A,B),N(this,u,"sort",r,u,A,B))),a.active&&N(this,u,"end",r,u,A,B)),u=r=s=v=t=w=x=D=E=y=z=C=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?r&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[H]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:q,throttle:p,closest:d,toggleClass:h,index:o},a.version="1.2.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index c5e42aac3..4ae98d7ec 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.1.1", + "version": "1.2.0", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index de414f10e..04a090a1e 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.1.1", + "version": "1.2.0", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ From 711695c9119531208548aca9bfe7736171aa278f Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 14 Apr 2015 22:13:19 +0300 Subject: [PATCH 080/594] #281: + exportName for jQuery extention --- Gruntfile.js | 25 +++++++++++++++++++------ README.md | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 26e165684..5d67184bb 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -35,9 +35,7 @@ module.exports = function (grunt) { } }, jquery: { - files: { - 'jquery.fn.sortable.min.js': 'jquery.fn.sortable.js' - } + files: {} } }, @@ -54,22 +52,37 @@ module.exports = function (grunt) { }); - grunt.registerTask('jquery', function (arg) { + grunt.registerTask('jquery', function (exportName, uglify) { + if (exportName == 'min') { + exportName = null; + uglify = 'min'; + } + + if (!exportName) { + exportName = 'sortable'; + } + var fs = require('fs'), - filename = 'jquery.fn.sortable.js'; + filename = 'jquery.fn.' + exportName + '.js'; grunt.log.oklns(filename); fs.writeFileSync( filename, (fs.readFileSync('jquery.binding.js') + '') + .replace('$.fn.sortable', '$.fn.' + exportName) .replace('/* CODE */', (fs.readFileSync('Sortable.js') + '') .replace(/^[\s\S]*?function[\s\S]*?(var[\s\S]+)\/\/\s+Export[\s\S]+/, '$1') ) ); - if (arg === 'min') { + if (uglify) { + var opts = {}; + + opts['jquery.fn.' + exportName + '.min.js'] = filename; + grunt.config.set('uglify.jquery.files', opts); + grunt.task.run('uglify:jquery'); } }); diff --git a/README.md b/README.md index c68502587..60caa87f1 100644 --- a/README.md +++ b/README.md @@ -603,6 +603,7 @@ Now you can use `jquery.fn.sortable.js`:
        $("#list").sortable("{method-name}", "foo", "bar"); // call an instance method with parameters ``` +And `grunt jquery:mySortableFunc` → `jquery.fn.mySortableFunc.js` --- From 34328a81b527218358b4bb17ca8613d2891a2c82 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 15 Apr 2015 13:19:18 +0300 Subject: [PATCH 081/594] #273: + onMove event --- README.md | 10 +++++ Sortable.js | 113 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 82 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 60caa87f1..a935ba460 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,16 @@ var sortable = new Sortable(el, { // Attempt to drag a filtered element onFilter: function (/**Event*/evt) { var itemEl = evt.item; // HTMLElement receiving the `mousedown|tapstart` event. + }, + + // Event when you move an item in the list or between lists + onMove: function (/**Event*/evt) { + // Example: http://jsbin.com/tuyafe/1/edit?js,output + evt.dragged; // dragged HTMLElement + evt.draggedRect; // TextRectangle {left, top, right и bottom} + evt.related; // HTMLElement on which have guided + evt.relatedRect; // TextRectangle + // retrun false; — for cancel } }); ``` diff --git a/Sortable.js b/Sortable.js index 4527f6c19..346887e61 100644 --- a/Sortable.js +++ b/Sortable.js @@ -58,27 +58,6 @@ _silent = false, - _dispatchEvent = function (sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) { - var evt = document.createEvent('Event'), - options = (sortable || rootEl[expando]).options, - onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1); - - evt.initEvent(name, true, true); - - evt.item = targetEl || rootEl; - evt.from = fromEl || rootEl; - evt.clone = cloneEl; - - evt.oldIndex = startIndex; - evt.newIndex = newIndex; - - if (options[onName]) { - options[onName].call(sortable, evt); - } - - rootEl.dispatchEvent(evt); - }, - abs = Math.abs, slice = [].slice, @@ -537,13 +516,13 @@ if (activeGroup && !options.disabled && (isOwner - ? canSort || (revert = !rootEl.contains(dragEl)) + ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list : activeGroup.pull && groupPut && ( (activeGroup.name === group.name) || // by Name (groupPut.indexOf && ~groupPut.indexOf(activeGroup.name)) // by Array ) ) && - (evt.rootEl === void 0 || evt.rootEl === this.el) + (evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback ) { // Smart auto-scrolling _autoScroll(evt, options, this.el); @@ -582,9 +561,11 @@ _cloneHide(isOwner); - el.appendChild(dragEl); - this._animate(dragRect, dragEl); - target && this._animate(targetRect, target); + if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect)) { + el.appendChild(dragEl); + this._animate(dragRect, dragEl); + target && this._animate(targetRect, target); + } } else if (target && !target.animated && target !== dragEl && (target.parentNode[expando] !== void 0)) { if (lastEl !== target) { @@ -604,25 +585,27 @@ after ; - _silent = true; - setTimeout(_unsilent, 30); + if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect)) { + _silent = true; + setTimeout(_unsilent, 30); - _cloneHide(isOwner); + _cloneHide(isOwner); - if (floating) { - after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide; - } else { - after = (nextSibling !== dragEl) && !isLong || halfway && isLong; - } + if (floating) { + after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide; + } else { + after = (nextSibling !== dragEl) && !isLong || halfway && isLong; + } - if (after && !nextSibling) { - el.appendChild(dragEl); - } else { - target.parentNode.insertBefore(dragEl, after ? nextSibling : target); - } + if (after && !nextSibling) { + el.appendChild(dragEl); + } else { + target.parentNode.insertBefore(dragEl, after ? nextSibling : target); + } - this._animate(dragRect, dragEl); - this._animate(targetRect, target); + this._animate(dragRect, dragEl); + this._animate(targetRect, target); + } } } }, @@ -986,6 +969,54 @@ } + + function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) { + var evt = document.createEvent('Event'), + options = (sortable || rootEl[expando]).options, + onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1); + + evt.initEvent(name, true, true); + + evt.to = rootEl; + evt.from = fromEl || rootEl; + evt.item = targetEl || rootEl; + evt.clone = cloneEl; + + evt.oldIndex = startIndex; + evt.newIndex = newIndex; + + if (options[onName]) { + options[onName].call(sortable, evt); + } + + rootEl.dispatchEvent(evt); + } + + + function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) { + var evt, + sortable = fromEl[expando], + onMoveFn = sortable.options.onMove, + retVal; + + if (onMoveFn) { + evt = document.createEvent('Event'); + evt.initEvent('move', true, true); + + evt.to = toEl; + evt.from = fromEl; + evt.dragged = dragEl; + evt.draggedRect = dragRect; + evt.related = targetEl || toEl; + evt.relatedRect = targetRect || toEl.getBoundingClientRect(); + + retVal = onMoveFn.call(sortable, evt); + } + + return retVal !== false; + } + + function _disableDraggable(el) { el.draggable = false; } From a89b3b3edc6422f1b3540a4811434d4900d91719 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 15 Apr 2015 14:27:28 +0300 Subject: [PATCH 082/594] #347: + moveVector --- Sortable.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index 346887e61..7888d053a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -561,7 +561,7 @@ _cloneHide(isOwner); - if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect)) { + if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect) !== false) { el.appendChild(dragEl); this._animate(dragRect, dragEl); target && this._animate(targetRect, target); @@ -582,16 +582,20 @@ isLong = (target.offsetHeight > dragEl.offsetHeight), halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5, nextSibling = target.nextElementSibling, + moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect), after ; - if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect)) { + if (moveVector !== false) { _silent = true; setTimeout(_unsilent, 30); _cloneHide(isOwner); - if (floating) { + if (moveVector === 1 || moveVector === -1) { + after = (moveVector === 1); + } + else if (floating) { after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide; } else { after = (nextSibling !== dragEl) && !isLong || halfway && isLong; @@ -1013,7 +1017,7 @@ retVal = onMoveFn.call(sortable, evt); } - return retVal !== false; + return retVal; } From 14864bc067dc937b88031dac77344ad9c44fa7aa Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 16 Apr 2015 18:15:27 +0300 Subject: [PATCH 083/594] #335: call save only if 'active' --- Sortable.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index 7888d053a..6de4e0506 100644 --- a/Sortable.js +++ b/Sortable.js @@ -704,8 +704,13 @@ } } - // Drag end event - Sortable.active && _dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); + if (Sortable.active) { + // Drag end event + _dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); + + // Save sorting + this.save(); + } } // Nulling @@ -726,9 +731,6 @@ activeGroup = Sortable.active = null; - - // Save sorting - this.save(); } }, From a479eae115afc39d3ffc803cccb74f3a7a61007a Mon Sep 17 00:00:00 2001 From: c4605 Date: Fri, 17 Apr 2015 16:08:47 +0800 Subject: [PATCH 084/594] clean watcher after element destroy --- ng-sortable.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index d340a59a9..09055b4fb 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -69,6 +69,7 @@ ngSortable = attrs.ngSortable, options = scope.$eval(ngSortable) || {}, source = getSource(el), + watchers = [], sortable ; @@ -154,7 +155,11 @@ })); $el.on('$destroy', function () { + angular.forEach(watchers, function (/** Function */unwatch) { + unwatch(); + }); sortable.destroy(); + watchers = null; sortable = null; nextSibling = null; }); @@ -164,7 +169,7 @@ 'sort', 'disabled', 'draggable', 'handle', 'animation', 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' ], function (name) { - scope.$watch(ngSortable + '.' + name, function (value) { + watchers.push(scope.$watch(ngSortable + '.' + name, function (value) { if (value !== void 0) { options[name] = value; @@ -172,7 +177,7 @@ sortable.option(name, value); } } - }); + })); }); } } From 1ab661f10e69b2e67724f0796a3cd961d7dfacfc Mon Sep 17 00:00:00 2001 From: ha-D Date: Fri, 24 Apr 2015 12:31:34 +0430 Subject: [PATCH 085/594] Use isolated scope with two-way binding in ng-sortable --- ng-sortable.js | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 09055b4fb..c292791c8 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -64,10 +64,10 @@ // Export return { restrict: 'AC', + scope: { ngSortable: "=?" }, link: function (scope, $el, attrs) { var el = $el[0], - ngSortable = attrs.ngSortable, - options = scope.$eval(ngSortable) || {}, + options = scope.ngSortable || {}, source = getSource(el), watchers = [], sortable @@ -164,22 +164,20 @@ nextSibling = null; }); - if (ngSortable && !/{|}/.test(ngSortable)) { // todo: ugly - angular.forEach([ - 'sort', 'disabled', 'draggable', 'handle', 'animation', - 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' - ], function (name) { - watchers.push(scope.$watch(ngSortable + '.' + name, function (value) { - if (value !== void 0) { - options[name] = value; - - if (!/^on[A-Z]/.test(name)) { - sortable.option(name, value); - } + angular.forEach([ + 'sort', 'disabled', 'draggable', 'handle', 'animation', + 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' + ], function (name) { + watchers.push(scope.$watch('ngSortable.' + name, function (value) { + if (value !== void 0) { + options[name] = value; + + if (!/^on[A-Z]/.test(name)) { + sortable.option(name, value); } - })); - }); - } + } + })); + }); } }; }]); From 8e8558f023412f20b7690af215b863c4a390099b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matic=20Jurgli=C4=8D?= Date: Wed, 29 Apr 2015 10:33:49 +0200 Subject: [PATCH 086/594] Fix AngularJS typo --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index 3e8334644..c7064436e 100644 --- a/index.html +++ b/index.html @@ -173,7 +173,7 @@

        The JavaScript library for modern browser
        -
        AngluarJS / ng-sortable
        +
        AngularJS / ng-sortable
        From 08c31fc0bba9509280f2f3847ab47bee2ea9bab9 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 7 May 2015 23:14:18 +0300 Subject: [PATCH 087/594] #379: + 'delay' description --- README.md | 12 +++++++++++- Sortable.js | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a935ba460..4da1a5501 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ You can use any element for the list and its elements, not just `ul`/`li`. Here var sortable = new Sortable(el, { group: "name", // or { name: "...", pull: [true, false, clone], put: [true, false, array] } sort: true, // sorting inside list + delay: 0, // time in milliseconds to define when the sorting should start disabled: false, // Disables the sortable if set to true. store: null, // @see Store animation: 150, // ms, animation speed moving items when sorting, `0` — without animation @@ -140,7 +141,7 @@ You can also define whether lists can give away, give and keep a copy (`clone`), #### `sort` option -Sorting inside list +Sorting inside list. Demo: http://jsbin.com/xizeh/2/edit?html,js,output @@ -148,6 +149,15 @@ Demo: http://jsbin.com/xizeh/2/edit?html,js,output --- +#### `delay` option +time in milliseconds to define when the sorting should start. + +Demo: http://jsbin.com/xizeh/4/edit?html,js,output + + +--- + + #### `disabled` options Disables the sortable if set to `true`. diff --git a/Sortable.js b/Sortable.js index 6de4e0506..c4ab1669d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1035,7 +1035,9 @@ /** @returns {HTMLElement|false} */ function _ghostInBottom(el, evt) { - var lastEl = el.lastElementChild, rect = lastEl.getBoundingClientRect(); + var lastEl = el.lastElementChild, + rect = lastEl.getBoundingClientRect(); + return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta } From 590a5de981ec5de4cdec092ce8455acca4791cc6 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 7 May 2015 23:15:27 +0300 Subject: [PATCH 088/594] #379: * typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4da1a5501..40cc199a3 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ Demo: http://jsbin.com/xizeh/2/edit?html,js,output #### `delay` option -time in milliseconds to define when the sorting should start. +Time in milliseconds to define when the sorting should start. Demo: http://jsbin.com/xizeh/4/edit?html,js,output From 72be2e91aec387a23cf84fb9ec831a906df4ae7c Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 7 May 2015 23:28:28 +0300 Subject: [PATCH 089/594] #376: * fixed 'evt.target' --- Sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index c4ab1669d..cf0b5f047 100644 --- a/Sortable.js +++ b/Sortable.js @@ -991,11 +991,11 @@ evt.oldIndex = startIndex; evt.newIndex = newIndex; + rootEl.dispatchEvent(evt); + if (options[onName]) { options[onName].call(sortable, evt); } - - rootEl.dispatchEvent(evt); } From 06f95308549d3f45d921872fc9f0c9729b584743 Mon Sep 17 00:00:00 2001 From: Lebedev Konstantin Date: Fri, 8 May 2015 11:39:30 +0300 Subject: [PATCH 090/594] Update CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ef9d5d18d..dba06578d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ 1. Try [dev](https://github.com/RubaXa/Sortable/tree/dev/)-branch, perhaps the problem has been solved; 2. [Use the search](https://github.com/RubaXa/Sortable/search?q=problem), maybe already have an answer; - 3. If not found, create example on [jsbin.com](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. + 3. If not found, create example on [jsbin.com (draft)](http://jsbin.com/zunibaxada/1/edit?html,js,output) and describe the problem. --- From 9846ed0bc26c04b212ce6aa08b5342ee86e33c03 Mon Sep 17 00:00:00 2001 From: Diego Castillo Date: Mon, 11 May 2015 19:57:53 -0500 Subject: [PATCH 091/594] Fixed small typo on documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c68502587..dc380a64d 100644 --- a/README.md +++ b/README.md @@ -195,7 +195,7 @@ Sortable.create(el, { Sortable.create(list, { filter: ".js-remove, .js-edit", onFilter: function (evt) { - var item = el.item, + var item = evt.item, ctrl = evt.target; if (Sortable.utils.is(ctrl, ".js-remove")) { // Click on remove button From c132cab953dff19841705ae30bcd033676813767 Mon Sep 17 00:00:00 2001 From: wangchj Date: Tue, 12 May 2015 15:53:42 -0500 Subject: [PATCH 092/594] Remove circular symlink. --- meteor/example/packages/Sortable | 1 - 1 file changed, 1 deletion(-) delete mode 120000 meteor/example/packages/Sortable diff --git a/meteor/example/packages/Sortable b/meteor/example/packages/Sortable deleted file mode 120000 index 1b20c9fb8..000000000 --- a/meteor/example/packages/Sortable +++ /dev/null @@ -1 +0,0 @@ -../../../ \ No newline at end of file From aa80521cb25b7df076826ca5f8b3d321a35944dc Mon Sep 17 00:00:00 2001 From: Dan Dascalescu Date: Sun, 24 May 2015 20:09:59 -0700 Subject: [PATCH 093/594] Fix security issue allowing modification of arbitrary numeric fields --- meteor/README.md | 12 ++ meteor/example/.meteor/.finished-upgraders | 8 ++ meteor/example/.meteor/.id | 7 ++ meteor/example/.meteor/platforms | 2 + meteor/example/.meteor/release | 2 +- meteor/example/.meteor/versions | 109 +++++++++--------- meteor/example/README.md | 2 +- meteor/example/package.json | 1 - meteor/example/server/sortable-collections.js | 3 + meteor/{methods.js => methods-client.js} | 10 +- meteor/methods-server.js | 31 +++++ meteor/package.js | 9 +- meteor/reactivize.js | 2 +- 13 files changed, 127 insertions(+), 71 deletions(-) create mode 100644 meteor/example/.meteor/.finished-upgraders create mode 100644 meteor/example/.meteor/.id create mode 100644 meteor/example/.meteor/platforms delete mode 120000 meteor/example/package.json create mode 100644 meteor/example/server/sortable-collections.js rename meteor/{methods.js => methods-client.js} (64%) create mode 100644 meteor/methods-server.js diff --git a/meteor/README.md b/meteor/README.md index 0faf2b244..c3403582e 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -25,10 +25,18 @@ Simplest invocation - order will be lost when the page is refreshed: Persist the sort order in the 'order' field of each document in the collection: +*Client:* + ```handlebars {{#sortable items= sortField="order"}} ``` +*Server:* + +```js +Sortable.collections = ; // the name, not the variable +``` + Along with `items`, `sortField` is the only Meteor-specific option. If it's missing, the package will assume there is a field called "order" in the collection, holding unique `Number`s such that every `order` differs from that before and after it by at least 1. Basically, keep to 0, 1, 2, ... . @@ -36,6 +44,10 @@ Try not to depend on a particular format for this field; it *is* though guarante produce lexicographical order, and that the order will be maintained after an arbitrary number of reorderings, unlike with [naive solutions](http://programmers.stackexchange.com/questions/266451/maintain-ordered-collection-by-updating-as-few-order-fields-as-possible). +Remember to declare on the server which collections you want to be reorderable from the client. +Otherwise, the library will error because the client would be able to modify numerical fields in +any collection, which represents a security risk. + ## Passing options to the Sortable library diff --git a/meteor/example/.meteor/.finished-upgraders b/meteor/example/.meteor/.finished-upgraders new file mode 100644 index 000000000..8a761038c --- /dev/null +++ b/meteor/example/.meteor/.finished-upgraders @@ -0,0 +1,8 @@ +# This file contains information which helps Meteor properly upgrade your +# app when you run 'meteor update'. You should check it into version control +# with your project. + +notices-for-0.9.0 +notices-for-0.9.1 +0.9.4-platform-file +notices-for-facebook-graph-api-2 diff --git a/meteor/example/.meteor/.id b/meteor/example/.meteor/.id new file mode 100644 index 000000000..b39baa1d8 --- /dev/null +++ b/meteor/example/.meteor/.id @@ -0,0 +1,7 @@ +# This file contains a token that is unique to your project. +# Check it into your repository along with the rest of this directory. +# It can be used for purposes such as: +# - ensuring you don't accidentally deploy one app on top of another +# - providing package authors with aggregated statistics + +ir0jg2douy3yo5mehw diff --git a/meteor/example/.meteor/platforms b/meteor/example/.meteor/platforms new file mode 100644 index 000000000..8a3a35f9f --- /dev/null +++ b/meteor/example/.meteor/platforms @@ -0,0 +1,2 @@ +browser +server diff --git a/meteor/example/.meteor/release b/meteor/example/.meteor/release index f1b625596..dab6b552c 100644 --- a/meteor/example/.meteor/release +++ b/meteor/example/.meteor/release @@ -1 +1 @@ -METEOR@1.0.1 +METEOR@1.1.0.2 diff --git a/meteor/example/.meteor/versions b/meteor/example/.meteor/versions index ce300af69..abcbcf0a3 100644 --- a/meteor/example/.meteor/versions +++ b/meteor/example/.meteor/versions @@ -1,56 +1,53 @@ -application-configuration@1.0.3 -autopublish@1.0.1 -autoupdate@1.1.3 -base64@1.0.1 -binary-heap@1.0.1 -blaze-tools@1.0.1 -blaze@2.0.3 -boilerplate-generator@1.0.1 -callback-hook@1.0.1 -check@1.0.2 -ctl-helper@1.0.4 -ctl@1.0.2 -dburles:mongo-collection-instances@0.2.5 -ddp@1.0.12 -deps@1.0.5 -ejson@1.0.4 -fastclick@1.0.1 -fezvrasta:bootstrap-material-design@0.2.1 -follower-livedata@1.0.2 -geojson-utils@1.0.1 -html-tools@1.0.2 -htmljs@1.0.2 -http@1.0.8 -id-map@1.0.1 -insecure@1.0.1 -jquery@1.0.1 -json@1.0.1 -launch-screen@1.0.0 -livedata@1.0.11 -logging@1.0.5 -meteor-platform@1.2.0 -meteor@1.1.3 -minifiers@1.1.2 -minimongo@1.0.5 -mobile-status-bar@1.0.1 -mongo@1.0.9 -observe-sequence@1.0.3 -ordered-dict@1.0.1 -random@1.0.1 -reactive-dict@1.0.4 -reactive-var@1.0.3 -reload@1.1.1 -retry@1.0.1 -routepolicy@1.0.2 -rubaxa:sortable@1.0.0 -session@1.0.4 -spacebars-compiler@1.0.3 -spacebars@1.0.3 -templating@1.0.9 -tracker@1.0.3 -twbs:bootstrap@3.3.1 -ui@1.0.4 -underscore@1.0.1 -url@1.0.2 -webapp-hashing@1.0.1 -webapp@1.1.4 +autopublish@1.0.3 +autoupdate@1.2.1 +base64@1.0.3 +binary-heap@1.0.3 +blaze@2.1.2 +blaze-tools@1.0.3 +boilerplate-generator@1.0.3 +callback-hook@1.0.3 +check@1.0.5 +dburles:mongo-collection-instances@0.3.3 +ddp@1.1.0 +deps@1.0.7 +ejson@1.0.6 +fastclick@1.0.3 +fezvrasta:bootstrap-material-design@0.3.0 +geojson-utils@1.0.3 +html-tools@1.0.4 +htmljs@1.0.4 +http@1.1.0 +id-map@1.0.3 +insecure@1.0.3 +jquery@1.11.3_2 +json@1.0.3 +lai:collection-extensions@0.1.3 +launch-screen@1.0.2 +livedata@1.0.13 +logging@1.0.7 +meteor@1.1.6 +meteor-platform@1.2.2 +minifiers@1.1.5 +minimongo@1.0.8 +mobile-status-bar@1.0.3 +mongo@1.1.0 +observe-sequence@1.0.6 +ordered-dict@1.0.3 +random@1.0.3 +reactive-dict@1.1.0 +reactive-var@1.0.5 +reload@1.1.3 +retry@1.0.3 +routepolicy@1.0.5 +rubaxa:sortable@1.2.0 +session@1.1.0 +spacebars@1.0.6 +spacebars-compiler@1.0.6 +templating@1.1.1 +tracker@1.0.7 +twbs:bootstrap@3.3.4 +ui@1.0.6 +underscore@1.0.3 +url@1.0.4 +webapp@1.2.0 +webapp-hashing@1.0.3 diff --git a/meteor/example/README.md b/meteor/example/README.md index 5e48aca4b..51d154718 100644 --- a/meteor/example/README.md +++ b/meteor/example/README.md @@ -35,7 +35,7 @@ run script: ### Differential Differential wrote [a blog post on reorderable lists with -Meteor](differential.com/blog/sortable-lists-in-meteor-using-jquery-ui) and +Meteor](http://differential.com/blog/sortable-lists-in-meteor-using-jquery-ui) and [jQuery UI Sortable](http://jqueryui.com/sortable/). It served as inspiration for integrating [rubaxa:sortable](rubaxa.github.io/Sortable/), which uses the HTML5 native drag&drop API (not without [its diff --git a/meteor/example/package.json b/meteor/example/package.json deleted file mode 120000 index 138a42cdf..000000000 --- a/meteor/example/package.json +++ /dev/null @@ -1 +0,0 @@ -../../package.json \ No newline at end of file diff --git a/meteor/example/server/sortable-collections.js b/meteor/example/server/sortable-collections.js new file mode 100644 index 000000000..76069a592 --- /dev/null +++ b/meteor/example/server/sortable-collections.js @@ -0,0 +1,3 @@ +'use strict'; + +Sortable.collections = ['attributes']; diff --git a/meteor/methods.js b/meteor/methods-client.js similarity index 64% rename from meteor/methods.js rename to meteor/methods-client.js index fe8d83433..52f4ebec2 100644 --- a/meteor/methods.js +++ b/meteor/methods-client.js @@ -2,19 +2,15 @@ Meteor.methods({ /** - * Update the orderField of documents with given ids in a collection, incrementing it by incDec + * Update the sortField of documents with given ids in a collection, incrementing it by incDec * @param {String} collectionName - name of the collection to update * @param {String[]} ids - array of document ids * @param {String} orderField - the name of the order field, usually "order" * @param {Number} incDec - pass 1 or -1 */ - 'rubaxa:sortable/collection-update': function (collectionName, ids, orderField, incDec) { - check(collectionName, String); - check(ids, [String]); - check(orderField, String); - check(incDec, Number); + 'rubaxa:sortable/collection-update': function (collectionName, ids, sortField, incDec) { var selector = {_id: {$in: ids}}, modifier = {$inc: {}}; - modifier.$inc[orderField] = incDec; + modifier.$inc[sortField] = incDec; Mongo.Collection.get(collectionName).update(selector, modifier, {multi: true}); } }); diff --git a/meteor/methods-server.js b/meteor/methods-server.js new file mode 100644 index 000000000..9598bfc99 --- /dev/null +++ b/meteor/methods-server.js @@ -0,0 +1,31 @@ +'use strict'; + +Sortable = {}; +Sortable.collections = []; // array of collection names that the client is allowed to reorder + +Meteor.methods({ + /** + * Update the sortField of documents with given ids in a collection, incrementing it by incDec + * @param {String} collectionName - name of the collection to update + * @param {String[]} ids - array of document ids + * @param {String} orderField - the name of the order field, usually "order" + * @param {Number} incDec - pass 1 or -1 + */ + 'rubaxa:sortable/collection-update': function (collectionName, ids, sortField, incDec) { + check(collectionName, String); + // don't allow the client to modify just any collection + if (!Sortable || !Array.isArray(Sortable.collections)) { + throw new Meteor.Error(500, 'Please define Sortable.collections'); + } + if (Sortable.collections.indexOf(collectionName) === -1) { + throw new Meteor.Error(403, 'Collection <' + collectionName + '> is not Sortable. Please add it to Sortable.collections in server code.'); + } + + check(ids, [String]); + check(sortField, String); + check(incDec, Number); + var selector = {_id: {$in: ids}}, modifier = {$inc: {}}; + modifier.$inc[sortField] = incDec; + Mongo.Collection.get(collectionName).update(selector, modifier, {multi: true}); + } +}); diff --git a/meteor/package.js b/meteor/package.js index 148561aea..51bf04b14 100644 --- a/meteor/package.js +++ b/meteor/package.js @@ -10,20 +10,21 @@ Package.describe({ summary: 'Sortable: reactive minimalist reorderable drag-and-drop lists on modern browsers and touch devices', version: packageJson.version, git: 'https://github.com/RubaXa/Sortable.git', - readme: 'https://github.com/RubaXa/Sortable/blob/master/meteor/README.md' + documentation: 'meteor/README.md' }); Package.onUse(function (api) { api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.use('templating', 'client'); - api.use('dburles:mongo-collection-instances@0.2.6'); // to watch collections getting created - api.export('Sortable'); + api.use('dburles:mongo-collection-instances@0.3.3'); // to watch collections getting created + api.export('Sortable'); // exported on the server too, as a global to hold the array of sortable collections (for security) api.addFiles([ 'Sortable.js', 'meteor/template.html', // the HTML comes first, so reactivize.js can refer to the template in it 'meteor/reactivize.js' ], 'client'); - api.addFiles('meteor/methods.js'); // add to both client and server + api.addFiles('meteor/methods-client.js', 'client'); + api.addFiles('meteor/methods-server.js', 'server'); }); Package.onTest(function (api) { diff --git a/meteor/reactivize.js b/meteor/reactivize.js index 34ff5018d..a068a5ebb 100644 --- a/meteor/reactivize.js +++ b/meteor/reactivize.js @@ -1,6 +1,6 @@ /* Make a Sortable reactive by binding it to a Mongo.Collection. -Calls `rubaxa:sortable/collection-update` on the server to update the sortField or affected records. +Calls `rubaxa:sortable/collection-update` on the server to update the sortField of affected records. TODO: * supply consecutive values if the `order` field doesn't have any From 5633c00d19ffd4265a87c391f196cf78e0926df0 Mon Sep 17 00:00:00 2001 From: Nick Sinopoli Date: Fri, 29 May 2015 23:35:00 -0400 Subject: [PATCH 094/594] Reset state when component receives new props --- react-sortable-mixin.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index 47d1c3656..c40c15ff0 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -134,6 +134,16 @@ this._sortableInstance = Sortable.create((this.refs[options.ref] || this).getDOMNode(), copyOptions); }, + componentWillReceiveProps: function (nextProps) { + var newState = {}, + modelName = _getModelName(this), + items; + + if (items = nextProps[modelName]) { + newState[modelName] = items; + this.setState(newState); + } + }, componentWillUnmount: function () { this._sortableInstance.destroy(); From 107bfa25c02f32cd0253460481e15b9c6c2a8fbb Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 30 May 2015 13:58:01 +0300 Subject: [PATCH 095/594] v1.2.1 - #376: 'target' is NULL --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b40d2a69..344c30b73 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.2.0", + "version": "1.2.1", "devDependencies": { "grunt": "*", "grunt-version": "*", From f33927bfd7aef2da995dd960890dffd08c3f74b7 Mon Sep 17 00:00:00 2001 From: just-boris Date: Mon, 18 May 2015 14:50:10 +0300 Subject: [PATCH 096/594] ng-sortable: support configuration constant --- ng-sortable.js | 5 +++-- st/app.js | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index c292791c8..19310fc23 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -26,7 +26,8 @@ angular.module('ng-sortable', []) .constant('version', '0.3.7') - .directive('ngSortable', ['$parse', function ($parse) { + .constant('ngSortableConfig', {}) + .directive('ngSortable', ['$parse', 'ngSortableConfig', function ($parse, ngSortableConfig) { var removed, nextSibling; @@ -67,7 +68,7 @@ scope: { ngSortable: "=?" }, link: function (scope, $el, attrs) { var el = $el[0], - options = scope.ngSortable || {}, + options = angular.extend(scope.ngSortable || {}, ngSortableConfig), source = getSource(el), watchers = [], sortable diff --git a/st/app.js b/st/app.js index fe50fe9d7..164270d9a 100644 --- a/st/app.js +++ b/st/app.js @@ -148,6 +148,9 @@ // Angular example angular.module('todoApp', ['ng-sortable']) + .constant('ngSortableConfig', {onEnd: function() { + console.log('default onEnd()'); + }}) .controller('TodoController', ['$scope', function ($scope) { $scope.todos = [ {text: 'learn angular', done: true}, From fa426fd835546d636b81a89f015a914a778f697f Mon Sep 17 00:00:00 2001 From: just-boris Date: Sun, 7 Jun 2015 23:32:24 +0300 Subject: [PATCH 097/594] ng-sortable: add prefix to version constant --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 19310fc23..4f0b8c58f 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -25,7 +25,7 @@ angular.module('ng-sortable', []) - .constant('version', '0.3.7') + .constant('ngSortableVersion', '0.3.7') .constant('ngSortableConfig', {}) .directive('ngSortable', ['$parse', 'ngSortableConfig', function ($parse, ngSortableConfig) { var removed, From 6f3699c79204dfbcbf0917a7220cfbf0e54e4485 Mon Sep 17 00:00:00 2001 From: Nick Sinopoli Date: Wed, 3 Jun 2015 20:37:55 -0400 Subject: [PATCH 098/594] Don't use assignment in condition --- react-sortable-mixin.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index c40c15ff0..1076d594a 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -139,7 +139,9 @@ modelName = _getModelName(this), items; - if (items = nextProps[modelName]) { + items = nextProps[modelName]; + + if (items) { newState[modelName] = items; this.setState(newState); } From 86d3d8b2287bdd69af5f9e8b9f05682f623bbdc6 Mon Sep 17 00:00:00 2001 From: Adam Fleming Date: Wed, 10 Jun 2015 12:46:14 -0400 Subject: [PATCH 099/594] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 344c30b73..2a1c170af 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "drag", "meteor", "angular", - "ng-srotable", + "ng-sortable", "react", "mixin" ], From be0fd1a1266820e1cb218a24bee7d2ff3d56fa40 Mon Sep 17 00:00:00 2001 From: Adam Fleming Date: Wed, 10 Jun 2015 13:10:51 -0400 Subject: [PATCH 100/594] Include ng-sortable.js in bower distribution --- bower.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index 4ae98d7ec..acfb17d01 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,9 @@ { "name": "Sortable", - "main": "Sortable.js", + "main": [ + "Sortable.js", + "ng-sortable.js" + ], "version": "1.2.0", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ From f4502a72b773c7f29587d28153264f4bcb5644c1 Mon Sep 17 00:00:00 2001 From: Adam Fleming Date: Wed, 10 Jun 2015 14:05:56 -0400 Subject: [PATCH 101/594] Update bower.json --- bower.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bower.json b/bower.json index acfb17d01..741a0527e 100644 --- a/bower.json +++ b/bower.json @@ -2,7 +2,9 @@ "name": "Sortable", "main": [ "Sortable.js", - "ng-sortable.js" + "ng-sortable.js", + "knockout-sortable.js", + "react-sortable-mixin.js" ], "version": "1.2.0", "homepage": "http://rubaxa.github.io/Sortable/", From 9940598312d9a88671cd0176619396b0a99efcf0 Mon Sep 17 00:00:00 2001 From: Alex Wild Date: Thu, 4 Jun 2015 17:50:05 +0200 Subject: [PATCH 102/594] Allow click events for touch devices --- Sortable.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index cf0b5f047..c7b8be661 100644 --- a/Sortable.js +++ b/Sortable.js @@ -45,6 +45,8 @@ tapEvt, touchEvt, + moved, + /** @const */ RSPACE = /\s+/g, @@ -427,6 +429,8 @@ dy = touch.clientY - tapEvt.clientY, translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)'; + moved = true; + touchEvt = touch; _css(ghostEl, 'webkitTransform', translate3d); @@ -514,6 +518,8 @@ !options.dragoverBubble && evt.stopPropagation(); } + moved = true; + if (activeGroup && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list @@ -666,8 +672,10 @@ this._offUpEvents(); if (evt) { - evt.preventDefault(); - !options.dropBubble && evt.stopPropagation(); + if (moved) { + evt.preventDefault(); + !options.dropBubble && evt.stopPropagation(); + } ghostEl && ghostEl.parentNode.removeChild(ghostEl); @@ -726,6 +734,8 @@ tapEvt = touchEvt = + moved = + lastEl = lastCSS = From 77675363819beadf457835c9c0b58185fe5b94e6 Mon Sep 17 00:00:00 2001 From: Adam Fleming Date: Fri, 12 Jun 2015 15:03:20 -0400 Subject: [PATCH 103/594] Correctly match multiple class names Assume that el.className === "foo bar" Assume that your selector is "DIV.foo.bar" (' ' + el.className + ' ').match(re) will only have one match - " foo " - because the "\\s" trailing character on "foo" prevents " bar " from being matched EZ fix is just to make sure the trailing whitespace is not consumed by the regex --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index cf0b5f047..5c619b52a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -885,7 +885,7 @@ selector = selector.split('.'); var tag = selector.shift().toUpperCase(), - re = new RegExp('\\s(' + selector.join('|') + ')\\s', 'g'); + re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g'); do { if ( From f3e090c2a384e5852c3cf59b628e9cdddd5885a4 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 18 Jun 2015 09:13:08 +0300 Subject: [PATCH 104/594] #429: dragStartTimer -> _dragStartTimer --- Sortable.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 5c619b52a..ba2397730 100644 --- a/Sortable.js +++ b/Sortable.js @@ -655,8 +655,7 @@ clearInterval(this._loopId); clearInterval(autoScroll.pid); - - clearTimeout(this.dragStartTimer); + clearTimeout(this._dragStartTimer); // Unbind events _off(document, 'drop', this); From 34357d8e85b2a1b51c7039c250977ecece61e98b Mon Sep 17 00:00:00 2001 From: Evan Villemez Date: Sat, 20 Jun 2015 18:25:28 -0400 Subject: [PATCH 105/594] added more draggable options for angular to watch --- ng-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ng-sortable.js b/ng-sortable.js index 4f0b8c58f..04e2f2736 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -166,7 +166,7 @@ }); angular.forEach([ - 'sort', 'disabled', 'draggable', 'handle', 'animation', + 'sort', 'disabled', 'draggable', 'handle', 'animation', 'group', 'ghostClass', 'filter', 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' ], function (name) { watchers.push(scope.$watch('ngSortable.' + name, function (value) { From 8935bea4e362373ba9a2f3204fb3fd9a74414416 Mon Sep 17 00:00:00 2001 From: Adam Fleming Date: Sat, 20 Jun 2015 21:03:48 -0400 Subject: [PATCH 106/594] Sortable 1.2.1 Bump minor version number --- README.md | 4 ++-- Sortable.js | 2 +- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cc767bb05..c90775fb5 100644 --- a/README.md +++ b/README.md @@ -583,11 +583,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index cf0b5f047..1b1ab9381 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1128,7 +1128,7 @@ }; - Sortable.version = '1.2.0'; + Sortable.version = '1.2.1'; /** diff --git a/Sortable.min.js b/Sortable.min.js index 6b3c9428f..355eb28bb 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.2.0 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=q({},b),a[H]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,r),t.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||J,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(G," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(G," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return J.defaultView&&J.defaultView.getComputedStyle?c=J.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){M=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function q(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var r,s,t,u,v,w,x,y,z,A,B,C,D,E,F={},G=/\s+/g,H="Sortable"+(new Date).getTime(),I=window,J=I.document,K=I.parseInt,L=!!("draggable"in J.createElement("div")),M=!1,N=function(a,b,c,d,e,f,g){var h=J.createEvent("Event"),i=(a||b[H]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.item=d||b,h.from=e||b,h.clone=t,h.oldIndex=f,h.newIndex=g,i[j]&&i[j].call(a,h),b.dispatchEvent(h)},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(x!==c&&(w=b.scroll,x=c,w===!0)){w=c;do if(w.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=I)),(F.vx!==f||F.vy!==g||F.el!==d)&&(F.el=d,F.vx=f,F.vy=g,clearInterval(F.pid),d&&(F.pid=setInterval(function(){d===I?I.scrollTo(I.pageXOffset+f*i,I.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(A=o(h),"function"==typeof j){if(j.call(this,a,h,this))return N(b,i,"filter",h,c,A),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(N(b,a,"filter",h,c,A),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!r&&c.parentNode===g&&(D=a,u=g,r=c,v=r.nextSibling,C=h.group,d=function(){e._disableDelayedDrag(),r.draggable=!0,h.ignore.split(",").forEach(function(a){j(r,a.trim(),k)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(D={target:r,clientX:a.clientX,clientY:a.clientY},this._onDragStart(D,"touch")):L?(f(r,"dragend",this),f(u,"dragstart",this._onDragStart)):this._onDragStart(D,!0);try{J.selection?J.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){u&&r&&(h(r,this.options.ghostClass,!0),a.active=this,N(this,u,"start",r,u,A))},_emulateDragOver:function(){if(E){i(s,"display","none");var a=J.elementFromPoint(E.clientX,E.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[H]&&b[H].options.groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:E.clientX,clientY:E.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(D){var b=a.touches?a.touches[0]:a,c=b.clientX-D.clientX,d=b.clientY-D.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";E=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==C.pull&&(t=r.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,r)),b){var e,g=r.getBoundingClientRect(),h=i(r);s=r.cloneNode(!0),i(s,"top",g.top-K(h.marginTop,10)),i(s,"left",g.left-K(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),"touch"===b?(f(J,"touchmove",this._onTouchMove),f(J,"touchend",this._onDrop),f(J,"touchcancel",this._onDrop)):(f(J,"mousemove",this._onTouchMove),f(J,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,r)),f(J,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=C===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),C&&!h.disabled&&(n?o||(f=!u.contains(r)):C.pull&&k&&(C.name===j.name||k.indexOf&&~k.indexOf(C.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(R(a,h,this.el),M)return;if(c=d(a.target,h.draggable,g),e=r.getBoundingClientRect(),f)return b(!0),void(t||v?u.insertBefore(r,t||v):o||u.appendChild(r));if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;q=c.getBoundingClientRect()}b(n),g.appendChild(r),this._animate(e,r),c&&this._animate(q,c)}else if(c&&!c.animated&&c!==r&&void 0!==c.parentNode[H]){y!==c&&(y=c,z=i(c));var p,q=c.getBoundingClientRect(),w=q.right-q.left,x=q.bottom-q.top,A=/left|right|inline/.test(z.cssFloat+z.display),B=c.offsetWidth>r.offsetWidth,D=c.offsetHeight>r.offsetHeight,E=(A?(a.clientX-q.left)/w:(a.clientY-q.top)/x)>.5,F=c.nextElementSibling;M=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===r&&!B||E&&B:F!==r&&!D||E&&D,p&&!F?g.appendChild(r):c.parentNode.insertBefore(r,p?F:c),this._animate(e,r),this._animate(q,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(J,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(F.pid),clearTimeout(this.dragStartTimer),g(J,"drop",this),g(J,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),s&&s.parentNode.removeChild(s),r&&(g(r,"dragend",this),k(r),h(r,this.options.ghostClass,!1),u!==r.parentNode?(B=o(r),N(null,r.parentNode,"sort",r,u,A,B),N(this,u,"sort",r,u,A,B),N(null,r.parentNode,"add",r,u,A,B),N(this,u,"remove",r,u,A,B)):(t&&t.parentNode.removeChild(t),r.nextSibling!==v&&(B=o(r),N(this,u,"update",r,u,A,B),N(this,u,"sort",r,u,A,B))),a.active&&N(this,u,"end",r,u,A,B)),u=r=s=v=t=w=x=D=E=y=z=C=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?r&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[H]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:q,throttle:p,closest:d,toggleClass:h,index:o},a.version="1.2.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.2.1 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=s({},b),a[J]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(i(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,t),v.state=a)}function c(a,b){var c=Q.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(Q.call(arguments)))}}function d(a,b,c){if(a){c=c||L,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(I," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(I," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return L.defaultView&&L.defaultView.getComputedStyle?c=L.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a,b,c,d,e,f,g){var h=L.createEvent("Event"),i=(a||b[J]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function l(a,b,c,d,e,f){var g,h,i=a[J],j=i.options.onMove;return j&&(g=L.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),h=j.call(i,g)),h}function m(a){a.draggable=!1}function n(){O=!1}function o(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function p(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function q(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function r(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function s(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var t,u,v,w,x,y,z,A,B,C,D,E,F,G,H={},I=/\s+/g,J="Sortable"+(new Date).getTime(),K=window,L=K.document,M=K.parseInt,N=!!("draggable"in L.createElement("div")),O=!1,P=Math.abs,Q=[].slice,R=[],S=r(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=K)),(H.vx!==f||H.vy!==g||H.el!==d)&&(H.el=d,H.vx=f,H.vy=g,clearInterval(H.pid),d&&(H.pid=setInterval(function(){d===K?K.scrollTo(K.pageXOffset+f*i,K.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(C=q(h),"function"==typeof j){if(j.call(this,a,h,this))return k(b,i,"filter",h,c,C),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(k(b,a,"filter",h,c,C),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!t&&c.parentNode===g&&(F=a,w=g,t=c,x=t.nextSibling,E=h.group,d=function(){e._disableDelayedDrag(),t.draggable=!0,h.ignore.split(",").forEach(function(a){j(t,a.trim(),m)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:t,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):N?(f(t,"dragend",this),f(w,"dragstart",this._onDragStart)):this._onDragStart(F,!0);try{L.selection?L.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&t&&(h(t,this.options.ghostClass,!0),a.active=this,k(this,w,"start",t,w,C))},_emulateDragOver:function(){if(G){i(u,"display","none");var a=L.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[J]&&b[J].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(u,"display","")}},_onTouchMove:function(a){if(F){var b=a.touches?a.touches[0]:a,c=b.clientX-F.clientX,d=b.clientY-F.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";G=b,i(u,"webkitTransform",e),i(u,"mozTransform",e),i(u,"msTransform",e),i(u,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==E.pull&&(v=t.cloneNode(!0),i(v,"display","none"),w.insertBefore(v,t)),b){var e,g=t.getBoundingClientRect(),h=i(t);u=t.cloneNode(!0),i(u,"top",g.top-M(h.marginTop,10)),i(u,"left",g.left-M(h.marginLeft,10)),i(u,"width",g.width),i(u,"height",g.height),i(u,"opacity","0.8"),i(u,"position","fixed"),i(u,"zIndex","100000"),w.appendChild(u),e=u.getBoundingClientRect(),i(u,"width",2*g.width-e.width),i(u,"height",2*g.height-e.height),"touch"===b?(f(L,"touchmove",this._onTouchMove),f(L,"touchend",this._onDrop),f(L,"touchcancel",this._onDrop)):(f(L,"mousemove",this._onTouchMove),f(L,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,t)),f(L,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,m=E===j,p=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),E&&!h.disabled&&(m?p||(f=!w.contains(t)):E.pull&&k&&(E.name===j.name||k.indexOf&&~k.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,h,this.el),O)return;if(c=d(a.target,h.draggable,g),e=t.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(t,v||x):p||w.appendChild(t));if(0===g.children.length||g.children[0]===u||g===a.target&&(c=o(g,a))){if(c){if(c.animated)return;r=c.getBoundingClientRect()}b(m),l(w,g,t,e,c,r)!==!1&&(g.appendChild(t),this._animate(e,t),c&&this._animate(r,c))}else if(c&&!c.animated&&c!==t&&void 0!==c.parentNode[J]){A!==c&&(A=c,B=i(c));var q,r=c.getBoundingClientRect(),s=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=c.offsetWidth>t.offsetWidth,D=c.offsetHeight>t.offsetHeight,F=(z?(a.clientX-r.left)/s:(a.clientY-r.top)/y)>.5,G=c.nextElementSibling,H=l(w,g,t,e,c,r);H!==!1&&(O=!0,setTimeout(n,30),b(m),q=1===H||-1===H?1===H:z?c.previousElementSibling===t&&!C||F&&C:G!==t&&!D||F&&D,q&&!G?g.appendChild(t):c.parentNode.insertBefore(t,q?G:c),this._animate(e,t),this._animate(r,c))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(L,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(H.pid),clearTimeout(this.dragStartTimer),g(L,"drop",this),g(L,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),u&&u.parentNode.removeChild(u),t&&(g(t,"dragend",this),m(t),h(t,this.options.ghostClass,!1),w!==t.parentNode?(D=q(t),k(null,t.parentNode,"sort",t,w,C,D),k(this,w,"sort",t,w,C,D),k(null,t.parentNode,"add",t,w,C,D),k(this,w,"remove",t,w,C,D)):(v&&v.parentNode.removeChild(v),t.nextSibling!==x&&(D=q(t),k(this,w,"update",t,w,C,D),k(this,w,"sort",t,w,C,D))),a.active&&(k(this,w,"end",t,w,C,D),this.save())),w=t=u=x=v=y=z=F=G=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?t&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||p(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[J]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:s,throttle:r,closest:d,toggleClass:h,index:q},a.version="1.2.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index 741a0527e..5f5fc8117 100644 --- a/bower.json +++ b/bower.json @@ -6,7 +6,7 @@ "knockout-sortable.js", "react-sortable-mixin.js" ], - "version": "1.2.0", + "version": "1.2.1", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index 04a090a1e..31a2a57e2 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.2.0", + "version": "1.2.1", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ From 429dc043abc681a7d9d309462a81c7ab71519fc4 Mon Sep 17 00:00:00 2001 From: ChiefORZ Date: Mon, 22 Jun 2015 17:04:13 +0200 Subject: [PATCH 107/594] fix click event for mobile devices and old browser added forcePolyfill option. forcePolyfill is made to make cross-browser testing more easy. forcePolyfill provides a reliable, consistent cross-browser Solution for Sortable. forcePolyfill gives us the possibility to change the way "dragged items" lok like. --- README.md | 19 +++++++++++++++++ Sortable.js | 59 +++++++++++++++++++++++++++++++++------------------- package.json | 2 +- 3 files changed, 58 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index cc767bb05..411cd53d1 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,13 @@ var sortable = new Sortable(el, { ghostClass: "sortable-ghost", // Class name for the drop placeholder dataIdAttr: 'data-id', + /* + ignore the HTML5 DnD behaviour and force the fallback to kick in + - provide a more reliable cross-browser solution + - grants the ability to display a different "dragged" element + */ + forcePolyfill: false, + scroll: true, // or HTMLElement scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. scrollSpeed: 10, // px @@ -253,6 +260,18 @@ Sortable.create(list, { --- +#### `forcePolyfill` option +If set to `true`, the polyfill - or Fallback for non HTML5 Browser - will be used, even if we are using an HTML5 Browser. +This gives us the possiblity to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers. + +On top of that, the polyfill always generates a copy of that DOM Element in the Document's Body. This behaviour can be exploited to give us more control over the look of this 'dragged' Element. + +Demo: http://jsbin.com/zejimolava/edit?html,css,js,output + + +--- + + #### `scroll` option If set to `true`, the page (or sortable-area) scrolls when coming to an edge. diff --git a/Sortable.js b/Sortable.js index ba2397730..76a5a706e 100644 --- a/Sortable.js +++ b/Sortable.js @@ -176,7 +176,8 @@ dropBubble: false, dragoverBubble: false, dataIdAttr: 'data-id', - delay: 0 + delay: 0, + forcePolyfill: false }; @@ -323,8 +324,12 @@ _on(ownerDocument, 'touchcancel', _this._onDrop); if (options.delay) { - // If the user moves the pointer before the delay has been reached: + // If the user moves the pointer or let go the click or touch + // before the delay has been reached: // disable the delayed drag + _on(ownerDocument, 'mouseup', _this._disableDelayedDrag); + _on(ownerDocument, 'touchend', _this._disableDelayedDrag); + _on(ownerDocument, 'touchcancel', _this._disableDelayedDrag); _on(ownerDocument, 'mousemove', _this._disableDelayedDrag); _on(ownerDocument, 'touchmove', _this._disableDelayedDrag); @@ -339,7 +344,9 @@ var ownerDocument = this.el.ownerDocument; clearTimeout(this._dragStartTimer); - + _off(ownerDocument, 'mouseup', this._disableDelayedDrag); + _off(ownerDocument, 'touchend', this._disableDelayedDrag); + _off(ownerDocument, 'touchcancel', this._disableDelayedDrag); _off(ownerDocument, 'mousemove', this._disableDelayedDrag); _off(ownerDocument, 'touchmove', this._disableDelayedDrag); }, @@ -355,7 +362,7 @@ this._onDragStart(tapEvt, 'touch'); } - else if (!supportDraggable) { + else if (!supportDraggable || this.options.forcePolyfill) { this._onDragStart(tapEvt, true); } else { @@ -422,6 +429,12 @@ _onTouchMove: function (/**TouchEvent*/evt) { if (tapEvt) { + // only set the status to dragging, when we are actually dragging + if(!Sortable.active) { + this._dragStarted(); + } + // as well as creating the ghost element on the document body + this._appendGhost(); var touch = evt.touches ? evt.touches[0] : evt, dx = touch.clientX - tapEvt.clientX, dy = touch.clientY - tapEvt.clientY, @@ -438,20 +451,8 @@ } }, - - _onDragStart: function (/**Event*/evt, /**boolean*/useFallback) { - var dataTransfer = evt.dataTransfer, - options = this.options; - - this._offUpEvents(); - - if (activeGroup.pull == 'clone') { - cloneEl = dragEl.cloneNode(true); - _css(cloneEl, 'display', 'none'); - rootEl.insertBefore(cloneEl, dragEl); - } - - if (useFallback) { + _appendGhost: function() { + if(!ghostEl) { var rect = dragEl.getBoundingClientRect(), css = _css(dragEl), ghostRect; @@ -466,12 +467,28 @@ _css(ghostEl, 'position', 'fixed'); _css(ghostEl, 'zIndex', '100000'); - rootEl.appendChild(ghostEl); + document.body.appendChild(ghostEl); // Fixing dimensions. ghostRect = ghostEl.getBoundingClientRect(); _css(ghostEl, 'width', rect.width * 2 - ghostRect.width); _css(ghostEl, 'height', rect.height * 2 - ghostRect.height); + } + }, + + _onDragStart: function (/**Event*/evt, /**boolean*/useFallback) { + var dataTransfer = evt.dataTransfer, + options = this.options; + + this._offUpEvents(); + + if (activeGroup.pull == 'clone') { + cloneEl = dragEl.cloneNode(true); + _css(cloneEl, 'display', 'none'); + rootEl.insertBefore(cloneEl, dragEl); + } + + if (useFallback) { if (useFallback === 'touch') { // Bind touch events @@ -493,9 +510,9 @@ } _on(document, 'drop', this); + setTimeout(this._dragStarted, 0); } - - setTimeout(this._dragStarted, 0); + }, _onDragOver: function (/**Event*/evt) { diff --git a/package.json b/package.json index 344c30b73..f92bbad9c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.2.1", + "version": "1.2.2", "devDependencies": { "grunt": "*", "grunt-version": "*", From 5d6747a9c7a5effb3b17ce661798f88c82bbd0ca Mon Sep 17 00:00:00 2001 From: ChiefORZ Date: Mon, 22 Jun 2015 19:57:15 +0200 Subject: [PATCH 108/594] react handleMove/onMove event modified the private _onMove prototype, so it calls events on it's source Element like it's sibling function _dispatchEvent added the handleMove, which listens to the onMove events to the react mixin --- Sortable.js | 20 +++++++++++--------- react-sortable-mixin.js | 5 +++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Sortable.js b/Sortable.js index 76a5a706e..e48916a77 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1021,17 +1021,19 @@ onMoveFn = sortable.options.onMove, retVal; - if (onMoveFn) { - evt = document.createEvent('Event'); - evt.initEvent('move', true, true); + evt = document.createEvent('Event'); + evt.initEvent('move', true, true); + + evt.to = toEl; + evt.from = fromEl; + evt.dragged = dragEl; + evt.draggedRect = dragRect; + evt.related = targetEl || toEl; + evt.relatedRect = targetRect || toEl.getBoundingClientRect(); - evt.to = toEl; - evt.from = fromEl; - evt.dragged = dragEl; - evt.draggedRect = dragRect; - evt.related = targetEl || toEl; - evt.relatedRect = targetRect || toEl.getBoundingClientRect(); + fromEl.dispatchEvent(evt); + if (onMoveFn) { retVal = onMoveFn.call(sortable, evt); } diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index c40c15ff0..0736c8f2f 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -34,7 +34,8 @@ onUpdate: 'handleUpdate', onRemove: 'handleRemove', onSort: 'handleSort', - onFilter: 'handleFilter' + onFilter: 'handleFilter', + onMove: 'handleMove' }; @@ -90,7 +91,7 @@ // Bind callbacks so that "this" refers to the component - 'onStart onEnd onAdd onSort onUpdate onRemove onFilter'.split(' ').forEach(function (/** string */name) { + 'onStart onEnd onAdd onSort onUpdate onRemove onFilter onMove'.split(' ').forEach(function (/** string */name) { copyOptions[name] = function (evt) { if (name === 'onStart') { _nextSibling = evt.item.nextElementSibling; From 2f06d97b3627b6350a1d91b943a29f9b8ff0659a Mon Sep 17 00:00:00 2001 From: ChiefORZ Date: Tue, 23 Jun 2015 00:19:39 +0200 Subject: [PATCH 109/594] missed some stuff wasn't merging all necessary stuff. now it should be fully functional --- Sortable.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index e48916a77..be7d423b0 100644 --- a/Sortable.js +++ b/Sortable.js @@ -45,6 +45,8 @@ tapEvt, touchEvt, + moved, + /** @const */ RSPACE = /\s+/g, @@ -442,6 +444,8 @@ touchEvt = touch; + moved = true; + _css(ghostEl, 'webkitTransform', translate3d); _css(ghostEl, 'mozTransform', translate3d); _css(ghostEl, 'msTransform', translate3d); @@ -682,9 +686,10 @@ this._offUpEvents(); if (evt) { - evt.preventDefault(); - !options.dropBubble && evt.stopPropagation(); - + if(moved) { + evt.preventDefault(); + !options.dropBubble && evt.stopPropagation(); + } ghostEl && ghostEl.parentNode.removeChild(ghostEl); if (dragEl) { @@ -742,6 +747,8 @@ tapEvt = touchEvt = + moved = + lastEl = lastCSS = From 6be61ce97ef9e22463b75f9c49078c05a61b2725 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Thu, 25 Jun 2015 10:58:13 +0800 Subject: [PATCH 110/594] remove _bind function for Function.bind polyfill --- Sortable.js | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Sortable.js b/Sortable.js index ba2397730..03d9f67e7 100644 --- a/Sortable.js +++ b/Sortable.js @@ -206,7 +206,7 @@ // Bind all private methods for (var fn in this) { if (fn.charAt(0) === '_') { - this[fn] = _bind(this, this[fn]); + this[fn] = this[fn].bind(this); } } @@ -870,14 +870,6 @@ } - function _bind(ctx, fn) { - var args = slice.call(arguments, 2); - return fn.bind ? fn.bind.apply(fn, [ctx].concat(args)) : function () { - return fn.apply(ctx, args.concat(slice.call(arguments))); - }; - } - - function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) { if (el) { ctx = ctx || document; @@ -1115,7 +1107,6 @@ off: _off, css: _css, find: _find, - bind: _bind, is: function (el, selector) { return !!_closest(el, selector, el); }, From a092094d1120a5c64998c720d0d20154db00f279 Mon Sep 17 00:00:00 2001 From: Kuitos Date: Thu, 25 Jun 2015 11:01:10 +0800 Subject: [PATCH 111/594] remove _bind function for Function.bind polyfill --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index 03d9f67e7..0b969d0c0 100644 --- a/Sortable.js +++ b/Sortable.js @@ -206,7 +206,7 @@ // Bind all private methods for (var fn in this) { if (fn.charAt(0) === '_') { - this[fn] = this[fn].bind(this); + this[fn] = this[fn].bind(this); } } From d56e4d41dbe52168de5d8d2bff010a126b62af1c Mon Sep 17 00:00:00 2001 From: ChiefORZ Date: Thu, 25 Jun 2015 12:33:03 +0200 Subject: [PATCH 112/594] forceFallback changes removed the default behaviour to append the cloned Element to the body. now the cloned Element gets added in the same parent, with the addition of the class defined in options.fallbackClass. added the possibility to change the fallback class. added the possibility to decide wheter the fallback should be cloned into the same parent or to the document's body. --- README.md | 17 +++++++---------- Sortable.js | 11 ++++++++--- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 411cd53d1..2128b33fa 100644 --- a/README.md +++ b/README.md @@ -65,12 +65,9 @@ var sortable = new Sortable(el, { ghostClass: "sortable-ghost", // Class name for the drop placeholder dataIdAttr: 'data-id', - /* - ignore the HTML5 DnD behaviour and force the fallback to kick in - - provide a more reliable cross-browser solution - - grants the ability to display a different "dragged" element - */ - forcePolyfill: false, + forceFallback: false, // ignore the HTML5 DnD behaviour and force the fallback to kick in + fallbackClass: "sortable-fallback" // Class name for the cloned DOM Element when using forceFallback + fallbackOnBody: false // Appends the cloned DOM Element into the Document's Body scroll: true, // or HTMLElement scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. @@ -260,13 +257,13 @@ Sortable.create(list, { --- -#### `forcePolyfill` option -If set to `true`, the polyfill - or Fallback for non HTML5 Browser - will be used, even if we are using an HTML5 Browser. +#### `forceFallback` option +If set to `true`, the Fallback for non HTML5 Browser will be used, even if we are using an HTML5 Browser. This gives us the possiblity to test the behaviour for older Browsers even in newer Browser, or make the Drag 'n Drop feel more consistent between Desktop , Mobile and old Browsers. -On top of that, the polyfill always generates a copy of that DOM Element in the Document's Body. This behaviour can be exploited to give us more control over the look of this 'dragged' Element. +On top of that, the Fallback always generates a copy of that DOM Element and appends the class `fallbackClass` definied in the options. This behaviour controls the look of this 'dragged' Element. -Demo: http://jsbin.com/zejimolava/edit?html,css,js,output +Demo: http://jsbin.com/xinuyenabi/edit?html,css,js,output --- diff --git a/Sortable.js b/Sortable.js index be7d423b0..fd5c1c0c8 100644 --- a/Sortable.js +++ b/Sortable.js @@ -179,7 +179,9 @@ dragoverBubble: false, dataIdAttr: 'data-id', delay: 0, - forcePolyfill: false + forceFallback: false, + fallbackClass: 'sortable-fallback', + fallbackOnBody: false }; @@ -364,7 +366,7 @@ this._onDragStart(tapEvt, 'touch'); } - else if (!supportDraggable || this.options.forcePolyfill) { + else if (!supportDraggable || this.options.forceFallback) { this._onDragStart(tapEvt, true); } else { @@ -463,6 +465,9 @@ ghostEl = dragEl.cloneNode(true); + _toggleClass(ghostEl, this.options.ghostClass, false); + _toggleClass(ghostEl, this.options.fallbackClass, true); + _css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10)); _css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10)); _css(ghostEl, 'width', rect.width); @@ -471,7 +476,7 @@ _css(ghostEl, 'position', 'fixed'); _css(ghostEl, 'zIndex', '100000'); - document.body.appendChild(ghostEl); + this.options.fallbackOnBody && document.body.appendChild(ghostEl) || rootEl.appendChild(ghostEl); // Fixing dimensions. ghostRect = ghostEl.getBoundingClientRect(); From 8ae82072d3ce942eb4079c7d68a10134bf37616e Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sat, 27 Jun 2015 12:45:06 +0200 Subject: [PATCH 113/594] remove drag/drop handlers in forceFallback mode drag/drop handlers should be disabled in fallback mode to avoid unwanted behaviors --- Sortable.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Sortable.js b/Sortable.js index a2477f6fd..cbd14a282 100644 --- a/Sortable.js +++ b/Sortable.js @@ -56,8 +56,6 @@ document = win.document, parseInt = win.parseInt, - supportDraggable = !!('draggable' in document.createElement('div')), - _silent = false, abs = Math.abs, @@ -190,6 +188,11 @@ !(name in options) && (options[name] = defaults[name]); } + if (options.forceFallback) { + this.nativeDragMode = false; + } else { + this.nativeDragMode = !!('draggable' in document.createElement('div')); + } var group = options.group; @@ -220,8 +223,10 @@ _on(el, 'mousedown', this._onTapStart); _on(el, 'touchstart', this._onTapStart); - _on(el, 'dragover', this); - _on(el, 'dragenter', this); + if (this.nativeDragMode) { + _on(el, 'dragover', this); + _on(el, 'dragenter', this); + } touchDragOverListeners.push(this._onDragOver); @@ -366,7 +371,7 @@ this._onDragStart(tapEvt, 'touch'); } - else if (!supportDraggable || this.options.forceFallback) { + else if (!this.nativeDragMode) { this._onDragStart(tapEvt, true); } else { @@ -521,7 +526,6 @@ _on(document, 'drop', this); setTimeout(this._dragStarted, 0); } - }, _onDragOver: function (/**Event*/evt) { @@ -684,9 +688,12 @@ clearTimeout(this._dragStartTimer); // Unbind events - _off(document, 'drop', this); _off(document, 'mousemove', this._onTouchMove); - _off(el, 'dragstart', this._onDragStart); + + if (this.nativeDragMode) { + _off(document, 'drop', this); + _off(el, 'dragstart', this._onDragStart); + } this._offUpEvents(); @@ -698,7 +705,9 @@ ghostEl && ghostEl.parentNode.removeChild(ghostEl); if (dragEl) { - _off(dragEl, 'dragend', this); + if (this.nativeDragMode) { + _off(dragEl, 'dragend', this); + } _disableDraggable(dragEl); _toggleClass(dragEl, this.options.ghostClass, false); @@ -873,8 +882,10 @@ _off(el, 'mousedown', this._onTapStart); _off(el, 'touchstart', this._onTapStart); - _off(el, 'dragover', this); - _off(el, 'dragenter', this); + if (this.nativeDragMode) { + _off(el, 'dragover', this); + _off(el, 'dragenter', this); + } // Remove draggable attributes Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) { From 0eb010e2198e78a7c652ef0ef649889eeba8e595 Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sat, 27 Jun 2015 15:12:31 +0200 Subject: [PATCH 114/594] #422: fix fallback moves in owner container see #422 --- Sortable.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index a2477f6fd..790f514b6 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1057,9 +1057,11 @@ /** @returns {HTMLElement|false} */ function _ghostInBottom(el, evt) { - var lastEl = el.lastElementChild, - rect = lastEl.getBoundingClientRect(); - + var lastEl = el.lastElementChild; + if (lastEl===ghostEl) { + lastEl = lastEl.previousElementSibling || ghostEl; + } + var rect = lastEl.getBoundingClientRect(); return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta } From 53c9355a0cd7df8dfab4edca4924b5dbdc5b698e Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sat, 27 Jun 2015 15:13:43 +0200 Subject: [PATCH 115/594] Revert "#422: fix fallback moves in owner container" --- Sortable.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index 790f514b6..a2477f6fd 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1057,11 +1057,9 @@ /** @returns {HTMLElement|false} */ function _ghostInBottom(el, evt) { - var lastEl = el.lastElementChild; - if (lastEl===ghostEl) { - lastEl = lastEl.previousElementSibling || ghostEl; - } - var rect = lastEl.getBoundingClientRect(); + var lastEl = el.lastElementChild, + rect = lastEl.getBoundingClientRect(); + return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta } From 9e3e0a81a07b24ecfe9a57c00be965d9cdf66cd7 Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Sat, 27 Jun 2015 17:04:20 +0200 Subject: [PATCH 116/594] improves the fallback mode fluidity _emulateDragOver optimized to reduce the interval tics. That provides a fluidity similar to the native drag and drop mode. --- Sortable.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index a2477f6fd..6b246d30d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -398,6 +398,12 @@ _emulateDragOver: function () { if (touchEvt) { + if (this._lastX===touchEvt.clientX && this._lastY===touchEvt.clientY ) { + return; + } + this._lastX=touchEvt.clientX; + this._lastY=touchEvt.clientY; + _css(ghostEl, 'display', 'none'); var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY), @@ -510,7 +516,7 @@ _on(document, 'mouseup', this._onDrop); } - this._loopId = setInterval(this._emulateDragOver, 150); + this._loopId = setInterval(this._emulateDragOver, 50); } else { if (dataTransfer) { From 5a3ce29d0758d4847962a99f67e33452ead3b44b Mon Sep 17 00:00:00 2001 From: Derek Berner Date: Mon, 13 Jul 2015 09:46:05 -0500 Subject: [PATCH 117/594] Error when dragged item is removed from parent before drag ends --- README.md | 4 ++-- Sortable.js | 19 +++++++++++-------- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 2f062b9ea..ca309830b 100644 --- a/README.md +++ b/README.md @@ -599,11 +599,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index a2477f6fd..45510f068 100644 --- a/Sortable.js +++ b/Sortable.js @@ -25,6 +25,7 @@ "use strict"; var dragEl, + parentEl, ghostEl, cloneEl, rootEl, @@ -303,6 +304,7 @@ rootEl = el; dragEl = target; + parentEl = target.parentNode; nextEl = dragEl.nextSibling; activeGroup = options.group; @@ -434,7 +436,7 @@ _onTouchMove: function (/**TouchEvent*/evt) { if (tapEvt) { // only set the status to dragging, when we are actually dragging - if(!Sortable.active) { + if (!Sortable.active) { this._dragStarted(); } // as well as creating the ghost element on the document body @@ -457,8 +459,8 @@ } }, - _appendGhost: function() { - if(!ghostEl) { + _appendGhost: function () { + if (!ghostEl) { var rect = dragEl.getBoundingClientRect(), css = _css(dragEl), ghostRect; @@ -691,7 +693,7 @@ this._offUpEvents(); if (evt) { - if(moved) { + if (moved) { evt.preventDefault(); !options.dropBubble && evt.stopPropagation(); } @@ -703,15 +705,15 @@ _disableDraggable(dragEl); _toggleClass(dragEl, this.options.ghostClass, false); - if (rootEl !== dragEl.parentNode) { + if (rootEl !== parentEl) { newIndex = _index(dragEl); // drag from one list and drop into another - _dispatchEvent(null, dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); // Add event - _dispatchEvent(null, dragEl.parentNode, 'add', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex); // Remove event _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); @@ -742,6 +744,7 @@ // Nulling rootEl = dragEl = + parentEl = ghostEl = nextEl = cloneEl = @@ -1149,7 +1152,7 @@ }; - Sortable.version = '1.2.1'; + Sortable.version = '1.2.2'; /** diff --git a/Sortable.min.js b/Sortable.min.js index 355eb28bb..f7adeb7fa 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.2.1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=s({},b),a[J]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(i(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,t),v.state=a)}function c(a,b){var c=Q.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(Q.call(arguments)))}}function d(a,b,c){if(a){c=c||L,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(I," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(I," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return L.defaultView&&L.defaultView.getComputedStyle?c=L.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a,b,c,d,e,f,g){var h=L.createEvent("Event"),i=(a||b[J]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function l(a,b,c,d,e,f){var g,h,i=a[J],j=i.options.onMove;return j&&(g=L.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),h=j.call(i,g)),h}function m(a){a.draggable=!1}function n(){O=!1}function o(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function p(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function q(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function r(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function s(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var t,u,v,w,x,y,z,A,B,C,D,E,F,G,H={},I=/\s+/g,J="Sortable"+(new Date).getTime(),K=window,L=K.document,M=K.parseInt,N=!!("draggable"in L.createElement("div")),O=!1,P=Math.abs,Q=[].slice,R=[],S=r(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=K)),(H.vx!==f||H.vy!==g||H.el!==d)&&(H.el=d,H.vx=f,H.vy=g,clearInterval(H.pid),d&&(H.pid=setInterval(function(){d===K?K.scrollTo(K.pageXOffset+f*i,K.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(C=q(h),"function"==typeof j){if(j.call(this,a,h,this))return k(b,i,"filter",h,c,C),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(k(b,a,"filter",h,c,C),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!t&&c.parentNode===g&&(F=a,w=g,t=c,x=t.nextSibling,E=h.group,d=function(){e._disableDelayedDrag(),t.draggable=!0,h.ignore.split(",").forEach(function(a){j(t,a.trim(),m)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:t,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):N?(f(t,"dragend",this),f(w,"dragstart",this._onDragStart)):this._onDragStart(F,!0);try{L.selection?L.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&t&&(h(t,this.options.ghostClass,!0),a.active=this,k(this,w,"start",t,w,C))},_emulateDragOver:function(){if(G){i(u,"display","none");var a=L.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[J]&&b[J].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(u,"display","")}},_onTouchMove:function(a){if(F){var b=a.touches?a.touches[0]:a,c=b.clientX-F.clientX,d=b.clientY-F.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";G=b,i(u,"webkitTransform",e),i(u,"mozTransform",e),i(u,"msTransform",e),i(u,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==E.pull&&(v=t.cloneNode(!0),i(v,"display","none"),w.insertBefore(v,t)),b){var e,g=t.getBoundingClientRect(),h=i(t);u=t.cloneNode(!0),i(u,"top",g.top-M(h.marginTop,10)),i(u,"left",g.left-M(h.marginLeft,10)),i(u,"width",g.width),i(u,"height",g.height),i(u,"opacity","0.8"),i(u,"position","fixed"),i(u,"zIndex","100000"),w.appendChild(u),e=u.getBoundingClientRect(),i(u,"width",2*g.width-e.width),i(u,"height",2*g.height-e.height),"touch"===b?(f(L,"touchmove",this._onTouchMove),f(L,"touchend",this._onDrop),f(L,"touchcancel",this._onDrop)):(f(L,"mousemove",this._onTouchMove),f(L,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,t)),f(L,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,m=E===j,p=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),E&&!h.disabled&&(m?p||(f=!w.contains(t)):E.pull&&k&&(E.name===j.name||k.indexOf&&~k.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,h,this.el),O)return;if(c=d(a.target,h.draggable,g),e=t.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(t,v||x):p||w.appendChild(t));if(0===g.children.length||g.children[0]===u||g===a.target&&(c=o(g,a))){if(c){if(c.animated)return;r=c.getBoundingClientRect()}b(m),l(w,g,t,e,c,r)!==!1&&(g.appendChild(t),this._animate(e,t),c&&this._animate(r,c))}else if(c&&!c.animated&&c!==t&&void 0!==c.parentNode[J]){A!==c&&(A=c,B=i(c));var q,r=c.getBoundingClientRect(),s=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=c.offsetWidth>t.offsetWidth,D=c.offsetHeight>t.offsetHeight,F=(z?(a.clientX-r.left)/s:(a.clientY-r.top)/y)>.5,G=c.nextElementSibling,H=l(w,g,t,e,c,r);H!==!1&&(O=!0,setTimeout(n,30),b(m),q=1===H||-1===H?1===H:z?c.previousElementSibling===t&&!C||F&&C:G!==t&&!D||F&&D,q&&!G?g.appendChild(t):c.parentNode.insertBefore(t,q?G:c),this._animate(e,t),this._animate(r,c))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(L,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(H.pid),clearTimeout(this.dragStartTimer),g(L,"drop",this),g(L,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),u&&u.parentNode.removeChild(u),t&&(g(t,"dragend",this),m(t),h(t,this.options.ghostClass,!1),w!==t.parentNode?(D=q(t),k(null,t.parentNode,"sort",t,w,C,D),k(this,w,"sort",t,w,C,D),k(null,t.parentNode,"add",t,w,C,D),k(this,w,"remove",t,w,C,D)):(v&&v.parentNode.removeChild(v),t.nextSibling!==x&&(D=q(t),k(this,w,"update",t,w,C,D),k(this,w,"sort",t,w,C,D))),a.active&&(k(this,w,"end",t,w,C,D),this.save())),w=t=u=x=v=y=z=F=G=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?t&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||p(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[J]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:s,throttle:r,closest:d,toggleClass:h,index:q},a.version="1.2.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):!O||this.options.forceFallback?this._onDragStart(F,!0):(e(s,"dragend",this),e(w,"dragstart",this._onDragStart));try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";G=c,H=!0,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),t=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=d.offsetWidth>s.offsetWidth,D=d.offsetHeight>s.offsetHeight,F=(z?(a.clientX-r.left)/t:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(w,g,s,e,d,r);H!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:z?d.previousElementSibling===s&&!C||F&&C:G!==s&&!D||F&&D,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"drop",this),f(M,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D)):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.version="1.2.2",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index 5f5fc8117..45bf6eef1 100644 --- a/bower.json +++ b/bower.json @@ -6,7 +6,7 @@ "knockout-sortable.js", "react-sortable-mixin.js" ], - "version": "1.2.1", + "version": "1.2.2", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index 31a2a57e2..d28254a59 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.2.1", + "version": "1.2.2", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ From 1a437a63beaf129bbbb8926c894436ea9950dfe6 Mon Sep 17 00:00:00 2001 From: Derek Berner Date: Tue, 14 Jul 2015 12:37:59 -0500 Subject: [PATCH 118/594] Additional work on concurrent dom modification --- Sortable.js | 33 ++++++++++++++++++--------------- Sortable.min.js | 2 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Sortable.js b/Sortable.js index 45510f068..af45db225 100644 --- a/Sortable.js +++ b/Sortable.js @@ -707,16 +707,17 @@ if (rootEl !== parentEl) { newIndex = _index(dragEl); + if (newIndex != -1) { + // drag from one list and drop into another + _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); - // drag from one list and drop into another - _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); - - // Add event - _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex); + // Add event + _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex); - // Remove event - _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); + // Remove event + _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); + } } else { // Remove clone @@ -725,10 +726,11 @@ if (dragEl.nextSibling !== nextEl) { // Get the index of the dragged element within its parent newIndex = _index(dragEl); - - // drag & drop within the same list - _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + if (newIndex != -1) { + // drag & drop within the same list + _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + } } } @@ -740,7 +742,7 @@ this.save(); } } - + // Nulling rootEl = dragEl = @@ -1092,6 +1094,9 @@ * @private */ function _index(/**HTMLElement*/el) { + if (!el || !el.parentNode) { + return -1; + } var index = 0; while (el && (el = el.previousElementSibling)) { if (el.nodeName.toUpperCase() !== 'TEMPLATE') { @@ -1151,10 +1156,8 @@ index: _index }; - Sortable.version = '1.2.2'; - /** * Create sortable instance * @param {HTMLElement} el diff --git a/Sortable.min.js b/Sortable.min.js index f7adeb7fa..9bd1858a7 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):!O||this.options.forceFallback?this._onDragStart(F,!0):(e(s,"dragend",this),e(w,"dragstart",this._onDragStart));try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";G=c,H=!0,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),t=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=d.offsetWidth>s.offsetWidth,D=d.offsetHeight>s.offsetHeight,F=(z?(a.clientX-r.left)/t:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(w,g,s,e,d,r);H!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:z?d.previousElementSibling===s&&!C||F&&C:G!==s&&!D||F&&D,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"drop",this),f(M,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D)):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.version="1.2.2",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):!O||this.options.forceFallback?this._onDragStart(F,!0):(e(s,"dragend",this),e(w,"dragstart",this._onDragStart));try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";G=c,H=!0,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),t=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=d.offsetWidth>s.offsetWidth,D=d.offsetHeight>s.offsetHeight,F=(z?(a.clientX-r.left)/t:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(w,g,s,e,d,r);H!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:z?d.previousElementSibling===s&&!C||F&&C:G!==s&&!D||F&&D,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"drop",this),f(M,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),-1!=D&&(j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),-1!=D&&(j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D)))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.version="1.2.2",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file From e912d00edb70f0da82dc8351c8d21e358f0df7d9 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 09:25:36 +0300 Subject: [PATCH 119/594] v1.2.1 --- README.md | 4 ++-- Sortable.js | 2 +- Sortable.min.js | 4 ++-- bower.json | 2 +- component.json | 2 +- react-sortable-mixin.js | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index cc767bb05..c90775fb5 100644 --- a/README.md +++ b/README.md @@ -583,11 +583,11 @@ Link to the active instance. ```html - + - + diff --git a/Sortable.js b/Sortable.js index ba2397730..9a24f6e97 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1127,7 +1127,7 @@ }; - Sortable.version = '1.2.0'; + Sortable.version = '1.2.1'; /** diff --git a/Sortable.min.js b/Sortable.min.js index 6b3c9428f..754718913 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.2.0 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=q({},b),a[H]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){t&&t.state!==a&&(i(t,"display",a?"none":""),!a&&t.state&&u.insertBefore(t,r),t.state=a)}function c(a,b){var c=P.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(P.call(arguments)))}}function d(a,b,c){if(a){c=c||J,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(G," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(G," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return J.defaultView&&J.defaultView.getComputedStyle?c=J.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a){a.draggable=!1}function l(){M=!1}function m(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function n(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function o(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function p(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function q(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var r,s,t,u,v,w,x,y,z,A,B,C,D,E,F={},G=/\s+/g,H="Sortable"+(new Date).getTime(),I=window,J=I.document,K=I.parseInt,L=!!("draggable"in J.createElement("div")),M=!1,N=function(a,b,c,d,e,f,g){var h=J.createEvent("Event"),i=(a||b[H]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.item=d||b,h.from=e||b,h.clone=t,h.oldIndex=f,h.newIndex=g,i[j]&&i[j].call(a,h),b.dispatchEvent(h)},O=Math.abs,P=[].slice,Q=[],R=p(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(x!==c&&(w=b.scroll,x=c,w===!0)){w=c;do if(w.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=I)),(F.vx!==f||F.vy!==g||F.el!==d)&&(F.el=d,F.vx=f,F.vy=g,clearInterval(F.pid),d&&(F.pid=setInterval(function(){d===I?I.scrollTo(I.pageXOffset+f*i,I.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(A=o(h),"function"==typeof j){if(j.call(this,a,h,this))return N(b,i,"filter",h,c,A),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(N(b,a,"filter",h,c,A),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!r&&c.parentNode===g&&(D=a,u=g,r=c,v=r.nextSibling,C=h.group,d=function(){e._disableDelayedDrag(),r.draggable=!0,h.ignore.split(",").forEach(function(a){j(r,a.trim(),k)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(D={target:r,clientX:a.clientX,clientY:a.clientY},this._onDragStart(D,"touch")):L?(f(r,"dragend",this),f(u,"dragstart",this._onDragStart)):this._onDragStart(D,!0);try{J.selection?J.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){u&&r&&(h(r,this.options.ghostClass,!0),a.active=this,N(this,u,"start",r,u,A))},_emulateDragOver:function(){if(E){i(s,"display","none");var a=J.elementFromPoint(E.clientX,E.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[H]&&b[H].options.groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:E.clientX,clientY:E.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(s,"display","")}},_onTouchMove:function(a){if(D){var b=a.touches?a.touches[0]:a,c=b.clientX-D.clientX,d=b.clientY-D.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";E=b,i(s,"webkitTransform",e),i(s,"mozTransform",e),i(s,"msTransform",e),i(s,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==C.pull&&(t=r.cloneNode(!0),i(t,"display","none"),u.insertBefore(t,r)),b){var e,g=r.getBoundingClientRect(),h=i(r);s=r.cloneNode(!0),i(s,"top",g.top-K(h.marginTop,10)),i(s,"left",g.left-K(h.marginLeft,10)),i(s,"width",g.width),i(s,"height",g.height),i(s,"opacity","0.8"),i(s,"position","fixed"),i(s,"zIndex","100000"),u.appendChild(s),e=s.getBoundingClientRect(),i(s,"width",2*g.width-e.width),i(s,"height",2*g.height-e.height),"touch"===b?(f(J,"touchmove",this._onTouchMove),f(J,"touchend",this._onDrop),f(J,"touchcancel",this._onDrop)):(f(J,"mousemove",this._onTouchMove),f(J,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,r)),f(J,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,n=C===j,o=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),C&&!h.disabled&&(n?o||(f=!u.contains(r)):C.pull&&k&&(C.name===j.name||k.indexOf&&~k.indexOf(C.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(R(a,h,this.el),M)return;if(c=d(a.target,h.draggable,g),e=r.getBoundingClientRect(),f)return b(!0),void(t||v?u.insertBefore(r,t||v):o||u.appendChild(r));if(0===g.children.length||g.children[0]===s||g===a.target&&(c=m(g,a))){if(c){if(c.animated)return;q=c.getBoundingClientRect()}b(n),g.appendChild(r),this._animate(e,r),c&&this._animate(q,c)}else if(c&&!c.animated&&c!==r&&void 0!==c.parentNode[H]){y!==c&&(y=c,z=i(c));var p,q=c.getBoundingClientRect(),w=q.right-q.left,x=q.bottom-q.top,A=/left|right|inline/.test(z.cssFloat+z.display),B=c.offsetWidth>r.offsetWidth,D=c.offsetHeight>r.offsetHeight,E=(A?(a.clientX-q.left)/w:(a.clientY-q.top)/x)>.5,F=c.nextElementSibling;M=!0,setTimeout(l,30),b(n),p=A?c.previousElementSibling===r&&!B||E&&B:F!==r&&!D||E&&D,p&&!F?g.appendChild(r):c.parentNode.insertBefore(r,p?F:c),this._animate(e,r),this._animate(q,c)}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(J,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(F.pid),clearTimeout(this.dragStartTimer),g(J,"drop",this),g(J,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),s&&s.parentNode.removeChild(s),r&&(g(r,"dragend",this),k(r),h(r,this.options.ghostClass,!1),u!==r.parentNode?(B=o(r),N(null,r.parentNode,"sort",r,u,A,B),N(this,u,"sort",r,u,A,B),N(null,r.parentNode,"add",r,u,A,B),N(this,u,"remove",r,u,A,B)):(t&&t.parentNode.removeChild(t),r.nextSibling!==v&&(B=o(r),N(this,u,"update",r,u,A,B),N(this,u,"sort",r,u,A,B))),a.active&&N(this,u,"end",r,u,A,B)),u=r=s=v=t=w=x=D=E=y=z=C=a.active=null,this.save())},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?r&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||n(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[H]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:q,throttle:p,closest:d,toggleClass:h,index:o},a.version="1.2.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +/*! Sortable 1.2.1 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=s({},b),a[J]=this;var d={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0};for(var e in d)!(e in b)&&(b[e]=d[e]);var g=b.group;g&&"object"==typeof g||(g=b.group={name:g}),["pull","put"].forEach(function(a){a in g||(g[a]=!0)}),b.groups=" "+g.name+(g.put.join?" "+g.put.join(" "):"")+" ";for(var h in this)"_"===h.charAt(0)&&(this[h]=c(this,this[h]));f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(i(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,t),v.state=a)}function c(a,b){var c=Q.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(Q.call(arguments)))}}function d(a,b,c){if(a){c=c||L,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function e(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function f(a,b,c){a.addEventListener(b,c,!1)}function g(a,b,c){a.removeEventListener(b,c,!1)}function h(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(I," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(I," ")}}function i(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return L.defaultView&&L.defaultView.getComputedStyle?c=L.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function j(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function k(a,b,c,d,e,f,g){var h=L.createEvent("Event"),i=(a||b[J]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function l(a,b,c,d,e,f){var g,h,i=a[J],j=i.options.onMove;return j&&(g=L.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),h=j.call(i,g)),h}function m(a){a.draggable=!1}function n(){O=!1}function o(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function p(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function q(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function r(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function s(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var t,u,v,w,x,y,z,A,B,C,D,E,F,G,H={},I=/\s+/g,J="Sortable"+(new Date).getTime(),K=window,L=K.document,M=K.parseInt,N=!!("draggable"in L.createElement("div")),O=!1,P=Math.abs,Q=[].slice,R=[],S=r(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=K)),(H.vx!==f||H.vy!==g||H.el!==d)&&(H.el=d,H.vx=f,H.vy=g,clearInterval(H.pid),d&&(H.pid=setInterval(function(){d===K?K.scrollTo(K.pageXOffset+f*i,K.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,c=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,j=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=d(h,e.draggable,c))){if(C=q(h),"function"==typeof j){if(j.call(this,a,h,this))return k(b,i,"filter",h,c,C),void a.preventDefault()}else if(j&&(j=j.split(",").some(function(a){return a=d(i,a.trim(),c),a?(k(b,a,"filter",h,c,C),!0):void 0})))return void a.preventDefault();(!e.handle||d(i,e.handle,c))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,e=this,g=e.el,h=e.options,i=g.ownerDocument;c&&!t&&c.parentNode===g&&(F=a,w=g,t=c,x=t.nextSibling,E=h.group,d=function(){e._disableDelayedDrag(),t.draggable=!0,h.ignore.split(",").forEach(function(a){j(t,a.trim(),m)}),e._triggerDragStart(b)},f(i,"mouseup",e._onDrop),f(i,"touchend",e._onDrop),f(i,"touchcancel",e._onDrop),h.delay?(f(i,"mousemove",e._disableDelayedDrag),f(i,"touchmove",e._disableDelayedDrag),e._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),g(a,"mousemove",this._disableDelayedDrag),g(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:t,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):N?(f(t,"dragend",this),f(w,"dragstart",this._onDragStart)):this._onDragStart(F,!0);try{L.selection?L.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&t&&(h(t,this.options.ghostClass,!0),a.active=this,k(this,w,"start",t,w,C))},_emulateDragOver:function(){if(G){i(u,"display","none");var a=L.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[J]&&b[J].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);i(u,"display","")}},_onTouchMove:function(a){if(F){var b=a.touches?a.touches[0]:a,c=b.clientX-F.clientX,d=b.clientY-F.clientY,e=a.touches?"translate3d("+c+"px,"+d+"px,0)":"translate("+c+"px,"+d+"px)";G=b,i(u,"webkitTransform",e),i(u,"mozTransform",e),i(u,"msTransform",e),i(u,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),"clone"==E.pull&&(v=t.cloneNode(!0),i(v,"display","none"),w.insertBefore(v,t)),b){var e,g=t.getBoundingClientRect(),h=i(t);u=t.cloneNode(!0),i(u,"top",g.top-M(h.marginTop,10)),i(u,"left",g.left-M(h.marginLeft,10)),i(u,"width",g.width),i(u,"height",g.height),i(u,"opacity","0.8"),i(u,"position","fixed"),i(u,"zIndex","100000"),w.appendChild(u),e=u.getBoundingClientRect(),i(u,"width",2*g.width-e.width),i(u,"height",2*g.height-e.height),"touch"===b?(f(L,"touchmove",this._onTouchMove),f(L,"touchend",this._onDrop),f(L,"touchcancel",this._onDrop)):(f(L,"mousemove",this._onTouchMove),f(L,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)}else c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,t)),f(L,"drop",this);setTimeout(this._dragStarted,0)},_onDragOver:function(a){var c,e,f,g=this.el,h=this.options,j=h.group,k=j.put,m=E===j,p=h.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!h.dragoverBubble&&a.stopPropagation()),E&&!h.disabled&&(m?p||(f=!w.contains(t)):E.pull&&k&&(E.name===j.name||k.indexOf&&~k.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,h,this.el),O)return;if(c=d(a.target,h.draggable,g),e=t.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(t,v||x):p||w.appendChild(t));if(0===g.children.length||g.children[0]===u||g===a.target&&(c=o(g,a))){if(c){if(c.animated)return;r=c.getBoundingClientRect()}b(m),l(w,g,t,e,c,r)!==!1&&(g.appendChild(t),this._animate(e,t),c&&this._animate(r,c))}else if(c&&!c.animated&&c!==t&&void 0!==c.parentNode[J]){A!==c&&(A=c,B=i(c));var q,r=c.getBoundingClientRect(),s=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=c.offsetWidth>t.offsetWidth,D=c.offsetHeight>t.offsetHeight,F=(z?(a.clientX-r.left)/s:(a.clientY-r.top)/y)>.5,G=c.nextElementSibling,H=l(w,g,t,e,c,r);H!==!1&&(O=!0,setTimeout(n,30),b(m),q=1===H||-1===H?1===H:z?c.previousElementSibling===t&&!C||F&&C:G!==t&&!D||F&&D,q&&!G?g.appendChild(t):c.parentNode.insertBefore(t,q?G:c),this._animate(e,t),this._animate(r,c))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();i(b,"transition","none"),i(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,i(b,"transition","all "+c+"ms"),i(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){i(b,"transition",""),i(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;g(L,"touchmove",this._onTouchMove),g(a,"mouseup",this._onDrop),g(a,"touchend",this._onDrop),g(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(H.pid),clearTimeout(this._dragStartTimer),g(L,"drop",this),g(L,"mousemove",this._onTouchMove),g(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation(),u&&u.parentNode.removeChild(u),t&&(g(t,"dragend",this),m(t),h(t,this.options.ghostClass,!1),w!==t.parentNode?(D=q(t),k(null,t.parentNode,"sort",t,w,C,D),k(this,w,"sort",t,w,C,D),k(null,t.parentNode,"add",t,w,C,D),k(this,w,"remove",t,w,C,D)):(v&&v.parentNode.removeChild(v),t.nextSibling!==x&&(D=q(t),k(this,w,"update",t,w,C,D),k(this,w,"sort",t,w,C,D))),a.active&&(k(this,w,"end",t,w,C,D),this.save())),w=t=u=x=v=y=z=F=G=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?t&&(this._onDragOver(a),e(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],c=this.el.children,e=0,f=c.length,g=this.options;f>e;e++)a=c[e],d(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||p(a));return b},sort:function(a){var b={},c=this.el;this.toArray().forEach(function(a,e){var f=c.children[e];d(f,this.options.draggable,c)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(c.removeChild(b[a]),c.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return d(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[J]=null,g(a,"mousedown",this._onTapStart),g(a,"touchstart",this._onTapStart),g(a,"dragover",this),g(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:f,off:g,css:i,find:j,bind:c,is:function(a,b){return!!d(a,b,a)},extend:s,throttle:r,closest:d,toggleClass:h,index:q},a.version="1.2.1",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file diff --git a/bower.json b/bower.json index 741a0527e..5f5fc8117 100644 --- a/bower.json +++ b/bower.json @@ -6,7 +6,7 @@ "knockout-sortable.js", "react-sortable-mixin.js" ], - "version": "1.2.0", + "version": "1.2.1", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " diff --git a/component.json b/component.json index 04a090a1e..31a2a57e2 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.2.0", + "version": "1.2.1", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/react-sortable-mixin.js b/react-sortable-mixin.js index c40c15ff0..56ae93da7 100644 --- a/react-sortable-mixin.js +++ b/react-sortable-mixin.js @@ -137,9 +137,9 @@ componentWillReceiveProps: function (nextProps) { var newState = {}, modelName = _getModelName(this), - items; + items = nextProps[modelName]; - if (items = nextProps[modelName]) { + if (items) { newState[modelName] = items; this.setState(newState); } From 9e6d0060408adf9c965a462a049a12d01c5734a2 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 09:42:34 +0300 Subject: [PATCH 120/594] #459: * code style --- Sortable.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index aefee82f4..4bcd22d5d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -400,11 +400,12 @@ _emulateDragOver: function () { if (touchEvt) { - if (this._lastX===touchEvt.clientX && this._lastY===touchEvt.clientY ) { + if (this._lastX === touchEvt.clientX && this._lastY === touchEvt.clientY) { return; } - this._lastX=touchEvt.clientX; - this._lastY=touchEvt.clientY; + + this._lastX = touchEvt.clientX; + this._lastY = touchEvt.clientY; _css(ghostEl, 'display', 'none'); From aa414b090992634019b23315a1b1c995f7ad7dbd Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 09:49:15 +0300 Subject: [PATCH 121/594] #457: nativeDragMode -> nativeDraggable --- Sortable.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Sortable.js b/Sortable.js index bb1d1f573..3bc16dd4d 100644 --- a/Sortable.js +++ b/Sortable.js @@ -57,6 +57,8 @@ document = win.document, parseInt = win.parseInt, + supportDraggable = !!('draggable' in document.createElement('div')), + _silent = false, abs = Math.abs, @@ -189,12 +191,6 @@ !(name in options) && (options[name] = defaults[name]); } - if (options.forceFallback) { - this.nativeDragMode = false; - } else { - this.nativeDragMode = !!('draggable' in document.createElement('div')); - } - var group = options.group; if (!group || typeof group != 'object') { @@ -219,12 +215,14 @@ } } + // Setup drag mode + this.nativeDraggable = options.forceFallback ? false : supportDraggable; // Bind events _on(el, 'mousedown', this._onTapStart); _on(el, 'touchstart', this._onTapStart); - if (this.nativeDragMode) { + if (this.nativeDraggable) { _on(el, 'dragover', this); _on(el, 'dragenter', this); } @@ -373,7 +371,7 @@ this._onDragStart(tapEvt, 'touch'); } - else if (!this.nativeDragMode) { + else if (!this.nativeDraggable) { this._onDragStart(tapEvt, true); } else { @@ -701,7 +699,7 @@ // Unbind events _off(document, 'mousemove', this._onTouchMove); - if (this.nativeDragMode) { + if (this.nativeDraggable) { _off(document, 'drop', this); _off(el, 'dragstart', this._onDragStart); } @@ -717,7 +715,7 @@ ghostEl && ghostEl.parentNode.removeChild(ghostEl); if (dragEl) { - if (this.nativeDragMode) { + if (this.nativeDraggable) { _off(dragEl, 'dragend', this); } @@ -897,7 +895,7 @@ _off(el, 'mousedown', this._onTapStart); _off(el, 'touchstart', this._onTapStart); - if (this.nativeDragMode) { + if (this.nativeDraggable) { _off(el, 'dragover', this); _off(el, 'dragenter', this); } From 71f3fb935f9be2517311493c732f1869ad52b073 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 09:50:50 +0300 Subject: [PATCH 122/594] #423: - version --- bower.json | 1 - 1 file changed, 1 deletion(-) diff --git a/bower.json b/bower.json index 45bf6eef1..fae6f7a22 100644 --- a/bower.json +++ b/bower.json @@ -6,7 +6,6 @@ "knockout-sortable.js", "react-sortable-mixin.js" ], - "version": "1.2.2", "homepage": "http://rubaxa.github.io/Sortable/", "authors": [ "RubaXa " From 5f28ec870388be3200c975e473b77f26535ac1b9 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 09:55:28 +0300 Subject: [PATCH 123/594] #411: - duplicate --- Sortable.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index d3fb22c1c..482b2953c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -459,11 +459,8 @@ translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)'; moved = true; - touchEvt = touch; - moved = true; - _css(ghostEl, 'webkitTransform', translate3d); _css(ghostEl, 'mozTransform', translate3d); _css(ghostEl, 'msTransform', translate3d); From d1069a97a7792d33fad29c9a8f94a1d32efa85d2 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Sat, 18 Jul 2015 10:00:42 +0300 Subject: [PATCH 124/594] #481: * call method --- jquery.binding.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.binding.js b/jquery.binding.js index 16d7729b4..e81bfd020 100644 --- a/jquery.binding.js +++ b/jquery.binding.js @@ -46,8 +46,8 @@ sortable.destroy(); $el.removeData('sortable'); } - else if (options in sortable) { - retVal = sortable[sortable].apply(sortable, [].slice.call(arguments, 1)); + else if (typeof sortable[options] === 'function') { + retVal = sortable[options].apply(sortable, [].slice.call(arguments, 1)); } } }); From 7bb9348649f0d452e4e5aa71c6ac2b8800ced14c Mon Sep 17 00:00:00 2001 From: Richard Lai Date: Sun, 19 Jul 2015 18:32:54 -0400 Subject: [PATCH 125/594] Update dependency of mongo-collection-instances --- meteor/package.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meteor/package.js b/meteor/package.js index 51bf04b14..90af16592 100644 --- a/meteor/package.js +++ b/meteor/package.js @@ -16,7 +16,7 @@ Package.describe({ Package.onUse(function (api) { api.versionsFrom(['METEOR@0.9.0', 'METEOR@1.0']); api.use('templating', 'client'); - api.use('dburles:mongo-collection-instances@0.3.3'); // to watch collections getting created + api.use('dburles:mongo-collection-instances@0.3.4'); // to watch collections getting created api.export('Sortable'); // exported on the server too, as a global to hold the array of sortable collections (for security) api.addFiles([ 'Sortable.js', From 97d38acb6f7d234d953660e478864f55e2be5cc0 Mon Sep 17 00:00:00 2001 From: sp-kilobug Date: Mon, 20 Jul 2015 20:59:26 +0200 Subject: [PATCH 126/594] fix flex containers in row mode fix http://jsbin.com/cuduyo/edit?html,css,output compatible with flex-direction: row flex-direction: row-reverse https://developer.mozilla.org/fr/docs/Web/CSS/flex-direction --- Sortable.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sortable.js b/Sortable.js index 482b2953c..0c05729df 100644 --- a/Sortable.js +++ b/Sortable.js @@ -36,6 +36,7 @@ lastEl, lastCSS, + lastParentCSS, oldIndex, newIndex, @@ -611,13 +612,15 @@ if (lastEl !== target) { lastEl = target; lastCSS = _css(target); + lastParentCSS = _css(target.parentNode); } var targetRect = target.getBoundingClientRect(), width = targetRect.right - targetRect.left, height = targetRect.bottom - targetRect.top, - floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display), + floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display) + || (lastParentCSS.display == 'flex' && lastParentCSS['flex-direction'].indexOf('row') === 0), isWide = (target.offsetWidth > dragEl.offsetWidth), isLong = (target.offsetHeight > dragEl.offsetHeight), halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5, @@ -760,7 +763,7 @@ this.save(); } } - + // Nulling rootEl = dragEl = @@ -1185,7 +1188,7 @@ Sortable.create = function (el, options) { return new Sortable(el, options); }; - + // Export Sortable.version = '1.2.2'; From 5b4737f6288460725ee1f992a744e7e6edecb4b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20G=C3=B3is?= Date: Tue, 21 Jul 2015 14:42:33 +0100 Subject: [PATCH 127/594] Update ng-sortable.js --- ng-sortable.js | 59 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 4f0b8c58f..642340e34 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -31,35 +31,6 @@ var removed, nextSibling; - function getSource(el) { - var scope = angular.element(el).scope(); - var ngRepeat = [].filter.call(el.childNodes, function (node) { - return ( - (node.nodeType === 8) && - (node.nodeValue.indexOf('ngRepeat:') !== -1) - ); - })[0]; - - if (!ngRepeat) { - // Without ng-repeat - return null; - } - - // tests: http://jsbin.com/kosubutilo/1/edit?js,output - ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); - - var itemExpr = $parse(ngRepeat[1]); - var itemsExpr = $parse(ngRepeat[2]); - - return { - item: function (el) { - return itemExpr(angular.element(el).scope()); - }, - items: function () { - return itemsExpr(scope); - } - }; - } // Export @@ -67,6 +38,36 @@ restrict: 'AC', scope: { ngSortable: "=?" }, link: function (scope, $el, attrs) { + + function getSource(el) { + var ngRepeat = [].filter.call(el.childNodes, function (node) { + return ( + (node.nodeType === 8) && + (node.nodeValue.indexOf('ngRepeat:') !== -1) + ); + })[0]; + + if (!ngRepeat) { + // Without ng-repeat + return null; + } + + // tests: http://jsbin.com/kosubutilo/1/edit?js,output + ngRepeat = ngRepeat.nodeValue.match(/ngRepeat:\s*(?:\(.*?,\s*)?([^\s)]+)[\s)]+in\s+([^\s|]+)/); + + var itemExpr = $parse(ngRepeat[1]); + var itemsExpr = $parse(ngRepeat[2]); + + return { + item: function (el) { + return itemExpr(angular.element(el).scope()); + }, + items: function () { + return itemsExpr(scope); + } + }; + } + var el = $el[0], options = angular.extend(scope.ngSortable || {}, ngSortableConfig), source = getSource(el), From 8510d422ffb574d97efa9c116df680d4c93ca613 Mon Sep 17 00:00:00 2001 From: Uros Smolnik Date: Mon, 27 Jul 2015 12:21:44 +0200 Subject: [PATCH 128/594] meteor: option to specify collection selector --- meteor/README.md | 14 ++++++++++++++ meteor/reactivize.js | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/meteor/README.md b/meteor/README.md index c3403582e..e5cacc3d6 100644 --- a/meteor/README.md +++ b/meteor/README.md @@ -81,6 +81,20 @@ Template.myTemplate.helpers({ }); ``` +#### meteor specific options + +* `selector` - you can specify collection selector if your list operates only on subset of collection. Example: + +```js +Template.myTemplate.helpers({ + playerOptions: function() { + return { + selector: { city: 'San Francisco' } + } + } +}); +``` + ## Events diff --git a/meteor/reactivize.js b/meteor/reactivize.js index a068a5ebb..42a4bef6a 100644 --- a/meteor/reactivize.js +++ b/meteor/reactivize.js @@ -90,7 +90,7 @@ Template.sortable.created = function () { */ templateInstance.adjustOrders = function adjustOrders(itemId, orderPrevItem, orderNextItem) { var orderField = templateInstance.options.sortField; - var selector = {}, modifier = {$set: {}}; + var selector = templateInstance.options.selector || {}, modifier = {$set: {}}; var ids = []; var startOrder = templateInstance.collection.findOne(itemId)[orderField]; if (orderPrevItem !== null) { From 304c04fd2d985d286e1882404d7ead11659c4f38 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 28 Jul 2015 10:56:52 +0300 Subject: [PATCH 129/594] #489: * Fixed 'clone' --- Sortable.js | 7 ++++--- Sortable.min.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Sortable.js b/Sortable.js index 482b2953c..fbe0464df 100644 --- a/Sortable.js +++ b/Sortable.js @@ -573,7 +573,7 @@ target = _closest(evt.target, options.draggable, el); dragRect = dragEl.getBoundingClientRect(); - + parentEl = target && target.parentNode; // actualization if (revert) { _cloneHide(true); @@ -725,6 +725,7 @@ if (rootEl !== parentEl) { newIndex = _index(dragEl); + if (newIndex != -1) { // drag from one list and drop into another _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); @@ -760,7 +761,7 @@ this.save(); } } - + // Nulling rootEl = dragEl = @@ -1185,7 +1186,7 @@ Sortable.create = function (el, options) { return new Sortable(el, options); }; - + // Export Sortable.version = '1.2.2'; diff --git a/Sortable.min.js b/Sortable.min.js index 29cb54502..bad5acd21 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):!O||this.options.forceFallback?this._onDragStart(F,!0):(e(s,"dragend",this),e(w,"dragstart",this._onDragStart));try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";G=c,H=!0,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),t=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=d.offsetWidth>s.offsetWidth,D=d.offsetHeight>s.offsetHeight,F=(z?(a.clientX-r.left)/t:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(w,g,s,e,d,r);H!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:z?d.previousElementSibling===s&&!C||F&&C:G!==s&&!D||F&&D,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"drop",this),f(M,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),-1!=D&&(j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),-1!=D&&(j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D)))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:O,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(F,!0);try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){if(this._lastX===G.clientX&&this._lastY===G.clientY)return;this._lastX=G.clientX,this._lastY=G.clientY,h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";H=!0,G=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),H=!0,E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,C=/left|right|inline/.test(B.cssFloat+B.display),D=d.offsetWidth>s.offsetWidth,F=d.offsetHeight>s.offsetHeight,G=(C?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,I=d.nextElementSibling,J=k(w,g,s,e,d,r);J!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===J||-1===J?1===J:C?d.previousElementSibling===s&&!D||G&&D:I!==s&&!F||G&&F,q&&!I?g.appendChild(s):d.parentNode.insertBefore(s,q?I:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(M,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),-1!=D&&(j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),-1!=D&&(j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D)))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file From 3be3b60ababe1d08cd9567aef83fb83e5f0010ea Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 28 Jul 2015 11:05:56 +0300 Subject: [PATCH 130/594] #488: reset 'newIndex' --- Sortable.js | 1 + 1 file changed, 1 insertion(+) diff --git a/Sortable.js b/Sortable.js index d66cc1c16..74a018c63 100644 --- a/Sortable.js +++ b/Sortable.js @@ -780,6 +780,7 @@ touchEvt = moved = + newIndex = lastEl = lastCSS = From 15cae094236af1be8328469b96d271e4ca425e8c Mon Sep 17 00:00:00 2001 From: JP Date: Thu, 30 Jul 2015 13:43:09 -0400 Subject: [PATCH 131/594] #356 Fixing issue where dropping an item on the right end of a horizontally layed out drop zone does not add the item --- Sortable.js | 8 ++++---- Sortable.min.js | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sortable.js b/Sortable.js index 74a018c63..d9dae7c70 100644 --- a/Sortable.js +++ b/Sortable.js @@ -591,7 +591,7 @@ if ((el.children.length === 0) || (el.children[0] === ghostEl) || - (el === evt.target) && (target = _ghostInBottom(el, evt)) + (el === evt.target) && (target = _ghostIsLast(el, evt)) ) { if (target) { if (target.animated) { @@ -1086,11 +1086,11 @@ /** @returns {HTMLElement|false} */ - function _ghostInBottom(el, evt) { + function _ghostIsLast(el, evt) { var lastEl = el.lastElementChild, - rect = lastEl.getBoundingClientRect(); + rect = lastEl.getBoundingClientRect(); - return (evt.clientY - (rect.top + rect.height) > 5) && lastEl; // min delta + return ((evt.clientY - (rect.top + rect.height) > 5) || (evt.clientX - (rect.right + rect.width) > 5)) && lastEl; // min delta } diff --git a/Sortable.min.js b/Sortable.min.js index bad5acd21..d44551c10 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:O,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(F,!0);try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){if(this._lastX===G.clientX&&this._lastY===G.clientY)return;this._lastX=G.clientX,this._lastY=G.clientY,h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";H=!0,G=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),H=!0,E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,C=/left|right|inline/.test(B.cssFloat+B.display),D=d.offsetWidth>s.offsetWidth,F=d.offsetHeight>s.offsetHeight,G=(C?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,I=d.nextElementSibling,J=k(w,g,s,e,d,r);J!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===J||-1===J?1===J:C?d.previousElementSibling===s&&!D||G&&D:I!==s&&!F||G&&F,q&&!I?g.appendChild(s):d.parentNode.insertBefore(s,q?I:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(M,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),-1!=D&&(j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),-1!=D&&(j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D)))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),S.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){Q=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=!1,R=Math.abs,S=([].slice,[]),T=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(G=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,F=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=S.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)S[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(T(a,i,this.el),Q)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);K!==!1&&(Q=!0,setTimeout(m,30),b(o),q=1===K||-1===K?1===K:D?d.previousElementSibling===s&&!E||H&&E:J!==s&&!G||H&&G,q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),S.splice(S.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file From 09a75c35d99d98f4b8d2208e5ce57d684c6d9cae Mon Sep 17 00:00:00 2001 From: RubaXa Date: Thu, 30 Jul 2015 21:14:34 +0300 Subject: [PATCH 132/594] #488: fixed xxxxx undefined --- Sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sortable.js b/Sortable.js index d9dae7c70..178e0f72c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -574,7 +574,7 @@ target = _closest(evt.target, options.draggable, el); dragRect = dragEl.getBoundingClientRect(); - parentEl = target && target.parentNode; // actualization + parentEl = target && target.parentNode || parentEl; // actualization if (revert) { _cloneHide(true); From 04553782b58efb20a600ad2d825d42823f6f083a Mon Sep 17 00:00:00 2001 From: Sebastian Rosengren Date: Fri, 31 Jul 2015 20:11:16 +0200 Subject: [PATCH 133/594] Added UMD definition to knockout-sortable Fixes #488 --- Sortable.min.js | 2 +- knockout-sortable.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Sortable.min.js b/Sortable.min.js index d44551c10..1836f9b05 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),S.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){Q=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=!1,R=Math.abs,S=([].slice,[]),T=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(G=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,F=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=S.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)S[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(T(a,i,this.el),Q)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);K!==!1&&(Q=!0,setTimeout(m,30),b(o),q=1===K||-1===K?1===K:D?d.previousElementSibling===s&&!E||H&&E:J!==s&&!G||H&&G,q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),S.splice(S.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),S.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){Q=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=!1,R=Math.abs,S=([].slice,[]),T=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(G=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,F=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=S.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)S[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(T(a,i,this.el),Q)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode||t,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);K!==!1&&(Q=!0,setTimeout(m,30),b(o),q=1===K||-1===K?1===K:D?d.previousElementSibling===s&&!E||H&&E:J!==s&&!G||H&&G,q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),S.splice(S.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file diff --git a/knockout-sortable.js b/knockout-sortable.js index 6a7f70137..8955343fe 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -1,4 +1,17 @@ -(function () { +(function (factory) { + "use strict"; + if (typeof define === "function" && define.amd) { + // AMD anonymous module + define(["knockout"], factory); + } else if (typeof require === "function" && typeof exports === "object" && typeof module === "object") { + // CommonJS module + var ko = require("knockout"); + factory(ko); + } else { + // No module loader (plain + - + diff --git a/Sortable.js b/Sortable.js index 17a3cc495..6f5c9c9af 100644 --- a/Sortable.js +++ b/Sortable.js @@ -661,7 +661,8 @@ else if (floating) { var elTop = dragEl.offsetTop, tgTop = target.offsetTop; - if (elTop===tgTop) { + + if (elTop === tgTop) { after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide; } else { after = tgTop > elTop; @@ -1232,6 +1233,6 @@ // Export - Sortable.version = '1.2.2'; + Sortable.version = '1.3.0-rc1'; return Sortable; }); diff --git a/Sortable.min.js b/Sortable.min.js index 0550b44f9..5a90378de 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),S.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){Q=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=!1,R=Math.abs,S=([].slice,[]),T=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(G=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,F=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=S.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)S[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(T(a,i,this.el),Q)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),t=d&&d.parentNode||t,f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);K!==!1&&(Q=!0,setTimeout(m,30),b(o),q=1===K||-1===K?1===K:D?d.previousElementSibling===s&&!E||H&&E:J!==s&&!G||H&&G,s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),S.splice(S.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file +/*! Sortable 1.3.0-rc1 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);V(b);for(var f in this)"_"===f.charAt(0)&&(this[f]=this[f].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),T.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){R=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=function(a){return a=N.createElement("x"),a.style.cssText="pointer-events:auto","auto"===a.style.pointerEvents}(),R=!1,S=Math.abs,T=([].slice,[]),U=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30),V=function(a){var b=a.group;b&&"object"==typeof b||(b=a.group={name:b}),["pull","put"].forEach(function(a){a in b||(b[a]=!0)}),a.groups=" "+b.name+(b.put.join?" "+b.put.join(" "):"")+" "};return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,h=f.el,j=f.options,k=h.ownerDocument;c&&!s&&c.parentNode===h&&(G=a,w=h,s=c,t=s.parentNode,x=s.nextSibling,F=j.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,g(s,f.options.chosenClass,!0),f._triggerDragStart(b)},j.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),e(k,"mouseup",f._onDrop),e(k,"touchend",f._onDrop),e(k,"touchcancel",f._onDrop),j.delay?(e(k,"mouseup",f._disableDelayedDrag),e(k,"touchend",f._disableDelayedDrag),e(k,"touchcancel",f._disableDelayedDrag),e(k,"mousemove",f._disableDelayedDrag),e(k,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,j.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,Q||h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=T.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)T[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);Q||h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),h(u,"pointerEvents","none"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(U(a,i,this.el),R)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||(g.appendChild(s),t=g),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);if(K!==!1){if(R=!0,setTimeout(m,30),b(o),1===K||-1===K)q=1===K;else if(D){var M=s.offsetTop,N=d.offsetTop;q=M===N?d.previousElementSibling===s&&!E||H&&E:N>M}else q=J!==s&&!G||H&&G;s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),t=s.parentNode,this._animate(e,s),this._animate(r,d)}}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),g(s,this.options.chosenClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void("group"===a&&V(c)))},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),T.splice(T.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.3.0-rc1",a}); \ No newline at end of file diff --git a/component.json b/component.json index d28254a59..09e7d6f16 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.2.2", + "version": "1.3.0-rc1", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/package.json b/package.json index a03ce9be5..d2df097eb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.2.2", + "version": "1.3.0-rc1", "devDependencies": { "grunt": "*", "grunt-version": "*", From 4a67b43188cbf14133aea2191cfd1f7e89c7fe13 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 15 Sep 2015 22:07:42 +0300 Subject: [PATCH 153/594] #447: emit 'onEnd' Only if we really move the item --- Sortable.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Sortable.js b/Sortable.js index 6f5c9c9af..3faf0a06f 100644 --- a/Sortable.js +++ b/Sortable.js @@ -763,7 +763,7 @@ if (rootEl !== parentEl) { newIndex = _index(dragEl); - if (newIndex != -1) { + if (newIndex >= 0) { // drag from one list and drop into another _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); @@ -782,7 +782,8 @@ if (dragEl.nextSibling !== nextEl) { // Get the index of the dragged element within its parent newIndex = _index(dragEl); - if (newIndex != -1) { + + if (newIndex >= 0) { // drag & drop within the same list _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); @@ -790,8 +791,8 @@ } } - if (Sortable.active) { - // Drag end event + if (newIndex >= 0) { + // Only if we really move the item. _dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); // Save sorting @@ -1154,20 +1155,22 @@ /** * Returns the index of an element within its parent - * @param el - * @returns {number} - * @private + * @param {HTMLElement} el + * @return {number} */ - function _index(/**HTMLElement*/el) { + function _index(el) { + var index = 0; + if (!el || !el.parentNode) { return -1; } - var index = 0; + while (el && (el = el.previousElementSibling)) { if (el.nodeName.toUpperCase() !== 'TEMPLATE') { index++; } } + return index; } From 7fd16cb0a573159bc36b2590567f186df295704a Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 15 Sep 2015 22:11:45 +0300 Subject: [PATCH 154/594] #447: fixed newIndex if eq null or -1 --- Sortable.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sortable.js b/Sortable.js index 3faf0a06f..caa55e105 100644 --- a/Sortable.js +++ b/Sortable.js @@ -791,8 +791,11 @@ } } - if (newIndex >= 0) { - // Only if we really move the item. + if (Sortable.active) { + if (newIndex == null || newIndex === -1) { + newIndex = oldIndex; + } + _dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex); // Save sorting From c4c060b93eefe653721f37d81e1887a737840b0f Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 15 Sep 2015 22:31:51 +0300 Subject: [PATCH 155/594] v1.3.0-rc2 --- Sortable.js | 4 ++-- Sortable.min.js | 4 ++-- component.json | 2 +- package.json | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sortable.js b/Sortable.js index caa55e105..e102d2fc5 100644 --- a/Sortable.js +++ b/Sortable.js @@ -792,7 +792,7 @@ } if (Sortable.active) { - if (newIndex == null || newIndex === -1) { + if (newIndex === null || newIndex === -1) { newIndex = oldIndex; } @@ -1239,6 +1239,6 @@ // Export - Sortable.version = '1.3.0-rc1'; + Sortable.version = '1.3.0-rc2'; return Sortable; }); diff --git a/Sortable.min.js b/Sortable.min.js index 5a90378de..45b1cb8eb 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.3.0-rc1 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);V(b);for(var f in this)"_"===f.charAt(0)&&(this[f]=this[f].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),T.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){R=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=function(a){return a=N.createElement("x"),a.style.cssText="pointer-events:auto","auto"===a.style.pointerEvents}(),R=!1,S=Math.abs,T=([].slice,[]),U=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30),V=function(a){var b=a.group;b&&"object"==typeof b||(b=a.group={name:b}),["pull","put"].forEach(function(a){a in b||(b[a]=!0)}),a.groups=" "+b.name+(b.put.join?" "+b.put.join(" "):"")+" "};return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,h=f.el,j=f.options,k=h.ownerDocument;c&&!s&&c.parentNode===h&&(G=a,w=h,s=c,t=s.parentNode,x=s.nextSibling,F=j.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,g(s,f.options.chosenClass,!0),f._triggerDragStart(b)},j.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),e(k,"mouseup",f._onDrop),e(k,"touchend",f._onDrop),e(k,"touchcancel",f._onDrop),j.delay?(e(k,"mouseup",f._disableDelayedDrag),e(k,"touchend",f._disableDelayedDrag),e(k,"touchcancel",f._disableDelayedDrag),e(k,"mousemove",f._disableDelayedDrag),e(k,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,j.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,Q||h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=T.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)T[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);Q||h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),h(u,"pointerEvents","none"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(U(a,i,this.el),R)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||(g.appendChild(s),t=g),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);if(K!==!1){if(R=!0,setTimeout(m,30),b(o),1===K||-1===K)q=1===K;else if(D){var M=s.offsetTop,N=d.offsetTop;q=M===N?d.previousElementSibling===s&&!E||H&&E:N>M}else q=J!==s&&!G||H&&G;s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),t=s.parentNode,this._animate(e,s),this._animate(r,d)}}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),g(s,this.options.chosenClass,!1),w!==t?(E=p(s),-1!=E&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),-1!=E&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&(j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void("group"===a&&V(c)))},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),T.splice(T.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.3.0-rc1",a}); \ No newline at end of file +/*! Sortable 1.3.0-rc2 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);V(b);for(var f in this)"_"===f.charAt(0)&&(this[f]=this[f].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),T.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){R=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){var b=0;if(!a||!a.parentNode)return-1;for(;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=function(a){return a=N.createElement("x"),a.style.cssText="pointer-events:auto","auto"===a.style.pointerEvents}(),R=!1,S=Math.abs,T=([].slice,[]),U=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30),V=function(a){var b=a.group;b&&"object"==typeof b||(b=a.group={name:b}),["pull","put"].forEach(function(a){a in b||(b[a]=!0)}),a.groups=" "+b.name+(b.put.join?" "+b.put.join(" "):"")+" "};return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,h=f.el,j=f.options,k=h.ownerDocument;c&&!s&&c.parentNode===h&&(G=a,w=h,s=c,t=s.parentNode,x=s.nextSibling,F=j.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,g(s,f.options.chosenClass,!0),f._triggerDragStart(b)},j.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),e(k,"mouseup",f._onDrop),e(k,"touchend",f._onDrop),e(k,"touchcancel",f._onDrop),j.delay?(e(k,"mouseup",f._disableDelayedDrag),e(k,"touchend",f._disableDelayedDrag),e(k,"touchcancel",f._disableDelayedDrag),e(k,"mousemove",f._disableDelayedDrag),e(k,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,j.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,Q||h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=T.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)T[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);Q||h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),h(u,"pointerEvents","none"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(U(a,i,this.el),R)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||(g.appendChild(s),t=g),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);if(K!==!1){if(R=!0,setTimeout(m,30),b(o),1===K||-1===K)q=1===K;else if(D){var M=s.offsetTop,N=d.offsetTop;q=M===N?d.previousElementSibling===s&&!E||H&&E:N>M}else q=J!==s&&!G||H&&G;s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),t=s.parentNode,this._animate(e,s),this._animate(r,d)}}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),g(s,this.options.chosenClass,!1),w!==t?(E=p(s),E>=0&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),E>=0&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&((null===E||-1===E)&&(E=D),j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void("group"===a&&V(c)))},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),T.splice(T.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.3.0-rc2",a}); \ No newline at end of file diff --git a/component.json b/component.json index 09e7d6f16..75c1944fc 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.3.0-rc1", + "version": "1.3.0-rc2", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/package.json b/package.json index d2df097eb..8bbc4aaf1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortablejs", "exportName": "Sortable", - "version": "1.3.0-rc1", + "version": "1.3.0-rc2", "devDependencies": { "grunt": "*", "grunt-version": "*", From 0043e4796ec57f4892e0f5d9eebe0d8e88a87454 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Wed, 16 Sep 2015 10:18:34 +0300 Subject: [PATCH 156/594] #558: + Error initializing --- Sortable.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sortable.js b/Sortable.js index 6f5c9c9af..438dcf03a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -172,6 +172,10 @@ * @param {Object} [options] */ function Sortable(el, options) { + if (!(el && el.nodeType && el.nodeType === 1)) { + throw 'Sortable: `el` must be HTMLElement, and not ' + {}.toString.call(el); + } + this.el = el; // root element this.options = options = _extend({}, options); From 70d04f9346080ace4f9417a1175b5955e30d31f3 Mon Sep 17 00:00:00 2001 From: fendy3002 Date: Wed, 16 Sep 2015 14:24:13 +0700 Subject: [PATCH 157/594] Update knockout-sortable.js Use closure local variable instead of attaching the element to viewmodel. This is to prevent error caused by bound dom element as in issue 559. https://github.com/RubaXa/Sortable/issues/559 --- knockout-sortable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index 224573d36..54a339306 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -36,11 +36,11 @@ }.bind(undefined, e, viewModel, allBindings, options[e]); }); - viewModel._sortable = Sortable.create(element, options); + sortableElement = Sortable.create(element, options); //Destroy the sortable if knockout disposes the element it's connected to ko.utils.domNodeDisposal.addDisposeCallback(element, function () { - viewModel._sortable.destroy(); + sortableElement.destroy(); }); return ko.bindingHandlers.template.init(element, valueAccessor); }, From 6c86b334d23edebddd595c8e0628d2b33dcbc1a0 Mon Sep 17 00:00:00 2001 From: fendy3002 Date: Wed, 16 Sep 2015 15:14:56 +0700 Subject: [PATCH 158/594] Fix the missing 'var' syntax The var syntax is missing. Added to explicitly define local variable. --- knockout-sortable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knockout-sortable.js b/knockout-sortable.js index 54a339306..fcf7d667a 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -36,7 +36,7 @@ }.bind(undefined, e, viewModel, allBindings, options[e]); }); - sortableElement = Sortable.create(element, options); + var sortableElement = Sortable.create(element, options); //Destroy the sortable if knockout disposes the element it's connected to ko.utils.domNodeDisposal.addDisposeCallback(element, function () { From 555adc36fd5601ea1702339cd867cc0294326985 Mon Sep 17 00:00:00 2001 From: Joshua Ferdaszewski Date: Fri, 18 Sep 2015 21:29:23 -0700 Subject: [PATCH 159/594] Added Browserify support for ng-sortable --- ng-sortable.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ng-sortable.js b/ng-sortable.js index 2e2db4dfc..a33b3c9c1 100644 --- a/ng-sortable.js +++ b/ng-sortable.js @@ -5,12 +5,17 @@ (function (factory) { 'use strict'; - if (window.angular && window.Sortable) { - factory(angular, Sortable); - } - else if (typeof define === 'function' && define.amd) { + if (typeof define === 'function' && define.amd) { define(['angular', './Sortable'], factory); } + else if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') { + require('angular'); + factory(angular, require('./Sortable')); + module.exports = 'ng-sortable'; + } + else if (window.angular && window.Sortable) { + factory(angular, Sortable); + } })(function (angular, Sortable) { 'use strict'; From f7e2c04336f612be00e48b325deb8afe72855f3a Mon Sep 17 00:00:00 2001 From: Marko Jovanovic Date: Mon, 21 Sep 2015 11:42:47 +0200 Subject: [PATCH 160/594] Bugfix in jquery.binding.js --- jquery.binding.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jquery.binding.js b/jquery.binding.js index 64b1cf148..d8cf610e0 100644 --- a/jquery.binding.js +++ b/jquery.binding.js @@ -28,7 +28,7 @@ */ $.fn.sortable = function (options) { var retVal; - + var callArgs = arguments; this.each(function () { var $el = $(this), sortable = $el.data('sortable'); @@ -47,14 +47,14 @@ $el.removeData('sortable'); } else if (typeof sortable[options] === 'function') { - retVal = sortable[options].apply(sortable, [].slice.call(arguments, 1)); + retVal = sortable[options].apply(sortable, [].slice.call(callArgs, 1)); } else if (options in sortable.options) { - retVal = sortable.option.apply(sortable, arguments); + retVal = sortable.option.apply(sortable, callArgs); } } }); return (retVal === void 0) ? this : retVal; }; -}); +}); \ No newline at end of file From 16bf388a8128dcb5de5d764df41c677371c70505 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 22 Sep 2015 08:45:21 +0300 Subject: [PATCH 161/594] * callArgs -> args --- jquery.binding.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/jquery.binding.js b/jquery.binding.js index d8cf610e0..9e9f4b93c 100644 --- a/jquery.binding.js +++ b/jquery.binding.js @@ -27,8 +27,9 @@ * @returns {jQuery|*} */ $.fn.sortable = function (options) { - var retVal; - var callArgs = arguments; + var retVal, + args = arguments; + this.each(function () { var $el = $(this), sortable = $el.data('sortable'); @@ -47,14 +48,14 @@ $el.removeData('sortable'); } else if (typeof sortable[options] === 'function') { - retVal = sortable[options].apply(sortable, [].slice.call(callArgs, 1)); + retVal = sortable[options].apply(sortable, [].slice.call(args, 1)); } else if (options in sortable.options) { - retVal = sortable.option.apply(sortable, callArgs); + retVal = sortable.option.apply(sortable, args); } } }); return (retVal === void 0) ? this : retVal; }; -}); \ No newline at end of file +}); From 385f03e5d0d82ea8f839929c1d447102f795b363 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Tue, 22 Sep 2015 22:27:21 +0300 Subject: [PATCH 162/594] v1.3.0: Improved stability and performance on touch devices; Added a new option `chosenClass` And so on: #558, #547, #542, #537, #532, #516, #500, #489, #489, #447, #475, #459, ##422, #411, #356 --- Sortable.js | 2 +- Sortable.min.js | 4 +- component.json | 2 +- log.txt | 1401 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 5 files changed, 1406 insertions(+), 5 deletions(-) create mode 100644 log.txt diff --git a/Sortable.js b/Sortable.js index e98909b6c..77ffd6fc1 100644 --- a/Sortable.js +++ b/Sortable.js @@ -1243,6 +1243,6 @@ // Export - Sortable.version = '1.3.0-rc2'; + Sortable.version = '1.3.0'; return Sortable; }); diff --git a/Sortable.min.js b/Sortable.min.js index 45b1cb8eb..bef7fa3a1 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ -/*! Sortable 1.3.0-rc2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);V(b);for(var f in this)"_"===f.charAt(0)&&(this[f]=this[f].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),T.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){R=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){var b=0;if(!a||!a.parentNode)return-1;for(;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=function(a){return a=N.createElement("x"),a.style.cssText="pointer-events:auto","auto"===a.style.pointerEvents}(),R=!1,S=Math.abs,T=([].slice,[]),U=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30),V=function(a){var b=a.group;b&&"object"==typeof b||(b=a.group={name:b}),["pull","put"].forEach(function(a){a in b||(b[a]=!0)}),a.groups=" "+b.name+(b.put.join?" "+b.put.join(" "):"")+" "};return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,h=f.el,j=f.options,k=h.ownerDocument;c&&!s&&c.parentNode===h&&(G=a,w=h,s=c,t=s.parentNode,x=s.nextSibling,F=j.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,g(s,f.options.chosenClass,!0),f._triggerDragStart(b)},j.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),e(k,"mouseup",f._onDrop),e(k,"touchend",f._onDrop),e(k,"touchcancel",f._onDrop),j.delay?(e(k,"mouseup",f._disableDelayedDrag),e(k,"touchend",f._disableDelayedDrag),e(k,"touchcancel",f._disableDelayedDrag),e(k,"mousemove",f._disableDelayedDrag),e(k,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,j.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,Q||h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=T.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)T[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);Q||h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),h(u,"pointerEvents","none"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(U(a,i,this.el),R)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||(g.appendChild(s),t=g),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);if(K!==!1){if(R=!0,setTimeout(m,30),b(o),1===K||-1===K)q=1===K;else if(D){var M=s.offsetTop,N=d.offsetTop;q=M===N?d.previousElementSibling===s&&!E||H&&E:N>M}else q=J!==s&&!G||H&&G;s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),t=s.parentNode,this._animate(e,s),this._animate(r,d)}}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),g(s,this.options.chosenClass,!1),w!==t?(E=p(s),E>=0&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),E>=0&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&((null===E||-1===E)&&(E=D),j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void("group"===a&&V(c)))},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),T.splice(T.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.3.0-rc2",a}); \ No newline at end of file +/*! Sortable 1.3.0 - MIT | git://github.com/rubaxa/Sortable.git */ +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){if(!a||!a.nodeType||1!==a.nodeType)throw"Sortable: `el` must be HTMLElement, and not "+{}.toString.call(a);this.el=a,this.options=b=r({},b),a[L]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);V(b);for(var f in this)"_"===f.charAt(0)&&(this[f]=this[f].bind(this));this.nativeDraggable=b.forceFallback?!1:P,e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),this.nativeDraggable&&(e(a,"dragover",this),e(a,"dragenter",this)),T.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||N,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer&&(a.dataTransfer.dropEffect="move"),a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(K," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(K," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return N.defaultView&&N.defaultView.getComputedStyle?c=N.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=N.createEvent("Event"),i=(a||b[L]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[L],j=i.options.onMove;return g=N.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){R=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return(b.clientY-(d.top+d.height)>5||b.clientX-(d.right+d.width)>5)&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){var b=0;if(!a||!a.parentNode)return-1;for(;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J={},K=/\s+/g,L="Sortable"+(new Date).getTime(),M=window,N=M.document,O=M.parseInt,P=!!("draggable"in N.createElement("div")),Q=function(a){return a=N.createElement("x"),a.style.cssText="pointer-events:auto","auto"===a.style.pointerEvents}(),R=!1,S=Math.abs,T=([].slice,[]),U=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=M)),(J.vx!==f||J.vy!==g||J.el!==d)&&(J.el=d,J.vx=f,J.vy=g,clearInterval(J.pid),d&&(J.pid=setInterval(function(){d===M?M.scrollTo(M.pageXOffset+f*i,M.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30),V=function(a){var b=a.group;b&&"object"==typeof b||(b=a.group={name:b}),["pull","put"].forEach(function(a){a in b||(b[a]=!0)}),a.groups=" "+b.name+(b.put.join?" "+b.put.join(" "):"")+" "};return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(D=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,D),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,D),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,h=f.el,j=f.options,k=h.ownerDocument;c&&!s&&c.parentNode===h&&(G=a,w=h,s=c,t=s.parentNode,x=s.nextSibling,F=j.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,g(s,f.options.chosenClass,!0),f._triggerDragStart(b)},j.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),e(k,"mouseup",f._onDrop),e(k,"touchend",f._onDrop),e(k,"touchcancel",f._onDrop),j.delay?(e(k,"mouseup",f._disableDelayedDrag),e(k,"touchend",f._disableDelayedDrag),e(k,"touchcancel",f._disableDelayedDrag),e(k,"mousemove",f._disableDelayedDrag),e(k,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,j.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(G={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(G,"touch")):this.nativeDraggable?(e(s,"dragend",this),e(w,"dragstart",this._onDragStart)):this._onDragStart(G,!0);try{N.selection?N.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,D))},_emulateDragOver:function(){if(H){if(this._lastX===H.clientX&&this._lastY===H.clientY)return;this._lastX=H.clientX,this._lastY=H.clientY,Q||h(u,"display","none");var a=N.elementFromPoint(H.clientX,H.clientY),b=a,c=" "+this.options.group.name,d=T.length;if(b)do{if(b[L]&&b[L].options.groups.indexOf(c)>-1){for(;d--;)T[d]({clientX:H.clientX,clientY:H.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);Q||h(u,"display","")}},_onTouchMove:function(b){if(G){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-G.clientX,e=c.clientY-G.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";I=!0,H=c,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-O(c.marginTop,10)),h(u,"left",b.left-O(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),h(u,"pointerEvents","none"),this.options.fallbackOnBody&&N.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==F.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(N,"touchmove",this._onTouchMove),e(N,"touchend",this._onDrop),e(N,"touchcancel",this._onDrop)):(e(N,"mousemove",this._onTouchMove),e(N,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,50)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(N,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=F===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),I=!0,F&&!i.disabled&&(o?p||(f=!w.contains(s)):F.pull&&l&&(F.name===j.name||l.indexOf&&~l.indexOf(F.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(U(a,i,this.el),R)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(s.contains(g)||(g.appendChild(s),t=g),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[L]){A!==d&&(A=d,B=h(d),C=h(d.parentNode));var q,r=d.getBoundingClientRect(),y=r.right-r.left,z=r.bottom-r.top,D=/left|right|inline/.test(B.cssFloat+B.display)||"flex"==C.display&&0===C["flex-direction"].indexOf("row"),E=d.offsetWidth>s.offsetWidth,G=d.offsetHeight>s.offsetHeight,H=(D?(a.clientX-r.left)/y:(a.clientY-r.top)/z)>.5,J=d.nextElementSibling,K=k(w,g,s,e,d,r);if(K!==!1){if(R=!0,setTimeout(m,30),b(o),1===K||-1===K)q=1===K;else if(D){var M=s.offsetTop,N=d.offsetTop;q=M===N?d.previousElementSibling===s&&!E||H&&E:N>M}else q=J!==s&&!G||H&&G;s.contains(g)||(q&&!J?g.appendChild(s):d.parentNode.insertBefore(s,q?J:d)),t=s.parentNode,this._animate(e,s),this._animate(r,d)}}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(N,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(J.pid),clearTimeout(this._dragStartTimer),f(N,"mousemove",this._onTouchMove),this.nativeDraggable&&(f(N,"drop",this),f(c,"dragstart",this._onDragStart)),this._offUpEvents(),b&&(I&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(this.nativeDraggable&&f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),g(s,this.options.chosenClass,!1),w!==t?(E=p(s),E>=0&&(j(null,t,"sort",s,w,D,E),j(this,w,"sort",s,w,D,E),j(null,t,"add",s,w,D,E),j(this,w,"remove",s,w,D,E))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(E=p(s),E>=0&&(j(this,w,"update",s,w,D,E),j(this,w,"sort",s,w,D,E)))),a.active&&((null===E||-1===E)&&(E=D),j(this,w,"end",s,w,D,E),this.save())),w=s=t=u=x=v=y=z=G=H=I=E=A=B=F=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void("group"===a&&V(c)))},destroy:function(){var a=this.el;a[L]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),this.nativeDraggable&&(f(a,"dragover",this),f(a,"dragenter",this)),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),T.splice(T.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.3.0",a}); \ No newline at end of file diff --git a/component.json b/component.json index 75c1944fc..20bfb914f 100644 --- a/component.json +++ b/component.json @@ -1,7 +1,7 @@ { "name": "Sortable", "main": "Sortable.js", - "version": "1.3.0-rc2", + "version": "1.3.0", "homepage": "http://rubaxa.github.io/Sortable/", "repo": "RubaXa/Sortable", "authors": [ diff --git a/log.txt b/log.txt new file mode 100644 index 000000000..3acc32890 --- /dev/null +++ b/log.txt @@ -0,0 +1,1401 @@ +commit 72be2e91aec387a23cf84fb9ec831a906df4ae7c +Author: RubaXa +Date: Thu May 7 23:28:28 2015 +0300 + + #376: * fixed 'evt.target' + + Sortable.js | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 08c31fc0bba9509280f2f3847ab47bee2ea9bab9 +Author: RubaXa +Date: Thu May 7 23:14:18 2015 +0300 + + #379: + 'delay' description + + Sortable.js | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit 14864bc067dc937b88031dac77344ad9c44fa7aa +Author: RubaXa +Date: Thu Apr 16 18:15:27 2015 +0300 + + #335: call save only if 'active' + + Sortable.js | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +commit a89b3b3edc6422f1b3540a4811434d4900d91719 +Author: RubaXa +Date: Wed Apr 15 14:27:28 2015 +0300 + + #347: + moveVector + + Sortable.js | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +commit 34328a81b527218358b4bb17ca8613d2891a2c82 +Author: RubaXa +Date: Wed Apr 15 13:19:18 2015 +0300 + + #273: + onMove event + + Sortable.js | 113 ++++++++++++++++++++++++++++++++++++++---------------------- + 1 file changed, 72 insertions(+), 41 deletions(-) + +commit b30ece99c5c87752db61b452e04467e0a3cf5f79 +Author: RubaXa +Date: Tue Apr 14 21:37:41 2015 +0300 + + v1.2.0: Events, Nested, Drop text, IE11, iframe and etc + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit c1f6cf50c4fc6fa16d12c0c804fe8464bbda0c0f +Author: RubaXa +Date: Sat Apr 11 11:13:32 2015 +0300 + + #308: * allow drop text + + Sortable.js | 10 ++++------ + 1 file changed, 4 insertions(+), 6 deletions(-) + +commit 5c4e3dce2a8b0b28c0e7d7235377d13cc71a9bbd +Author: RubaXa +Date: Thu Apr 9 11:42:14 2015 +0300 + + #318, #328: + Improved work with events transmitted through the options + + Sortable.js | 63 ++++++++++++++++++++++++++++--------------------------------- + 1 file changed, 29 insertions(+), 34 deletions(-) + +commit fcdb0c915b0e4c7fb429f765cdb5a10ab3226e27 +Merge: 40af728 c6a536a +Author: RubaXa +Date: Thu Apr 9 10:57:16 2015 +0300 + + + master v1.1.1 + +commit 40af728d53c8ed6ca41dead85ceb08d71b8a77fa +Author: RubaXa +Date: Mon Apr 6 00:00:55 2015 +0300 + + #325: * changed the order of the methods (code style) + + Sortable.js | 156 ++++++++++++++++++++++++++++++------------------------------ + 1 file changed, 78 insertions(+), 78 deletions(-) + +commit 723bc1e605de32555fa9e5fd5d531832cfc9848e +Author: RubaXa +Date: Sun Apr 5 23:57:39 2015 +0300 + + #325: PR refactoring: - _enableDragStart & revert lost fixes + + Sortable.js | 103 +++++++++++++++++++++++++++++++----------------------------- + 1 file changed, 54 insertions(+), 49 deletions(-) + +commit 78c53ba5e19c6616893183e655cf9d28cb1ec77d +Author: jboulouloubi +Date: Wed Apr 1 18:35:36 2015 -0400 + + Add delay between touchstart and dragstart + + Sortable.js | 135 ++++++++++++++++++++++++++++++++++++++---------------------- + 1 file changed, 86 insertions(+), 49 deletions(-) + +commit 5fd36b19b18ef81148ae38078a159fbd281120aa +Author: RubaXa +Date: Wed Mar 11 18:36:32 2015 +0300 + + * RSPACE + + Sortable.js | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +commit 6dc1159d3166272f579da1618b80c9bc3bcd3437 +Merge: 8b818ed f802c84 +Author: Lebedev Konstantin +Date: Wed Mar 11 18:35:47 2015 +0300 + + Merge pull request #296 from bmustiata/dev + + Don't join class names when removing classes after additions. + +commit 8b818ed280bfe54e4e51d5ff375f751eb590239f +Author: RubaXa +Date: Wed Mar 11 18:33:36 2015 +0300 + + #288: + use 'ownerDocument' for correct working with/into iframe + + Sortable.js | 17 ++++++++++------- + 1 file changed, 10 insertions(+), 7 deletions(-) + +commit 7309734dbf52e0e9d9682ad563660a5d0acb51de +Author: RubaXa +Date: Wed Mar 11 18:06:34 2015 +0300 + + #290: + clone simple 'option' and 'extend' method + + Sortable.js | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +commit 1f58b1b10b7eca676654e0989c7831ae8e9f9fdd +Author: Noah Chase +Date: Tue Mar 10 12:38:43 2015 -0400 + + use `page{d}Offset` instead of `scroll{d}` + + All modern browsers seem to support `window.pageXOffset` and `window.pageYOffset`, which are aliases for `window.scrollX` and `window.scrollY`. + + IE doesn't seem to have `window.scrollX` and `window.scrollY`. + + fixes #302 + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit f802c84d05f49adcbf8627dedb689225a27afba9 +Author: Bogdan Mustiata +Date: Thu Mar 5 12:13:56 2015 +0100 + + Use precompiled RegExp. + + Sortable.js | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +commit c7257ae198ba136ebec55b9cfae760f9e89c4e9a +Author: Bogdan Mustiata +Date: Tue Mar 3 14:53:15 2015 +0100 + + Don't join class names when removing classes after additions. + + Sortable.js | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +commit c6a536aa3f999b2c556f301527fa1e7186a67d65 +Author: RubaXa +Date: Fri Feb 20 08:49:33 2015 +0300 + + v1.1.1: #227, #285 + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 0b909aa59d24e90220f549e4d4106b6e0b760f05 +Author: RubaXa +Date: Thu Feb 19 21:20:16 2015 +0300 + + #285: * fixed dragover handler + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 87e336a175ec4d0e593df685fe1f9ced612395fd +Author: RubaXa +Date: Mon Feb 16 08:57:02 2015 +0300 + + #277: * fixed handle & filter + + Sortable.js | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +commit 1482449b1816b7bdce9f96be51c47000b9a73453 +Author: RubaXa +Date: Thu Feb 19 21:20:16 2015 +0300 + + #285: * fixed dragover handler + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 8b3e8f949710d3360c92b8fdc2d9f3fcd58d7e30 +Author: RubaXa +Date: Mon Feb 16 18:06:58 2015 +0300 + + #279: * dataAttr -> dataIdAttr + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 7dc8be57559534d5a93cf5aff1306a0f83daf56d +Author: RubaXa +Date: Mon Feb 16 17:55:24 2015 +0300 + + #279: + dataIdAttr + + Sortable.js | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +commit 1c8839f08fdbe5399a216cfa4872df97eda794a6 +Author: RubaXa +Date: Mon Feb 16 08:57:02 2015 +0300 + + #277: * fixed handle & filter + + Sortable.js | 14 ++++++++++---- + 1 file changed, 10 insertions(+), 4 deletions(-) + +commit 070a5715084c860dc8ddd5bedd17be09ccf7a102 +Author: RubaXa +Date: Fri Feb 13 22:01:00 2015 +0300 + + v1.1.0: Support IE9, CDN, enhancement auto-scrolling, React-mixin and more. + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 563311f25eddbeb7b0276593f5a7d787504c7026 +Author: RubaXa +Date: Wed Feb 11 23:16:46 2015 +0300 + + #271: + remove 'transform' (#issuecomment-73954644) + + Sortable.js | 1 + + 1 file changed, 1 insertion(+) + +commit 4c0f1afd324e8b598782a8fa62bfa5b8a21401ef +Author: RubaXa +Date: Wed Feb 11 19:12:00 2015 +0300 + + #256: - _onDrag + + Sortable.js | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +commit e97970b303af821d517ecc42a5f97c8a5fd77e28 +Author: RubaXa +Date: Wed Feb 11 18:12:28 2015 +0300 + + #256: uber-autoscroll, support drag between lists + + Sortable.js | 172 +++++++++++++++++++++++++++++++----------------------------- + 1 file changed, 90 insertions(+), 82 deletions(-) + +commit f0d7ff7339f48f417c0ad549123809fe9c7fa6e0 +Merge: ab52c13 750bef7 +Author: RubaXa +Date: Wed Feb 11 16:56:07 2015 +0300 + + Merge branch 'dev' into scroll + +commit 750bef7a8f95349b158d7fafcda05ee25de77d6b +Merge: 64ec81a 15d6f07 +Author: RubaXa +Date: Wed Feb 11 16:55:55 2015 +0300 + + Merge branch 'drop-text' into dev + +commit ab52c138509968f1c85dd2c3d5205a85e54ef797 +Author: RubaXa +Date: Tue Feb 10 23:20:37 2015 +0300 + + #271: * logic of auto-scrolling + + Sortable.js | 20 ++++++++++++++------ + 1 file changed, 14 insertions(+), 6 deletions(-) + +commit d2fa23b897900043cfdc156e09dfbabd62a63f8f +Merge: c71b88f 21bf07a +Author: RubaXa +Date: Mon Feb 9 17:21:50 2015 +0300 + + + merge 'dev' + +commit 21bf07a93fe0ec9a997a6d81b117ce64198e2837 +Author: RubaXa +Date: Mon Feb 9 17:16:40 2015 +0300 + + #256: * fixed auto-scrolling + + Sortable.js | 16 ++++++---------- + 1 file changed, 6 insertions(+), 10 deletions(-) + +commit 15d6f07a01f299bc1aa2f4240ae6713414e797ad +Author: RubaXa +Date: Sat Feb 7 23:06:01 2015 +0300 + + #254: + check 'effectAllowed' on 'dragover' + + Sortable.js | 4 ++++ + 1 file changed, 4 insertions(+) + +commit 7bff4352d60cc1991f245777bfa858e663a8faaa +Author: RubaXa +Date: Fri Feb 6 12:24:01 2015 +0300 + + #250: + additional check + + Sortable.js | 12 +++++++----- + 1 file changed, 7 insertions(+), 5 deletions(-) + +commit c71b88f0756a3cafe62eec4a93ddf82b8798d120 +Author: RubaXa +Date: Fri Feb 6 11:38:35 2015 +0300 + + #251: + 'mousemove' unbind + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit c9051c24e18269ad13ce5ba4ddcf5ac7406f4e0a +Author: RubaXa +Date: Mon Feb 2 14:20:04 2015 +0300 + + + support IE9 + + Sortable.js | 37 ++++++++++++++++++++++--------------- + 1 file changed, 22 insertions(+), 15 deletions(-) + +commit fb3abe8224d40e6d168f832d73a6caa0e96e004f +Merge: 705b3ed dce3eb2 +Author: RubaXa +Date: Tue Jan 27 23:47:58 2015 +0300 + + Merge branch 'dev' of github.com:RubaXa/Sortable into dev + +commit f500b679f22b5aadf794a522751d5bb13ba881a0 +Author: RubaXa +Date: Tue Jan 27 23:47:16 2015 +0300 + + #238: * disabled + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 5325c8a84224f231578f092ca56382480652cc91 +Author: Markus Ast +Date: Tue Jan 27 16:41:11 2015 +0100 + + fix index calculation to skip templates + + Sortable.js | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +commit 0ce769bb479c562882aab65bf5e5c9c5afba5f55 +Merge: 8f2aa5e fa2651f +Author: RubaXa +Date: Mon Jan 26 22:07:44 2015 +0300 + + v1.0.1: #231, #210, #207, #205, #151 + +commit 8f2aa5eb68f5f31fc1cd0db7a5a3d76c06878803 +Author: RubaXa +Date: Mon Jan 26 16:02:31 2015 +0300 + + + create 'cloneEl' on dragStart + + Sortable.js | 13 ++++++------- + 1 file changed, 6 insertions(+), 7 deletions(-) + +commit 06aac74871f3fd25a454df2fd7709ae5494e48ab +Author: RubaXa +Date: Mon Jan 12 18:56:35 2015 +0300 + + #210: + 'dropBubble: false' & 'dragoverBubble: false' options + + Sortable.js | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +commit 3f909d84df4dcbc5e82367d7cde65536117f4660 +Author: RubaXa +Date: Sat Jan 10 21:15:37 2015 +0300 + + #207: * newIndex + + Sortable.js | 39 ++++++++++++++++++++++----------------- + 1 file changed, 22 insertions(+), 17 deletions(-) + +commit a5532380f9956b13b969ede386c85e568ba26a30 +Author: RubaXa +Date: Sat Jan 10 20:19:41 2015 +0300 + + #205: * support 'clone' for angular + + Sortable.js | 1 + + 1 file changed, 1 insertion(+) + +commit b1daa70a2a067bb3c9a577dff7b1f0986e3cf057 +Author: raphj +Date: Sun Dec 28 10:26:28 2014 +0100 + + Make Sotable compatible xhtml + + comparisons of node names (via the nodeName property) are done in upper case. However, nodeName is lower case in xhtml. Let's do everything in upper case. + + Sortable.js | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 0ffa616f100fb340944ccb38e8b6f85020e10c51 +Author: RubaXa +Date: Fri Dec 26 09:20:11 2014 +0300 + + #199: + check 'dataTransfer' exists + + Sortable.js | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +commit 9c618aa83b30dea81fa621a1376776c770df91bf +Author: RubaXa +Date: Fri Dec 19 17:57:25 2014 +0300 + + #185: finaly fix group & mobile + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit 8ee92ddd32722240343d7e2e53ba27e2b149b1aa +Author: RubaXa +Date: Fri Dec 19 17:39:24 2014 +0300 + + #185: fixed group & touch + + Sortable.js | 34 ++++++++++++++++++++++------------ + 1 file changed, 22 insertions(+), 12 deletions(-) + +commit 126cd94a0a3b4f71fb87928857eafc5a69119c84 +Merge: 9a9670e 91a1569 +Author: RubaXa +Date: Fri Dec 19 10:10:29 2014 +0300 + + Merge branch 'dev' of github.com:RubaXa/Sortable into dev + +commit 9a9670ec4c6bb61dc8beb0acbb0d7b09109e17e3 +Author: RubaXa +Date: Fri Dec 19 10:10:02 2014 +0300 + + #184: * 'start' event + + Sortable.js | 36 +++++++++++++++++------------------- + 1 file changed, 17 insertions(+), 19 deletions(-) + +commit a22f9c1fc784b8dd92a2d3cb049e337a0410fa44 +Author: Roel van Duijnhoven +Date: Thu Dec 18 12:18:02 2014 +0100 + + Sort event does not always fire + + In the dev branch the `sort` event is not always correctly called on the receiving list. This IS working in the latest released branch. The fix is trivial and included in this PR. + + The case is illustrated in this JsBin: http://jsbin.com/muxojulevo/3/edit. It occurs whenever an item is picked up from a list and dropped in a nested container. + + Sortable.js | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +commit b2fe4710125b98366d030f9b2e12e84bd8e5ee0d +Author: RubaXa +Date: Thu Dec 18 00:16:05 2014 +0300 + + #131: v1.0, done + + Sortable.js | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +commit 6656e45f302469f37aa7da0f9b68d70ff0b2f100 +Author: RubaXa +Date: Tue Dec 16 20:50:38 2014 +0300 + + #166: fixed _onDragOver & group + + Sortable.js | 13 ++++++++----- + 1 file changed, 8 insertions(+), 5 deletions(-) + +commit 8141f12db3d179b4c89fbc407d3176de81032744 +Author: RubaXa +Date: Tue Dec 16 19:53:14 2014 +0300 + + #173: + save() method + + Sortable.js | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +commit 73f1f09aad6aa441fef46a0bcff18a815b38f4ce +Author: RubaXa +Date: Tue Dec 16 19:42:04 2014 +0300 + + #172: + _cloneHide + + Sortable.js | 23 +++++++++++++++++------ + 1 file changed, 17 insertions(+), 6 deletions(-) + +commit c5b305011d58ba995555c68819b2c671517d7e95 +Author: RubaXa +Date: Mon Dec 15 11:35:06 2014 +0300 + + #171: + preventDefault + + Sortable.js | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +commit 0163bcd1660cd849af499cb01d9fa579102cce15 +Merge: ea1aa2d a71c6a0 +Author: RubaXa +Date: Mon Dec 15 00:31:12 2014 +0300 + + Merge branch 'dev' of github.com:RubaXa/Sortable into dev + +commit ea1aa2de6b0569384db5ebed939ee3443824ca5a +Author: RubaXa +Date: Mon Dec 15 00:27:40 2014 +0300 + + #166: + stopPropagation in _onDragOver + + Sortable.js | 7 ++++++- + 1 file changed, 6 insertions(+), 1 deletion(-) + +commit a71c6a0f401824466338fcade05509072ee01299 +Merge: d6dcc64 df59738 +Author: Lebedev Konstantin +Date: Sun Dec 14 10:27:26 2014 +0300 + + Merge pull request #168 from ghjunior/index-ignore-template + + Ignore