workarea-google_address_autocomplete 4.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.editorconfig +20 -0
- data/.eslintignore +2 -0
- data/.eslintrc +24 -0
- data/.github/ISSUE_TEMPLATE/bug_report.md +37 -0
- data/.github/ISSUE_TEMPLATE/documentation-request.md +17 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.gitignore +16 -0
- data/.rspec +2 -0
- data/.scss-lint.yml +188 -0
- data/CHANGELOG.md +119 -0
- data/CODE_OF_CONDUCT.md +3 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +9 -0
- data/LICENSE +52 -0
- data/README.md +88 -0
- data/Rakefile +64 -0
- data/app/assets/javascripts/workarea/storefront/google_address_autocomplete/config.js.erb +38 -0
- data/app/assets/javascripts/workarea/storefront/google_address_autocomplete/modules/google_address_autocomplete.js.erb +175 -0
- data/app/assets/javascripts/workarea/storefront/google_address_autocomplete/templates/autocomplete_text_box.jst.ejs +1 -0
- data/bin/rails +18 -0
- data/config/initializers/append_points.rb +19 -0
- data/config/initializers/workarea.rb +2 -0
- data/config/locales/en.yml +6 -0
- data/example.png +0 -0
- data/lib/workarea/google_address_autocomplete.rb +12 -0
- data/lib/workarea/google_address_autocomplete/engine.rb +8 -0
- data/lib/workarea/google_address_autocomplete/version.rb +5 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +4 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/jobs/application_job.rb +2 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +34 -0
- data/test/dummy/bin/update +29 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/cable.yml +9 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +54 -0
- data/test/dummy/config/environments/production.rb +86 -0
- data/test/dummy/config/environments/test.rb +43 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +6 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/new_framework_defaults.rb +21 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/workarea.rb +5 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/puma.rb +47 -0
- data/test/dummy/config/routes.rb +5 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/lib/assets/.keep +0 -0
- data/test/dummy/log/.keep +0 -0
- data/test/javascripts/fixtures/address_fields.html.haml +59 -0
- data/test/javascripts/google_address_autocomplete_spec.js +92 -0
- data/test/javascripts/spec_helper.js +4 -0
- data/test/teaspoon_env.rb +10 -0
- data/test/test_helper.rb +10 -0
- data/workarea-google_address_autocomplete.gemspec +24 -0
- metadata +151 -0
data/CODE_OF_CONDUCT.md
ADDED
data/CONTRIBUTING.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
WebLinc
|
2
|
+
Business Source License
|
3
|
+
|
4
|
+
Licensor: WebLinc Corporation, 22 S. 3rd Street, 2nd Floor, Philadelphia PA 19106
|
5
|
+
|
6
|
+
Licensed Work: Workarea Commerce Platform
|
7
|
+
The Licensed Work is (c) 2019 WebLinc Corporation
|
8
|
+
|
9
|
+
Additional Use Grant:
|
10
|
+
You may make production use of the Licensed Work without an additional license agreement with WebLinc so long as you do not use the Licensed Work for a Commerce Service.
|
11
|
+
|
12
|
+
A "Commerce Service" is a commercial offering that allows third parties (other than your employees and contractors) to access the functionality of the Licensed Work by creating or managing commerce functionality, the products, taxonomy, assets and/or content of which are controlled by such third parties.
|
13
|
+
|
14
|
+
For information about obtaining an additional license agreement with WebLinc, contact licensing@workarea.com.
|
15
|
+
|
16
|
+
Change Date: 2019-08-20
|
17
|
+
|
18
|
+
Change License: Version 2.0 or later of the GNU General Public License as published by the Free Software Foundation
|
19
|
+
|
20
|
+
Terms
|
21
|
+
|
22
|
+
The Licensor hereby grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work. The Licensor may make an Additional Use Grant, above, permitting limited production use.
|
23
|
+
|
24
|
+
Effective on the Change Date, or the fourth anniversary of the first publicly available distribution of a specific version of the Licensed Work under this License, whichever comes first, the Licensor hereby grants you rights under the terms of the Change License, and the rights granted in the paragraph above terminate.
|
25
|
+
|
26
|
+
If your use of the Licensed Work does not comply with the requirements currently in effect as described in this License, you must purchase a commercial license from the Licensor, its affiliated entities, or authorized resellers, or you must refrain from using the Licensed Work.
|
27
|
+
|
28
|
+
All copies of the original and modified Licensed Work, and derivative works of the Licensed Work, are subject to this License. This License applies separately for each version of the Licensed Work and the Change Date may vary for each version of the Licensed Work released by Licensor.
|
29
|
+
|
30
|
+
You must conspicuously display this License on each original or modified copy of the Licensed Work. If you receive the Licensed Work in original or modified form from a third party, the terms and conditions set forth in this License apply to your use of that work.
|
31
|
+
|
32
|
+
Any use of the Licensed Work in violation of this License will automatically terminate your rights under this License for the current and all other versions of the Licensed Work.
|
33
|
+
|
34
|
+
This License does not grant you any right in any trademark or logo of Licensor or its affiliates (provided that you may use a trademark or logo of Licensor as expressly required by this License). TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE. MariaDB hereby grants you permission to use this License’s text to license your works and to refer to it using the trademark "Business Source License" as long as you comply with the Covenants of Licensor below.
|
35
|
+
|
36
|
+
Covenants of Licensor
|
37
|
+
In consideration of the right to use this License’s text and the "Business Source License" name and trademark, Licensor covenants to MariaDB, and to all other recipients of the licensed work to be provided by Licensor:
|
38
|
+
|
39
|
+
To specify as the Change License the GPL Version 2.0 or any later version, or a license that is compatible with GPL Version 2.0 or a later version, where "compatible" means that software provided under the Change License can be included in a program with software provided under GPL Version 2.0 or a later version. Licensor may specify additional Change Licenses without limitation.
|
40
|
+
|
41
|
+
To either: (a) specify an additional grant of rights to use that does not impose any additional restriction on the right granted in this License, as the Additional Use Grant; or (b) insert the text "None."
|
42
|
+
|
43
|
+
To specify a Change Date.
|
44
|
+
|
45
|
+
Not to modify this License in any other way.
|
46
|
+
|
47
|
+
Notice
|
48
|
+
The Business Source License (this document, or the "License") is not an Open Source license. However, the Licensed Work will eventually be made available under an Open Source License, as stated in this License.
|
49
|
+
|
50
|
+
For more information on the use of the Business Source License generally, please visit the Adopting and Developing Business Source License FAQ.
|
51
|
+
|
52
|
+
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved. "Business Source License" is a trademark of MariaDB Corporation Ab.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
Workarea Google Address Autocomplete
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
A Workarea Commerce plugin that adds a [Google Maps address autocomplete](https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete-addressform) field to the addresses step of checkout in the Workarea Storefront. This
|
5
|
+
field searches Google Maps for an address and autocompletes the standard address
|
6
|
+
fields with the selected address.
|
7
|
+
|
8
|
+
![Google Address Autocomplete Example](example.png)
|
9
|
+
|
10
|
+
Getting Started
|
11
|
+
--------------------------------------------------------------------------------
|
12
|
+
|
13
|
+
Add the gem to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
# ...
|
17
|
+
gem 'workarea-google_address_autocomplete'
|
18
|
+
# ...
|
19
|
+
```
|
20
|
+
|
21
|
+
Update your application's bundle.
|
22
|
+
|
23
|
+
```bash
|
24
|
+
cd path/to/application
|
25
|
+
bundle
|
26
|
+
```
|
27
|
+
|
28
|
+
Configuration
|
29
|
+
--------------------------------------------------------------------------------
|
30
|
+
|
31
|
+
To integrate your Workarea application with Google Address Autocomplete you need configure your host application with your Google Address Autocomplete `apiKey`,
|
32
|
+
which must be obtained [here](https://developers.google.com/maps/documentation/javascript/get-api-key)
|
33
|
+
|
34
|
+
You should use application secrets to do this. Add the following config to your `secrets.yml` file
|
35
|
+
|
36
|
+
```yaml
|
37
|
+
# ...
|
38
|
+
google_address_autocomplete:
|
39
|
+
:api_key: 'YOUR_API_KEY'
|
40
|
+
# ...
|
41
|
+
```
|
42
|
+
|
43
|
+
This plugin adds a `config.js` file to the Storefront's JavaScript manifest.
|
44
|
+
|
45
|
+
The object that this file provides contains two properties:
|
46
|
+
|
47
|
+
- `apiKey`
|
48
|
+
which must be added to `secrets.yml` (see above)
|
49
|
+
which must be obtained [here](https://developers.google.com/maps/documentation/javascript/get-api-key)
|
50
|
+
and,
|
51
|
+
- `mappings` which contains an object that maps Google Places [component types](https://github.com/ubilabs/geocomplete#address-and-places-specific-component-types)
|
52
|
+
and selector strings that match input elements within the autocomplete-enabled
|
53
|
+
form. For example:
|
54
|
+
|
55
|
+
```javascript
|
56
|
+
mappings: {
|
57
|
+
'street_number': { // Google Places Component Type
|
58
|
+
selector: '[name$="address[street]"]', // Selector for a form field
|
59
|
+
shortName: false // Abbreviated?
|
60
|
+
},
|
61
|
+
'route': {
|
62
|
+
selector: '[name$="address[street]"]',
|
63
|
+
shortName: false
|
64
|
+
},
|
65
|
+
'locality': {
|
66
|
+
selector: '[name$="address[city]"]',
|
67
|
+
shortName: false
|
68
|
+
},
|
69
|
+
|
70
|
+
... etc ...
|
71
|
+
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
75
|
+
If none of the input `[name]`s for the address partial have been changed in your
|
76
|
+
project, this plugin should work out of the box. If you have modified any of these
|
77
|
+
attributes, or if you are wishing to collect more data from this plugin, you'll
|
78
|
+
need to modify or expand this configuration object for your project.
|
79
|
+
|
80
|
+
Workarea Commerce Documentation
|
81
|
+
--------------------------------------------------------------------------------
|
82
|
+
|
83
|
+
See [https://developer.workarea.com](https://developer.workarea.com) for Workarea Commerce documentation.
|
84
|
+
|
85
|
+
License
|
86
|
+
--------------------------------------------------------------------------------
|
87
|
+
|
88
|
+
Workarea Google Address Autocomplete is released under the [Business Software License](LICENSE)
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'GoogleAddressAutocomplete'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
# Load the dummy app's rake tasks
|
18
|
+
APP_RAKEFILE = File.expand_path('../test/dummy/Rakefile', __FILE__)
|
19
|
+
load 'rails/tasks/engine.rake'
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
load 'workarea/changelog.rake'
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
|
25
|
+
Rake::TestTask.new(:test) do |t|
|
26
|
+
t.libs << 'lib'
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
33
|
+
|
34
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
|
35
|
+
require 'workarea/google_address_autocomplete/version'
|
36
|
+
|
37
|
+
desc "Release version #{Workarea::GoogleAddressAutocomplete::VERSION} of the gem"
|
38
|
+
task :release do
|
39
|
+
host = "https://#{ENV['BUNDLE_GEMS__WEBLINC__COM']}@gems.weblinc.com"
|
40
|
+
|
41
|
+
#Rake::Task['workarea:changelog'].execute
|
42
|
+
#system 'git add CHANGELOG.md'
|
43
|
+
#system 'git commit -m "Update CHANGELOG"'
|
44
|
+
#system 'git push origin HEAD'
|
45
|
+
|
46
|
+
system "git tag -a v#{Workarea::GoogleAddressAutocomplete::VERSION} -m 'Tagging #{Workarea::GoogleAddressAutocomplete::VERSION}'"
|
47
|
+
system 'git push --tags'
|
48
|
+
|
49
|
+
system 'gem build workarea-google_address_autocomplete.gemspec'
|
50
|
+
system "gem push workarea-google_address_autocomplete-#{Workarea::GoogleAddressAutocomplete::VERSION}.gem"
|
51
|
+
system "gem push workarea-google_address_autocomplete-#{Workarea::GoogleAddressAutocomplete::VERSION}.gem --host #{host}"
|
52
|
+
system "rm workarea-google_address_autocomplete-#{Workarea::GoogleAddressAutocomplete::VERSION}.gem"
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'Run the JavaScript tests'
|
56
|
+
ENV['TEASPOON_RAILS_ENV'] = File.expand_path('../test/dummy/config/environment', __FILE__)
|
57
|
+
task teaspoon: 'app:teaspoon'
|
58
|
+
|
59
|
+
desc 'Start a server at http://localhost:3000/teaspoon for JavaScript tests'
|
60
|
+
task :teaspoon_server do
|
61
|
+
Dir.chdir('test/dummy')
|
62
|
+
teaspoon_env = File.expand_path('../test/teaspoon_env.rb', __FILE__)
|
63
|
+
system "RAILS_ENV=test TEASPOON_ENV=#{teaspoon_env} rails s"
|
64
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
(function () {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* @namespace WORKAREA.config
|
6
|
+
* @property {object} googleAddressAutocomplete
|
7
|
+
*/
|
8
|
+
WORKAREA.config.googleAddressAutocomplete = {
|
9
|
+
apiKey: '<%= Workarea.config.google_address_autocomplete_api_key %>',
|
10
|
+
selector: '[name$="address[street]"]',
|
11
|
+
mappings: {
|
12
|
+
'street_number': {
|
13
|
+
selector: '[name$="address[street]"]',
|
14
|
+
shortName: false
|
15
|
+
},
|
16
|
+
'route': {
|
17
|
+
selector: '[name$="address[street]"]',
|
18
|
+
shortName: false
|
19
|
+
},
|
20
|
+
'locality': {
|
21
|
+
selector: '[name$="address[city]"]',
|
22
|
+
shortName: false
|
23
|
+
},
|
24
|
+
'administrative_area_level_1': {
|
25
|
+
selector: '[name$="address_region_select"], [name$="address[region]"]',
|
26
|
+
shortName: true
|
27
|
+
},
|
28
|
+
'country': {
|
29
|
+
selector: '[name$="address[country]"]',
|
30
|
+
shortName: true
|
31
|
+
},
|
32
|
+
'postal_code': {
|
33
|
+
selector: '[name$="address[postal_code]"]',
|
34
|
+
shortName: false
|
35
|
+
}
|
36
|
+
}
|
37
|
+
};
|
38
|
+
})();
|
@@ -0,0 +1,175 @@
|
|
1
|
+
/**
|
2
|
+
* Displays a jQuery Geocomplete-enabled form control within a set of address-
|
3
|
+
* specific form controls.
|
4
|
+
*
|
5
|
+
* @namespace WORKAREA.googleAddressAutocomplete
|
6
|
+
*/
|
7
|
+
WORKAREA.registerModule('googleAddressAutocomplete', (function () {
|
8
|
+
'use strict';
|
9
|
+
|
10
|
+
var autocompleteTemplate = JST['workarea/storefront/google_address_autocomplete/templates/autocomplete_text_box'],
|
11
|
+
apiEndpoint = '//maps.googleapis.com/maps/api/js',
|
12
|
+
loadingPlacesApi = $.Deferred(),
|
13
|
+
|
14
|
+
updateInput = function ($container, component) {
|
15
|
+
var mappings = WORKAREA.config.googleAddressAutocomplete.mappings,
|
16
|
+
$inputs, value;
|
17
|
+
|
18
|
+
if (_.isUndefined(mappings[component.type])) { return; }
|
19
|
+
|
20
|
+
$inputs = $(mappings[component.type].selector, $container);
|
21
|
+
|
22
|
+
if (mappings[component.type].shortName) {
|
23
|
+
value = component.value.short_name;
|
24
|
+
} else {
|
25
|
+
value = component.value.long_name;
|
26
|
+
}
|
27
|
+
|
28
|
+
$inputs.each(function (index, input) {
|
29
|
+
var $input = $(input);
|
30
|
+
|
31
|
+
if (_.isEmpty(input.value)) {
|
32
|
+
$input.val(value);
|
33
|
+
} else {
|
34
|
+
$input.val($input.val() + ' ' + value);
|
35
|
+
}
|
36
|
+
|
37
|
+
// Prevents a race condition with base's region select feature
|
38
|
+
if ($input.is('[name$=region_select]')) {
|
39
|
+
_.defer(function() {
|
40
|
+
$input.val(value);
|
41
|
+
});
|
42
|
+
}
|
43
|
+
|
44
|
+
$input.trigger('change');
|
45
|
+
});
|
46
|
+
},
|
47
|
+
|
48
|
+
mutateResult = function (result) {
|
49
|
+
return _.map(result.address_components, function (component) {
|
50
|
+
return {
|
51
|
+
type: component.types[0],
|
52
|
+
value: {
|
53
|
+
long_name: component.long_name,
|
54
|
+
short_name: component.short_name
|
55
|
+
}
|
56
|
+
};
|
57
|
+
});
|
58
|
+
},
|
59
|
+
|
60
|
+
getInputs = function ($container) {
|
61
|
+
var mappings = WORKAREA.config.googleAddressAutocomplete.mappings,
|
62
|
+
inputSelectors = _.map(mappings, function (mapping) {
|
63
|
+
return mapping.selector;
|
64
|
+
});
|
65
|
+
|
66
|
+
return $(inputSelectors.join(','), $container);
|
67
|
+
},
|
68
|
+
|
69
|
+
updateForm = function (input, event, result) {
|
70
|
+
var $container = $(input).closest('.property').parent(),
|
71
|
+
$inputs = getInputs($container);
|
72
|
+
|
73
|
+
event.preventDefault();
|
74
|
+
|
75
|
+
$inputs.val(null);
|
76
|
+
|
77
|
+
_.forEach(mutateResult(result), _.partial(updateInput, $container));
|
78
|
+
},
|
79
|
+
|
80
|
+
injectNewProperty = function (input, $newProperty) {
|
81
|
+
$(input)
|
82
|
+
.closest('.property')
|
83
|
+
.before($newProperty);
|
84
|
+
},
|
85
|
+
|
86
|
+
updatePropertyLabel = function ($newProperty, input) {
|
87
|
+
var id = $(autocompleteTemplate({
|
88
|
+
index: $('[data-google-address-autocomplete]').length
|
89
|
+
})).attr('id');
|
90
|
+
|
91
|
+
$('[for]', $newProperty)
|
92
|
+
.text(I18n.t('workarea.storefront.google_address_autocomplete.property_label'))
|
93
|
+
.attr('for', id);
|
94
|
+
|
95
|
+
WORKAREA.initModules($newProperty);
|
96
|
+
},
|
97
|
+
|
98
|
+
replacePropertyTextbox = function ($newProperty, index) {
|
99
|
+
$('.value', $newProperty).html(autocompleteTemplate({
|
100
|
+
index: $('[data-google-address-autocomplete]').length
|
101
|
+
}));
|
102
|
+
},
|
103
|
+
|
104
|
+
cloneProperty = function (input) {
|
105
|
+
return $(input).closest('.property').clone();
|
106
|
+
},
|
107
|
+
|
108
|
+
initAutocomplete = function (index, input) {
|
109
|
+
loadingPlacesApi.done(function () {
|
110
|
+
var $newProperty = cloneProperty(input);
|
111
|
+
|
112
|
+
replacePropertyTextbox($newProperty, input);
|
113
|
+
updatePropertyLabel($newProperty, index);
|
114
|
+
|
115
|
+
injectNewProperty(input, $newProperty);
|
116
|
+
|
117
|
+
$('.text-box', $newProperty)
|
118
|
+
.geocomplete()
|
119
|
+
.on('geocode:result', _.partial(updateForm, input));
|
120
|
+
});
|
121
|
+
},
|
122
|
+
|
123
|
+
apiLoaded = function () {
|
124
|
+
var $apiScript = $('script').filter(function (index, script) {
|
125
|
+
return ! _.isEmpty(script.src.match('maps.googleapis.com'));
|
126
|
+
});
|
127
|
+
|
128
|
+
return ! _.isEmpty($apiScript);
|
129
|
+
},
|
130
|
+
|
131
|
+
loadPlacesApi = function (index) {
|
132
|
+
if (apiLoaded()) { return; }
|
133
|
+
|
134
|
+
$.getScript(
|
135
|
+
apiEndpoint +
|
136
|
+
'?libraries=places' +
|
137
|
+
'&key=' + WORKAREA.config.googleAddressAutocomplete.apiKey +
|
138
|
+
'&callback=WORKAREA.googleAddressAutocomplete.resolveLoadingPlacesApi'
|
139
|
+
);
|
140
|
+
},
|
141
|
+
|
142
|
+
setupAutocomplete = function (index, input) {
|
143
|
+
loadPlacesApi();
|
144
|
+
initAutocomplete(index, input);
|
145
|
+
},
|
146
|
+
|
147
|
+
/**
|
148
|
+
* A callback method responsible for resolving a module-specific promise
|
149
|
+
* that announces the availability of the Google Places API.
|
150
|
+
*
|
151
|
+
* @method
|
152
|
+
* @name resolveLoadingPlacesApi
|
153
|
+
* @memberOf WORKAREA.googleAddressAutocomplete
|
154
|
+
* @return {Deferred} required for testing purposes
|
155
|
+
*/
|
156
|
+
resolveLoadingPlacesApi = function () {
|
157
|
+
return loadingPlacesApi.resolve();
|
158
|
+
},
|
159
|
+
|
160
|
+
/**
|
161
|
+
* @method
|
162
|
+
* @name init
|
163
|
+
* @memberof WORKAREA.googleAddressAutocomplete
|
164
|
+
*/
|
165
|
+
init = function ($scope) {
|
166
|
+
if (!WORKAREA.environment.isTest || <%= ENV['CI'] == 'true' %>) {
|
167
|
+
$(WORKAREA.config.googleAddressAutocomplete.selector, $scope).each(setupAutocomplete);
|
168
|
+
}
|
169
|
+
};
|
170
|
+
|
171
|
+
return {
|
172
|
+
init: init,
|
173
|
+
resolveLoadingPlacesApi: resolveLoadingPlacesApi
|
174
|
+
};
|
175
|
+
}()));
|
@@ -0,0 +1 @@
|
|
1
|
+
<input id="google-address-autocomplete-<%= index %>" class="text-box" placeholder="<%= I18n.t('workarea.storefront.google_address_autocomplete.placeholder') %>" data-google-address-autocomplete=''>
|
data/bin/rails
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/workarea/google_address_autocomplete/engine', __FILE__)
|
7
|
+
|
8
|
+
# Set up gems listed in the Gemfile.
|
9
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
10
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
11
|
+
|
12
|
+
require 'action_controller/railtie'
|
13
|
+
require 'action_view/railtie'
|
14
|
+
require 'action_mailer/railtie'
|
15
|
+
require 'rails/test_unit/railtie'
|
16
|
+
require 'sprockets/railtie'
|
17
|
+
|
18
|
+
require 'rails/engine/commands'
|