Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle current content + allow to keep model clean #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "international-phone-number",
"version": "0.0.1",
"version": "0.0.4",
"main": "releases/international-phone-number.js",
"description": "AngularJS directive for intl-tel-input jQuery plugin",
"author": "Marek Pietrucha (http://enginearch.com)",
"license": "MIT",
"dependencies": {
"angular": "~1.2.9",
"intl-tel-input": "~3.6.5"
"intl-tel-input": "~5.1.0"
}
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "international-phone-number",
"version": "0.0.1",
"version": "0.0.2",
"description": "AngularJS directive for intl-tel-input jQuery plugin",
"keywords": [
"international",
Expand All @@ -20,6 +20,6 @@
"author": "Marek Pietrucha (http://enginearch.com)",
"repository": {
"type": "git",
"url": "https://github.com/mareczek/international-phone-number.git"
"url": "https://github.com/yhourdel/international-phone-number.git"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing the URL?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I'm using this version in my project and I believe bower needs the URL to pull the repo. Of course you will need to put your repo's URL back into place afterwards.

}
}
}
28 changes: 21 additions & 7 deletions releases/international-phone-number.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion releases/international-phone-number.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions src/international-phone-number.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/mareczek/international-phone-number

"use strict"
angular.module("internationalPhoneNumber", []).directive 'internationalPhoneNumber', () ->
angular.module("internationalPhoneNumber", []).directive 'internationalPhoneNumber', ($timeout) ->

restrict: 'A'
require: '^ngModel'
Expand All @@ -29,27 +29,38 @@ angular.module("internationalPhoneNumber", []).directive 'internationalPhoneNumb
preferredCountries: ['us', 'gb']
responsiveDropdown: false
utilsScript: ""
keepModelClean: false

angular.forEach options, (value, key) ->
option = eval("attrs.#{key}")
if angular.isDefined(option)
if key == 'preferredCountries'
options.preferredCountries = handleWhatsSupposedToBeAnArray option
else if key == 'onlyCountries'
options.onlyCountries = handleWhatsSupposedToBeAnArray option
options.onlyCountries = handleWhatsSupposedToBeAnArray option
else if typeof(value) == "boolean"
options[key] = (option == "true")
else
options[key] = option

element.intlTelInput(options)
# timeout so that the angular content has time to execute
$timeout ->
element.intlTelInput(options)
if options.nationalMode
selectedCountryData = element.intlTelInput('getSelectedCountryData')
return true unless selectedCountryData
newNumber = element.val().replace new RegExp("\\+#{selectedCountryData.dialCode}"), 0
element.intlTelInput 'setNumber', newNumber

unless options.utilsScript
element.intlTelInput('loadUtils', 'bower_components/intl-tel-input/lib/libphonenumber/build/utils.js')

ctrl.$parsers.push (value) ->
return value if !value
value.replace(/[^\d]/g, '')
if options.keepModelClean
element.intlTelInput('getNumber')
else
value.replace(/[^\d]/g, '')

ctrl.$parsers.push (value) ->
if value
Expand Down