gorriecoe/silverstripe-directionslink

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Adds a directions link type to Link Object.

Fund package maintenance!
Ko Fi

Installs: 2

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

dev-master 2020-04-15 22:21 UTC

This package is auto-updated.

Last update: 2021-11-16 01:42:16 UTC


README

Adds a direction link type to gorriecoe/silverstripe-link. Allowing editor to select a location on google maps, that will then produce a google maps direction link.

Installation

Composer is the recommended way of installing SilverStripe modules.

composer require gorriecoe/silverstripe-directionslink

Directions link uses GoogleMapField. So you will need to configure this in your config.yml.

BetterBrief\GoogleMapField:
  default_options:
    api_key: '[google-api-key]'

For more information check out BetterBrief\GoogleMapField.

Requirements

Maintainers

Example

Below are examples of link output:

Open in apple maps if iProduct

Below is a basic example that can be added to the frontend of your project to detect apple devices and open the link in apple maps instead.

var googlemapsurl = "https://maps.google.com/maps:";
var links = document.querySelectorAll('a[href*="' + googlemapsurl +'"]'), i;
for (i = 0; i < links.length; ++i) {
    links[i].addEventListener("click", function(event) {
        event.preventDefault();
        var link = this.getAttribute("href");

        if ((navigator.platform.indexOf("iPhone") != -1) || (navigator.platform.indexOf("iPod") != -1) || (navigator.platform.indexOf("iPad") != -1)) {
            link.replace(googlemapsurl, "maps://maps.apple.com/");
        }

        window.open(link);
    });
}