Browse Source

- CustomEvents; * evt.detail -> evt.item

pull/10/head
RubaXa 11 years ago
parent
commit
6619d05703
  1. 6
      README.md
  2. 28
      Sortable.js
  3. 4
      Sortable.min.js
  4. 16
      index.html
  5. 4
      package.json

6
README.md

@ -32,15 +32,15 @@ new Sortable(elem, {
ghostClass: "sortable-ghost",
onAdd: function (evt){
var itemEl = ui.detail;
var itemEl = evt.item;
},
onUpdate: function (evt){
var itemEl = ui.detail; // the current dragged HTMLElement
var itemEl = evt.item; // the current dragged HTMLElement
},
onRemove: function (evt){
var itemEl = ui.detail;
var itemEl = evt.item;
}
});
```

28
Sortable.js

@ -38,18 +38,13 @@
, parseInt = win.parseInt
, _silent = false
, Event = (function (){
function CustomEvent(event, params){
var evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
, _createEvent = function (event/**String*/, item/**HTMLElement*/){
var evt = document.createEvent('Event');
evt.initEvent(event, true, true);
evt.item = item;
return evt;
}
CustomEvent.prototype = win.CustomEvent.prototype;
return CustomEvent;
})()
, noop = function (){}
, slice = [].slice
@ -132,6 +127,7 @@
tapEvt = evt;
target.draggable = true;
// Disable "draggable"
_find(target, 'a', _disableDraggable);
_find(target, 'img', _disableDraggable);
@ -262,11 +258,11 @@
, target = _closest(evt.target, this.options.draggable, el)
;
if( target[expando] === void 0 ){
if( target && target[expando] === void 0 ){
if( el.children.length === 0 ){
el.appendChild(dragEl);
}
else if( target && (target !== dragEl) ){
else if( target !== dragEl ){
if( lastEl !== target ){
lastEl = target;
lastCSS = _css(target)
@ -327,20 +323,18 @@
}
if( dragEl ){
var opts = { bubbles: true, cancelable: true, detail: dragEl };
_toggleClass(dragEl, this.options.ghostClass, false);
if( !rootEl.contains(dragEl) ){
// Remove event
rootEl.dispatchEvent(new Event('remove', opts));
rootEl.dispatchEvent(_createEvent('remove', dragEl));
// Add event
dragEl.dispatchEvent(new Event('add', opts));
dragEl.dispatchEvent(_createEvent('add', dragEl));
}
else if( dragEl.nextSibling !== nextEl ){
// Update event
dragEl.dispatchEvent(new Event('update', opts));
dragEl.dispatchEvent(_createEvent('update', dragEl));
}
}
@ -500,7 +494,7 @@
};
Sortable.version = '0.1.3';
Sortable.version = '0.1.4';
// Export
return Sortable;

4
Sortable.min.js vendored

File diff suppressed because one or more lines are too long

16
index.html

@ -311,16 +311,16 @@ sort.destroy();
new Sortable(foo, {
group: "words",
onAdd: function (evt){ console.log('onAdd.foo:', evt.detail); },
onUpdate: function (evt){ console.log('onUpdate.foo:', evt.detail); },
onRemove: function (evt){ console.log('onRemove.foo:', evt.detail); }
onAdd: function (evt){ console.log('onAdd.foo:', evt.item); },
onUpdate: function (evt){ console.log('onUpdate.foo:', evt.item); },
onRemove: function (evt){ console.log('onRemove.foo:', evt.item); }
});
new Sortable(bar, {
group: "words",
onAdd: function (evt){ console.log('onAdd.bar:', evt.detail); },
onUpdate: function (evt){ console.log('onUpdate.bar:', evt.detail); },
onRemove: function (evt){ console.log('onRemove.bar:', evt.detail); }
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); }
});
@ -366,7 +366,7 @@ sort.destroy();
<!-- Parallax -->
<script>
(function (){
var x, y;
var x, y, reqAnimFrame = window.requestAnimationFrame || function (fn){ setTimeout(fn, 1000/60); };
var items = [].slice.call(document.querySelectorAll('.layer')).map(function (el){
var rect = el.getBoundingClientRect();
@ -410,7 +410,7 @@ sort.destroy();
});
}
requestAnimationFrame(_loop);
reqAnimFrame(_loop);
})();
})();
</script>

4
package.json

@ -1,7 +1,7 @@
{
"name": "sortable",
"exportName": "Sortable",
"version": "0.1.3",
"version": "0.1.4",
"devDependencies": {
"grunt": "*",
"grunt-version": "*",
@ -16,7 +16,7 @@
"type": "git",
"url": "git://github.com/rubaxa/Sortable.git"
},
"keywords": ["sortable", "reorder"],
"keywords": ["sortable", "reorder", "drag"],
"author": "Konstantin Lebedev <ibnRubaXa@gmail.com>",
"license": "MIT"
}

Loading…
Cancel
Save