mirror of
https://github.com/wassname/angular-timezone-selector.git
synced 2026-06-27 19:13:51 +08:00
Added options for primary & local timezones, and show and sort by offset
This commit is contained in:
Vendored
+43
-3
@@ -77,19 +77,59 @@ angular.module('angular-timezone-selector', [])
|
||||
text: CCToCountryName[CC] + ': ',
|
||||
children: zonesByCountry
|
||||
firstNOffset: zonesByCountry[0].nOffset,
|
||||
firstOffset: zonesByCountry[0].offset
|
||||
}
|
||||
|
||||
data.push(zonesForCountry)
|
||||
})
|
||||
|
||||
// Sort by country name
|
||||
data = _.sortBy(data, 'text')
|
||||
// Sort by UTC or country name
|
||||
if (attrs.sortBy=="offset"){
|
||||
data = _.sortBy(data, 'firstNOffset');
|
||||
_.forEach(data,function(zonesForCountry,key){
|
||||
zonesForCountry.children=_.sortBy(zonesForCountry.children, 'nOffset');
|
||||
});
|
||||
} else {
|
||||
data = _.sortBy(data, 'text')
|
||||
}
|
||||
|
||||
// add initial options forlocal
|
||||
if (attrs.showLocal!=undefined){
|
||||
if (jstz!=undefined){
|
||||
var extraTZs = _.where(timezones,{'name':jstz.determine().name() });
|
||||
} else {
|
||||
var localUTC = 'UTC'+moment().format('Z');
|
||||
var extraTZs = _.where(timezones,{'offset':localUTC});
|
||||
}
|
||||
data.splice(0,0,{
|
||||
text: 'Local' + ': ',
|
||||
children: extraTZs,
|
||||
firstNOffset: extraTZs[0].nOffset,
|
||||
firstOffset: extraTZs[0].offset
|
||||
})
|
||||
}
|
||||
|
||||
// add initial options
|
||||
if (attrs.primaryChoices!=undefined){
|
||||
// var primaryChoices=['UTC','GB','WET','GMT','Asia/Macau']
|
||||
var primaryChoices = attrs.primaryChoices.split(' ');
|
||||
var extraTZs = _.filter(timezones,function(tz){return _.contains(primaryChoices,tz.name)});
|
||||
data.splice(0,0,{
|
||||
text: 'Primary' + ': ',
|
||||
children: extraTZs,
|
||||
firstNOffset: extraTZs[0].nOffset,
|
||||
firstOffset: extraTZs[0].offset
|
||||
})
|
||||
}
|
||||
|
||||
// Construct a select box with the timezones grouped by country
|
||||
_.forEach(data, function (group) {
|
||||
var $optgroup = $('<optgroup label="' + group.text + '">')
|
||||
group.children.forEach(function (option) {
|
||||
|
||||
if (attrs.displayUtc=="true" && !option.name.includes('(UTC')){
|
||||
option.name = option.name + ' (' + option.offset+')';
|
||||
}
|
||||
|
||||
$optgroup.append('<option value="' + option.id + '">' +
|
||||
option.name + '</option>')
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user