Skip to content

Commit

Permalink
Merge branch 'release/v1.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
ramontayag committed Jun 9, 2011
2 parents 2bac162 + b56c5d2 commit ef1fba5
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
*.swp
**/*.swp
*.sw*
**/*.sw*
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Please note: every `<li>` must have either one or two direct children, the first

<dl>
<dt>serialize</dt>
<dd>Serializes the nested list into a string like <b>setName[item1Id]=parentId&setName[item2Id]=parentId</b>, reading from each item's id formatted as 'setName_itemId' (where itemId is a number).
<dd>Serializes the nested list into a string like <code>setName[setName_item1Id][parent_id]=parentId&setName[setName_item1Id][position]=position...</code>, reading from each item's id formatted as 'setName_itemId' (where itemId is a number).
It accepts the same options as the original Sortable method (<b>key</b>, <b>attribute</b> and <b>expression</b>).</dd>
<dt>toArray</dt>
<dd>Builds an array where each element is in the form:
Expand Down Expand Up @@ -97,4 +97,4 @@ Tested with: IE 6/7/8, Firefox 3.6/4, Chrome, Safari 3
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

This work is *pizzaware*. If it saved your life, or you just feel good at heart, please consider offering me a pizza. This can be done in two ways: (1) use the Paypal button at the bottom of the project's [home page](http://mjsarfatti.com/sandbox/nestedSortable); (2) send me cash via traditional mail to my home address in Italy. Is the second method legal? It is in Italy if you use Posta assicurata. You should check with your local laws if you live elsewhere.


50 changes: 37 additions & 13 deletions jquery.ui.nestedSortable.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* jQuery UI Nested Sortable
* v 1.3.5 / 28 apr 2011
* v 1.3.6 / 28 apr 2011
* http://mjsarfatti.com/sandbox/nestedSortable
*
* Depends:
Expand Down Expand Up @@ -200,22 +200,46 @@
$.ui.sortable.prototype._mouseStop.apply(this, arguments);
},//_mouseStop
serialize: function(o) {
// 'o' is a hash of the options of the plugin (?)

// items is an array the dom elements lifted from the page, so we can work on them.
// It looks something like [li#menu_item_37.menu_item, li#menu_item_38.menu_item, ...]
var items = this._getItemsAsjQuery(o && o.connected),
str = []; o = o || {};
str = []; o = o || {};

// Now we go through each of these items
$(items).each(function() {
var res = ($(o.item || this).attr(o.attribute || 'id') || '')
.match(o.expression || (/(.+)[-=_](.+)/)),
pid = ($(o.item || this).parent(o.listType)
.parent('li')
.attr(o.attribute || 'id') || '')
.match(o.expression || (/(.+)[-=_](.+)/));

if (res) {
str.push((o.key || res[1] + '[' + (o.key && o.expression ? res[1] : res[2]) + ']')
+ '='
+ (pid ? (o.key && o.expression ? pid[1] : pid[2]) : 'root'));
}
.match(
o.expression || (/(.+)[-=_](.+)/)),
pid = ($(o.item || this).parent(o.listType)
.parent('li')
.attr(o.attribute || 'id') || '')
.match(o.expression || (/(.+)[-=_](.+)/));

// At this point...
// 'res' looks like this: ["menu_item_47", "menu_item", "47"]
// pid looks like this, IF the item (res) has a parent: ["menu_item_46", "menu_item", "46"]

// Here we setup the response's parent_id
if (res) {
// Updated the following line to have res[0] (instead of res[2]), which will make the itemName be menu_item_47
itemName = (o.key && o.expression ? res[1] : res[0]);

// itemScope looks like this: menu_item[menu_item_37]
itemScope = o.key || res[1] + '[' + itemName + ']'

//create the parentId string, which will look like menu_item[menu_item_37][parent_id]=root
parentStr = itemScope + '[parent_id]=' + (pid ? (o.key && o.expression ? pid[1] : pid[2]) : 'root')

//create the position string, which will look like menu_item[menu_item_37][position]=0
//this is 0-based position
positionStr = itemScope + '[position]=' + $(this).index();

//push the parentStr and positionStr strings into the str array
str.push(parentStr);
str.push(positionStr);
}
});

if(!str.length && o.key) {
Expand Down

0 comments on commit ef1fba5

Please sign in to comment.