Created
September 14, 2012 07:41
-
-
Save dordenis/3720567 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Phone = function(input) { | |
var $this = this; | |
this.input = input; | |
this.init = function(options) { | |
this.option = this.cloneObj(options); | |
this.bild(); | |
}; | |
this.bild = function() { | |
var val = this.input.val().split(' '); | |
var val1 = val[0]; | |
var val2 = val[1]; | |
this.input1 = $('<input>').keydown(this.keydown).blur(this.setValue).addClass('span1').val(val1).attr('type', 'text').attr('placeholder', 'код'); | |
this.input2 = $('<input>').keydown(this.keydown).blur(this.setValue).addClass('span2').val(val2).attr('type', 'text').attr('placeholder', 'номер телефона'); | |
this.input.hide().after(this.input1, this.input2); | |
}; | |
this.keydown = function(event) { | |
if (event.which < 58 || (event.which > 95 && event.which < 106)) { | |
return true; | |
} | |
event.preventDefault(); | |
}; | |
this.setValue = function() { | |
$this.input.val($this.input1.val()+' '+$this.input2.val()); | |
}; | |
this.cloneObj = function(obj) { | |
var ret = {}; | |
for ( var k in obj ) | |
ret[k] = obj[k]; | |
return ret; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment