-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from pra85/release
initialize $viewValue and Make release files minification friendly
- Loading branch information
Showing
4 changed files
with
134 additions
and
94 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
bower_components |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,97 +1,119 @@ | ||
(function() { | ||
"use strict"; | ||
angular.module("internationalPhoneNumber", []).directive('internationalPhoneNumber', function($timeout) { | ||
return { | ||
restrict: 'A', | ||
require: '^ngModel', | ||
scope: { | ||
ngModel: '=', | ||
defaultCountry: '@' | ||
}, | ||
link: function(scope, element, attrs, ctrl) { | ||
var handleWhatsSupposedToBeAnArray, options, read, watchOnce; | ||
read = function() { | ||
return ctrl.$setViewValue(element.val()); | ||
}; | ||
handleWhatsSupposedToBeAnArray = function(value) { | ||
if (value instanceof Array) { | ||
return value; | ||
} else { | ||
return value.toString().replace(/[ ]/g, '').split(','); | ||
} | ||
}; | ||
options = { | ||
autoFormat: true, | ||
autoHideDialCode: true, | ||
defaultCountry: '', | ||
nationalMode: false, | ||
numberType: '', | ||
onlyCountries: void 0, | ||
preferredCountries: ['us', 'gb'], | ||
responsiveDropdown: false, | ||
utilsScript: "" | ||
}; | ||
angular.forEach(options, function(value, key) { | ||
var option; | ||
if (!(attrs.hasOwnProperty(key) && angular.isDefined(attrs[key]))) { | ||
return; | ||
} | ||
option = attrs[key]; | ||
if (key === 'preferredCountries') { | ||
return options.preferredCountries = handleWhatsSupposedToBeAnArray(option); | ||
} else if (key === 'onlyCountries') { | ||
return options.onlyCountries = handleWhatsSupposedToBeAnArray(option); | ||
} else if (typeof value === "boolean") { | ||
return options[key] = option === "true"; | ||
} else { | ||
return options[key] = option; | ||
angular.module("internationalPhoneNumber", []).directive('internationalPhoneNumber', [ | ||
'$timeout', function($timeout) { | ||
return { | ||
restrict: 'A', | ||
require: '^ngModel', | ||
scope: { | ||
ngModel: '=', | ||
defaultCountry: '@' | ||
}, | ||
link: function(scope, element, attrs, ctrl) { | ||
var handleWhatsSupposedToBeAnArray, options, read, watchOnce; | ||
if (ctrl) { | ||
if (element.val() !== '') { | ||
$timeout(function() { | ||
element.intlTelInput('setNumber', element.val()); | ||
return ctrl.$setViewValue(element.val()); | ||
}, 0); | ||
} | ||
} | ||
}); | ||
watchOnce = scope.$watch('ngModel', function(newValue) { | ||
return scope.$$postDigest(function() { | ||
options.defaultCountry = scope.defaultCountry; | ||
if (newValue !== null && newValue !== void 0 && newValue !== '') { | ||
element.val(newValue); | ||
read = function() { | ||
return ctrl.$setViewValue(element.val()); | ||
}; | ||
handleWhatsSupposedToBeAnArray = function(value) { | ||
if (value instanceof Array) { | ||
return value; | ||
} else { | ||
return value.toString().replace(/[ ]/g, '').split(','); | ||
} | ||
}; | ||
options = { | ||
autoFormat: true, | ||
autoHideDialCode: true, | ||
defaultCountry: '', | ||
nationalMode: false, | ||
numberType: '', | ||
onlyCountries: void 0, | ||
preferredCountries: ['us', 'gb'], | ||
responsiveDropdown: false, | ||
utilsScript: "" | ||
}; | ||
angular.forEach(options, function(value, key) { | ||
var option; | ||
if (!(attrs.hasOwnProperty(key) && angular.isDefined(attrs[key]))) { | ||
return; | ||
} | ||
element.intlTelInput(options); | ||
if (!(attrs.skipUtilScriptDownload !== void 0 || options.utilsScript)) { | ||
element.intlTelInput('loadUtils', '/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js'); | ||
option = attrs[key]; | ||
if (key === 'preferredCountries') { | ||
return options.preferredCountries = handleWhatsSupposedToBeAnArray(option); | ||
} else if (key === 'onlyCountries') { | ||
return options.onlyCountries = handleWhatsSupposedToBeAnArray(option); | ||
} else if (typeof value === "boolean") { | ||
return options[key] = option === "true"; | ||
} else { | ||
return options[key] = option; | ||
} | ||
return watchOnce(); | ||
}); | ||
}); | ||
ctrl.$formatters.push(function(value) { | ||
if (!value) { | ||
return value; | ||
} else { | ||
$timeout(function() { | ||
return element.intlTelInput('setNumber', value); | ||
}, 0); | ||
return element.val(); | ||
} | ||
}); | ||
ctrl.$parsers.push(function(value) { | ||
if (!value) { | ||
return value; | ||
} | ||
return value.replace(/[^\d]/g, ''); | ||
}); | ||
ctrl.$validators.internationalPhoneNumber = function(value) { | ||
if (!value) { | ||
return value; | ||
} else { | ||
return element.intlTelInput("isValidNumber"); | ||
} | ||
}; | ||
element.on('blur keyup change', function(event) { | ||
return scope.$apply(read); | ||
}); | ||
return element.on('$destroy', function() { | ||
element.intlTelInput('destroy'); | ||
return element.off('blur keyup change'); | ||
}); | ||
} | ||
}; | ||
}); | ||
watchOnce = scope.$watch('ngModel', function(newValue) { | ||
return scope.$$postDigest(function() { | ||
options.defaultCountry = scope.defaultCountry; | ||
if (newValue !== null && newValue !== void 0 && newValue !== '') { | ||
element.val(newValue); | ||
} | ||
element.intlTelInput(options); | ||
if (!(attrs.skipUtilScriptDownload !== void 0 || options.utilsScript)) { | ||
element.intlTelInput('loadUtils', '/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js'); | ||
} | ||
return watchOnce(); | ||
}); | ||
}); | ||
ctrl.$formatters.push(function(value) { | ||
if (!value) { | ||
return value; | ||
} else { | ||
$timeout(function() { | ||
return element.intlTelInput('setNumber', value); | ||
}, 0); | ||
return element.val(); | ||
} | ||
}); | ||
ctrl.$parsers.push(function(value) { | ||
if (!value) { | ||
return value; | ||
} | ||
return value.replace(/[^\d]/g, ''); | ||
}); | ||
ctrl.$validators.internationalPhoneNumber = function(value) { | ||
if (element.attr('required')) { | ||
if (!value) { | ||
return false; | ||
} else { | ||
return element.intlTelInput("isValidNumber"); | ||
} | ||
} else { | ||
if (element.intlTelInput("getSelectedCountryData").dialCode === value) { | ||
return true; | ||
} else { | ||
if (!value) { | ||
return true; | ||
} else { | ||
return element.intlTelInput("isValidNumber"); | ||
} | ||
} | ||
} | ||
}; | ||
element.on('blur keyup change', function(event) { | ||
return scope.$apply(read); | ||
}); | ||
return element.on('$destroy', function() { | ||
element.intlTelInput('destroy'); | ||
return element.off('blur keyup change'); | ||
}); | ||
} | ||
}; | ||
} | ||
]); | ||
|
||
}).call(this); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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