From add0b933670444d042bccda491c55186ca0a5b4e Mon Sep 17 00:00:00 2001 From: Kosta Korenkov <7r0ggy@gmail.com> Date: Wed, 30 Dec 2015 20:07:47 +0300 Subject: [PATCH 1/6] Use intl-tel-input 7.0.0 In has API changes, hence major version number was bumped: - Handler for ``geoIpLocate`` now should be specified by caller, if he wants to use ``initialCountry`` set to ``auto``. - Rename ``selectCountry`` to ``setCountry`` - Rename ``defaultCountry`` to ``initialCountry`` --- bower.json | 3 ++- package.json | 2 +- releases/international-phone-number.js | 4 ++-- releases/international-phone-number.min.js | 4 ++-- src/international-phone-number.coffee | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bower.json b/bower.json index 85ed0fb..0edc858 100644 --- a/bower.json +++ b/bower.json @@ -1,11 +1,12 @@ { "name": "international-phone-number", + "version": "1.0.0", "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.3.0", - "intl-tel-input": "~5.1.0" + "intl-tel-input": "~7.0.0" } } diff --git a/package.json b/package.json index ac92b3f..0f28dd7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "international-phone-number", - "version": "0.0.11", + "version": "1.0.0", "description": "AngularJS directive for intl-tel-input jQuery plugin", "keywords": [ "international", diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index 3c9a66d..66f874b 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -6,7 +6,7 @@ autoHideDialCode: true, autoPlaceholder: true, customPlaceholder: null, - defaultCountry: "", + initialCountry: "", geoIpLookup: null, nationalMode: true, numberType: "MOBILE", @@ -77,7 +77,7 @@ }); scope.$watch('country', function(newValue) { if (newValue !== null && newValue !== void 0 && newValue !== '') { - return element.intlTelInput("selectCountry", newValue); + return element.intlTelInput("setCountry", newValue); } }); ctrl.$formatters.push(function(value) { diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index 315b32c..c8663a8 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2015-12-21 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,defaultCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"="},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(h),h.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("selectCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2015-12-30 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"="},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(h),h.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file diff --git a/src/international-phone-number.coffee b/src/international-phone-number.coffee index 3177860..69a8b62 100644 --- a/src/international-phone-number.coffee +++ b/src/international-phone-number.coffee @@ -10,7 +10,7 @@ angular.module("internationalPhoneNumber", []) autoHideDialCode: true autoPlaceholder: true customPlaceholder: null - defaultCountry: "" + initialCountry: "" geoIpLookup: null nationalMode: true numberType: "MOBILE" @@ -84,7 +84,7 @@ angular.module("internationalPhoneNumber", []) scope.$watch('country', (newValue) -> if newValue != null && newValue != undefined && newValue != '' - element.intlTelInput("selectCountry", newValue) + element.intlTelInput("setCountry", newValue) ) ctrl.$formatters.push (value) -> From 58bd311fbe9f081f2c956c26906dd477e98017d6 Mon Sep 17 00:00:00 2001 From: Kosta Korenkov <7r0ggy@gmail.com> Date: Wed, 30 Dec 2015 20:36:24 +0300 Subject: [PATCH 2/6] Set geoIpLookup as function, not string --- releases/international-phone-number.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index 66f874b..2d1d2be 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -21,7 +21,8 @@ require: '^ngModel', scope: { ngModel: '=', - country: '=' + country: '=', + geoIpLookup: '&' }, link: function(scope, element, attrs, ctrl) { var handleWhatsSupposedToBeAnArray, options, read, watchOnce; @@ -60,6 +61,7 @@ return options[key] = option; } }); + options['geoIpLookup'] = scope.geoIpLookup ? scope.geoIpLookup() : null; watchOnce = scope.$watch('ngModel', function(newValue) { return scope.$$postDigest(function() { if (newValue !== null && newValue !== void 0 && newValue.length > 0) { From 3cda2c9727020484b43970c725849e90081b7fe7 Mon Sep 17 00:00:00 2001 From: Kosta Korenkov <7r0ggy@gmail.com> Date: Mon, 4 Jan 2016 22:22:11 +0300 Subject: [PATCH 3/6] Fix last commit: change to src and uglified version --- releases/international-phone-number.min.js | 4 ++-- src/international-phone-number.coffee | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index c8663a8..9d42ccc 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2015-12-30 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"="},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(h),h.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2016-01-04 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"=",geoIpLookup:"&"},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),h.geoIpLookup=c.geoIpLookup?c.geoIpLookup():null,j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(h),h.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file diff --git a/src/international-phone-number.coffee b/src/international-phone-number.coffee index 69a8b62..4aad985 100644 --- a/src/international-phone-number.coffee +++ b/src/international-phone-number.coffee @@ -27,6 +27,7 @@ angular.module("internationalPhoneNumber", []) scope: ngModel: '=' country: '=' + geoIpLookup: '&' link: (scope, element, attrs, ctrl) -> @@ -60,7 +61,7 @@ angular.module("internationalPhoneNumber", []) options[key] = (option == "true") else options[key] = option - + options['geoIpLookup'] = if scope.geoIpLookup then scope.geoIpLookup() else null # Wait for ngModel to be set watchOnce = scope.$watch('ngModel', (newValue) -> # Wait to see if other scope variables were set at the same time From 371e9f9ec819bce1d0668d234bafe5ce752e8a1b Mon Sep 17 00:00:00 2001 From: Diones Franco de Andrade Date: Fri, 8 Jan 2016 12:37:38 -0200 Subject: [PATCH 4/6] Adding readonly option --- releases/international-phone-number.js | 22 +++++++++++++++++++++- releases/international-phone-number.min.js | 4 ++-- src/international-phone-number.coffee | 17 +++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index 2d1d2be..a7f8018 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -25,7 +25,7 @@ geoIpLookup: '&' }, link: function(scope, element, attrs, ctrl) { - var handleWhatsSupposedToBeAnArray, options, read, watchOnce; + var checkReadOnly, handleWhatsSupposedToBeAnArray, options, read, watchOnce; if (ctrl) { if (element.val() !== '') { $timeout(function() { @@ -44,6 +44,25 @@ return value.toString().replace(/[ ]/g, '').split(','); } }; + checkReadOnly = function() { + var divIntlTelInput, readOnly, readOnlyClass, readOnlySpan; + readOnly = attrs.readonly; + if (readOnly) { + readOnlyClass = 'intl-tel-input-read-only'; + divIntlTelInput = element.parents('.intl-tel-input:first'); + divIntlTelInput.find('select:first').attr('disabled', true); + divIntlTelInput.find('.iti-arrow').hide(); + readOnlySpan = divIntlTelInput.find('span.' + readOnlyClass); + if (readOnlySpan.length === 0) { + readOnlySpan = angular.element(''); + readOnlySpan.attr('class', readOnlyClass); + readOnlySpan.attr('style', 'padding-left: 38px'); + element.hide(); + element.after(readOnlySpan); + } + return readOnlySpan.text(element.val()); + } + }; options = angular.copy(ipnConfig); angular.forEach(options, function(value, key) { var option; @@ -87,6 +106,7 @@ return value; } element.intlTelInput('setNumber', value); + checkReadOnly(); return element.val(); }); ctrl.$parsers.push(function(value) { diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index 9d42ccc..a39da88 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2016-01-04 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"=",geoIpLookup:"&"},link:function(c,d,e,f){var g,h,i,j;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),i=function(){return f.$setViewValue(d.val())},g=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},h=angular.copy(b),angular.forEach(h,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?h.preferredCountries=g(c):"onlyCountries"===b?h.onlyCountries=g(c):"boolean"==typeof a?h[b]="true"===c:h[b]=c}),h.geoIpLookup=c.geoIpLookup?c.geoIpLookup():null,j=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(h),h.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||h.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),j()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(i)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2016-01-08 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"=",geoIpLookup:"&"},link:function(c,d,e,f){var g,h,i,j,k;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),j=function(){return f.$setViewValue(d.val())},h=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},g=function(){var a,b,c,f;return b=e.readonly,b?(c="intl-tel-input-read-only",a=d.parents(".intl-tel-input:first"),a.find("select:first").attr("disabled",!0),a.find(".iti-arrow").hide(),f=a.find("span."+c),0===f.length&&(f=angular.element(""),f.attr("class",c),f.attr("style","padding-left: 38px"),d.hide(),d.after(f)),f.text(d.val())):void 0},i=angular.copy(b),angular.forEach(i,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?i.preferredCountries=h(c):"onlyCountries"===b?i.onlyCountries=h(c):"boolean"==typeof a?i[b]="true"===c:i[b]=c}),i.geoIpLookup=c.geoIpLookup?c.geoIpLookup():null,k=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(i),i.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||i.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),k()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),g(),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(j)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file diff --git a/src/international-phone-number.coffee b/src/international-phone-number.coffee index 4aad985..7cf0c51 100644 --- a/src/international-phone-number.coffee +++ b/src/international-phone-number.coffee @@ -48,6 +48,22 @@ angular.module("internationalPhoneNumber", []) else value.toString().replace(/[ ]/g, '').split(',') + checkReadOnly = () -> + readOnly = attrs.readonly + if readOnly + readOnlyClass = 'intl-tel-input-read-only' + divIntlTelInput = element.parents('.intl-tel-input:first') + divIntlTelInput.find('select:first').attr('disabled', true) + divIntlTelInput.find('.iti-arrow').hide() + readOnlySpan = divIntlTelInput.find('span.' + readOnlyClass) + if readOnlySpan.length == 0 + readOnlySpan = angular.element('') + readOnlySpan.attr('class', readOnlyClass) + readOnlySpan.attr('style', 'padding-left: 38px') + element.hide() + element.after(readOnlySpan) + readOnlySpan.text(element.val()) + options = angular.copy(ipnConfig) angular.forEach options, (value, key) -> @@ -93,6 +109,7 @@ angular.module("internationalPhoneNumber", []) return value element.intlTelInput 'setNumber', value + checkReadOnly() element.val() ctrl.$parsers.push (value) -> From 7f3309cabfe2a7c7842fe5041634a313ef5816b5 Mon Sep 17 00:00:00 2001 From: Diones Franco de Andrade Date: Fri, 8 Jan 2016 12:42:11 -0200 Subject: [PATCH 5/6] Adding read only example to README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index e43d427..cf96b1e 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,11 @@ with countries only: ``` +read only field: +```html + +``` + Feel free to mix options together: ```html From 5fa2b1edff5c2a2dc77fc9289d91b8b717cc047b Mon Sep 17 00:00:00 2001 From: Diones Franco de Andrade Date: Mon, 8 Feb 2016 12:27:42 -0200 Subject: [PATCH 6/6] Fix: A readonly span was being added in duplicity --- releases/international-phone-number.js | 4 ++-- releases/international-phone-number.min.js | 4 ++-- src/international-phone-number.coffee | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/releases/international-phone-number.js b/releases/international-phone-number.js index a7f8018..f038b2d 100644 --- a/releases/international-phone-number.js +++ b/releases/international-phone-number.js @@ -53,14 +53,14 @@ divIntlTelInput.find('select:first').attr('disabled', true); divIntlTelInput.find('.iti-arrow').hide(); readOnlySpan = divIntlTelInput.find('span.' + readOnlyClass); - if (readOnlySpan.length === 0) { + if (readOnlySpan.length === 0 && element.val() !== '') { readOnlySpan = angular.element(''); readOnlySpan.attr('class', readOnlyClass); readOnlySpan.attr('style', 'padding-left: 38px'); element.hide(); element.after(readOnlySpan); } - return readOnlySpan.text(element.val()); + readOnlySpan.text(element.val()); } }; options = angular.copy(ipnConfig); diff --git a/releases/international-phone-number.min.js b/releases/international-phone-number.min.js index a39da88..35d5da5 100644 --- a/releases/international-phone-number.min.js +++ b/releases/international-phone-number.min.js @@ -1,2 +1,2 @@ -/*! international-phone-number 2016-01-08 */ -(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"=",geoIpLookup:"&"},link:function(c,d,e,f){var g,h,i,j,k;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),j=function(){return f.$setViewValue(d.val())},h=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},g=function(){var a,b,c,f;return b=e.readonly,b?(c="intl-tel-input-read-only",a=d.parents(".intl-tel-input:first"),a.find("select:first").attr("disabled",!0),a.find(".iti-arrow").hide(),f=a.find("span."+c),0===f.length&&(f=angular.element(""),f.attr("class",c),f.attr("style","padding-left: 38px"),d.hide(),d.after(f)),f.text(d.val())):void 0},i=angular.copy(b),angular.forEach(i,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?i.preferredCountries=h(c):"onlyCountries"===b?i.onlyCountries=h(c):"boolean"==typeof a?i[b]="true"===c:i[b]=c}),i.geoIpLookup=c.geoIpLookup?c.geoIpLookup():null,k=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(i),i.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||i.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),k()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),g(),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(j)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file +/*! international-phone-number 2016-02-08 */ +(function(){"use strict";angular.module("internationalPhoneNumber",[]).constant("ipnConfig",{allowExtensions:!1,autoFormat:!0,autoHideDialCode:!0,autoPlaceholder:!0,customPlaceholder:null,initialCountry:"",geoIpLookup:null,nationalMode:!0,numberType:"MOBILE",onlyCountries:void 0,preferredCountries:["us","gb"],skipUtilScriptDownload:!1,utilsScript:""}).directive("internationalPhoneNumber",["$timeout","ipnConfig",function(a,b){return{restrict:"A",require:"^ngModel",scope:{ngModel:"=",country:"=",geoIpLookup:"&"},link:function(c,d,e,f){var g,h,i,j,k;return f&&""!==d.val()&&a(function(){return d.intlTelInput("setNumber",d.val()),f.$setViewValue(d.val())},0),j=function(){return f.$setViewValue(d.val())},h=function(a){return a instanceof Array?a:a.toString().replace(/[ ]/g,"").split(",")},g=function(){var a,b,c,f;b=e.readonly,b&&(c="intl-tel-input-read-only",a=d.parents(".intl-tel-input:first"),a.find("select:first").attr("disabled",!0),a.find(".iti-arrow").hide(),f=a.find("span."+c),0===f.length&&""!==d.val()&&(f=angular.element(""),f.attr("class",c),f.attr("style","padding-left: 38px"),d.hide(),d.after(f)),f.text(d.val()))},i=angular.copy(b),angular.forEach(i,function(a,b){var c;if(e.hasOwnProperty(b)&&angular.isDefined(e[b]))return c=e[b],"preferredCountries"===b?i.preferredCountries=h(c):"onlyCountries"===b?i.onlyCountries=h(c):"boolean"==typeof a?i[b]="true"===c:i[b]=c}),i.geoIpLookup=c.geoIpLookup?c.geoIpLookup():null,k=c.$watch("ngModel",function(a){return c.$$postDigest(function(){return null!==a&&void 0!==a&&a.length>0&&("+"!==a[0]&&(a="+"+a),f.$modelValue=a),d.intlTelInput(i),i.skipUtilScriptDownload||void 0!==e.skipUtilScriptDownload||i.utilsScript||d.intlTelInput("loadUtils","/bower_components/intl-tel-input/lib/libphonenumber/build/utils.js"),k()})}),c.$watch("country",function(a){return null!==a&&void 0!==a&&""!==a?d.intlTelInput("setCountry",a):void 0}),f.$formatters.push(function(a){return a?(d.intlTelInput("setNumber",a),g(),d.val()):a}),f.$parsers.push(function(a){return a?a.replace(/[^\d]/g,""):a}),f.$validators.internationalPhoneNumber=function(a){var b;return b=d.intlTelInput("getSelectedCountryData"),!a||b&&b.dialCode===a?!0:d.intlTelInput("isValidNumber")},d.on("blur keyup change",function(a){return c.$apply(j)}),d.on("$destroy",function(){return d.intlTelInput("destroy"),d.off("blur keyup change")})}}}])}).call(this); \ No newline at end of file diff --git a/src/international-phone-number.coffee b/src/international-phone-number.coffee index 7cf0c51..e03bcd0 100644 --- a/src/international-phone-number.coffee +++ b/src/international-phone-number.coffee @@ -56,13 +56,14 @@ angular.module("internationalPhoneNumber", []) divIntlTelInput.find('select:first').attr('disabled', true) divIntlTelInput.find('.iti-arrow').hide() readOnlySpan = divIntlTelInput.find('span.' + readOnlyClass) - if readOnlySpan.length == 0 + if readOnlySpan.length == 0 and element.val() != '' readOnlySpan = angular.element('') readOnlySpan.attr('class', readOnlyClass) readOnlySpan.attr('style', 'padding-left: 38px') element.hide() element.after(readOnlySpan) readOnlySpan.text(element.val()) + return options = angular.copy(ipnConfig)