Browse Source

Merge branch 'master' into gh-pages

pull/70/head 0.4.1
RubaXa 11 years ago
parent
commit
4a9aa694b2
  1. 2
      README.md
  2. 68
      Sortable.js
  3. 4
      Sortable.min.js
  4. 2
      bower.json
  5. 2
      component.json
  6. 2
      package.json

2
README.md

@ -67,7 +67,7 @@ new Sortable(el, {
Serializes the sortable's item data-id's into an array of string. Serializes the sortable's item data-id's into an array of string.
##### sort(order:`Array`) ##### sort(order:`String[]`)
Sorts the elements according to the array. Sorts the elements according to the array.
```js ```js
var order = sortable.toArray(); var order = sortable.toArray();

68
Sortable.js

@ -77,11 +77,11 @@
options.ghostClass = options.ghostClass || 'sortable-ghost'; options.ghostClass = options.ghostClass || 'sortable-ghost';
options.ignore = options.ignore || 'a, img'; options.ignore = options.ignore || 'a, img';
options.onAdd = _bind(this, options.onAdd || noop);
options.onUpdate = _bind(this, options.onUpdate || noop); // Define events
options.onRemove = _bind(this, options.onRemove || noop); 'onAdd onUpdate onRemove onStart onEnd'.split(' ').forEach(function (name) {
options.onStart = _bind(this, options.onStart || noop); options[name] = _bind(this, options[name] || noop);
options.onEnd = _bind(this, options.onEnd || noop); });
// Export group name // Export group name
@ -149,10 +149,16 @@
if( target && !dragEl && (target.parentNode === el) ){ if( target && !dragEl && (target.parentNode === el) ){
tapEvt = evt; tapEvt = evt;
target.draggable = true;
rootEl = this.el;
dragEl = target;
nextEl = dragEl.nextSibling;
activeGroup = this.options.group;
dragEl.draggable = true;
// Disable "draggable" // Disable "draggable"
Array.prototype.forEach.call(options.ignore.split(','), function (criteria) { options.ignore.split(',').forEach(function (criteria) {
_find(target, criteria.trim(), _disableDraggable); _find(target, criteria.trim(), _disableDraggable);
}); });
@ -163,10 +169,14 @@
, clientX: touch.clientX , clientX: touch.clientX
, clientY: touch.clientY , clientY: touch.clientY
}; };
this._onDragStart(tapEvt, true); this._onDragStart(tapEvt, true);
evt.preventDefault(); evt.preventDefault();
} }
_on(document, 'mouseup', this._onDrop);
_on(document, 'touchend', this._onDrop);
_on(document, 'touchcancel', this._onDrop);
_on(this.el, 'dragstart', this._onDragStart); _on(this.el, 'dragstart', this._onDragStart);
_on(this.el, 'dragend', this._onDrop); _on(this.el, 'dragend', this._onDrop);
@ -180,10 +190,12 @@
window.getSelection().removeAllRanges() window.getSelection().removeAllRanges()
} }
} catch (err){ } } catch (err){ }
dragEl.dispatchEvent(_createEvent('start', dragEl));
} }
}, },
_emulateDragOver: function (){ _emulateDragOver: function (){
if( touchEvt ){ if( touchEvt ){
_css(ghostEl, 'display', 'none'); _css(ghostEl, 'display', 'none');
@ -241,24 +253,18 @@
_onDragStart: function (evt/**Event*/, isTouch/**Boolean*/){ _onDragStart: function (evt/**Event*/, isTouch/**Boolean*/){
var var dataTransfer = evt.dataTransfer;
target = evt.target
, dataTransfer = evt.dataTransfer
;
rootEl = this.el; this._offUpEvents();
dragEl = target;
nextEl = target.nextSibling;
activeGroup = this.options.group;
if( isTouch ){ if( isTouch ){
var var
rect = target.getBoundingClientRect() rect = dragEl.getBoundingClientRect()
, css = _css(target) , css = _css(dragEl)
, ghostRect , ghostRect
; ;
ghostEl = target.cloneNode(true); ghostEl = dragEl.cloneNode(true);
_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10)); _css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10));
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10)); _css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10));
@ -284,12 +290,11 @@
} }
else { else {
dataTransfer.effectAllowed = 'move'; dataTransfer.effectAllowed = 'move';
dataTransfer.setData('Text', target.textContent); dataTransfer.setData('Text', dragEl.textContent);
_on(document, 'drop', this._onDrop); _on(document, 'drop', this._onDrop);
} }
dragEl.dispatchEvent(_createEvent('start', dragEl));
setTimeout(this._applyEffects); setTimeout(this._applyEffects);
}, },
@ -317,10 +322,10 @@
, width = rect.right - rect.left , width = rect.right - rect.left
, height = rect.bottom - rect.top , height = rect.bottom - rect.top
, floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display) , floating = /left|right|inline/.test(lastCSS.cssFloat + lastCSS.display)
, skew = (floating ? (evt.clientX - rect.left)/width : (evt.clientY - rect.top)/height) > .5
, isWide = (target.offsetWidth > dragEl.offsetWidth) , isWide = (target.offsetWidth > dragEl.offsetWidth)
, isLong = (target.offsetHeight > dragEl.offsetHeight) , isLong = (target.offsetHeight > dragEl.offsetHeight)
, nextSibling = target.nextSibling , halfway = (floating ? (evt.clientX - rect.left)/width : (evt.clientY - rect.top)/height) > .5
, nextSibling = target.nextElementSibling
, after , after
; ;
@ -328,9 +333,9 @@
setTimeout(_unsilent, 30); setTimeout(_unsilent, 30);
if( floating ){ if( floating ){
after = (target.previousElementSibling === dragEl) && !isWide || (skew > .5) && isWide after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide
} else { } else {
after = (target.nextElementSibling !== dragEl) && !isLong || (skew > .5) && isLong; after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
} }
if( after && !nextSibling ){ if( after && !nextSibling ){
@ -342,6 +347,12 @@
} }
}, },
_offUpEvents: function () {
_off(document, 'mouseup', this._onDrop);
_off(document, 'touchmove', this._onTouchMove);
_off(document, 'touchend', this._onDrop);
_off(document, 'touchcancel', this._onDrop);
},
_onDrop: function (evt/**Event*/){ _onDrop: function (evt/**Event*/){
clearInterval(this._loopId); clearInterval(this._loopId);
@ -354,10 +365,7 @@
_off(this.el, 'dragstart', this._onDragStart); _off(this.el, 'dragstart', this._onDragStart);
_off(this.el, 'selectstart', this._onTapStart); _off(this.el, 'selectstart', this._onTapStart);
_off(document, 'touchmove', this._onTouchMove); this._offUpEvents();
_off(document, 'touchend', this._onDrop);
_off(document, 'touchcancel', this._onDrop);
if( evt ){ if( evt ){
evt.preventDefault(); evt.preventDefault();
@ -621,7 +629,7 @@
}; };
Sortable.version = '0.4.0'; Sortable.version = '0.4.1';
// Export // Export

4
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

2
bower.json

@ -1,7 +1,7 @@
{ {
"name": "Sortable", "name": "Sortable",
"main": "Sortable.js", "main": "Sortable.js",
"version": "0.4.0", "version": "0.4.1",
"homepage": "http://rubaxa.github.io/Sortable/", "homepage": "http://rubaxa.github.io/Sortable/",
"authors": [ "authors": [
"RubaXa <ibnRubaXa@gmail.com>" "RubaXa <ibnRubaXa@gmail.com>"

2
component.json

@ -1,7 +1,7 @@
{ {
"name": "Sortable", "name": "Sortable",
"main": "Sortable.js", "main": "Sortable.js",
"version": "0.4.0", "version": "0.4.1",
"homepage": "http://rubaxa.github.io/Sortable/", "homepage": "http://rubaxa.github.io/Sortable/",
"repo": "RubaXa/Sortable", "repo": "RubaXa/Sortable",
"authors": [ "authors": [

2
package.json

@ -1,7 +1,7 @@
{ {
"name": "sortable", "name": "sortable",
"exportName": "Sortable", "exportName": "Sortable",
"version": "0.4.0", "version": "0.4.1",
"devDependencies": { "devDependencies": {
"grunt": "*", "grunt": "*",
"grunt-version": "*", "grunt-version": "*",

Loading…
Cancel
Save