From 0d6af22fa1be1753cc985b669d4ed55d9984b294 Mon Sep 17 00:00:00 2001 From: Sam Leighton Date: Thu, 23 Jul 2020 09:40:19 +1000 Subject: [PATCH 1/2] update readme to note API requirements of map --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7f028f1..6df40aa 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Address field powered by Google's dataset ([commerceguys/addressing](https://git Features: * Auto-complete powered by Google Place API +* Map powered by Google Maps Javascript API and Google Maps Geocoding API * Address form formatting based on country powered by [commerceguys/addressing](https://github.com/commerceguys/addressing) * Validation / Geo-coding on submission (TODO) @@ -143,10 +144,10 @@ of the Composer documentation. ### Step 2: Install Install plugin in the Craft Control Panel under Settings > Plugins. - + ## Configuration -The plugin comes with a config.php file that defines some sensible defaults. +The plugin comes with a config.php file that defines some sensible defaults. Copy `src/config.php` to `CRAFT_CONFIG_PATH` and rename the file to `nsm-fields.php`. From ca6e742df90dbcc727f74925db5a04737e2efef2 Mon Sep 17 00:00:00 2001 From: Sam Leighton Date: Thu, 23 Jul 2020 12:11:43 +1000 Subject: [PATCH 2/2] fix error with google instantiation --- .../addressfield/dist/js/Address.js | 520 ++++++++++-------- src/fields/Address.php | 1 + .../fieldtypes/Address/settings.twig | 2 + 3 files changed, 280 insertions(+), 243 deletions(-) diff --git a/src/assetbundles/addressfield/dist/js/Address.js b/src/assetbundles/addressfield/dist/js/Address.js index 6951ef8..e0fb777 100644 --- a/src/assetbundles/addressfield/dist/js/Address.js +++ b/src/assetbundles/addressfield/dist/js/Address.js @@ -10,249 +10,283 @@ * @since 1.0.0NsmFieldsAddress */ -;(function ($, Craft, window, document, undefined) { - // We need to create a callback for the Google Maps API to use when it has loaded - window.googleMapsPlacesApiLoaded = window.googleMapsPlacesApiLoaded || false; - window.googleMapsPlacesApiLoadedCallback = function () { - window.googleMapsPlacesApiLoaded = true; - document.body.dispatchEvent(new Event('googleMapsPlacesApiLoaded')); - }; - - var pluginName = 'NsmFieldsAddress', - defaults = {}; - - // Plugin constructor - function Plugin (element, options) { - this.$element = $(element); - this.options = $.extend({}, defaults, options); - this._defaults = defaults; - this._name = pluginName; - this.init(); - } - - Plugin.prototype = { - - getElement: function (element) { - return this.$element.find('#' + this.options.namespace + '-' + element); - }, - - init: function (id) { - - // Init country code - this.$addressFieldsContainer = this.$element.find('.nsmFields-address-addressFieldsContainer'); - this.$autoCompleteInput = this.getElement('autoComplete'); - this.$countryCodeInput = this.getElement('countryCode'); - this.currentCountryCode = this.$countryCodeInput.val(); - this.$countryCodeInput.on('change', $.proxy(this.refreshCountry, this)); - - // Add loading state - this.$spinner = $('