Select timezone using world map
timezone-picker is the plugin to select and get timezone value of selected area(country) from WorldMap.
npm install --save timezone-pickeror
Include the following lines of code in the section of your HTML.
$(selector).timezonePicker();Set a custom value on load
If defaultValue is null then system timezone is selected
$(selector).timezonePicker({ defaultValue: { value: "EAT", attribute: "zonename" }});$(selector).timezonePicker({ defaultValue: { value: "IN", attribute: "country" }});$(selector).timezonePicker({ defaultValue: { value: "Asia/Calcutta", attribute: "timezone" }});$(selector).timezonePicker({ defaultValue: { value: "5.5", attribute: "offset" }});You can create custom shortcuts link using quickLink options.
$(selector).timezonePicker({
quickLink: [{
"IST": "IST",
"LONDON": "Europe/London"
}]
});Example:
You can pass following value.
$(selector).timezonePicker({
quickLink: [{
"LONDON1": "Europe/London"
}]
});
$(selector).timezonePicker({
quickLink: [{
"LONDON2": "GB"
}]
});
$(selector).timezonePicker({
quickLink: [{
"LONDON3": "GMT"
}]
});
$(selector).timezonePicker({
quickLink: [{
"GMT": "GMT"
}]
});$(selector).timezonePicker({
hoverText: function(e, data){
return (data.timezone + " (" + data.zonename + ")");
}
});Class name for the quickLink container.
$(selector).timezonePicker({
quickLinkClass: "quick-class"
});Output
Class name for the country drop-down.
$('body').timezonePicker({
selectClass: "select-class"
});Output
Class name for the filter box container.
$('body').timezonePicker({
filterBoxClass: "filter-class"
});Output
+
Class name for the hover text container.
$('body').timezonePicker({
hoverTextClass: "hover-class"
});Output
+
| Parameter | Type | Default | Description |
|---|---|---|---|
| width | Number |
500 |
width of map |
| height | Number |
250 |
height of map |
| defaultValue | Object |
System timezone | Set custome value on load { value: "EAT", attribute: "zonename" } |
| quickLink | Array |
[{"IST": "IST","LONDON": "Europe/London"}] |
Creates shortcuts to select zone |
| quickLinkClass | String |
quick-link |
quickLinkClass will be appended with the default value |
| filterBoxClass | String |
filter-box |
filterBoxClass will be appended with the default value |
| selectBox | Boolean |
true |
If it is set to false select box will not be created |
| selectClass | String |
country-lov |
selectClass is appended with the default value |
| showHoverText | Boolean |
true |
If it is set to false hover text will not be shown |
| hoverText | Function |
timezone(zonename) |
Called on hover of country (works only if showHoverText is true) |
| hoverTextClass | String |
hover-text |
hoverTextClass is appended with the default value |
| hoverTextEl | Jquery selector |
Appened in filter-box |
hover text element is appended in selector |
| mapHoverType | String |
hover polygon(area) | by default it will show hovered polygon(area) on which mouse is pointed other hover options |
| Parameter | Type | Description |
|---|---|---|
| timezone | String |
when you hover on the map it will highlight all country with the same timezone |
| country | String |
when you hover on the map it will highlight all country with same country code |
| zonename | String |
when you hover on the map it will highlight all country with the same zone name |
Select the value(country) based on value and attribute parameter.
$(selector).data('timezonePicker').setValue('Asia/Kolkata')$(selector).data('timezonePicker').setValue('5.5','offset')$(selector).data('timezonePicker').setValue('IN','country')$(selector).data('timezonePicker').setValue('IST','zonename')It returns object containing timezone details of seleted area:
$(selector).data('timezonePicker').getValue()Sample returned Object
[
{
"selected":true,
"zonename":"IST",
"offset":5.5,
"pin":"361,115",
"country":"LK",
"timezone": "Asia/Colombo",
},
{
"zonename":"IST",
"offset":5.5,
"pin": "373,94",
"country":"IN",
"timezone": "Asia/Kolkata",
}
]It returns an object containing system timezone details.
It returns an object containing timezone details based on value and attribute.
Object using timezone string example: 'Asia/Kolkata'.$(selector).data('timezonePicker').getTimeZoneObject('Asia/Kolkata');$(selector).data('timezonePicker').getTimeZoneObject('5.5','offset');$(selector).data('timezonePicker').getTimeZoneObject('IN','country');$(selector).data('timezonePicker').getTimeZoneObject('IST','zonename');It returns an zonename based on value and attribute.
String using timezone string example: 'Asia/Kolkata'.$(selector).data('timezonePicker').getZoneName('Asia/Kolkata');$(selector).data('timezonePicker').getZoneName('5.5','offset');$(selector).data('timezonePicker').getZoneName('IN','country');It returns an timezone string based on value and attribute.
String using country code example: 'IN'.$(selector).data('timezonePicker').getZoneName('IN');$(selector).data('timezonePicker').getTimeZoneString('5.5','offset');$(selector).data('timezonePicker').getTimeZoneString('IST','zonename');As soon as the map is loaded and ready the map:loaded is fired. To catch it you can use:
$(selector).on("map:loaded" , function(){
console.log("Map is loaded, have fun!");
});Whenever the value of the timezone changes, the event map:value:changed is fired. To catch it you can use:
$(selector).on("map:value:changed" , function(){
console.log($(selector).data('timezonePicker').getValue());
});Event map:country:clicked is fired, when a user clicks on the country. To catch it you can use:
$(selector).on("map:country:clicked" , function(){
console.log($(selector).data('timezonePicker').getValue());
});Event map:quickLink:clicked is fired, when a user clicks on the quickLink button. To catch it you can use:
$(selector).on("map:quickLink:clicked" , function(){
console.log($(selector).data('timezonePicker').getValue());
});Event map:option:changed is fired, when a user changes the value from the country drop-down. To catch it you can use:
$(selector).on("map:option:changed" , function(){
console.log($(selector).data('timezonePicker').getValue());
});It is available under the MIT LICENSE
No open issues yet, or sync has not completed.