@@ -34,26 +34,29 @@ $.mobile.table.prototype.options.classes = $.extend(
34
34
}
35
35
) ;
36
36
37
- $ . mobile . document . delegate ( ":jqmData(role='table')" , "tablecreate" , function ( ) {
38
-
37
+ $ . mobile . document . delegate ( ":jqmData(role='table')" , "tablecreate refresh " , function ( e ) {
38
+
39
39
var $table = $ ( this ) ,
40
40
self = $table . data ( "mobile-table" ) ,
41
+ event = e . type ,
41
42
o = self . options ,
42
- ns = $ . mobile . ns ;
43
+ ns = $ . mobile . ns ,
44
+ id = ( $table . attr ( "id" ) || o . classes . popup ) + "-popup" ; //TODO BETTER FALLBACK ID HERE
43
45
44
46
if ( o . mode !== "columntoggle" ) {
45
47
return ;
46
48
}
47
49
48
- self . element . addClass ( o . classes . columnToggleTable ) ;
50
+ if ( event !== "refresh" ) {
51
+ self . element . addClass ( o . classes . columnToggleTable ) ;
49
52
50
- var id = ( $table . attr ( "id" ) || o . classes . popup ) + "- popup" , //TODO BETTER FALLBACK ID HERE
51
- $menuButton = $ ( "<a href='# " + id + "' class='" + o . classes . columnBtn + " ' data-" + ns + "rel='popup' data- " + ns + "mini='true'> " + o . columnBtnText + "</a>" ) ,
52
- $popup = $ ( "<div data-" + ns + "role='popup' data-" + ns + "role='fieldcontain' class='" + o . classes . popup + "' id='" + id + "' ></div >") ,
53
- $menu = $ ( "<fieldset data-" + ns + "role='controlgroup'></fieldset>" ) ;
53
+ var $menuButton = $ ( "<a href='#" + id + "' class='" + o . classes . columnBtn + "' data-" + ns + "rel=' popup' data-" + ns + "mini='true'>" + o . columnBtnText + "</a>" ) ,
54
+ $popup = $ ( "<div data- " + ns + "role='popup ' data-" + ns + "role='fieldcontain' class=' " + o . classes . popup + "' id=' " + id + "'></div>" ) ,
55
+ $menu = $ ( "<fieldset data-" + ns + "role='controlgroup' ></fieldset >" ) ;
56
+ }
54
57
55
58
// create the hide/show toggles
56
- self . headers . not ( "td" ) . each ( function ( ) {
59
+ self . headers . not ( "td" ) . each ( function ( i ) {
57
60
58
61
var priority = $ ( this ) . jqmData ( "priority" ) ,
59
62
$cells = $ ( this ) . add ( $ ( this ) . jqmData ( "cells" ) ) ;
@@ -62,48 +65,68 @@ $.mobile.document.delegate( ":jqmData(role='table')", "tablecreate", function()
62
65
63
66
$cells . addClass ( o . classes . priorityPrefix + priority ) ;
64
67
65
- $ ( "<label><input type='checkbox' checked />" + $ ( this ) . text ( ) + "</label>" )
66
- . appendTo ( $menu )
67
- . children ( 0 )
68
- . jqmData ( "cells" , $cells )
69
- . checkboxradio ( {
70
- theme : o . columnPopupTheme
71
- } ) ;
68
+ if ( event !== "refresh" ) {
69
+ $ ( "<label><input type='checkbox' checked />" + $ ( this ) . text ( ) + "</label>" )
70
+ . appendTo ( $menu )
71
+ . children ( 0 )
72
+ . jqmData ( "cells" , $cells )
73
+ . checkboxradio ( {
74
+ theme : o . columnPopupTheme
75
+ } ) ;
76
+ } else {
77
+ $ ( '#' + id + ' fieldset div:eq(' + i + ')' ) . find ( 'input' ) . jqmData ( "cells" , $cells )
78
+ }
72
79
}
73
80
} ) ;
81
+ if ( event !== "refresh" ) {
74
82
$menu . appendTo ( $popup ) ;
83
+ }
75
84
76
85
// bind change event listeners to inputs - TODO: move to a private method?
77
- $menu . on ( "change" , "input" , function ( e ) {
78
- if ( this . checked ) {
79
- $ ( this ) . jqmData ( "cells" ) . removeClass ( "ui-table-cell-hidden" ) . addClass ( "ui-table-cell-visible" ) ;
80
- }
81
- else {
82
- $ ( this ) . jqmData ( "cells" ) . removeClass ( "ui-table-cell-visible" ) . addClass ( "ui-table-cell-hidden" ) ;
83
- }
84
- } ) ;
86
+ if ( $menu === undefined ) {
87
+ $switchboard = $ ( '#' + id + ' fieldset' ) ;
88
+ } else {
89
+ $switchboard = $menu ;
90
+ }
85
91
86
- $menuButton
87
- . insertBefore ( $table )
88
- . buttonMarkup ( {
89
- theme : o . columnBtnTheme
92
+ if ( event !== "refresh" ) {
93
+ $switchboard . on ( "change" , "input" , function ( e ) {
94
+ if ( this . checked ) {
95
+ $ ( this ) . jqmData ( "cells" ) . removeClass ( "ui-table-cell-hidden" ) . addClass ( "ui-table-cell-visible" ) ;
96
+ } else {
97
+ $ ( this ) . jqmData ( "cells" ) . removeClass ( "ui-table-cell-visible" ) . addClass ( "ui-table-cell-hidden" ) ;
98
+ }
90
99
} ) ;
91
100
92
- $popup
93
- . insertBefore ( $table )
94
- . popup ( ) ;
101
+ $menuButton
102
+ . insertBefore ( $table )
103
+ . buttonMarkup ( {
104
+ theme : o . columnBtnTheme
105
+ } ) ;
106
+
107
+ $popup
108
+ . insertBefore ( $table )
109
+ . popup ( ) ;
110
+ }
95
111
96
112
// refresh method
97
- self . refresh = function ( ) {
98
- $menu . find ( "input" ) . each ( function ( ) {
99
- this . checked = $ ( this ) . jqmData ( "cells" ) . eq ( 0 ) . css ( "display" ) === "table-cell" ;
113
+ self . update = function ( ) {
114
+ $switchboard . find ( "input" ) . each ( function ( ) {
115
+ if ( this . checked ) {
116
+ this . checked = $ ( this ) . jqmData ( "cells" ) . eq ( 0 ) . css ( "display" ) === "table-cell" ;
117
+ if ( event === "refresh" ) {
118
+ $ ( this ) . jqmData ( "cells" ) . addClass ( 'ui-table-cell-visible' ) ;
119
+ }
120
+ } else {
121
+ $ ( this ) . jqmData ( "cells" ) . addClass ( 'ui-table-cell-hidden' ) ;
122
+ }
100
123
$ ( this ) . checkboxradio ( "refresh" ) ;
101
124
} ) ;
102
125
} ;
103
126
104
- $ . mobile . window . on ( "throttledresize" , self . refresh ) ;
127
+ $ . mobile . window . on ( "throttledresize" , self . update ) ;
105
128
106
- self . refresh ( ) ;
129
+ self . update ( ) ;
107
130
108
131
} ) ;
109
132
0 commit comments