From 7dc8be57559534d5a93cf5aff1306a0f83daf56d Mon Sep 17 00:00:00 2001 From: RubaXa Date: Mon, 16 Feb 2015 17:55:24 +0300 Subject: [PATCH] #279: + dataIdAttr --- README.md | 3 ++- Sortable.js | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7056008..1c1867d 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 6f1d4f0..c6295b5 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)); } }