Skip to content

Commit

Permalink
Merge pull request #3 from sofyansitorus/v1.2.6
Browse files Browse the repository at this point in the history
V1.2.6
  • Loading branch information
sofyansitorus authored Feb 17, 2018
2 parents 2b4087b + 316dd6b commit 575a0ad
Show file tree
Hide file tree
Showing 9 changed files with 172 additions and 92 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
WooCommerce per kilometer shipping rates calculator for GoSend Go-Jek Indonesia courier.

**Contributors:** [sofyansitorus](https://profiles.wordpress.org/sofyansitorus)<br>
**Tags:** [woocommerce shipping](https://wordpress.org/plugins/tags/woocommerce shipping), [go-jek](https://wordpress.org/plugins/tags/go-jek), [ojek shipping](https://wordpress.org/plugins/tags/ojek shipping), [gosend](https://wordpress.org/plugins/tags/gosend), [gojek shipping](https://wordpress.org/plugins/tags/gojek shipping)<br>
**Tags:** [woocommerce](https://wordpress.org/plugins/tags/woocommerce), [woocommerce-shipping](https://wordpress.org/plugins/tags/woocommerce-shipping), [gojek](https://wordpress.org/plugins/tags/gojek), [gojek-shipping](https://wordpress.org/plugins/tags/gojek-shipping), [gosend](https://wordpress.org/plugins/tags/gosend), [gosend-shipping](https://wordpress.org/plugins/tags/gosend-shipping)<br>
**Requires at least:** 4.8<br>
**Tested up to:** 4.9.4<br>
**Stable tag:** trunk (master)<br>
Expand All @@ -23,13 +23,13 @@ This plugin require Google Maps Distance Matrix API Services enabled in your Goo
* Available 2 shipping services: Instant Delivery, Same Day Delivery.
* Set shipping cost per kilometer.
* Set minimum cost that will be billed to customer.
* Set maximum cost that will be billed to customer.
* Set maximum shipping distances that allowed to use the courier.
* Set maximum package weight and dimensions that allowed to use the courier.
* Set shipping origin info by store location coordinates.
* Set travel mode: Driving, Walking, Bicycling.
* Set route restrictions: Avoid Tolls, Avoid Highways, Avoid Ferries, Avoid Indoor.
* Set visibility distance info to customer.
* Set fallback request if there is no results for API request using full address.


## Installation ##
Expand Down Expand Up @@ -97,8 +97,11 @@ I always welcome and encourage contributions to this plugin. Please visit the pl

## Changelog ##

### 1.2.6 ###
* Improvements - Enhance Maps Picker.

### 1.2.5 ###
* Improvements -Add new option: Enable Fallback Request.
* Improvements - Add new option: Enable Fallback Request.
* Fix - Added fallback to input store location manually on google map error.

### 1.2.4 ###
Expand Down Expand Up @@ -146,7 +149,7 @@ I always welcome and encourage contributions to this plugin. Please visit the pl

## Upgrade Notice ##

### 1.2.5 ###
This version include bug fixes and improvements. Upgrade immediately.
### 1.2.6 ###
This version include improvements. Upgrade immediately.


14 changes: 9 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
=== WooGoSend ===
Contributors: sofyansitorus
Tags: woocommerce shipping,go-jek,ojek shipping,gosend,gojek shipping
Tags: woocommerce,woocommerce-shipping,gojek,gojek-shipping,gosend,gosend-shipping
Requires at least: 4.8
Tested up to: 4.9.4
Requires PHP: 5.6
Expand All @@ -23,13 +23,13 @@ This plugin require Google Maps Distance Matrix API Services enabled in your Goo
* Available 2 shipping services: Instant Delivery, Same Day Delivery.
* Set shipping cost per kilometer.
* Set minimum cost that will be billed to customer.
* Set maximum cost that will be billed to customer.
* Set maximum shipping distances that allowed to use the courier.
* Set maximum package weight and dimensions that allowed to use the courier.
* Set shipping origin info by store location coordinates.
* Set travel mode: Driving, Walking, Bicycling.
* Set route restrictions: Avoid Tolls, Avoid Highways, Avoid Ferries, Avoid Indoor.
* Set visibility distance info to customer.
* Set fallback request if there is no results for API request using full address.

== Installation ==
= Minimum Requirements =
Expand Down Expand Up @@ -83,9 +83,13 @@ I always welcome and encourage contributions to this plugin. Please visit the pl

== Changelog ==

= 1.2.6 =

* Improvements - Enhance Maps Picker.

= 1.2.5 =

* Improvements -Add new option: Enable Fallback Request.
* Improvements - Add new option: Enable Fallback Request.
* Fix - Added fallback to input store location manually on google map error.

= 1.2.4 =
Expand Down Expand Up @@ -142,5 +146,5 @@ I always welcome and encourage contributions to this plugin. Please visit the pl

== Upgrade Notice ==

= 1.2.5 =
This version include bug fixes and improvements. Upgrade immediately.
= 1.2.6 =
This version include improvements. Upgrade immediately.
32 changes: 30 additions & 2 deletions assets/css/woogosend-admin.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.woogosend-map-wrapper {
position: relative; }
position: relative;
width: 100%;
padding-right: 10px; }
.woogosend-map-wrapper .controls {
margin-top: 10px;
border: 1px solid transparent;
Expand All @@ -11,7 +13,7 @@
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
.woogosend-map-wrapper .woogosend-map-canvas {
position: relative;
height: 300px; }
height: 360px; }
.woogosend-map-wrapper .woogosend-map-search {
position: relative;
background-color: #fff;
Expand All @@ -26,6 +28,32 @@
.woogosend-map-wrapper .woogosend-map-search:focus {
border-color: #4d90fe; }

#woogosend-lat-lng-wrap {
width: 100%;
padding-right: 10px; }
#woogosend-lat-lng-wrap div {
width: 50%; }
#woogosend-lat-lng-wrap div:first-child {
float: left;
padding-right: 10px; }
#woogosend-lat-lng-wrap div:last-child {
margin-left: 50%;
padding-left: 10px; }
#woogosend-lat-lng-wrap div label {
display: block; }
#woogosend-lat-lng-wrap div input {
display: block;
width: 100%; }
@media only screen and (max-width: 1070px) {
#woogosend-lat-lng-wrap div {
width: 100%; }
#woogosend-lat-lng-wrap div:first-child {
float: none;
padding-right: 0; }
#woogosend-lat-lng-wrap div:last-child {
margin-left: 0;
padding-left: 0; } }

.pac-container {
z-index: 999999 !important; }
.pac-container #type-selector {
Expand Down
2 changes: 1 addition & 1 deletion assets/css/woogosend-admin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 66 additions & 52 deletions assets/js/woogosend-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@
"use strict";

var wooGoSend = {
_inputLatId: "woocommerce_woogosend_origin_lat",
_inputLngId: "woocommerce_woogosend_origin_lng",
_mapWrapperId: "woogosend-map-wrapper",
_mapSearchId: "woogosend-map-search",
_mapCanvasId: "woogosend-map-canvas",
_inputLatSel: "",
_inputLngSel: "",
_mapWrapperSel: "",
_mapSearchSel: "",
_mapCanvasSel: "",
_serviceToggleSel: "",
_zoomLevel: 16,
_keyStr:
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
init: function() {
_params: {},
init: function(params) {
var self = this;

if (woogosend_params.show_settings) {
self._params = params;

self._inputLatSel =
"woocommerce_" + self._params.method_id + "_origin_lat";
self._inputLngSel =
"woocommerce_" + self._params.method_id + "_origin_lng";
self._mapWrapperSel = self._params.method_id + "-map-wrapper";
self._mapSearchSel = self._params.method_id + "-map-search";
self._mapCanvasSel = self._params.method_id + "-map-canvas";
self._serviceToggleSel = self._params.method_id + "-toggle-service";

if (self._params.show_settings) {
setTimeout(function() {
// Try show settings modal on settings page.
var isMethodAdded = false;
var methods = $(document).find(".wc-shipping-zone-method-type");
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
if ($(method).text() == woogosend_params.method_title) {
if ($(method).text() == self._params.method_title) {
$(method)
.closest("tr")
.find(".row-actions .wc-shipping-zone-method-settings")
Expand All @@ -34,7 +47,7 @@
if (!isMethodAdded) {
$(".wc-shipping-zone-add-method").trigger("click");
$("select[name='add_method_id']")
.val(woogosend_params.method_id)
.val(self._params.method_id)
.trigger("change");
}
}, 200);
Expand All @@ -45,14 +58,24 @@
$(this)
.closest("tr")
.find(".wc-shipping-zone-method-type")
.text() === woogosend_params.method_title
.text() === self._params.method_title
) {
$(".woogosend-toggle-service").trigger("change");
$("." + self._serviceToggleSel).trigger("change");
self._initGoogleMaps();
}
});

$(document).on("change", ".woogosend-toggle-service", function() {
$(document).on(
"change",
"#" + self._inputLatSel + ", #" + self._inputLngSel,
function() {
if (!$(".gm-err-content").length) {
self._initGoogleMaps();
}
}
);

$(document).on("change", "." + self._serviceToggleSel, function() {
if ($(this).is(":checked")) {
$(this)
.closest("table")
Expand All @@ -68,11 +91,9 @@
},
_initGoogleMaps: function(e) {
var self = this;
$("#" + self._inputLatId)
.closest("tr")
.hide();
$("#" + self._inputLngId)
.closest("tr")
$("#" + self._mapWrapperSel)
.show()
.siblings(".description")
.hide();
try {
if (
Expand All @@ -88,7 +109,7 @@
"https://maps.googleapis.com/maps/api/js?key=" +
self._decode($("#map-secret-key").val()) +
"&libraries=geometry,places&&language=" +
woogosend_params.language,
self._params.language,
function() {
self._buildGoogleMaps();
}
Expand All @@ -99,23 +120,23 @@
var self = this;
var defaultLat = -6.175392;
var defaultLng = 106.827153;
var curLat = $("#" + self._inputLatId).val();
var curLng = $("#" + self._inputLngId).val();
var curLat = $("#" + self._inputLatSel).val();
var curLng = $("#" + self._inputLngSel).val();
curLat = curLat.length ? parseFloat(curLat) : defaultLat;
curLng = curLng.length ? parseFloat(curLng) : defaultLng;
var curLatLng = { lat: curLat, lng: curLng };
var tmplMapCanvas = wp.template(self._mapCanvasId);
var tmplMapSearch = wp.template(self._mapSearchId);
if (!$("#" + self._mapCanvasId).length) {
$("#" + self._mapWrapperId).append(
var tmplMapCanvas = wp.template(self._mapCanvasSel);
var tmplMapSearch = wp.template(self._mapSearchSel);
if (!$("#" + self._mapCanvasSel).length) {
$("#" + self._mapWrapperSel).append(
tmplMapCanvas({
map_canvas_id: self._mapCanvasId
map_canvas_id: self._mapCanvasSel
})
);
}
var markers = [];
var map = new google.maps.Map(
document.getElementById(self._mapCanvasId),
document.getElementById(self._mapCanvasSel),
{
center: curLatLng,
zoom: self._zoomLevel,
Expand All @@ -126,13 +147,13 @@
map: map,
position: curLatLng,
draggable: true,
icon: woogosend_params.marker
icon: self._params.marker
});

var infowindow = new google.maps.InfoWindow({ maxWidth: 350 });

if (curLat == defaultLat && curLng == defaultLng) {
infowindow.setContent(woogosend_params.txt.drag_marker);
infowindow.setContent(self._params.txt.drag_marker);
infowindow.open(map, marker);
} else {
self._setLatLng(marker.position, marker, map, infowindow);
Expand All @@ -148,15 +169,15 @@

markers.push(marker);

if (!$("#" + self._mapSearchId).length) {
$("#" + self._mapWrapperId).append(
if (!$("#" + self._mapSearchSel).length) {
$("#" + self._mapWrapperSel).append(
tmplMapSearch({
map_search_id: self._mapSearchId
map_search_id: self._mapSearchSel
})
);
}
// Create the search box and link it to the UI element.
var inputAddress = document.getElementById(self._mapSearchId);
var inputAddress = document.getElementById(self._mapSearchSel);
var searchBox = new google.maps.places.SearchBox(inputAddress);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(inputAddress);
// Bias the SearchBox results towards current map's viewport.
Expand Down Expand Up @@ -185,7 +206,7 @@
map: map,
position: place.geometry.location,
draggable: true,
icon: woogosend_params.marker
icon: self._params.marker
});
self._setLatLng(place.geometry.location, marker, map, infowindow);
google.maps.event.addListener(marker, "dragstart", function(event) {
Expand All @@ -203,21 +224,16 @@
bounds.extend(place.geometry.location);
}
});
map.setZoom(self._zoomLevel);
map.fitBounds(bounds);
});

setInterval(function() {
if ($(".gm-err-content").length) {
$("#" + self._mapCanvasId)
.closest("tr")
.hide();
$("#" + self._inputLatId)
.closest("tr")
.show();
$("#" + self._inputLngId)
.closest("tr")
$("#" + self._mapWrapperSel)
.hide()
.siblings(".description")
.show();
$("#" + self._mapSearchSel).remove();
google = undefined;
}
}, 1000);
Expand All @@ -230,20 +246,18 @@
latLng: location
},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
infowindow.setContent(results[0].formatted_address);
if (status == google.maps.GeocoderStatus.OK && results[0]) {
infowindow.setContent(results[0].formatted_address);
infowindow.open(map, marker);
marker.addListener("click", function() {
infowindow.open(map, marker);
$("#" + self._inputLatId).val(location.lat());
$("#" + self._inputLngId).val(location.lng());
} else {
$("#" + self._inputLatId).val("");
$("#" + self._inputLngId).val("");
}
});
}
}
);
map.setCenter(location);
$("#" + self._inputLatSel).val(location.lat());
$("#" + self._inputLngSel).val(location.lng());
},
_encode: function(e) {
var self = this;
Expand Down Expand Up @@ -346,6 +360,6 @@
};

$(document).ready(function() {
wooGoSend.init();
wooGoSend.init(woogosend_params);
});
})(jQuery);
Loading

0 comments on commit 575a0ad

Please sign in to comment.