29
29
this . options = $ . extend ( { } , $ . fn . bfhphone . defaults , options )
30
30
this . $element = $ ( element )
31
31
if ( this . $element . is ( 'input[type="text"]' ) || this . $element . is ( 'input[type="tel"]' ) ) {
32
- this . $element . on ( 'propertychange.bfhphone.data-api change.bfhphone.data-api input.bfhphone.data-api keyup.bfhphone.data-api paste.bfhphone.data-api' , { phoneObject : this } , this . change )
33
-
34
32
var country = this . options . country
35
33
36
34
var formObject = this . $element . closest ( 'form' )
40
38
41
39
if ( countryObject . length != 0 ) {
42
40
this . options . format = BFHPhoneFormatList [ countryObject . val ( ) ]
43
- countryObject . on ( 'change.bfhphone.data-api' , { phoneObject : this } , this . changeCountry )
44
41
} else {
45
42
this . options . format = BFHPhoneFormatList [ country ]
46
43
}
100
97
, addFormatter : function ( ) {
101
98
var formattedNumber = this . getFormattedNumber ( )
102
99
100
+ this . $element . addClass ( 'disabled' ) ;
103
101
this . $element . val ( formattedNumber )
102
+ this . $element . removeClass ( 'disabled' ) ;
104
103
}
105
104
106
105
, displayFormatter : function ( ) {
111
110
112
111
, changeCountry : function ( e ) {
113
112
var $this = $ ( this )
114
- var phoneObject = e . data . phoneObject
113
+ var phoneObject = $ ( this ) . data ( 'bfhphone' )
115
114
116
115
phoneObject . options . format = BFHPhoneFormatList [ $this . val ( ) ]
117
116
121
120
, change : function ( e ) {
122
121
var $this
123
122
124
- $this = e . data . phoneObject
123
+ $this = $ ( this ) . data ( 'bfhphone' )
125
124
126
- if ( $this . $element . is ( '.disabled, :disabled' ) ) return
125
+ if ( $this . $element . is ( '.disabled, :disabled' ) ) return false
127
126
128
127
var number = $this . $element . val ( )
129
128
var newNumber = ""
177
176
$phone . bfhphone ( $phone . data ( ) )
178
177
} )
179
178
} )
179
+
180
+ $ ( function ( ) {
181
+ $ ( 'body' )
182
+ . on ( 'propertychange.bfhphone.data-api change.bfhphone.data-api input.bfhphone.data-api keyup.bfhphone.data-api paste.bfhphone.data-api' , '.bfh-phone' , BFHPhone . prototype . change )
183
+ . on ( 'change.bfhphone.data-api' , '.bfh-country' , BFHPhone . prototype . changeCountry )
184
+ } )
180
185
181
186
} ( window . jQuery ) ;
0 commit comments