-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributors.js
108 lines (90 loc) · 3.08 KB
/
distributors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* @file
* Modal window behaviors.
*/
(function ($, Drupal, drupalSettings) {
'use strict';
/**
* Attach handlers to resize the modal window
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
*/
Drupal.behaviors.distributors = {
attach: function (context, settings) {
}
};
if($("input[name^='address_box']").length>0) {
$("input[name^='address_box']").geocomplete();
}
if (!navigator.geolocation) {
//console.log( 'Track your location is blocked.');
alert(Drupal.t('Track your location is blocked.'));
}
else {
/* HTML5 Geolocation */
navigator.geolocation.getCurrentPosition(
function( position ){ // success cb
/* Current Coordinate */
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var google_map_pos = new google.maps.LatLng( lat, lng );
/* Use Geocoder to get address */
var google_maps_geocoder = new google.maps.Geocoder();
google_maps_geocoder.geocode(
{ 'latLng': google_map_pos },
function( results, status ) {
if ( status == google.maps.GeocoderStatus.OK && results[0] ) {
//console.log( results[0].formatted_address );
$('#edit-address-box').val(results[0].formatted_address);
$(".distributors-search-box .actions .form-submit" ).trigger( "click" );
return false;
}
}
);
},
function(){ // fail cb
console.log( 'Failed to get address' );
//alert(Drupal.t('Failed to get address'));
return false;
}
);
$( "#distributors-location-icon" ).click( function(e) {
e.preventDefault();
/* Chrome need SSL! */
var is_chrome = /chrom(e|ium)/.test( navigator.userAgent.toLowerCase() );
var is_ssl = 'https:' == document.location.protocol;
if( is_chrome && ! is_ssl ){
alert(Drupal.t('https need to enable.'));
return false;
}
/* HTML5 Geolocation */
navigator.geolocation.getCurrentPosition(
function( position ){ // success cb
/* Current Coordinate */
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var google_map_pos = new google.maps.LatLng( lat, lng );
/* Use Geocoder to get address */
var google_maps_geocoder = new google.maps.Geocoder();
google_maps_geocoder.geocode(
{ 'latLng': google_map_pos },
function( results, status ) {
if ( status == google.maps.GeocoderStatus.OK && results[0] ) {
//console.log( results[0].formatted_address );
$('#edit-address-box').val(results[0].formatted_address);
return false;
}
}
);
},
function(){ // fail cb
console.log( 'Failed to get address' );
//alert(Drupal.t('Failed to get address'));
return false;
}
);
});
}
})(jQuery, Drupal, drupalSettings);