Simplify map script loading
This commit is contained in:
@@ -103,17 +103,7 @@ class SP_Admin_Setup_Wizard {
|
||||
wp_register_script( 'jquery-tiptip', SP()->plugin_url() . '/assets/js/jquery.tipTip.min.js', array( 'jquery' ), '1.3', true );
|
||||
wp_register_script( 'sportspress-setup', SP()->plugin_url() . '/assets/js/admin/sportspress-setup.js', array( 'jquery', 'chosen', 'jquery-tiptip' ), SP_VERSION, true );
|
||||
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
wp_register_script( 'google-maps', '//tboy.co/maps_js' );
|
||||
wp_register_script( 'jquery-locationpicker', SP_GOOGLE_MAPS_URL . 'js/locationpicker.jquery.js', array( 'jquery', 'google-maps' ), '0.1.6', true );
|
||||
wp_register_script( 'sportspress-admin-locationpicker', SP_GOOGLE_MAPS_URL . 'js/admin/locationpicker.js', array( 'jquery', 'google-maps', 'jquery-locationpicker' ), SP_GOOGLE_MAPS_VERSION, true );
|
||||
} else {
|
||||
wp_register_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
|
||||
wp_register_script( 'control-geocoder', SP()->plugin_url() . '/assets/js/Control.Geocoder.js', array( 'leaflet_js' ) );
|
||||
wp_register_script( 'sportspress-admin-setup-geocoder', SP()->plugin_url() . '/assets/js/admin/sp-setup-geocoder.js', array( 'leaflet_js', 'control-geocoder' ), SP_VERSION, true );
|
||||
wp_enqueue_style( 'control-geocoder', SP()->plugin_url() . '/assets/css/Control.Geocoder.css', array() );
|
||||
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
|
||||
}
|
||||
do_action( 'sp_setup_geocoder_scripts' );
|
||||
|
||||
$strings = apply_filters( 'sportspress_localized_strings', array(
|
||||
'none' => __( 'None', 'sportspress' ),
|
||||
@@ -523,12 +513,7 @@ class SP_Admin_Setup_Wizard {
|
||||
* Venue Step.
|
||||
*/
|
||||
public function sp_setup_venue() {
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
wp_print_scripts( 'google-maps' );
|
||||
}else{
|
||||
wp_print_scripts( 'leaflet_js' );
|
||||
wp_print_scripts( 'control-geocoder' );
|
||||
}
|
||||
do_action( 'sp_setup_venue_geocoder_scripts' );
|
||||
?>
|
||||
<h1><?php _e( 'Venue Setup', 'sportspress' ); ?></h1>
|
||||
<form method="post">
|
||||
@@ -559,12 +544,7 @@ class SP_Admin_Setup_Wizard {
|
||||
</p>
|
||||
</form>
|
||||
<?php
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
wp_print_scripts( 'sportspress-admin-locationpicker' );
|
||||
} else {
|
||||
wp_print_scripts( 'sportspress-admin-setup-geocoder' );
|
||||
}?>
|
||||
<?php
|
||||
do_action( 'sp_admin_geocoder_scripts' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -130,11 +130,7 @@ class SP_Admin_Taxonomies {
|
||||
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
|
||||
</div>
|
||||
<?php
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
wp_print_scripts( 'sportspress-admin-locationpicker' );
|
||||
} else {
|
||||
wp_print_scripts( 'sportspress-admin-geocoder' );
|
||||
}
|
||||
do_action( 'sp_admin_geocoder_scripts' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -175,11 +171,7 @@ class SP_Admin_Taxonomies {
|
||||
</td>
|
||||
</tr>
|
||||
<?php
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
wp_print_scripts( 'sportspress-admin-locationpicker' );
|
||||
} else {
|
||||
wp_print_scripts( 'sportspress-admin-geocoder' );
|
||||
}
|
||||
do_action( 'sp_admin_geocoder_scripts' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ Version: 2.7
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
if ( ! class_exists( 'SportsPress_OpenStreetMap' ) && get_option( 'sportspress_load_google_maps_module', 'no' ) == 'no' ) :
|
||||
if ( ! class_exists( 'SportsPress_OpenStreetMap' ) ):
|
||||
|
||||
/**
|
||||
* Main SportsPress OpenStreetMap Class
|
||||
@@ -33,11 +33,10 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) && get_option( 'sportspress_l
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
|
||||
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
|
||||
add_action( 'sp_venue_show_openstreetmap', array( $this, 'show_venue_openstreetmap' ), 10, 5 );
|
||||
|
||||
// Filters
|
||||
//add_filter( 'sportspress_openstreetmap', array( $this, 'add_options' ) );
|
||||
|
||||
add_action( 'sp_venue_show_map', array( $this, 'show_venue_map' ), 10, 5 );
|
||||
add_action( 'sp_admin_geocoder_scripts', array( $this, 'admin_geocoder_scripts' ), 10 );
|
||||
add_action( 'sp_setup_geocoder_scripts', array( $this, 'setup_geocoder_scripts' ), 10 );
|
||||
add_action( 'sp_setup_venue_geocoder_scripts', array( $this, 'setup_venue_geocoder_scripts' ), 10 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +96,7 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) && get_option( 'sportspress_l
|
||||
*
|
||||
* @return mix
|
||||
*/
|
||||
public function show_venue_openstreetmap( $latitude, $longitude, $address, $zoom, $maptype ) {
|
||||
public function show_venue_map( $latitude, $longitude, $address, $zoom, $maptype ) {
|
||||
$lat = abs($latitude);
|
||||
$lat_deg = floor($lat);
|
||||
$lat_sec = ($lat - $lat_deg) * 3600;
|
||||
@@ -141,9 +140,33 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) && get_option( 'sportspress_l
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Print geocoder script in admin
|
||||
*/
|
||||
public function admin_geocoder_scripts() {
|
||||
wp_print_scripts( 'sportspress-admin-setup-geocoder' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print geocoder script in setup
|
||||
*/
|
||||
public function setup_geocoder_scripts() {
|
||||
wp_register_script( 'leaflet_js', SP()->plugin_url() . '/assets/js/leaflet.js', array(), '1.4.0' );
|
||||
wp_register_script( 'control-geocoder', SP()->plugin_url() . '/assets/js/Control.Geocoder.js', array( 'leaflet_js' ) );
|
||||
wp_register_script( 'sportspress-admin-setup-geocoder', SP()->plugin_url() . '/assets/js/admin/sp-setup-geocoder.js', array( 'leaflet_js', 'control-geocoder' ), SP_VERSION, true );
|
||||
wp_enqueue_style( 'control-geocoder', SP()->plugin_url() . '/assets/css/Control.Geocoder.css', array() );
|
||||
wp_enqueue_style( 'leaflet_stylesheet', SP()->plugin_url() . '/assets/css/leaflet.css', array(), '1.4.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Print geocoder script in setup venue step
|
||||
*/
|
||||
public function setup_venue_geocoder_scripts() {
|
||||
wp_print_scripts( 'leaflet_js' );
|
||||
wp_print_scripts( 'control-geocoder' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'no' ) {
|
||||
|
||||
new SportsPress_OpenStreetMap();
|
||||
}
|
||||
|
||||
@@ -24,9 +24,5 @@ if ( '' === $address ) $address = '+';
|
||||
if ( 'satellite' !== $maptype ) $maptype = 'roadmap';
|
||||
|
||||
if ( $latitude != null && $longitude != null ){
|
||||
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) {
|
||||
do_action ( 'sp_venue_show_google_maps', $latitude, $longitude, $address, $zoom, $maptype );
|
||||
}else{
|
||||
do_action ( 'sp_venue_show_openstreetmap', $latitude, $longitude, $address, $zoom, $maptype );
|
||||
}
|
||||
do_action ( 'sp_venue_show_map', $latitude, $longitude, $address, $zoom, $maptype );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user