diff --git a/bower.json b/bower.json index 48f237c..b1f486f 100644 --- a/bower.json +++ b/bower.json @@ -3,7 +3,7 @@ "main": [ "dist/angular-libphonenumber.min.js" ], - "version": "1.1.0", + "version": "1.1.1", "homepage": "https://github.com/cwill747/angular-libphonenumber", "authors": [ "Cameron Will " diff --git a/dist/angular-libphonenumber.js b/dist/angular-libphonenumber.js index 1439acd..168f39a 100644 --- a/dist/angular-libphonenumber.js +++ b/dist/angular-libphonenumber.js @@ -1,7 +1,7 @@ /** * angular-libphonenumber * Nathan Hammond's libphonenumber ported to an angular filter - * @version v1.1.0 + * @version v1.1.1 * @link https://github.com/cwill747/angular-libphonenumber * @license Apache-2.0 */ @@ -18,7 +18,7 @@ */ /* global angular */ angular.module('cwill747.phonenumber', []) - .directive('phoneNumber', ['$log', '$window', function($log, $window) { + .directive('phoneNumber', ['$log', '$timeout', '$window', function($log, $timeout, $window) { function clearValue(value) { if (!value) { return value; @@ -99,7 +99,10 @@ angular.module('cwill747.phonenumber', []) ctrl.$setViewValue(formattedValue); ctrl.$render(); - el.setSelectionRange(start, end); + // Fix selection range on mobile devices + $timeout(function() { + el.setSelectionRange(start, end); + }); //return cleaned; return clearValue(formattedValue); } diff --git a/dist/angular-libphonenumber.min.js b/dist/angular-libphonenumber.min.js index 5d276e2..813d965 100644 --- a/dist/angular-libphonenumber.min.js +++ b/dist/angular-libphonenumber.min.js @@ -1,8 +1,8 @@ /** * angular-libphonenumber * Nathan Hammond's libphonenumber ported to an angular filter - * @version v1.1.0 + * @version v1.1.1 * @link https://github.com/cwill747/angular-libphonenumber * @license Apache-2.0 */ -!function(e){e.module("cwill747.phonenumber",[]).directive("phoneNumber",["$log","$window",function(e,t){function n(e){return e?e.replace(/([^0-9|+])/g,""):e}function r(n,r){var o=n;try{o=t.phoneUtils.formatAsTyped(n,r)}catch(t){e.debug(t)}return o}return{restrict:"A",require:"?ngModel",scope:{countryCode:"=",nonFormatted:"=?"},controllerAs:"",controller:function(){this.countryCode=this.countryCode||"us"},link:function(o,u,i,l){function c(e){var t=n(e);o.nonFormatted=t;var u="";return u=t&&t.length>1?r(t,o.countryCode):t,u.trim()}function a(e){return l.$isEmpty(e)?e:r(n(e),o.countryCode)}function s(e){if(l.$isEmpty(e))return o.nonFormatted="",e;var t=c(e);if(t===e)return e;var r=d.selectionStart,u=d.selectionEnd+t.length-e.length;return e.lengtht.length+1&&(r-=t.length-e.length),l.$setViewValue(t),l.$render(),d.setSelectionRange(r,u),n(t)}function h(n){var r=!1;try{r=t.phoneUtils.isValidNumberForRegion(n,o.countryCode)}catch(t){e.debug(t)}var u=l.$isEmpty(n)||r;return l.$setValidity("phoneNumber",u),n}var d=u[0];o.$watch("countryCode",function(){l.$modelValue=l.$viewValue+" "}),l.$formatters.push(a),l.$formatters.push(h),l.$parsers.push(s),l.$parsers.push(h)}}}])}(angular); \ No newline at end of file +!function(t){t.module("cwill747.phonenumber",[]).directive("phoneNumber",["$log","$timeout","$window",function(t,e,n){function r(t){return t?t.replace(/([^0-9|+])/g,""):t}function o(e,r){var o=e;try{o=n.phoneUtils.formatAsTyped(e,r)}catch(e){t.debug(e)}return o}return{restrict:"A",require:"?ngModel",scope:{countryCode:"=",nonFormatted:"=?"},controllerAs:"",controller:function(){this.countryCode=this.countryCode||"us"},link:function(u,i,c,l){function a(t){var e=r(t);u.nonFormatted=e;var n="";return n=e&&e.length>1?o(e,u.countryCode):e,n.trim()}function s(t){return l.$isEmpty(t)?t:o(r(t),u.countryCode)}function h(t){if(l.$isEmpty(t))return u.nonFormatted="",t;var n=a(t);if(n===t)return t;var o=g.selectionStart,i=g.selectionEnd+n.length-t.length;return t.lengthn.length+1&&(o-=n.length-t.length),l.$setViewValue(n),l.$render(),e(function(){g.setSelectionRange(o,i)}),r(n)}function d(e){var r=!1;try{r=n.phoneUtils.isValidNumberForRegion(e,u.countryCode)}catch(e){t.debug(e)}var o=l.$isEmpty(e)||r;return l.$setValidity("phoneNumber",o),e}var g=i[0];u.$watch("countryCode",function(){l.$modelValue=l.$viewValue+" "}),l.$formatters.push(s),l.$formatters.push(d),l.$parsers.push(h),l.$parsers.push(d)}}}])}(angular); \ No newline at end of file diff --git a/package.json b/package.json index 4b5bd20..85523c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angular-libphonenumber", - "version": "1.1.0", + "version": "1.1.1", "description": "Nathan Hammond's libphonenumber ported to an angular filter", "main": "dist/angular-libphonenumber.min.js", "repository": { @@ -25,6 +25,7 @@ "jshint": "^2.9.4" }, "devDependencies": { + "bower": "~1.8.2", "event-stream": "3.3.4", "express": "4.14.1", "gulp": "^3.9.1", diff --git a/src/phone-number.js b/src/phone-number.js index 9a5a85d..0887ff8 100644 --- a/src/phone-number.js +++ b/src/phone-number.js @@ -9,7 +9,7 @@ */ /* global angular */ angular.module('cwill747.phonenumber', []) - .directive('phoneNumber', ['$log', '$window', function($log, $window) { + .directive('phoneNumber', ['$log', '$timeout', '$window', function($log, $timeout, $window) { function clearValue(value) { if (!value) { return value; @@ -90,7 +90,10 @@ angular.module('cwill747.phonenumber', []) ctrl.$setViewValue(formattedValue); ctrl.$render(); - el.setSelectionRange(start, end); + // Fix selection range on mobile devices + $timeout(function() { + el.setSelectionRange(start, end); + }); //return cleaned; return clearValue(formattedValue); }