Add Google Maps selector to venue
This commit is contained in:
@@ -4,6 +4,8 @@ function sportspress_admin_enqueue_scripts() {
|
|||||||
wp_enqueue_style( 'sportspress-admin');
|
wp_enqueue_style( 'sportspress-admin');
|
||||||
|
|
||||||
wp_enqueue_script( 'jquery' );
|
wp_enqueue_script( 'jquery' );
|
||||||
|
wp_enqueue_script( 'google-maps', 'http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places' );
|
||||||
|
wp_enqueue_script( 'jquery-locationpicker', SPORTSPRESS_PLUGIN_URL .'/assets/js/locationpicker.jquery.js', array( 'jquery' ), '0.1.6', true );
|
||||||
wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'/assets/js/admin.js', array( 'jquery' ), time(), true );
|
wp_enqueue_script( 'sportspress-admin', SPORTSPRESS_PLUGIN_URL .'/assets/js/admin.js', array( 'jquery' ), time(), true );
|
||||||
}
|
}
|
||||||
add_action( 'admin_enqueue_scripts', 'sportspress_admin_enqueue_scripts' );
|
add_action( 'admin_enqueue_scripts', 'sportspress_admin_enqueue_scripts' );
|
||||||
|
|||||||
@@ -24,7 +24,20 @@ function sportspress_venue_edit_form_fields( $term ) {
|
|||||||
<tr class="form-field">
|
<tr class="form-field">
|
||||||
<th scope="row" valign="top"><label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label></th>
|
<th scope="row" valign="top"><label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label></th>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : ''; ?>">
|
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="<?php echo esc_attr( $term_meta['sp_address'] ) ? esc_attr( $term_meta['sp_address'] ) : ''; ?>">
|
||||||
|
<p><div class="sp-location-picker"></div></p>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="form-field">
|
||||||
|
<th scope="row" valign="top"><label for="term_meta[sp_latitude]"><?php _e( 'Latitude', 'sportspress' ); ?></label></th>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="<?php echo esc_attr( $term_meta['sp_latitude'] ) ? esc_attr( $term_meta['sp_latitude'] ) : ''; ?>">
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr class="form-field">
|
||||||
|
<th scope="row" valign="top"><label for="term_meta[sp_longitude]"><?php _e( 'Longitude', 'sportspress' ); ?></label></th>
|
||||||
|
<td>
|
||||||
|
<input type="text" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="<?php echo esc_attr( $term_meta['sp_longitude'] ) ? esc_attr( $term_meta['sp_longitude'] ) : ''; ?>">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php
|
<?php
|
||||||
@@ -33,10 +46,15 @@ add_action( 'sp_venue_edit_form_fields', 'sportspress_venue_edit_form_fields', 1
|
|||||||
|
|
||||||
function sportspress_venue_add_form_fields() {
|
function sportspress_venue_add_form_fields() {
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="form-field">
|
<div class="form-field">
|
||||||
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
|
<label for="term_meta[sp_address]"><?php _e( 'Address', 'sportspress' ); ?></label>
|
||||||
<input type="text" name="term_meta[sp_address]" id="term_meta[sp_address]" value="">
|
<input type="text" class="sp-address" name="term_meta[sp_address]" id="term_meta[sp_address]" value="">
|
||||||
|
<input type="hidden" class="sp-latitude" name="term_meta[sp_latitude]" id="term_meta[sp_latitude]" value="40.7324319">
|
||||||
|
<input type="hidden" class="sp-longitude" name="term_meta[sp_longitude]" id="term_meta[sp_longitude]" value="-73.82480799999996">
|
||||||
|
<p><div class="sp-location-picker"></div></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
add_action( 'sp_venue_add_form_fields', 'sportspress_venue_add_form_fields', 10, 2 );
|
add_action( 'sp_venue_add_form_fields', 'sportspress_venue_add_form_fields', 10, 2 );
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ table.widefat.sp-data-table td:first-child {
|
|||||||
}
|
}
|
||||||
table.widefat.sp-data-table input[type="text"],
|
table.widefat.sp-data-table input[type="text"],
|
||||||
table.widefat.sp-data-table input[type="number"] {
|
table.widefat.sp-data-table input[type="number"] {
|
||||||
min-width: 14px;
|
min-width: 1.25em;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
table.widefat.sp-data-table input.name {
|
table.widefat.sp-data-table input.name {
|
||||||
@@ -34,4 +34,20 @@ table.widefat td.column-sp_logo {
|
|||||||
#sp_player-adder h4,
|
#sp_player-adder h4,
|
||||||
#sp_position-adder h4 {
|
#sp_position-adder h4 {
|
||||||
margin: 10px 0;
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-field .sp-location-picker {
|
||||||
|
width: 95%;
|
||||||
|
height: 320px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media only screen and (max-width: 768px) {
|
||||||
|
|
||||||
|
.form-field .sp-location-picker {
|
||||||
|
width: 99%;
|
||||||
|
}
|
||||||
|
.form-field td .sp-location-picker {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,62 +1,62 @@
|
|||||||
jQuery(document).ready(function($){
|
jQuery(document).ready(function($){
|
||||||
|
|
||||||
// Auto key placeholder
|
// Auto key placeholder
|
||||||
$('#poststuff #title').on('keyup', function() {
|
$("#poststuff #title").on("keyup", function() {
|
||||||
$('#sp_key').attr('placeholder', $(this).val().replace(/[^a-z]/gi,'').toLowerCase());
|
$("#sp_key").attr("placeholder", $(this).val().replace(/[^a-z]/gi,"").toLowerCase());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate auto key placeholder
|
// Activate auto key placeholder
|
||||||
$('#poststuff #title').keyup();
|
$("#poststuff #title").keyup();
|
||||||
|
|
||||||
// Tab switcher
|
// Tab switcher
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-bar').find('a').click(function() {
|
$(".sp-tab-panel").siblings(".sp-tab-bar").find("a").click(function() {
|
||||||
$(this).closest('li').removeClass('wp-tab').addClass('wp-tab-active').siblings().removeClass('wp-tab-active').addClass('wp-tab').closest('.wp-tab-bar').siblings($(this).attr('href')).show().siblings('.wp-tab-panel').hide();
|
$(this).closest("li").removeClass("wp-tab").addClass("wp-tab-active").siblings().removeClass("wp-tab-active").addClass("wp-tab").closest(".wp-tab-bar").siblings($(this).attr("href")).show().siblings(".wp-tab-panel").hide();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Tab filter
|
// Tab filter
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change(function() {
|
$(".sp-tab-panel").siblings(".sp-tab-select").find("select").change(function() {
|
||||||
var val = $(this).val();
|
var val = $(this).val();
|
||||||
var filter = '.sp-filter-'+val;
|
var filter = ".sp-filter-"+val;
|
||||||
var $filters = $(this).closest('.sp-tab-select').siblings('.sp-tab-select');
|
var $filters = $(this).closest(".sp-tab-select").siblings(".sp-tab-select");
|
||||||
if($filters.length) {
|
if($filters.length) {
|
||||||
$filters.each(function() {
|
$filters.each(function() {
|
||||||
filter += '.sp-filter-'+$(this).find('select').val();
|
filter += ".sp-filter-"+$(this).find("select").val();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$(this).closest('.sp-tab-select').siblings('.sp-tab-panel').find('.sp-post').hide(0, function() {
|
$(this).closest(".sp-tab-select").siblings(".sp-tab-panel").find(".sp-post").hide(0, function() {
|
||||||
$(this).find('input').prop('disabled', true);
|
$(this).find("input").prop("disabled", true);
|
||||||
$(this).filter(filter).show(0, function() {
|
$(this).filter(filter).show(0, function() {
|
||||||
$(this).find('input').prop('disabled', false);
|
$(this).find("input").prop("disabled", false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger tab filter
|
// Trigger tab filter
|
||||||
$('.sp-tab-panel').siblings('.sp-tab-select').find('select').change();
|
$(".sp-tab-panel").siblings(".sp-tab-select").find("select").change();
|
||||||
|
|
||||||
// Self-cloning
|
// Self-cloning
|
||||||
$('.sp-clone:last').find('select').change(function() {
|
$(".sp-clone:last").find("select").change(function() {
|
||||||
$(this).closest('.sp-clone').siblings().find('select').change(function() {
|
$(this).closest(".sp-clone").siblings().find("select").change(function() {
|
||||||
if($(this).val() == '0') $(this).closest('.sp-clone').remove();
|
if($(this).val() == "0") $(this).closest(".sp-clone").remove();
|
||||||
}).find('option:first').text($(this).closest('.sp-clone').attr('data-remove-text'));
|
}).find("option:first").text($(this).closest(".sp-clone").attr("data-remove-text"));
|
||||||
if($(this).val() != '0') {
|
if($(this).val() != "0") {
|
||||||
$original = $(this).closest('.sp-clone');
|
$original = $(this).closest(".sp-clone");
|
||||||
$original.before($original.clone().find('select').attr('name', $original.attr('data-clone-name') + '[]').val($(this).val()).closest('.sp-clone')).attr('data-clone-num', parseInt($original.attr('data-clone-num')) + 1).find('select').val('0').change();
|
$original.before($original.clone().find("select").attr("name", $original.attr("data-clone-name") + "[]").val($(this).val()).closest(".sp-clone")).attr("data-clone-num", parseInt($original.attr("data-clone-num")) + 1).find("select").val("0").change();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Activate self-cloning
|
// Activate self-cloning
|
||||||
$('.sp-clone:last').find('select').change();
|
$(".sp-clone:last").find("select").change();
|
||||||
|
|
||||||
// Total stats calculator
|
// Total stats calculator
|
||||||
$('.sp-data-table .sp-total input').on('updateTotal', function() {
|
$(".sp-data-table .sp-total input").on("updateTotal", function() {
|
||||||
index = $(this).parent().index();
|
index = $(this).parent().index();
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
$(this).closest('.sp-data-table').find('.sp-post').each(function() {
|
$(this).closest(".sp-data-table").find(".sp-post").each(function() {
|
||||||
val = $(this).find('td').eq(index).find('input').val();
|
val = $(this).find("td").eq(index).find("input").val();
|
||||||
if(val == '') {
|
if(val == "") {
|
||||||
val = $(this).find('td').eq(index).find('input').attr('placeholder');
|
val = $(this).find("td").eq(index).find("input").attr("placeholder");
|
||||||
}
|
}
|
||||||
if($.isNumeric(val)) {
|
if($.isNumeric(val)) {
|
||||||
sum += parseInt(val, 10);
|
sum += parseInt(val, 10);
|
||||||
@@ -66,69 +66,69 @@ jQuery(document).ready(function($){
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Activate total stats calculator
|
// Activate total stats calculator
|
||||||
if($('.sp-data-table .sp-total').size()) {
|
if($(".sp-data-table .sp-total").size()) {
|
||||||
$('.sp-data-table .sp-post td input').on('keyup', function() {
|
$(".sp-data-table .sp-post td input").on("keyup", function() {
|
||||||
$(this).closest('.sp-data-table').find('.sp-total td').eq($(this).parent().index()).find('input').trigger('updateTotal');
|
$(this).closest(".sp-data-table").find(".sp-total td").eq($(this).parent().index()).find("input").trigger("updateTotal");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equation selector
|
// Equation selector
|
||||||
$('.sp-equation-selector select:last').change(function() {
|
$(".sp-equation-selector select:last").change(function() {
|
||||||
$(this).siblings().change(function() {
|
$(this).siblings().change(function() {
|
||||||
if($(this).val() == '') $(this).remove();
|
if($(this).val() == "") $(this).remove();
|
||||||
}).find('option:first').text($(this).attr('data-remove-text'));
|
}).find("option:first").text($(this).attr("data-remove-text"));
|
||||||
if($(this).val() != '') {
|
if($(this).val() != "") {
|
||||||
$(this).before($(this).clone().val($(this).val())).val('').change();
|
$(this).before($(this).clone().val($(this).val())).val("").change();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger equation selector
|
// Trigger equation selector
|
||||||
$('.sp-equation-selector select:last').change().siblings().change();
|
$(".sp-equation-selector select:last").change().siblings().change();
|
||||||
|
|
||||||
// Order selector
|
// Order selector
|
||||||
$('.sp-order-selector select:first').change(function() {
|
$(".sp-order-selector select:first").change(function() {
|
||||||
if($(this).val() == '0') {
|
if($(this).val() == "0") {
|
||||||
$(this).siblings().prop( 'disabled', true );
|
$(this).siblings().prop( "disabled", true );
|
||||||
} else {
|
} else {
|
||||||
$(this).siblings().prop( 'disabled', false )
|
$(this).siblings().prop( "disabled", false )
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger order selector
|
// Trigger order selector
|
||||||
$('.sp-order-selector select:first').change();
|
$(".sp-order-selector select:first").change();
|
||||||
|
|
||||||
// Format selector
|
// Format selector
|
||||||
$('.sp-format-selector select:first').change(function() {
|
$(".sp-format-selector select:first").change(function() {
|
||||||
|
|
||||||
$precisionselector = $('.sp-precision-selector input:first');
|
$precisionselector = $(".sp-precision-selector input:first");
|
||||||
$equationselector = $('.sp-equation-selector select');
|
$equationselector = $(".sp-equation-selector select");
|
||||||
|
|
||||||
// Precision settings
|
// Precision settings
|
||||||
if($(this).val() == 'decimal' || $(this).val() == 'time') {
|
if($(this).val() == "decimal" || $(this).val() == "time") {
|
||||||
$precisionselector.prop( 'disabled', false );
|
$precisionselector.prop( "disabled", false );
|
||||||
} else {
|
} else {
|
||||||
$precisionselector.prop( 'disabled', true )
|
$precisionselector.prop( "disabled", true )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equation settings
|
// Equation settings
|
||||||
if($(this).val() == 'custom') {
|
if($(this).val() == "custom") {
|
||||||
$equationselector.prop( 'disabled', true );
|
$equationselector.prop( "disabled", true );
|
||||||
} else {
|
} else {
|
||||||
$equationselector.prop( 'disabled', false );
|
$equationselector.prop( "disabled", false );
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger format selector
|
// Trigger format selector
|
||||||
$('.sp-format-selector select:first').change();
|
$(".sp-format-selector select:first").change();
|
||||||
|
|
||||||
// Status selector
|
// Status selector
|
||||||
$('.sp-status-selector select:first-child').change(function() {
|
$(".sp-status-selector select:first-child").change(function() {
|
||||||
|
|
||||||
$subselector = $(this).siblings();
|
$subselector = $(this).siblings();
|
||||||
|
|
||||||
// Sub settings
|
// Sub settings
|
||||||
if($(this).val() == 'sub') {
|
if($(this).val() == "sub") {
|
||||||
$subselector.show();
|
$subselector.show();
|
||||||
} else {
|
} else {
|
||||||
$subselector.hide();
|
$subselector.hide();
|
||||||
@@ -137,9 +137,29 @@ jQuery(document).ready(function($){
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Trigger status selector
|
// Trigger status selector
|
||||||
$('.sp-status-selector select:first-child').change();
|
$(".sp-status-selector select:first-child").change();
|
||||||
|
|
||||||
// Remove slug editor in quick edit for slug-sensitive post types
|
// Remove slug editor in quick edit for slug-sensitive post types
|
||||||
$('.inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_column, .inline-edit-sp_statistic').find('input[name=post_name]').closest('label').remove();
|
$(".inline-edit-sp_result, .inline-edit-sp_outcome, .inline-edit-sp_column, .inline-edit-sp_statistic").find("input[name=post_name]").closest("label").remove();
|
||||||
|
|
||||||
|
// Prevent address input from submitting form
|
||||||
|
$(".sp-address").keypress(function(event) {
|
||||||
|
return event.keyCode != 13;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Location picker
|
||||||
|
$(".sp-location-picker").locationpicker({
|
||||||
|
location: {
|
||||||
|
latitude: Number($(".sp-latitude").val()),
|
||||||
|
longitude: Number($(".sp-longitude").val())
|
||||||
|
},
|
||||||
|
radius: 0,
|
||||||
|
inputBinding: {
|
||||||
|
latitudeInput: $(".sp-latitude"),
|
||||||
|
longitudeInput: $(".sp-longitude"),
|
||||||
|
locationNameInput: $(".sp-address")
|
||||||
|
},
|
||||||
|
enableAutocomplete: true
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
296
assets/js/locationpicker.jquery.js
Executable file
296
assets/js/locationpicker.jquery.js
Executable file
@@ -0,0 +1,296 @@
|
|||||||
|
/*
|
||||||
|
* File: locationpicker.jquery.js
|
||||||
|
* Version: 0.1.6
|
||||||
|
* Author: Dmitry Berezovsky, Logicify (http://logicify.com/)
|
||||||
|
* Info: http://logicify.github.io/jquery-locationpicker-plugin/
|
||||||
|
*
|
||||||
|
* Copyright 2013 Logicify
|
||||||
|
*
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function ( $ ) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holds google map object and related utility entities.
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
function GMapContext(domElement, options) {
|
||||||
|
var _map = new google.maps.Map(domElement, options);
|
||||||
|
var _marker = new google.maps.Marker({
|
||||||
|
position: new google.maps.LatLng(54.19335, -3.92695),
|
||||||
|
map: _map,
|
||||||
|
title: "Drag Me",
|
||||||
|
draggable: true
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
map: _map,
|
||||||
|
marker: _marker,
|
||||||
|
circle: null,
|
||||||
|
location: _marker.position,
|
||||||
|
radius: options.radius,
|
||||||
|
locationName: options.locationName,
|
||||||
|
settings: options.settings,
|
||||||
|
domContainer: domElement,
|
||||||
|
geodecoder: new google.maps.Geocoder()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility functions for Google Map Manipulations
|
||||||
|
var GmUtility = {
|
||||||
|
/**
|
||||||
|
* Draw a circle over the the map. Returns circle object.
|
||||||
|
* Also writes new circle object in gmapContext.
|
||||||
|
*
|
||||||
|
* @param center - LatLng of the center of the circle
|
||||||
|
* @param radius - radius in meters
|
||||||
|
* @param gmapContext - context
|
||||||
|
* @param options
|
||||||
|
*/
|
||||||
|
drawCircle: function(gmapContext, center, radius, options) {
|
||||||
|
if (gmapContext.circle != null) {
|
||||||
|
gmapContext.circle.setMap(null);
|
||||||
|
}
|
||||||
|
if (radius > 0) {
|
||||||
|
radius *= 1;
|
||||||
|
options = $.extend({
|
||||||
|
strokeColor: "#0000FF",
|
||||||
|
strokeOpacity: 0.35,
|
||||||
|
strokeWeight: 2,
|
||||||
|
fillColor: "#0000FF",
|
||||||
|
fillOpacity: 0.20
|
||||||
|
}, options);
|
||||||
|
options.map = gmapContext.map;
|
||||||
|
options.radius = radius;
|
||||||
|
options.center = center;
|
||||||
|
gmapContext.circle = new google.maps.Circle(options);
|
||||||
|
return gmapContext.circle;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param gMapContext
|
||||||
|
* @param location
|
||||||
|
* @param callback
|
||||||
|
*/
|
||||||
|
setPosition: function(gMapContext, location, callback) {
|
||||||
|
gMapContext.location = location;
|
||||||
|
gMapContext.marker.setPosition(location);
|
||||||
|
gMapContext.map.panTo(location);
|
||||||
|
this.drawCircle(gMapContext, location, gMapContext.radius, {});
|
||||||
|
if (gMapContext.settings.enableReverseGeocode) {
|
||||||
|
gMapContext.geodecoder.geocode({latLng: gMapContext.location}, function(results, status){
|
||||||
|
if (status == google.maps.GeocoderStatus.OK && results.length > 0){
|
||||||
|
gMapContext.locationName = results[0].formatted_address;
|
||||||
|
}
|
||||||
|
if (callback) {
|
||||||
|
callback.call(this, gMapContext);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
if (callback) {
|
||||||
|
callback.call(this, gmapContext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
locationFromLatLng: function(lnlg) {
|
||||||
|
return {latitude: lnlg.lat(), longitude: lnlg.lng()}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPluginApplied(domObj) {
|
||||||
|
return getContextForElement(domObj) != undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getContextForElement(domObj) {
|
||||||
|
return $(domObj).data("locationpicker");
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateInputValues(inputBinding, gmapContext){
|
||||||
|
if (!inputBinding) return;
|
||||||
|
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
|
||||||
|
if (inputBinding.latitudeInput) {
|
||||||
|
inputBinding.latitudeInput.val(currentLocation.latitude);
|
||||||
|
}
|
||||||
|
if (inputBinding.longitudeInput) {
|
||||||
|
inputBinding.longitudeInput.val(currentLocation.longitude);
|
||||||
|
}
|
||||||
|
if (inputBinding.radiusInput) {
|
||||||
|
inputBinding.radiusInput.val(gmapContext.radius);
|
||||||
|
}
|
||||||
|
if (inputBinding.locationNameInput) {
|
||||||
|
inputBinding.locationNameInput.val(gmapContext.locationName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupInputListenersInput(inputBinding, gmapContext) {
|
||||||
|
if (inputBinding) {
|
||||||
|
if (inputBinding.radiusInput){
|
||||||
|
inputBinding.radiusInput.on("change", function() {
|
||||||
|
gmapContext.radius = $(this).val();
|
||||||
|
GmUtility.setPosition(gmapContext, gmapContext.location, function(context){
|
||||||
|
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (inputBinding.locationNameInput && gmapContext.settings.enableAutocomplete) {
|
||||||
|
gmapContext.autocomplete = new google.maps.places.Autocomplete(inputBinding.locationNameInput.get(0));
|
||||||
|
google.maps.event.addListener(gmapContext.autocomplete, 'place_changed', function() {
|
||||||
|
var place = gmapContext.autocomplete.getPlace();
|
||||||
|
if (!place.geometry) {
|
||||||
|
gmapContext.onlocationnotfound();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
GmUtility.setPosition(gmapContext, place.geometry.location, function(context) {
|
||||||
|
updateInputValues(inputBinding, context);
|
||||||
|
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (inputBinding.latitudeInput) {
|
||||||
|
inputBinding.latitudeInput.on("change", function() {
|
||||||
|
GmUtility.setPosition(gmapContext, new google.maps.LatLng($(this).val(), gmapContext.location.lng()), function(context){
|
||||||
|
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (inputBinding.longitudeInput) {
|
||||||
|
inputBinding.longitudeInput.on("change", function() {
|
||||||
|
GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.location.lat(), $(this).val()), function(context){
|
||||||
|
context.settings.onchanged(GmUtility.locationFromLatLng(context.location), context.radius, false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialization:
|
||||||
|
* $("#myMap").locationpicker(options);
|
||||||
|
* @param options
|
||||||
|
* @param params
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
$.fn.locationpicker = function( options, params ) {
|
||||||
|
if (typeof options == 'string') { // Command provided
|
||||||
|
var _targetDomElement = this.get(0);
|
||||||
|
// Plug-in is not applied - nothing to do.
|
||||||
|
if (!isPluginApplied(_targetDomElement)) return;
|
||||||
|
var gmapContext = getContextForElement(_targetDomElement);
|
||||||
|
switch (options) {
|
||||||
|
case "location":
|
||||||
|
if (params == undefined) { // Getter
|
||||||
|
var location = GmUtility.locationFromLatLng(gmapContext.location);
|
||||||
|
location.radius = gmapContext.radius;
|
||||||
|
location.name = gmapContext.locationName;
|
||||||
|
return location;
|
||||||
|
} else { // Setter
|
||||||
|
if (params.radius) {
|
||||||
|
gmapContext.radius = params.radius;
|
||||||
|
}
|
||||||
|
GmUtility.setPosition(gmapContext, new google.maps.LatLng(params.latitude, params.longitude), function(gmapContext) {
|
||||||
|
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "subscribe":
|
||||||
|
/**
|
||||||
|
* Provides interface for subscribing for GoogleMap events.
|
||||||
|
* See Google API documentation for details.
|
||||||
|
* Parameters:
|
||||||
|
* - event: string, name of the event
|
||||||
|
* - callback: function, callback function to be invoked
|
||||||
|
*/
|
||||||
|
if (options == undefined) { // Getter is not available
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
var event = params.event;
|
||||||
|
var callback = params.callback;
|
||||||
|
if (!event || ! callback) {
|
||||||
|
console.error("LocationPicker: Invalid arguments for method \"subscribe\"")
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
google.maps.event.addListener(gmapContext.map, event, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.each(function() {
|
||||||
|
var $target = $(this);
|
||||||
|
// If plug-in hasn't been applied before - initialize, otherwise - skip
|
||||||
|
if (isPluginApplied(this)) return;
|
||||||
|
// Plug-in initialization is required
|
||||||
|
// Defaults
|
||||||
|
var settings = $.extend({}, $.fn.locationpicker.defaults, options );
|
||||||
|
// Initialize
|
||||||
|
var gmapContext = new GMapContext(this, {
|
||||||
|
zoom: settings.zoom,
|
||||||
|
center: new google.maps.LatLng(settings.location.latitude, settings.location.longitude),
|
||||||
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
||||||
|
mapTypeControl: false,
|
||||||
|
disableDoubleClickZoom: false,
|
||||||
|
scrollwheel: settings.scrollwheel,
|
||||||
|
streetViewControl: false,
|
||||||
|
radius: settings.radius,
|
||||||
|
locationName: settings.locationName,
|
||||||
|
settings: settings
|
||||||
|
});
|
||||||
|
$target.data("locationpicker", gmapContext);
|
||||||
|
// Subscribe GMap events
|
||||||
|
google.maps.event.addListener(gmapContext.marker, "dragend", function(event) {
|
||||||
|
GmUtility.setPosition(gmapContext, gmapContext.marker.position, function(context){
|
||||||
|
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
|
||||||
|
context.settings.onchanged(currentLocation, context.radius, true);
|
||||||
|
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
GmUtility.setPosition(gmapContext, new google.maps.LatLng(settings.location.latitude, settings.location.longitude), function(context){
|
||||||
|
updateInputValues(settings.inputBinding, gmapContext);
|
||||||
|
context.settings.oninitialized($target);
|
||||||
|
});
|
||||||
|
// Set up input bindings if needed
|
||||||
|
setupInputListenersInput(settings.inputBinding, gmapContext);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
$.fn.locationpicker.defaults = {
|
||||||
|
location: {latitude: 40.7324319, longitude: -73.82480799999996},
|
||||||
|
locationName: "",
|
||||||
|
radius: 500,
|
||||||
|
zoom: 15,
|
||||||
|
scrollwheel: true,
|
||||||
|
inputBinding: {
|
||||||
|
latitudeInput: null,
|
||||||
|
longitudeInput: null,
|
||||||
|
radiusInput: null,
|
||||||
|
locationNameInput: null
|
||||||
|
},
|
||||||
|
enableAutocomplete: false,
|
||||||
|
enableReverseGeocode: true,
|
||||||
|
onchanged: function(currentLocation, radius, isMarkerDropped) {},
|
||||||
|
onlocationnotfound: function(locationName) {},
|
||||||
|
oninitialized: function (component) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}( jQuery ));
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
Contributors: themeboy
|
Contributors: themeboy
|
||||||
Tags: sports, sports journalism, teams, team management, fixtures, results, standings, league tables, leagues, reporting, themeboy, wordpress sports, configurable
|
Tags: sports, sports journalism, teams, team management, fixtures, results, standings, league tables, leagues, reporting, themeboy, wordpress sports, configurable
|
||||||
Requires at least: 3.5
|
Requires at least: 3.5
|
||||||
Tested up to: 3.6
|
Tested up to: 3.8
|
||||||
Stable tag: 0.1.3
|
Stable tag: 0.1.3
|
||||||
License: GPLv3
|
License: GPLv3
|
||||||
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
License URI: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|||||||
Reference in New Issue
Block a user