gorriecoe/silverstripe-directionslink

Adds a directions link type to Link Object.

Fund package maintenance!
Ko Fi

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:silverstripe-vendormodule

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

This package is auto-updated.

Last update: 2024-04-16 07:43:46 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);
    });
}