Skip to content

Commit

Permalink
Add ability to use data- attributes to show up in the hierarchy.
Browse files Browse the repository at this point in the history
  • Loading branch information
bfcoder committed Dec 16, 2015
1 parent 397fa6f commit 674b349
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ Also, the default list type is `<ol>`.
'2' ...
'id' => itemId
</pre>
Similarly to <code>toArray</code>, it accepts <b>attribute</b> and <b>expression</b> options.</dd>
Similarly to <code>toArray</code>, it accepts <b>attribute</b> and <b>expression</b> options.
Optionally adding `data-` attributes will cause them to show up in the hierarchy. See demo for example.
</dd>
</dl>

## Events
Expand Down
4 changes: 2 additions & 2 deletions example.html
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ <h2>2.0</h2>

<section id="demo">
<ol class="sortable ui-sortable mjs-nestedSortable-branch mjs-nestedSortable-expanded">
<li style="display: list-item;" class="mjs-nestedSortable-branch mjs-nestedSortable-expanded" id="menuItem_2">
<li style="display: list-item;" class="mjs-nestedSortable-branch mjs-nestedSortable-expanded" id="menuItem_2" data-foo="bar">
<div class="menuDiv">
<span title="Click to show/hide children" class="disclose ui-icon ui-icon-minusthick">
<span></span>
Expand All @@ -305,7 +305,7 @@ <h2>2.0</h2>
</div>
</div>
<ol>
<li style="display: list-item;" class="mjs-nestedSortable-branch mjs-nestedSortable-expanded" id="menuItem_4">
<li style="display: list-item;" class="mjs-nestedSortable-branch mjs-nestedSortable-expanded" id="menuItem_4" data-foo="baz">
<div class="menuDiv">
<span title="Click to show/hide children" class="disclose ui-icon ui-icon-minusthick">
<span></span>
Expand Down
8 changes: 8 additions & 0 deletions jquery.mjs.nestedSortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,19 @@
function _recursiveItems(item) {
var id = ($(item).attr(o.attribute || "id") || "").match(o.expression || (/(.+)[-=_](.+)/)),
currentItem;

var data = $(item).data();
if (data.nestedSortableItem) {
delete data.nestedSortableItem; // Remove the nestedSortableItem object from the data
}

if (id) {
currentItem = {
"id": id[2]
};

currentItem = $.extend({}, currentItem, data); // Combine the two objects

if ($(item).children(o.listType).children(o.items).length > 0) {
currentItem.children = [];
$(item).children(o.listType).children(o.items).each(function() {
Expand Down

0 comments on commit 674b349

Please sign in to comment.