-
Notifications
You must be signed in to change notification settings - Fork 11
/
jquery.mobile.nestedlists.js
64 lines (61 loc) · 1.85 KB
/
jquery.mobile.nestedlists.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function( $, window, undefined ) {
$.widget( "mobile.listview", $.mobile.listview, {
options: {
childPages: true,
page: "<div data-role='page'></div>",
header: "<div data-role='header'><a href='#' data-rel='back'>Back</a><h1></h1></div>",
content: "<div class='ui-content'></div>"
},
_create: function(){
this._super();
if( this.options.childPages ) {
this._setupChildren();
}
},
_setupChildren: function() {
this._attachBindings();
this.element.find( "ul" )
.css( "display","none" )
.parent()
.addClass("ui-btn ui-btn-icon-right ui-icon-carat-r");
},
_attachBindings: function() {
this._on({
"click": "_handleSubpageClick"
});
this._on( "body", {
"pagechange": function(){
if ( this.opening === true ) {
this.open = true;
this.opening = false;
} else if ( this.open === true ) {
this.newPage.remove();
this.open = false;
}
}
});
},
_handleSubpageClick: function( event ) {
if( $(event.target).closest( "li" ).children( "ul" ).length == 0 ) {
return;
}
this.opening = true;
this.newPage = $( this.options.page ).uniqueId();
this.nestedList = $( event.target ).children( "ul" )
.clone().attr( "data-" + $.mobile.ns + "role", "listview" )
.css( "display", "block" );
this.pageName = (
$( event.target.childNodes[0] ).text().replace(/^\s+|\s+$/g, '').length > 0 )?
$( event.target.childNodes[0] ).text() : $( event.target.childNodes[1] ).text();
this.pageID = this.newPage.attr( "id" );
// Build new page
this.newPage.append(
$( this.options.header ).find( "h1" ).text( this.pageName ).end()
).append(
$( this.options.content )
).find( "div.ui-content" ).append( this.nestedList );
$( "body" ).append( this.newPage );
$( "body" ).pagecontainer( "change", "#" + this.pageID );
}
});
})( jQuery, this );