From f3af805d75b078b89a6e84a9ba5942c369ca6c41 Mon Sep 17 00:00:00 2001 From: RubaXa Date: Fri, 18 Dec 2015 16:22:12 +0300 Subject: [PATCH] #671: + 'clone' support jQuery/Zepto/Polymer.dom --- README.md | 1 + Sortable.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 32327bd..f3b4df8 100644 --- a/README.md +++ b/README.md @@ -650,6 +650,7 @@ Link to the active instance. * bind(ctx`:Mixed`, fn`:Function`)`:Function` — Takes a function and returns a new one that will always have a particular context * is(el`:HTMLElement`, selector`:String`)`:Boolean` — check the current matched set of elements against a selector * closest(el`:HTMLElement`, selector`:String`[, ctx`:HTMLElement`])`:HTMLElement|Null` — for each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree +* clone(el`:HTMLElement`)`:HTMLElement` — create a deep copy of the set of matched elements * toggleClass(el`:HTMLElement`, name`:String`, state`:Boolean`) — add or remove one classes from each element diff --git a/Sortable.js b/Sortable.js index eca7c50..15425bb 100644 --- a/Sortable.js +++ b/Sortable.js @@ -58,6 +58,9 @@ document = win.document, parseInt = win.parseInt, + $ = win.jQuery || win.Zepto; + Polymer = win.Polymer, + supportDraggable = !!('draggable' in document.createElement('div')), supportCssPointerEvents = (function (el) { el = document.createElement('x'); @@ -546,7 +549,7 @@ this._offUpEvents(); if (activeGroup.pull == 'clone') { - cloneEl = dragEl.cloneNode(true); + cloneEl = _clone(dragEl); _css(cloneEl, 'display', 'none'); rootEl.insertBefore(cloneEl, dragEl); _dispatchEvent(this, rootEl, 'clone', dragEl); @@ -1251,6 +1254,15 @@ return dst; } + function _clone(el) { + return $ + ? $(el).clone(true)[0] + : (Polymer && Polymer.dom + ? Polymer.dom(el).cloneNode(true) + : el.cloneNode(true) + ); + } + // Export utils Sortable.utils = { @@ -1265,6 +1277,7 @@ throttle: _throttle, closest: _closest, toggleClass: _toggleClass, + clone: _clone, index: _index };