Simplify map script loading

This commit is contained in:
Brian Miyaji
2019-05-28 16:45:30 +10:00
parent 2150586ac6
commit 7fd5c609e2
4 changed files with 40 additions and 49 deletions

View File

@@ -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( '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 ); 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' ) { do_action( 'sp_setup_geocoder_scripts' );
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' );
}
$strings = apply_filters( 'sportspress_localized_strings', array( $strings = apply_filters( 'sportspress_localized_strings', array(
'none' => __( 'None', 'sportspress' ), 'none' => __( 'None', 'sportspress' ),
@@ -523,12 +513,7 @@ class SP_Admin_Setup_Wizard {
* Venue Step. * Venue Step.
*/ */
public function sp_setup_venue() { public function sp_setup_venue() {
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) { do_action( 'sp_setup_venue_geocoder_scripts' );
wp_print_scripts( 'google-maps' );
}else{
wp_print_scripts( 'leaflet_js' );
wp_print_scripts( 'control-geocoder' );
}
?> ?>
<h1><?php _e( 'Venue Setup', 'sportspress' ); ?></h1> <h1><?php _e( 'Venue Setup', 'sportspress' ); ?></h1>
<form method="post"> <form method="post">
@@ -558,13 +543,8 @@ class SP_Admin_Setup_Wizard {
<?php wp_nonce_field( 'sp-setup' ); ?> <?php wp_nonce_field( 'sp-setup' ); ?>
</p> </p>
</form> </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 <?php
do_action( 'sp_admin_geocoder_scripts' );
} }
/** /**

View File

@@ -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 ); ?>"> <input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $longitude ); ?>">
</div> </div>
<?php <?php
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) { do_action( 'sp_admin_geocoder_scripts' );
wp_print_scripts( 'sportspress-admin-locationpicker' );
} else {
wp_print_scripts( 'sportspress-admin-geocoder' );
}
} }
/** /**
@@ -175,11 +171,7 @@ class SP_Admin_Taxonomies {
</td> </td>
</tr> </tr>
<?php <?php
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) { do_action( 'sp_admin_geocoder_scripts' );
wp_print_scripts( 'sportspress-admin-locationpicker' );
} else {
wp_print_scripts( 'sportspress-admin-geocoder' );
}
} }
/** /**

View File

@@ -11,7 +11,7 @@ Version: 2.7
// Exit if accessed directly // Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit; 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 * 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_styles' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'frontend_scripts' ) );
add_action( 'sp_venue_show_openstreetmap', array( $this, 'show_venue_openstreetmap' ), 10, 5 ); 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 );
// Filters add_action( 'sp_setup_geocoder_scripts', array( $this, 'setup_geocoder_scripts' ), 10 );
//add_filter( 'sportspress_openstreetmap', array( $this, 'add_options' ) ); 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 * @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 = abs($latitude);
$lat_deg = floor($lat); $lat_deg = floor($lat);
$lat_sec = ($lat - $lat_deg) * 3600; $lat_sec = ($lat - $lat_deg) * 3600;
@@ -140,10 +139,34 @@ if ( ! class_exists( 'SportsPress_OpenStreetMap' ) && get_option( 'sportspress_l
</script> </script>
<?php <?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; endif;
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'no' ) {
new SportsPress_OpenStreetMap(); new SportsPress_OpenStreetMap();
}

View File

@@ -24,9 +24,5 @@ if ( '' === $address ) $address = '+';
if ( 'satellite' !== $maptype ) $maptype = 'roadmap'; if ( 'satellite' !== $maptype ) $maptype = 'roadmap';
if ( $latitude != null && $longitude != null ){ if ( $latitude != null && $longitude != null ){
if ( get_option( 'sportspress_load_google_maps_module', 'no' ) == 'yes' ) { do_action ( 'sp_venue_show_map', $latitude, $longitude, $address, $zoom, $maptype );
do_action ( 'sp_venue_show_google_maps', $latitude, $longitude, $address, $zoom, $maptype );
}else{
do_action ( 'sp_venue_show_openstreetmap', $latitude, $longitude, $address, $zoom, $maptype );
}
} }