1
1
( function ( $ , window , undefined ) {
2
- $ . mobile . document . on ( "pagecreate" , "div" , function ( ) {
3
- $ ( "ul>li>ul" ) . css ( "display" , "none" ) ;
4
- $ ( "ul>li>ul" ) . parent ( ) . addClass ( "ui-btn ui-btn-icon-right ui-icon-carat-r" ) ;
5
- } ) ;
6
- $ . mobile . document . on ( "click" , ".ui-listview>li" , function ( ) {
7
- if ( $ ( this ) . children ( "ul" ) . length == 0 ) {
8
- return ;
9
- }
10
- var newPage = $ . mobile . nestedlists . page . clone ( ) . uniqueId ( ) ,
11
- nestedList = $ ( this ) . children ( "ul" ) . clone ( ) . attr ( "data-" + $ . mobile . ns + "role" , "listview" ) . css ( "display" , "block" ) ,
12
- pageName = ( $ ( this . childNodes [ 0 ] ) . text ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . length > 0 ) ? $ ( this . childNodes [ 0 ] ) . text ( ) : $ ( this . childNodes [ 1 ] ) . text ( ) ,
13
- pageID = newPage . attr ( "id" ) ;
14
-
15
- // Build new page
16
- newPage . append ( $ . mobile . nestedlists . header . clone ( ) . find ( "h1" ) . text ( pageName ) . end ( ) )
17
- . append ( $ . mobile . nestedlists . content . clone ( ) )
18
- . find ( "div.ui-content" ) . append ( nestedList ) ;
19
-
20
- $ . mobile . pageContainer . append ( newPage ) ;
2
+ $ . widget ( "mobile.listview" , $ . mobile . listview , {
3
+ options : {
4
+ childPages : true ,
5
+ page : "<div data-role='page'></div>" ,
6
+ header : "<div data-role='header'><a href='#' data-rel='back'>Back</a><h1></h1></div>" ,
7
+ content : "<div class='ui-content'></div>"
8
+ } ,
9
+ _create : function ( ) {
10
+ this . _super ( ) ;
11
+ if ( this . options . childPages ) {
12
+ this . _attachBindings ( ) ;
13
+ this . element . find ( "ul" )
14
+ . css ( "display" , "none" )
15
+ . parent ( )
16
+ . addClass ( "ui-btn ui-btn-icon-right ui-icon-carat-r" ) ;
17
+ }
18
+ } ,
19
+ _attachBindings : function ( ) {
20
+ this . _on ( {
21
+ "click" : "_handleSubpageClick"
22
+ } ) ;
23
+ this . _on ( "body" , {
24
+ "pagechange" : function ( ) {
25
+ if ( this . opening === true ) {
26
+ this . open = true ;
27
+ this . opening = false ;
28
+ } else if ( this . open === true ) {
29
+ this . newPage . remove ( ) ;
30
+ this . open = false ;
31
+ }
32
+ }
33
+ } ) ;
34
+ } ,
35
+ _handleSubpageClick : function ( event ) {
36
+ if ( $ ( event . target ) . children ( "ul" ) . length == 0 ) {
37
+ return ;
38
+ }
39
+ this . opening = true ;
40
+ this . newPage = $ ( this . options . page ) . uniqueId ( ) ;
41
+ this . nestedList = $ ( event . target ) . children ( "ul" )
42
+ . clone ( ) . attr ( "data-" + $ . mobile . ns + "role" , "listview" )
43
+ . css ( "display" , "block" ) ;
44
+ this . pageName = (
45
+ $ ( event . target . childNodes [ 0 ] ) . text ( ) . replace ( / ^ \s + | \s + $ / g, '' ) . length > 0 ) ?
46
+ $ ( event . target . childNodes [ 0 ] ) . text ( ) : $ ( event . target . childNodes [ 1 ] ) . text ( ) ;
47
+ this . pageID = this . newPage . attr ( "id" ) ;
21
48
22
- $ . mobile . changePage ( "#" + pageID ) ;
49
+ // Build new page
50
+ this . newPage . append (
51
+ $ ( this . options . header ) . find ( "h1" ) . text ( this . pageName ) . end ( )
52
+ ) . append (
53
+ $ ( this . options . content )
54
+ ) . find ( "div.ui-content" ) . append ( this . nestedList ) ;
23
55
24
- // Remove Nested Page
25
- $ . mobile . document . one ( "pagechange" , function ( ) {
26
- $ . mobile . document . one ( "pagechange" , function ( ) {
27
- $ . mobile . document . one ( "pagechange" , function ( ) {
28
- $ ( ".nested-list-page" ) . remove ( ) ;
29
- } ) ;
30
- } ) ;
31
- } ) ;
32
- } ) ;
56
+ $ ( "body" ) . append ( this . newPage ) ;
33
57
34
- $ . extend ( $ . mobile , {
35
- nestedlists : {
36
- page : $ ( "<div data-role='page'></div>" ) ,
37
- header : $ ( "<div data-role='header'><a href='#' data-rel='back'>Back</a><h1></h1></div>" ) ,
38
- content : $ ( "<div class='ui-content'></div>" )
58
+ $ ( "body" ) . pagecontainer ( "change" , "#" + this . pageID ) ;
39
59
}
40
60
} ) ;
41
61
} ) ( jQuery , this ) ;
0 commit comments