This repository has been archived by the owner on Oct 8, 2021. It is now read-only.
/
jquery.mobile.collapsibleSet.js
102 lines (89 loc) · 3.1 KB
/
jquery.mobile.collapsibleSet.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: For creating grouped collapsible content areas.
//>>label: Collapsible Sets
//>>group: formatting
//>>css: ../css/themes/default/jquery.mobile.theme.css,../css/structure/jquery.mobile.collapsible.css
define( [ "jquery", "./jquery.mobile.widget", "./jquery.mobile.collapsible" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
$.widget( "mobile.collapsibleset", $.mobile.widget, {
options: {
initSelector: ":jqmData(role='collapsible-set')"
},
_create: function() {
var $el = this.element.addClass( "ui-collapsible-set" ),
o = this.options;
// Inherit the theme from collapsible-set
if ( !o.theme ) {
o.theme = $.mobile.getInheritedTheme( $el, "c" );
}
// Inherit the content-theme from collapsible-set
if ( !o.contentTheme ) {
o.contentTheme = $el.jqmData( "content-theme" );
}
if ( !o.corners ) {
o.corners = $el.jqmData( "corners" ) === undefined ? true : false;
}
// Initialize the collapsible set if it's not already initialized
if ( !$el.jqmData( "collapsiblebound" ) ) {
$el
.jqmData( "collapsiblebound", true )
.bind( "expand collapse", function( event ) {
var isCollapse = ( event.type === "collapse" ),
collapsible = $( event.target ).closest( ".ui-collapsible" ),
widget = collapsible.data( "collapsible" ),
contentTheme = widget.options.contentTheme;
if ( contentTheme && collapsible.jqmData( "collapsible-last" ) ) {
collapsible.find( widget.options.heading ).first()
.find( "a" ).first()
.add( ".ui-btn-inner" )
.toggleClass( "ui-corner-bottom", isCollapse );
collapsible.find( ".ui-collapsible-content" ).toggleClass( "ui-corner-bottom", !isCollapse );
}
})
.bind( "expand", function( event ) {
$( event.target )
.closest( ".ui-collapsible" )
.siblings( ".ui-collapsible" )
.trigger( "collapse" );
});
}
},
_init: function() {
this.refresh();
},
refresh: function() {
var $el = this.element,
o = this.options,
collapsiblesInSet = $el.children( ":jqmData(role='collapsible')" );
$.mobile.collapsible.prototype.enhance( collapsiblesInSet.not( ".ui-collapsible" ) );
// clean up borders
collapsiblesInSet.each( function() {
$( this ).find( $.mobile.collapsible.prototype.options.heading )
.find( "a" ).first()
.add( ".ui-btn-inner" )
.removeClass( "ui-corner-top ui-corner-bottom" );
});
collapsiblesInSet.first()
.find( "a" )
.first()
.addClass( o.corners ? "ui-corner-top" : "" )
.find( ".ui-btn-inner" )
.addClass( "ui-corner-top" );
collapsiblesInSet.last()
.jqmData( "collapsible-last", true )
.find( "a" )
.first()
.addClass( o.corners ? "ui-corner-bottom" : "" )
.find( ".ui-btn-inner" )
.addClass( "ui-corner-bottom" );
}
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$.mobile.collapsibleset.prototype.enhanceWithin( e.target );
});
})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");