-
Notifications
You must be signed in to change notification settings - Fork 1
/
jquery.smmNestedSortable.textSerializer.js
45 lines (41 loc) · 1.35 KB
/
jquery.smmNestedSortable.textSerializer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
SmmNestedSortables Text Serializer
Calling $.fn.smmNestedSortable.textSerializer.buildSpec() will return a serialized string of the first ul.sortable on the page.
smmNestedSortables can automatically calls buildSpec when the spec is changed. This is how you would do it:
$('.sortable').smmNestedSortable({
'serializer':function() {
var spec = $.fn.smmNestedSortable.textSerializer.buildSpec();
$("#spec").html("<b>text output</b><br /><br />"+ spec);
}
});
*/
(function($) {
$.fn.smmNestedSortable.textSerializer = {
newLine:"<br />",
indent:"*",
buildSpec: function() {
var spec = [];
var level = 0;
jQuery("ul.sortable:first").children().each(function() {
spec.push($.fn.smmNestedSortable.textSerializer._buildSpec($(this), level));
});
return spec.join('');
},
_buildSpec: function(liList, level) {
var spec = [];
level++;
liList.each(function() {
spec.push($.fn.smmNestedSortable.textSerializer.stars(level)+" "+this.id+$.fn.smmNestedSortable.textSerializer.newLine);
spec.push($.fn.smmNestedSortable.textSerializer._buildSpec(jQuery(this).children("ul").children("li"), level));
});
return spec.join('');
},
stars: function(number) {
var stars = [];
for (c=0;c<number;c++){
stars.push($.fn.smmNestedSortable.textSerializer.indent);
}
return stars.join('');
}
};
})(jQuery);