From 12e547a78e2eb6f1e7d7349507cd05d8a29b1eaa Mon Sep 17 00:00:00 2001 From: Leonardo Bispo de Oliveira Date: Wed, 16 Apr 2014 16:00:09 +0200 Subject: [PATCH 1/3] Added semi collon to the end of Lines - Most of linters are complaining about ; in the end of the line. --- src/ngAutocomplete.js | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ngAutocomplete.js b/src/ngAutocomplete.js index 3b0b33c..b027b21 100644 --- a/src/ngAutocomplete.js +++ b/src/ngAutocomplete.js @@ -40,45 +40,45 @@ angular.module( "ngAutocomplete", []) link: function(scope, element, attrs, controller) { //options for autocomplete - var opts - var watchEnter = false + var opts; + var watchEnter = false; //convert options provided to opts var initOpts = function() { - opts = {} + opts = {}; if (scope.options) { if (scope.options.watchEnter !== true) { - watchEnter = false + watchEnter = false; } else { - watchEnter = true + watchEnter = true; } if (scope.options.types) { - opts.types = [] - opts.types.push(scope.options.types) - scope.gPlace.setTypes(opts.types) + opts.types = []; + opts.types.push(scope.options.types); + scope.gPlace.setTypes(opts.types); } else { - scope.gPlace.setTypes([]) + scope.gPlace.setTypes([]); } if (scope.options.bounds) { - opts.bounds = scope.options.bounds - scope.gPlace.setBounds(opts.bounds) + opts.bounds = scope.options.bounds; + scope.gPlace.setBounds(opts.bounds); } else { - scope.gPlace.setBounds(null) + scope.gPlace.setBounds(null); } if (scope.options.country) { opts.componentRestrictions = { country: scope.options.country - } - scope.gPlace.setComponentRestrictions(opts.componentRestrictions) + }; + scope.gPlace.setComponentRestrictions(opts.componentRestrictions); } else { - scope.gPlace.setComponentRestrictions(null) + scope.gPlace.setComponentRestrictions(null); } } - } + }; if (scope.gPlace == undefined) { scope.gPlace = new google.maps.places.Autocomplete(element[0], {}); @@ -97,13 +97,13 @@ angular.module( "ngAutocomplete", []) } else { if (watchEnter) { - getPlace(result) + getPlace(result); } } } - }) + }); - //function to get retrieve the autocompletes first result using the AutocompleteService + //function to get retrieve the autocompletes first result using the AutocompleteService var getPlace = function(result) { var autocompleteService = new google.maps.places.AutocompleteService(); if (result.name.length > 0){ @@ -136,8 +136,8 @@ angular.module( "ngAutocomplete", []) //on focusout the value reverts, need to set it again. var watchFocusOut = element.on('focusout', function(event) { element.val(detailsResult.formatted_address); - element.unbind('focusout') - }) + element.unbind('focusout'); + }); }); } @@ -146,7 +146,7 @@ angular.module( "ngAutocomplete", []) } }); } - } + }; controller.$render = function () { var location = controller.$viewValue; @@ -155,10 +155,10 @@ angular.module( "ngAutocomplete", []) //watch options provided to directive scope.watchOptions = function () { - return scope.options + return scope.options; }; scope.$watch(scope.watchOptions, function () { - initOpts() + initOpts(); }, true); } From cb48a6ee235edc2d299b8a4aa13d879f8503a144 Mon Sep 17 00:00:00 2001 From: Leonardo Bispo de Oliveira Date: Wed, 16 Apr 2014 16:06:37 +0200 Subject: [PATCH 2/3] Removed opts variable - Removed the opts variable. It is not used outside initOpts. - Moved initOpts function to be inside the variable watcher. --- src/ngAutocomplete.js | 59 +++++++++++++------------------------------ 1 file changed, 18 insertions(+), 41 deletions(-) diff --git a/src/ngAutocomplete.js b/src/ngAutocomplete.js index b027b21..0860963 100644 --- a/src/ngAutocomplete.js +++ b/src/ngAutocomplete.js @@ -39,46 +39,7 @@ angular.module( "ngAutocomplete", []) link: function(scope, element, attrs, controller) { - //options for autocomplete - var opts; var watchEnter = false; - //convert options provided to opts - var initOpts = function() { - - opts = {}; - if (scope.options) { - - if (scope.options.watchEnter !== true) { - watchEnter = false; - } else { - watchEnter = true; - } - - if (scope.options.types) { - opts.types = []; - opts.types.push(scope.options.types); - scope.gPlace.setTypes(opts.types); - } else { - scope.gPlace.setTypes([]); - } - - if (scope.options.bounds) { - opts.bounds = scope.options.bounds; - scope.gPlace.setBounds(opts.bounds); - } else { - scope.gPlace.setBounds(null); - } - - if (scope.options.country) { - opts.componentRestrictions = { - country: scope.options.country - }; - scope.gPlace.setComponentRestrictions(opts.componentRestrictions); - } else { - scope.gPlace.setComponentRestrictions(null); - } - } - }; if (scope.gPlace == undefined) { scope.gPlace = new google.maps.places.Autocomplete(element[0], {}); @@ -158,9 +119,25 @@ angular.module( "ngAutocomplete", []) return scope.options; }; scope.$watch(scope.watchOptions, function () { - initOpts(); - }, true); + if (scope.options) { + watchEnter = scope.options.watchEnter; + + if (scope.options.types) + scope.gPlace.setTypes([ scope.options.types ]); + else + scope.gPlace.setTypes([]); + + if (scope.options.bounds) + scope.gPlace.setBounds(scope.options.bounds); + else + scope.gPlace.setBounds(null); + if (scope.options.country) + scope.gPlace.setComponentRestrictions({ country: scope.options.country }); + else + scope.gPlace.setComponentRestrictions(null); + } + }, true); } }; }); \ No newline at end of file From 4281dbce7936e68a3a3a86ec0668997fbb581659 Mon Sep 17 00:00:00 2001 From: Leonardo Bispo de Oliveira Date: Wed, 16 Apr 2014 16:13:52 +0200 Subject: [PATCH 3/3] Removed a not required if --- src/ngAutocomplete.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ngAutocomplete.js b/src/ngAutocomplete.js index 0860963..ee8e2a5 100644 --- a/src/ngAutocomplete.js +++ b/src/ngAutocomplete.js @@ -41,9 +41,8 @@ angular.module( "ngAutocomplete", []) var watchEnter = false; - if (scope.gPlace == undefined) { - scope.gPlace = new google.maps.places.Autocomplete(element[0], {}); - } + scope.gPlace = new google.maps.places.Autocomplete(element[0], {}); + google.maps.event.addListener(scope.gPlace, 'place_changed', function() { var result = scope.gPlace.getPlace(); if (result !== undefined) {