Load Google Maps script only when needed
This commit is contained in:
26
assets/js/sp-maps.js
Normal file
26
assets/js/sp-maps.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
(function($) {
|
||||||
|
function sp_maps() {
|
||||||
|
$maps = $('.sp-google-map');
|
||||||
|
$maps.each(function() {
|
||||||
|
$self = $(this);
|
||||||
|
address = $self.attr('data-address');
|
||||||
|
latitude = $self.attr('data-latitude');
|
||||||
|
longitude = $self.attr('data-longitude');
|
||||||
|
var ll = new google.maps.LatLng(latitude,longitude);
|
||||||
|
var mapOptions = {
|
||||||
|
scrollwheel: false,
|
||||||
|
zoom: 16,
|
||||||
|
center: ll
|
||||||
|
};
|
||||||
|
var map = new google.maps.Map($self[0], mapOptions)
|
||||||
|
var marker = new google.maps.Marker({
|
||||||
|
position: ll,
|
||||||
|
map: map,
|
||||||
|
animation: google.maps.Animation.DROP,
|
||||||
|
flat: true,
|
||||||
|
title: address
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
google.maps.event.addDomListener(window, "load", sp_maps);
|
||||||
|
})(jQuery);
|
||||||
@@ -200,58 +200,31 @@ function viewport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sp_unsplit_table(original) {
|
function sp_unsplit_table(original) {
|
||||||
original.closest(".sp-responsive-table-wrapper").find(".sp-pinned-table").remove();
|
original.closest(".sp-responsive-table-wrapper").find(".sp-pinned-table").remove();
|
||||||
original.unwrap();
|
original.unwrap();
|
||||||
original.unwrap();
|
original.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sp_set_cell_heights(original, copy) {
|
function sp_set_cell_heights(original, copy) {
|
||||||
var tr = original.find('tr'),
|
var tr = original.find('tr'),
|
||||||
tr_copy = copy.find('tr'),
|
tr_copy = copy.find('tr'),
|
||||||
heights = [];
|
heights = [];
|
||||||
|
|
||||||
tr.each(function (index) {
|
tr.each(function (index) {
|
||||||
var self = $(this),
|
var self = $(this),
|
||||||
tx = self.find('th, td');
|
tx = self.find('th, td');
|
||||||
|
|
||||||
tx.each(function () {
|
tx.each(function () {
|
||||||
var height = $(this).outerHeight(true);
|
var height = $(this).outerHeight(true);
|
||||||
heights[index] = heights[index] || 0;
|
heights[index] = heights[index] || 0;
|
||||||
if (height > heights[index]) heights[index] = height;
|
if (height > heights[index]) heights[index] = height;
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
tr_copy.each(function (index) {
|
tr_copy.each(function (index) {
|
||||||
$(this).height(heights[index]);
|
$(this).height(heights[index]);
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Google Maps */
|
|
||||||
function initialize_google_maps() {
|
|
||||||
$maps = $('.sp-google-map');
|
|
||||||
$maps.each(function() {
|
|
||||||
$self = $(this);
|
|
||||||
address = $self.attr('data-address');
|
|
||||||
latitude = $self.attr('data-latitude');
|
|
||||||
longitude = $self.attr('data-longitude');
|
|
||||||
var ll = new google.maps.LatLng(latitude,longitude);
|
|
||||||
var mapOptions = {
|
|
||||||
scrollwheel: false,
|
|
||||||
zoom: 16,
|
|
||||||
center: ll
|
|
||||||
};
|
|
||||||
var map = new google.maps.Map($self[0], mapOptions)
|
|
||||||
var marker = new google.maps.Marker({
|
|
||||||
position: ll,
|
|
||||||
map: map,
|
|
||||||
animation: google.maps.Animation.DROP,
|
|
||||||
flat: true,
|
|
||||||
title: address
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
google.maps.event.addDomListener(window, "load", initialize_google_maps);
|
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
@@ -40,13 +40,18 @@ class SP_Frontend_Scripts {
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function load_scripts() {
|
public function load_scripts() {
|
||||||
|
global $typenow;
|
||||||
// Scripts
|
// Scripts
|
||||||
wp_enqueue_script( 'jquery' );
|
wp_enqueue_script( 'jquery' );
|
||||||
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.exp', true );
|
|
||||||
wp_enqueue_script( 'jquery-datatables', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
|
wp_enqueue_script( 'jquery-datatables', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.dataTables.min.js', array( 'jquery' ), '1.9.4', true );
|
||||||
wp_enqueue_script( 'jquery-countdown', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.0.2', true );
|
wp_enqueue_script( 'jquery-countdown', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/jquery.countdown.min.js', array( 'jquery' ), '2.0.2', true );
|
||||||
wp_enqueue_script( 'sportspress', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/sportspress.js', array( 'jquery' ), time(), true );
|
wp_enqueue_script( 'sportspress', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/sportspress.js', array( 'jquery' ), time(), true );
|
||||||
|
|
||||||
|
if ( is_singular( 'sp_event' ) || is_tax( 'sp_venue' ) ):
|
||||||
|
wp_enqueue_script( 'google-maps', 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false', array(), '3.exp', true );
|
||||||
|
wp_enqueue_script( 'sp-maps', plugin_dir_url( SP_PLUGIN_FILE ) .'assets/js/sp-maps.js', array( 'jquery', 'google-maps' ), time(), true );
|
||||||
|
endif;
|
||||||
|
|
||||||
// Localize scripts.
|
// Localize scripts.
|
||||||
wp_localize_script( 'sportspress', 'localized_strings', array( 'days' => __( 'days', 'sportspress' ), 'hrs' => __( 'hrs', 'sportspress' ), 'mins' => __( 'mins', 'sportspress' ), 'secs' => __( 'secs', 'sportspress' ), 'previous' => __( 'Previous', 'sportspress' ), 'next' => __( 'Next', 'sportspress' ) ) );
|
wp_localize_script( 'sportspress', 'localized_strings', array( 'days' => __( 'days', 'sportspress' ), 'hrs' => __( 'hrs', 'sportspress' ), 'mins' => __( 'mins', 'sportspress' ), 'secs' => __( 'secs', 'sportspress' ), 'previous' => __( 'Previous', 'sportspress' ), 'next' => __( 'Next', 'sportspress' ) ) );
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user