(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _maps = require('./maps');

// initialize all elements
var componentsList = document.querySelectorAll(_maps.Maps.getSelector()); // Import all components

for (var i = 0; i < componentsList.length; i++) {
	new _maps.Maps(componentsList[i]);
}
},{"./maps":2}],2:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.Maps = undefined;

var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /**
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * maps.js
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      * load google maps with markers and related popups
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      */

var _googleMapsApi = require('./maps/google-maps-api');

var _mapStyle = require('./maps/map-style');

var _popupWrapper = require('./maps/popup-wrapper');

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
* Declare constants
*/
var attributeBase = 'data-rs-maps';
var Popup = null;

var Maps = exports.Maps = function () {
	function Maps(element) {
		_classCallCheck(this, Maps);

		this.map = null;
		this.element = element;
		this.markers = [];
		this.marker = null;
		this.popup = null;
		// get elements
		this.googleMapsKey = this.element.hasAttribute(this.attributes.googleMapsKey) && this.element.getAttribute(this.attributes.googleMapsKey);
		this.markerUrlPath = this.element.hasAttribute(this.attributes.markerUrl) ? this.element.getAttribute(this.attributes.markerUrl) : this.variables.defaultMarkerUrl;
		this.markerIsNotClickable = this.element.hasAttribute(this.attributes.markerIsNotClickable) || false;
		this.mapPlaceholderElement = this.element.querySelector(this.attributes.mapsPlaceholderElement);
		this.mapElement = this.mapPlaceholderElement.appendChild(document.createElement('div'));
		this.initializeMap();
	}

	/**
  * Declare attribute constants
  */


	_createClass(Maps, [{
		key: 'initializeMap',


		/**
   * Load google maps API
   */
		value: function initializeMap() {
			var _this = this;

			// create map, controls and markers after the API is ready
			var gmapApi = new _googleMapsApi.GoogleMapsApi(this.googleMapsKey);
			gmapApi.load().then(function () {
				_this.createMap();
				_this.customZoomControl(_this.mapPlaceholderElement);
				_this.handleMarkers();
			}).catch(function (reason) {
				console.error(reason);
			});
		}
	}, {
		key: 'createMap',
		value: function createMap() {
			//retrieve center location
			var zoom = parseInt(this.element.getAttribute('data-rs-maps-zoom'));
			if (isNaN(zoom)) {
				zoom = 6;
			}
			// get center of map

			var _element$getAttribute = this.element.getAttribute('data-rs-maps').split(','),
			    _element$getAttribute2 = _slicedToArray(_element$getAttribute, 2),
			    centerLat = _element$getAttribute2[0],
			    centerLng = _element$getAttribute2[1];
			// create map


			this.map = new google.maps.Map(this.mapPlaceholderElement, {
				center: new google.maps.LatLng(centerLat, centerLng),
				zoom: zoom,
				minZoom: 4,
				maxZoom: 17,
				disableDefaultUI: true,
				panControl: true,
				zoomControl: false,
				scaleControl: true,
				streetViewControl: false,
				styles: _mapStyle.MapStyle.custom,
				mapTypeId: google.maps.MapTypeId.ROADMAP
			});
		}

		/**
   * Create Popup class if not already exists
   * always AFTER the map is created
   */

	}, {
		key: 'createPopup',
		value: function createPopup() {
			if (Popup === null) {
				Popup = _popupWrapper.PopupWrapper.popupClass;
			}
		}

		/**
   * Retrieve markers from html elements with attribute 'data-rs-map-marker'
   * and add them to the map
   */

	}, {
		key: 'handleMarkers',
		value: function handleMarkers() {
			var _this2 = this;

			// create the popup class
			this.createPopup();
			this.markers = [].slice.call(this.element.querySelectorAll('[data-rs-map-marker]')).map(function (markerElement) {
				//build marker item
				var _markerElement$getAtt = markerElement.getAttribute('data-rs-map-marker').split(','),
				    _markerElement$getAtt2 = _slicedToArray(_markerElement$getAtt, 2),
				    lat = _markerElement$getAtt2[0],
				    lng = _markerElement$getAtt2[1];

				var item = {};
				item.lat = lat.trim();
				item.lng = lng.trim();
				item.content = document.createElement('div');
				item.content.innerHTML = markerElement.innerHTML;

				// add the marker to the map
				_this2.addMarker(item);

				return item;
			});

			// handle click on map related to popups
			google.maps.event.addListener(this.map, 'click', function () {
				if (_this2.marker !== null && typeof _this2.marker !== 'undefined') {
					_this2.marker.open = false;
					_this2.marker.customPopup.hide();
				}
			});
		}

		/**
   * Add marker to the map
   * @param {any} item Object containing base settings
   */

	}, {
		key: 'addMarker',
		value: function addMarker(item) {
			var _this3 = this;

			// create icon for marker
			var icon = {
				url: this.markerUrlPath,
				size: new google.maps.Size(26, 32)
			};

			// create popup for marker
			var popup = new Popup(new google.maps.LatLng(item.lat, item.lng), item.content);

			// create marker
			var marker = new google.maps.Marker({
				position: new google.maps.LatLng(item.lat, item.lng),
				icon: icon,
				map: this.map,
				customPopup: popup
			});

			popup.marker = marker;

			// handle marker click
			if (!this.markerIsNotClickable) {
				google.maps.event.addListener(marker, 'click', function () {
					// determine to show or hide the popup
					var openMarker = false;
					if (marker.open !== true) {
						openMarker = true;
					}
					if (_this3.marker !== null && marker !== _this3.marker) {
						_this3.marker.open = false;
						_this3.marker.customPopup.hide();
					}

					// set active marker
					_this3.marker = marker;

					// handle display popup
					if (openMarker) {
						_this3.marker.customPopup.setMap(_this3.marker.map);
						_this3.marker.open = true;
					} else {
						_this3.marker.customPopup.hide();
						_this3.marker.open = false;
					}
				});
			}
			return marker;
		}

		/**
   * Create a custom zoom control
   * @param {any} controlContainer
   */

	}, {
		key: 'customZoomControl',
		value: function customZoomControl(controlContainer) {
			var _this4 = this;

			// hide control container
			var controlWrapper = controlContainer.appendChild(document.createElement('div'));
			controlWrapper.classList.add('gmaps__control-container');
			controlWrapper.classList.add('gmaps__control-container--loading');

			// create element zoom in/out button
			var zoomInButton = document.createElement('div');
			var zoomOutButton = document.createElement('div');

			// create classes for buttons
			zoomInButton.classList.add('gmaps__button--zoom');
			zoomInButton.classList.add('gmaps__button--zoom-in');
			zoomOutButton.classList.add('gmaps__button--zoom');
			zoomOutButton.classList.add('gmaps__button--zoom-out');

			// append controls
			controlWrapper.appendChild(zoomInButton);
			controlWrapper.appendChild(zoomOutButton);

			// Setup the click event listener - zoomIn
			google.maps.event.addDomListener(zoomInButton, 'click', function () {
				_this4.map.setZoom(_this4.map.getZoom() + 1);
			});

			// Setup the click event listener - zoomOut
			google.maps.event.addDomListener(zoomOutButton, 'click', function () {
				_this4.map.setZoom(_this4.map.getZoom() - 1);
			});
		}

		/**
   * Get selector
   */

	}, {
		key: 'attributes',
		get: function get() {
			return {
				markerUrl: attributeBase + '-marker-url',
				markerIsNotClickable: attributeBase + '-marker-is-not-clickable',
				mapsPlaceholderElement: '[' + attributeBase + '-placeholder]',
				googleMapsKey: attributeBase + '-google-maps-key'
			};
		}

		/**
   * Declare variable constants
   */

	}, {
		key: 'variables',
		get: function get() {
			return {
				defaultMarkerUrl: '../_assets/image/marker.png'
			};
		}
	}], [{
		key: 'getSelector',
		value: function getSelector() {
			return '[' + attributeBase + ']';
		}
	}]);

	return Maps;
}();
},{"./maps/google-maps-api":3,"./maps/map-style":4,"./maps/popup-wrapper":5}],3:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * Use this class to ensure Google Maps API javascript is loaded before running any google map specific code.
 */
var GoogleMapsApi = exports.GoogleMapsApi = function () {

	/**
  * Constructor set up config.
  */
	function GoogleMapsApi(apiKey) {
		_classCallCheck(this, GoogleMapsApi);

		// api key for google maps
		this.apiKey = apiKey;
	}

	/**
  * Load the Google Maps API javascript
  */


	_createClass(GoogleMapsApi, [{
		key: 'load',
		value: function load() {
			var _this = this;

			var promise = new Promise(function (resolve) {
				_this.resolve = resolve;

				// set a globally scoped callback if it doesn't already exist
				if (typeof window.humanForward === 'undefined') {
					window.humanForward = {};
				}
				if (!window.humanForward.GoogleMapsApi) {
					_this.callbackName = 'humanForward.GoogleMapsApi.mapReady';
					window.humanForward.GoogleMapsApi = _this;
					window.humanForward.GoogleMapsApi.mapReady = _this.mapReady.bind(_this);
				}

				if ((typeof window.google === 'undefined' || typeof window.google.maps === 'undefined') && typeof _this.callbackName !== 'undefined') {
					_this.loaded = true;
					var script = document.createElement('script');
					script.src = '//maps.googleapis.com/maps/api/js?key=' + _this.apiKey + '&callback=' + _this.callbackName;
					script.async = true;
					document.body.appendChild(script);
				} else {
					_this.resolve();
				}
			});
			return promise;
		}

		/**
   * Globally scoped callback for the map loaded
   */

	}, {
		key: 'mapReady',
		value: function mapReady() {
			this.extendApi();
			// resolves promise in load
			this.resolve();
		}
	}, {
		key: 'extendApi',
		value: function extendApi() {
			google.maps.Map.prototype.panToWithOffset = function (latlng, offsetX, offsetY) {
				var map = this;
				var overlayView = new google.maps.OverlayView();
				overlayView.onAdd = function () {
					var proj = this.getProjection();
					var aPoint = proj.fromLatLngToContainerPixel(latlng);
					aPoint.x = aPoint.x + offsetX;
					aPoint.y = aPoint.y + offsetY;
					map.panTo(proj.fromContainerPixelToLatLng(aPoint));
				};
				overlayView.draw = function () {};
				overlayView.setMap(this);
			};
		}
	}]);

	return GoogleMapsApi;
}();
},{}],4:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var MapStyle = exports.MapStyle = function () {
	function MapStyle() {
		_classCallCheck(this, MapStyle);
	}

	_createClass(MapStyle, null, [{
		key: 'custom',
		get: function get() {
			return [{
				'featureType': 'administrative.land_parcel',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'administrative.locality',
				'elementType': 'labels',
				'stylers': [{
					'visibility': 'simplified'
				}]
			}, {
				'featureType': 'administrative.neighborhood',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'administrative.province',
				'elementType': 'labels',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'landscape.natural',
				'elementType': 'geometry.fill',
				'stylers': [{
					'color': '#f7f5f0'
				}]
			}, {
				'featureType': 'poi',
				'elementType': 'labels.text',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'poi.business',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'road',
				'elementType': 'labels',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'road',
				'elementType': 'labels.icon',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'road.arterial',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'road.highway',
				'elementType': 'labels',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'road.local',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'transit',
				'stylers': [{
					'visibility': 'off'
				}]
			}, {
				'featureType': 'water',
				'elementType': 'labels.text',
				'stylers': [{
					'visibility': 'off'
				}]
			}];
		}
	}]);

	return MapStyle;
}();
},{}],5:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var PopupWrapper = exports.PopupWrapper = function () {
	function PopupWrapper() {
		_classCallCheck(this, PopupWrapper);
	}

	_createClass(PopupWrapper, null, [{
		key: 'popupClass',

		/**
   * Returns the Popup class.
   *
   * Unfortunately, the Popup class can only be defined after
   * google.maps.OverlayView is defined, when the Maps API is loaded.
   */
		get: function get() {

			/**
    * A customized popup on the map.
    * @param {!google.maps.LatLng} position
    * @param {!Element} content The bubble div.
    * @constructor
    */
			function Popup(position, content, marker) {
				this.position = position;
				this.content = content;
				this.marker = marker;
				this.content.classList.add('popup-bubble');
				// This zero-height div is positioned at the bottom of the tip.
				this.containerDiv = document.createElement('div');
				this.containerDiv.classList.add('popup-bubble__container');
				this.containerDiv.appendChild(content);

				// Optionally stop clicks, etc., from bubbling up to the map.
				google.maps.OverlayView.preventMapHitsAndGesturesFrom(this.containerDiv);
			}

			// extend google.maps.OverlayView.
			Popup.prototype = Object.create(google.maps.OverlayView.prototype);

			/** Called when the popup is added to the map. */
			Popup.prototype.onAdd = function () {
				this.getPanes().floatPane.appendChild(this.containerDiv);
				this.show();
			};

			/** Called when the popup is removed from the map. */
			Popup.prototype.onRemove = function () {
				if (this.containerDiv.parentElement) {
					this.containerDiv.parentElement.removeChild(this.containerDiv);
				}
			};

			/** Called each frame when the popup needs to draw itself. */
			Popup.prototype.draw = function () {
				var divPosition = this.getProjection().fromLatLngToDivPixel(this.position);

				// Hide the popup when it is far out of view.
				var display = Math.abs(divPosition.x) < 4000 && Math.abs(divPosition.y) < 4000 ? 'block' : 'none';
				if (display === 'block') {
					this.containerDiv.style.left = divPosition.x + 'px';
					this.containerDiv.style.top = divPosition.y + 'px';
				}

				if (this.containerDiv.style.display !== display) {
					this.containerDiv.style.display = display;
				}
			};

			Popup.prototype.height = function () {
				return getComputedStyle(this.content).getPropertyValue('height');
			};

			Popup.prototype.hide = function () {
				var _this = this;

				this.content.addEventListener('transitionend', function () {
					var opacity = getComputedStyle(_this.content).getPropertyValue('opacity');
					if (opacity <= 0.1) {
						_this.setMap(null);
					}
				});

				this.content.classList.remove('active');
			};

			Popup.prototype.show = function () {
				var _this2 = this;

				setTimeout(function () {
					_this2.content.classList.add('active');
					setTimeout(function () {
						var popupHeight = parseInt(getComputedStyle(_this2.content).getPropertyValue('height'));
						if (!isNaN(popupHeight)) {
							var offsetY = -1 * (popupHeight / 2 + _this2.marker.icon.size.height);
							_this2.marker.map.panToWithOffset(_this2.marker.getPosition(), 0, offsetY);
						}
					});
				}, 50);
			};

			return Popup;
		}
	}]);

	return PopupWrapper;
}();
},{}]},{},[1]);
