Skip to content

Commit

Permalink
google map improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
RensTillmann committed May 29, 2020
1 parent b7da064 commit b954a4d
Show file tree
Hide file tree
Showing 10 changed files with 294 additions and 281 deletions.
16 changes: 16 additions & 0 deletions src/assets/css/frontend/elements.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/assets/css/frontend/elements.css.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/assets/css/frontend/elements.sass
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,19 @@ textarea
width: 50%
min-width: initial!important
float: left
.super-first-responsiveness,
.super-second-responsiveness
.super-google-map.super-has-panel
> div:first-child,
> .super-google-map-directions
width: 100%
.super-third-responsiveness,
.super-fourth-responsiveness,
.super-last-responsiveness
.super-google-map.super-has-panel
> div:first-child,
> .super-google-map-directions
width: 50%

.super-captcha
width: 100%
Expand Down
305 changes: 124 additions & 181 deletions src/assets/js/common.js

Large diffs are not rendered by default.

58 changes: 33 additions & 25 deletions src/assets/js/frontend/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,8 @@
parent,
column,
form,
last,
firstColumn,
lastColumn,
found,
limit,
unique_field_names = {},
Expand All @@ -976,7 +977,7 @@
added_fields_without_suffix = [],
field_counter = 0,
element,
foundHtmlFields,
foundElements,
html_fields,
data_fields,
conditions,
Expand Down Expand Up @@ -1020,7 +1021,8 @@
column = ( el.parentNode.classList.contains('super-column-custom-padding') ? el.closest('.super-column-custom-padding') : parent.closest('.super-column') );
form = SUPER.get_frontend_or_backend_form(el, form);
var duplicateColumns = column.querySelectorAll('.super-duplicate-column-fields');
last = duplicateColumns[duplicateColumns.length-1];
firstColumn = duplicateColumns[0];
lastColumn = duplicateColumns[duplicateColumns.length-1];
found = column.querySelectorAll('.super-duplicate-column-fields').length;
limit = parseInt(column.dataset.duplicateLimit, 10);
if( (limit!==0) && (found >= limit) ) {
Expand All @@ -1031,7 +1033,7 @@
field_names = {};
field_labels = {};
counter = 0;
nodes = last.querySelectorAll('.super-shortcode-field[name]');
nodes = firstColumn.querySelectorAll('.super-shortcode-field[name]');
for (i = 0; i < nodes.length; ++i) {
field = nodes[i];
if(field.classList.contains('super-fileupload')){
Expand All @@ -1045,7 +1047,7 @@
}

counter = column.querySelectorAll('.super-duplicate-column-fields').length;
clone = last.cloneNode(true);
clone = lastColumn.cloneNode(true);
column.appendChild(clone);

// @since 3.3.0 - hook after appending new column
Expand Down Expand Up @@ -1102,27 +1104,29 @@
if( field.classList.contains('ui-timepicker-input') ) field.classList.remove('ui-timepicker-input');
field_counter++;
}

// @since 4.6.0 - update html field tags attribute
// Get all HTML elements based on field tag attribute that contain one of these field names
// @since 4.6.0 - update accordion title and description field tags attribute
// @since 4.9.6 - update google maps field tags attribute
// Get all elements based on field tag attribute that contain one of these field names
// Then convert it to an array and append the missing field names
// @IMPORTANT: Only do this for HTML elements that are NOT inside a dynamic column
foundHtmlFields = [];
// @IMPORTANT: Only do this for elements that are NOT inside a dynamic column
foundElements = [];
$.each(added_fields_with_suffix, function( index ) {
html_fields = form.querySelectorAll('.super-html-content[data-fields*="{'+index+'}"], .super-accordion-title[data-fields*="{'+index+'}"], .super-accordion-desc[data-fields*="{'+index+'}"]');
html_fields = form.querySelectorAll('.super-google-map[data-fields*="{'+index+'}"], .super-html-content[data-fields*="{'+index+'}"], .super-accordion-title[data-fields*="{'+index+'}"], .super-accordion-desc[data-fields*="{'+index+'}"]');
for (i = 0; i < html_fields.length; ++i) {
if(!html_fields[i].closest('.super-duplicate-column-fields')){
found = false;
for (ii = 0; ii < foundHtmlFields.length; ++ii) {
if($(foundHtmlFields[ii]).is(html_fields[i])) found = true;
for (ii = 0; ii < foundElements.length; ++ii) {
if($(foundElements[ii]).is(html_fields[i])) found = true;
}
if(!found) foundHtmlFields.push(html_fields[i]);
if(!found) foundElements.push(html_fields[i]);
}
}
});
for (i = 0; i < foundHtmlFields.length; ++i) {
foundHtmlFields[i].dataset.fields = foundHtmlFields[i].dataset.fields+'{' + added_fields_without_suffix.join('}{') + '}';
for (i = 0; i < foundElements.length; ++i) {
foundElements[i].dataset.fields = foundElements[i].dataset.fields+'{' + added_fields_without_suffix.join('}{') + '}';
}

// Now we have updated the names accordingly, we can proceed updating conditional logic and variable fields etc.
nodes = clone.querySelectorAll('.super-shortcode');
for (i = 0; i < nodes.length; ++i) {
Expand Down Expand Up @@ -1310,41 +1314,42 @@
htmlFields,
dataFields,
parent = this.closest('.super-duplicate-column-fields'),
foundHtmlFields = [];
foundElements = [];

nodes = parent.querySelectorAll('.super-shortcode-field');
for (i = 0; i < nodes.length; ++i) {
removedFields[nodes[i].name] = nodes[i];
}

// @since 4.6.0 - update html field tags attribute
// Get all HTML elements based on field tag attribute that contain one of these field names
// @since 4.6.0 - update accordion title and description field tags attribute
// @since 4.9.6 - update google maps field tags attribute
// Get all elements based on field tag attribute that contain one of these field names
// Then convert it to an array and append the missing field names
// Only do this for HTML elements that are NOT inside a dynamic column
// @IMPORTANT: Only do this for elements that are NOT inside a dynamic column
Object.keys(removedFields).forEach(function(index) {
htmlFields = $(form).find('.super-html-content[data-fields*="{'+index+'}"]');
htmlFields = $(form).find('.super-google-map[data-fields*="{'+index+'}"], .super-html-content[data-fields*="{'+index+'}"], .super-accordion-title[data-fields*="{'+index+'}"], .super-accordion-desc[data-fields*="{'+index+'}"]');
htmlFields.each(function(){
var $this = $(this);
if(!$this.parents('.super-duplicate-column-fields:eq(0)').length){
var $found = false;
$.each(foundHtmlFields, function( index, el ){
$.each(foundElements, function( index, el ){
if(el.is($this)){
$found = true;
}
});
if(!$found){
foundHtmlFields.push($this);
foundElements.push($this);
}
}
});
});
// Update fields attribute and remove all {tags} which where removed/deleted from the DOM
for (i = 0; i < foundHtmlFields.length; ++i) {
dataFields = foundHtmlFields[i][0].dataset.fields;
for (i = 0; i < foundElements.length; ++i) {
dataFields = foundElements[i][0].dataset.fields;
$.each(removedFields, function( index ) {
dataFields = dataFields.replace('{'+index+'}','');
});
foundHtmlFields[i][0].dataset.fields = dataFields;
foundElements[i][0].dataset.fields = dataFields;
}
SUPER.init_replace_html_tags(undefined, form);

Expand All @@ -1367,6 +1372,9 @@

// Now we can remove the dynamic column
parent.remove();

// Reload google maps
SUPER.google_maps_api.initMaps(undefined, form);

});

Expand Down
16 changes: 16 additions & 0 deletions src/docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Super Forms - Changelog

## May 29, 2020 - Version 4.9.460

- **Added:** Option for Google Map element to set region code e.g `nl`, `de`, `uk`, `us` etc.uu
- **Added:** Option for Google Map element to set/adjust `zoom`
- **Added:** Option for Google Map element to enable/disable `UI (buttons)`
- **Added:** Option for Google Map element to `draw Route` from address A (origin) to address B (destination)
- **Added:** Option for Google Map element to optionally display the `directions panel` (list with route instructions)
- **Added:** Option for Google Map element to set it's travel mode `DRIVING`, `BICYCLKING`, `TRANSIT`, `WALKING`
- **Added:** Option for Google Map element to populate `distance` to field (including Calculator Add-on)
- **Added:** Option for Google Map element to populate `duration` to field (including Calculator Add-on)
- **Added:** Option for Google Map element to define the unit system `METRIC` or `IMPERIAL`
- **Added:** Option for Google Map element to draw Route with `Waypoints` (stops in between the route)
- **Added:** Option for Google Map element to optimize route with waypoints (to rearrange it in a more efficient order)
- **Added:** Option for Google Map element to avoid `Ferries`, `Major highways`, `Toll roads` (if possible)
- **Fix:** Incorrect incrementing field names in dynamic columns

## May 21, 2020 - Version 4.9.455

- **Fix:** MySQL error in prepare() statement when unique code is generated
Expand Down
17 changes: 16 additions & 1 deletion src/docs/google-map.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# Google map element

under construction...
You can find the google map element under `HTML Elements` > `Google Map`. When using the Google Map you must have a valid API key. You can obtain an API key from within your [API manger](https://console.developers.google.com/). Make sure to enable the `Google Maps JavaScript API` for your API.

**The Google Map comes with several features:**

- Option to set region code e.g `nl`, `de`, `uk`, `us` etc.uu
- Option to set/adjust `zoom`
- Option to enable/disable `UI (buttons)`
- Option to `draw Route` from address A (origin) to address B (destination)
- Option to optionally display the `directions panel` (list with route instructions)
- Option to set it's travel mode `DRIVING`, `BICYCLKING`, `TRANSIT`, `WALKING`
- Option to populate `distance` to field (including Calculator Add-on)
- Option to populate `duration` to field (including Calculator Add-on)
- Option to define the unit system `METRIC` or `IMPERIAL`
- Option to draw Route with `Waypoints` (stops in between the route)
- Option to optimize route with waypoints (to rearrange it in a more efficient order)
- Option to avoid `Ferries`, `Major highways`, `Toll roads` (if possible)
17 changes: 9 additions & 8 deletions src/includes/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4372,14 +4372,15 @@ public static function google_map( $tag, $atts ) {
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['avoidHighways']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['avoidTolls']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['region']);
// drivingOptions (only when travelMode is DRIVING)
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['departureTime']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['trafficModel']);
// transitOptions (only when travelMode is TRANSIT)
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['arrivalTime']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['transitDepartureTime']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['transitModes']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['routingPreference']);
// we will implement this in a later version // drivingOptions (only when travelMode is DRIVING)
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['departureTime']);
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['trafficModel']);
// we will implement this in a later version // transitOptions (only when travelMode is TRANSIT)
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['arrivalTime']);
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['transitDepartureTime']);
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['transitModes']);
// we will implement this in a later version $field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['routingPreference']);
// UI settings
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['zoom']);
$field_names = SUPER_Common::get_data_fields_attribute($field_names, $atts['disableDefaultUI']);

Expand Down
Loading

0 comments on commit b954a4d

Please sign in to comment.