resolved uncaught js error
This commit is contained in:
@@ -13,14 +13,25 @@ require_once(dirname(__FILE__) . '/mp_url_api.php');
|
|||||||
|
|
||||||
add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts' );
|
add_action( 'wp_enqueue_scripts', 'wpa_enqueue_scripts' );
|
||||||
function wpa_enqueue_scripts() {
|
function wpa_enqueue_scripts() {
|
||||||
wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', false);
|
wp_enqueue_style( 'mp_style', plugins_url('mp_style.css', __FILE__), '', '', '');
|
||||||
wp_enqueue_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true);
|
wp_enqueue_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true);
|
||||||
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
wp_enqueue_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
||||||
|
// wp_register_script('mp_init_map', plugins_url('mp_init_map.js', __FILE__), '', '', true);
|
||||||
|
// wp_register_script('mp_google_api', mp_url_api(), ['mp_init_map'], '', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//function wpa_defer_scripts($tag, $handle) {
|
||||||
|
// if ('mp_google_api' === $handle)
|
||||||
|
// return str_replace(' src="', ' async defer src="', $tag);
|
||||||
|
// if ('mp_googe_api' === $handle)
|
||||||
|
// return str_replace(' src="', ' defer src="', $tag);
|
||||||
|
// return $tag;
|
||||||
|
//}
|
||||||
|
//add_filter('script_loader_tag', 'wpa_defer_scripts', 10, 2);
|
||||||
|
|
||||||
add_shortcode('lejourduprof_map', 'mp_add_div');
|
add_shortcode('lejourduprof_map', 'mp_add_div');
|
||||||
function mp_add_div() {
|
function mp_add_div() {
|
||||||
$mp_api_script = '<div id="map">map here</div>';
|
$mp_api_script = '<div id="ljdp_map">map here</div>';
|
||||||
return $mp_api_script;
|
return $mp_api_script;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
srcs/plugins/map_prof/marker.png
Normal file
BIN
srcs/plugins/map_prof/marker.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -1,11 +1,28 @@
|
|||||||
function mp_init_map() {
|
function mp_init_map() {
|
||||||
var location = {lat: 38.8833, lng: -77.0167};
|
var locations = [
|
||||||
var map = new google.maps.Map(document.getElementById("map"), {
|
{lat: 38.8833, lng: -77.0167},
|
||||||
zoom: 12,
|
{lat: 39.8833, lng: -76.0167},
|
||||||
center: location
|
];
|
||||||
});
|
var map = new google.maps.Map(
|
||||||
var marker = new google.maps.Marker({
|
document.getElementById("ljdp_map"),
|
||||||
position: location,
|
{
|
||||||
map: map
|
zoom: 5,
|
||||||
});
|
disableDefaultUI: true,
|
||||||
|
center: locations[0],
|
||||||
|
}
|
||||||
|
);
|
||||||
|
var marker, icon;
|
||||||
|
// icon = "/wp-content/plugins/map_prof/marker.png";
|
||||||
|
icon = {
|
||||||
|
//url: document.location.href + "marker.png",
|
||||||
|
url: "/wp-content/plugins/map_prof/marker.png",
|
||||||
|
scaledSize: new google.maps.Size(35, 50)
|
||||||
|
};
|
||||||
|
for (loc of locations) {
|
||||||
|
marker = new google.maps.Marker({
|
||||||
|
position: loc,
|
||||||
|
map: map,
|
||||||
|
icon: icon,
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#map {
|
#ljdp_map {
|
||||||
height: 500px;
|
height: 500px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
function mp_url_api() {
|
function mp_url_api() {
|
||||||
$mp_url = array(
|
$mp_url = array(
|
||||||
'src' => 'https://maps.googleapis.com/maps/api/js',
|
'src' => 'https://maps.googleapis.com/maps/api/js',
|
||||||
'sensor' => 'false',
|
'sensor' => 'false',
|
||||||
'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE',
|
'key' => 'AIzaSyCvdGV2ssD4ov4a9CuIlQhoJyz5gWWiSvE',
|
||||||
'callback' => 'mp_init_map',
|
'callback' => 'mp_init_map',
|
||||||
);
|
);
|
||||||
$mp_src = "";
|
$mp_src = "";
|
||||||
foreach ($mp_url as $url_key => $url_value) {
|
foreach ($mp_url as $url_key => $url_value) {
|
||||||
@@ -17,9 +17,6 @@ function mp_url_api() {
|
|||||||
$mp_src .= "&" . $url_key . "=" . $url_value;
|
$mp_src .= "&" . $url_key . "=" . $url_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
//$mp_api_script = '<script async defer ';
|
|
||||||
//$mp_api_script .= 'src="' . $mp_src . '"></script>';
|
|
||||||
//return $mp_api_script;
|
|
||||||
return $mp_src;
|
return $mp_src;
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
Reference in New Issue
Block a user