@@ -15,9 +15,7 @@ if (typeof jQuery === 'undefined') {
1515( function ( $ ) {
1616 var Checkboxpicker = function ( element , options ) {
1717 this . element = element ;
18-
19- // Change .prop('hidden', true) -> .hide() in future
20- this . $element = $ ( element ) . prop ( 'hidden' , true ) ;
18+ this . $element = $ ( element ) . hide ( ) ;
2119
2220 this . options = $ . extend ( { } , $ . fn . checkboxpicker . defaults , options , this . $element . data ( ) ) ;
2321
@@ -65,19 +63,20 @@ if (typeof jQuery === 'undefined') {
6563
6664 if ( this . element . disabled ) {
6765 this . $buttons . addClass ( 'disabled' ) ;
68- this . $group . css ( 'cursor' , 'not-allowed' ) ;
6966 }
7067 else {
71- this . $element . change ( this . render . bind ( this ) ) ;
68+ this . $element . change ( this . toggle . bind ( this ) ) ;
7269
73- this . $group . attr ( 'tabindex' , 0 ) ;
70+ this . $group . attr ( 'tabindex' , this . element . tabIndex ) ;
7471
7572 if ( this . element . autofocus ) {
7673 this . $group . focus ( ) ;
7774 }
75+
76+ $ ( this . element . form ) . on ( 'reset' , this . reset . bind ( this ) ) ;
7877 }
7978 } ,
80- render : function ( ) {
79+ toggle : function ( ) {
8180 this . $group . not ( ':focus' ) . focus ( ) ;
8281 this . $buttons . toggleClass ( 'active ' + this . options . defaultClass ) ;
8382 this . $off . toggleClass ( this . options . offClass ) ;
@@ -99,12 +98,24 @@ if (typeof jQuery === 'undefined') {
9998
10099 this . change ( ) ;
101100 }
101+ } ,
102+ reset : function ( ) {
103+ if ( ( this . element . defaultChecked && this . $off . hasClass ( 'active' ) ) || ( ! this . element . defaultChecked && this . $on . hasClass ( 'active' ) ) ) {
104+ this . toggle ( ) ;
105+ }
102106 }
103107 } ;
104108
105109 $ . fn . checkboxpicker = function ( options ) {
106110 return this . each ( function ( ) {
107- new Checkboxpicker ( this , options ) ;
111+ var $this = $ ( this ) ;
112+ var data = $this . data ( 'checkboxpicker' ) ;
113+
114+ if ( ! data ) {
115+ new Checkboxpicker ( this , options ) ;
116+
117+ $this . data ( 'checkboxpicker' , true ) ;
118+ }
108119 } ) ;
109120 } ;
110121
0 commit comments