|
7 | 7 | <link rel="stylesheet" href="../demos.css">
|
8 | 8 | <script src="../../external/requirejs/require.js"></script>
|
9 | 9 | <script src="../bootstrap.js" data-modules="controlgroup">
|
10 |
| - $( "input" ).checkboxradio(); |
11 |
| - $( "[name='shape']").on( "change", function(){ |
12 |
| - $( ".shape" ).removeClass( "circle pill square rectangle" ) |
13 |
| - .addClass( $( this ).val() ); |
14 |
| - }); |
15 |
| - $( ".toggle" ).on( "change", function(){ |
16 |
| - if ( $( this ).is( ".brand-toggle" ) ) { |
17 |
| - var checked = $( this ).is( ":checked" ), |
18 |
| - value = $( "[name='brand']" ).filter( ":checked" ).attr( "data-" + this.id ) |
19 |
| - $( ".shape" ).css( this.id, checked ? value : "" ); |
| 10 | + function handleShape( e ) { |
| 11 | + $( ".shape" ) |
| 12 | + .removeClass( "circle pill square rectangle" ) |
| 13 | + .addClass( $( e.target ).val() ); |
| 14 | + }; |
| 15 | + function handleToggle( e ) { |
| 16 | + var target = $( e.target ); |
| 17 | + |
| 18 | + if ( target.is( ".brand-toggle" ) ) { |
| 19 | + var checked = target.is( ":checked" ), |
| 20 | + value = $( "[name='brand']" ) |
| 21 | + .filter( ":checked" ) |
| 22 | + .attr( "data-" + target[ 0 ].id ) |
| 23 | + $( ".shape" ).css( target[ 0 ].id, checked ? value : "" ); |
20 | 24 | } else {
|
21 |
| - $( ".shape" ).toggleClass( this.id, $( this ).is( ":checked") ); |
| 25 | + $( ".shape" ).toggleClass( target[ 0 ].id, target.is( ":checked") ); |
22 | 26 | }
|
23 |
| - }); |
24 |
| - $( "[name='brand']").on( "change", function(){ |
25 |
| - $( "input" ).filter( ":checked" ).not( this ).trigger( "change" ); |
26 |
| - }); |
27 |
| - $( "input" ).filter( ":checked" ).trigger( "change" ); |
| 27 | + } |
| 28 | + function updateBrand() { |
| 29 | + handleShape( { target: $( "[name='shape']:checked" ) } ); |
| 30 | + $( ".toggle:checked" ).each( function() { |
| 31 | + handleToggle( { target: $( this ) } ); |
| 32 | + } ); |
| 33 | + } |
| 34 | + |
| 35 | + // Initalize widgets |
| 36 | + $( "input" ).checkboxradio(); |
28 | 37 | $( ".shape-bar, .brand" ).controlgroup();
|
29 |
| - $( ".toggles" ).controlgroup({ |
| 38 | + $( ".toggles" ).controlgroup( { |
30 | 39 | direction: "vertical"
|
31 |
| - }); |
| 40 | + } ); |
| 41 | + |
| 42 | + // Bind event handlers |
| 43 | + $( "[name='shape']").on( "change", handleShape ); |
| 44 | + $( ".toggle" ).on( "change", handleToggle ); |
| 45 | + $( "[name='brand']").on( "change", updateBrand ); |
| 46 | + |
| 47 | + // Set initial values |
| 48 | + updateBrand(); |
32 | 49 | </script>
|
33 | 50 | <style>
|
34 | 51 | .shape {
|
|
74 | 91 | <h3>1.) Select a brand</h3>
|
75 | 92 | <div class="brand">
|
76 | 93 | <label for="brand-jquery">jQuery</label>
|
77 |
| - <input data-background-color="#0769AD" data-color="#7ACEF4" data-background-image="url(images/jquery.png)" type="radio" name="brand" id="brand-jquery"> |
| 94 | + <input type="radio" name="brand" id="brand-jquery" data-background-color="#0769AD" data-color="#7ACEF4" data-background-image="url(images/jquery.png)"> |
78 | 95 | <label for="brand-jquery-ui">jQuery UI</label>
|
79 |
| - <input data-background-color="#B24926" data-color="#FAA523" data-background-image="url(images/jquery-ui.png)" type="radio" name="brand" id="brand-jquery-ui" checked> |
| 96 | + <input type="radio" name="brand" id="brand-jquery-ui" data-background-color="#B24926" data-color="#FAA523" data-background-image="url(images/jquery-ui.png)" checked> |
80 | 97 | <label for="brand-jquery-mobile">jQuery Mobile</label>
|
81 |
| - <input data-background-color="#108040" data-color="#3EB249" data-background-image="url(images/jquery-mobile.png)" type="radio" name="brand" id="brand-jquery-mobile"> |
| 98 | + <input type="radio" name="brand" id="brand-jquery-mobile" data-background-color="#108040" data-color="#3EB249" data-background-image="url(images/jquery-mobile.png)"> |
82 | 99 | <label for="brand-sizzle">Sizzle</label>
|
83 |
| - <input data-background-color="#9A1B1E" data-color="#FAA523" data-background-image="url(images/sizzle.png)" type="radio" name="brand" id="brand-sizzle"> |
| 100 | + <input type="radio" name="brand" id="brand-sizzle" data-background-color="#9A1B1E" data-color="#FAA523" data-background-image="url(images/sizzle.png)"> |
84 | 101 | <label for="brand-qunit">QUnit</label>
|
85 |
| - <input data-background-color="#390F39" data-color="#9C3493" data-background-image="url(images/qunit.png)" type="radio" name="brand" id="brand-qunit"> |
| 102 | + <input type="radio" name="brand" id="brand-qunit" data-background-color="#390F39" data-color="#9C3493" data-background-image="url(images/qunit.png)"> |
86 | 103 | </div>
|
87 | 104 | </div>
|
88 | 105 | <div class="shape-wrap">
|
|
0 commit comments