Browse Source

#671: + 'clone' event

pull/699/head
RubaXa 9 years ago
parent
commit
2ec12f7ecd
  1. 6
      README.md
  2. 4
      Sortable.html
  3. 2
      Sortable.js
  4. 4
      knockout-sortable.js
  5. 2
      ng-sortable.js
  6. 7
      react-sortable-mixin.js

6
README.md

@ -131,6 +131,12 @@ var sortable = new Sortable(el, {
evt.related; // HTMLElement on which have guided evt.related; // HTMLElement on which have guided
evt.relatedRect; // TextRectangle evt.relatedRect; // TextRectangle
// return false; — for cancel // return false; — for cancel
},
// Called when creating a clone of element
onClone: function (/**Event*/evt) {
var origEl = evt.item;
var cloneEl = evt.clone;
} }
}); });
``` ```

4
Sortable.html

@ -110,6 +110,10 @@
onMove: function(e) { onMove: function(e) {
this.fire("move", e) this.fire("move", e)
},
onClone: function(e) {
this.fire("clone", e)
} }
})) }))
}, },

2
Sortable.js

@ -547,10 +547,10 @@
cloneEl = dragEl.cloneNode(true); cloneEl = dragEl.cloneNode(true);
_css(cloneEl, 'display', 'none'); _css(cloneEl, 'display', 'none');
rootEl.insertBefore(cloneEl, dragEl); rootEl.insertBefore(cloneEl, dragEl);
_dispatchEvent(this, rootEl, 'clone', dragEl);
} }
if (useFallback) { if (useFallback) {
if (useFallback === 'touch') { if (useFallback === 'touch') {
// Bind touch events // Bind touch events
_on(document, 'touchmove', this._onTouchMove); _on(document, 'touchmove', this._onTouchMove);

4
knockout-sortable.js

@ -1,4 +1,4 @@
(function (factory) { (function (factory) {
"use strict"; "use strict";
if (typeof define === "function" && define.amd) { if (typeof define === "function" && define.amd) {
// AMD anonymous module // AMD anonymous module
@ -21,7 +21,7 @@
// It's seems that we cannot update the eventhandlers after we've created // It's seems that we cannot update the eventhandlers after we've created
// the sortable, so define them in init instead of update // the sortable, so define them in init instead of update
['onStart', 'onEnd', 'onRemove', 'onAdd', 'onUpdate', 'onSort', 'onFilter'].forEach(function (e) { ['onStart', 'onEnd', 'onRemove', 'onAdd', 'onUpdate', 'onSort', 'onFilter', 'onMove', 'onClone'].forEach(function (e) {
if (options[e] || eventHandlers[e]) if (options[e] || eventHandlers[e])
options[e] = function (eventType, parentVM, parentBindings, handler, e) { options[e] = function (eventType, parentVM, parentBindings, handler, e) {
var itemVM = ko.dataFor(e.item), var itemVM = ko.dataFor(e.item),

2
ng-sortable.js

@ -173,7 +173,7 @@
angular.forEach([ angular.forEach([
'sort', 'disabled', 'draggable', 'handle', 'animation', 'group', 'ghostClass', 'filter', 'sort', 'disabled', 'draggable', 'handle', 'animation', 'group', 'ghostClass', 'filter',
'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort' 'onStart', 'onEnd', 'onAdd', 'onUpdate', 'onRemove', 'onSort', 'onMove', 'onClone'
], function (name) { ], function (name) {
watchers.push(scope.$watch('ngSortable.' + name, function (value) { watchers.push(scope.$watch('ngSortable.' + name, function (value) {
if (value !== void 0) { if (value !== void 0) {

7
react-sortable-mixin.js vendored

@ -35,7 +35,8 @@
onRemove: 'handleRemove', onRemove: 'handleRemove',
onSort: 'handleSort', onSort: 'handleSort',
onFilter: 'handleFilter', onFilter: 'handleFilter',
onMove: 'handleMove' onMove: 'handleMove',
onClone: 'handleClone'
}; };
@ -120,13 +121,13 @@
} }
newState[_getModelName(this)] = items; newState[_getModelName(this)] = items;
if (copyOptions.stateHandler) { if (copyOptions.stateHandler) {
this[copyOptions.stateHandler](newState); this[copyOptions.stateHandler](newState);
} else { } else {
this.setState(newState); this.setState(newState);
} }
(this !== _activeComponent) && _activeComponent.setState(remoteState); (this !== _activeComponent) && _activeComponent.setState(remoteState);
} }

Loading…
Cancel
Save