annotate static/js/timezone.js @ 454:5b2114cec3e3

Working on #220. Can't test locally, so committing in increments.
author Brian Neal <bgneal@gmail.com>
date Thu, 30 Jun 2011 02:30:30 +0000
parents 88b2b9cb8c1f
children
rev   line source
bgneal@312 1 var gcalTzInfo = {
bgneal@312 2 areas: ['Africa', 'America', 'Antarctica', 'Asia', 'Atlantic', 'Australia', 'Canada', 'Europe', 'Indian', 'Pacific', 'US'],
bgneal@312 3 locations: [['Abidjan', 'Accra', 'Addis Ababa', 'Algiers', 'Asmara', 'Bamako', 'Bangui', 'Banjul', 'Bissau', 'Blantyre', 'Brazzaville', 'Bujumbura', 'Cairo', 'Casablanca', 'Ceuta', 'Conakry', 'Dakar', 'Dar es Salaam', 'Djibouti', 'Douala', 'El Aaiun', 'Freetown', 'Gaborone', 'Harare', 'Johannesburg', 'Kampala', 'Khartoum', 'Kigali', 'Kinshasa', 'Lagos', 'Libreville', 'Lome', 'Luanda', 'Lubumbashi', 'Lusaka', 'Malabo', 'Maputo', 'Maseru', 'Mbabane', 'Mogadishu', 'Monrovia', 'Nairobi', 'Ndjamena', 'Niamey', 'Nouakchott', 'Ouagadougou', 'Porto-Novo', 'Sao Tome', 'Tripoli', 'Tunis', 'Windhoek'],
bgneal@312 4 ['Adak', 'Anchorage', 'Anguilla', 'Antigua', 'Araguaina', 'Argentina/Buenos Aires', 'Argentina/Catamarca', 'Argentina/Cordoba', 'Argentina/Jujuy', 'Argentina/La Rioja', 'Argentina/Mendoza', 'Argentina/Rio Gallegos', 'Argentina/Salta', 'Argentina/San Juan', 'Argentina/San Luis', 'Argentina/Tucuman', 'Argentina/Ushuaia', 'Aruba', 'Asuncion', 'Atikokan', 'Bahia', 'Barbados', 'Belem', 'Belize', 'Blanc-Sablon', 'Boa Vista', 'Bogota', 'Boise', 'Cambridge Bay', 'Campo Grande', 'Cancun', 'Caracas', 'Cayenne', 'Cayman', 'Chicago', 'Chihuahua', 'Costa Rica', 'Cuiaba', 'Curacao', 'Danmarkshavn', 'Dawson', 'Dawson Creek', 'Denver', 'Detroit', 'Dominica', 'Edmonton', 'Eirunepe', 'El Salvador', 'Fortaleza', 'Glace Bay', 'Godthab', 'Goose Bay', 'Grand Turk', 'Grenada', 'Guadeloupe', 'Guatemala', 'Guayaquil', 'Guyana', 'Halifax', 'Havana', 'Hermosillo', 'Indiana/Indianapolis', 'Indiana/Knox', 'Indiana/Marengo', 'Indiana/Petersburg', 'Indiana/Tell City', 'Indiana/Vevay', 'Indiana/Vincennes', 'Indiana/Winamac', 'Inuvik', 'Iqaluit', 'Jamaica', 'Juneau', 'Kentucky/Louisville', 'Kentucky/Monticello', 'La Paz', 'Lima', 'Los Angeles', 'Maceio', 'Managua', 'Manaus', 'Martinique', 'Matamoros', 'Mazatlan', 'Menominee', 'Merida', 'Mexico City', 'Miquelon', 'Moncton', 'Monterrey', 'Montevideo', 'Montreal', 'Montserrat', 'Nassau', 'New York', 'Nipigon', 'Nome', 'Noronha', 'North Dakota/Center', 'North Dakota/New Salem', 'Ojinaga', 'Panama', 'Pangnirtung', 'Paramaribo', 'Phoenix', 'Port of Spain', 'Port-au-Prince', 'Porto Velho', 'Puerto Rico', 'Rainy River', 'Rankin Inlet', 'Recife', 'Regina', 'Resolute', 'Rio Branco', 'Santa Isabel', 'Santarem', 'Santiago', 'Santo Domingo', 'Sao Paulo', 'Scoresbysund', 'St Johns', 'St Kitts', 'St Lucia', 'St Thomas', 'St Vincent', 'Swift Current', 'Tegucigalpa', 'Thule', 'Thunder Bay', 'Tijuana', 'Toronto', 'Tortola', 'Vancouver', 'Whitehorse', 'Winnipeg', 'Yakutat', 'Yellowknife'],
bgneal@312 5 ['Casey', 'Davis', 'DumontDUrville', 'Mawson', 'McMurdo', 'Palmer', 'Rothera', 'Syowa', 'Vostok'],
bgneal@312 6 ['Aden', 'Almaty', 'Amman', 'Anadyr', 'Aqtau', 'Aqtobe', 'Ashgabat', 'Baghdad', 'Bahrain', 'Baku', 'Bangkok', 'Beirut', 'Bishkek', 'Brunei', 'Choibalsan', 'Chongqing', 'Colombo', 'Damascus', 'Dhaka', 'Dili', 'Dubai', 'Dushanbe', 'Gaza', 'Harbin', 'Ho Chi Minh', 'Hong Kong', 'Hovd', 'Irkutsk', 'Jakarta', 'Jayapura', 'Jerusalem', 'Kabul', 'Kamchatka', 'Karachi', 'Kashgar', 'Kathmandu', 'Kolkata', 'Krasnoyarsk', 'Kuala Lumpur', 'Kuching', 'Kuwait', 'Macau', 'Magadan', 'Makassar', 'Manila', 'Muscat', 'Nicosia', 'Novokuznetsk', 'Novosibirsk', 'Omsk', 'Oral', 'Phnom Penh', 'Pontianak', 'Pyongyang', 'Qatar', 'Qyzylorda', 'Rangoon', 'Riyadh', 'Sakhalin', 'Samarkand', 'Seoul', 'Shanghai', 'Singapore', 'Taipei', 'Tashkent', 'Tbilisi', 'Tehran', 'Thimphu', 'Tokyo', 'Ulaanbaatar', 'Urumqi', 'Vientiane', 'Vladivostok', 'Yakutsk', 'Yekaterinburg', 'Yerevan'],
bgneal@312 7 ['Azores', 'Bermuda', 'Canary', 'Cape Verde', 'Faroe', 'Madeira', 'Reykjavik', 'South Georgia', 'St Helena', 'Stanley'],
bgneal@312 8 ['Adelaide', 'Brisbane', 'Broken Hill', 'Currie', 'Darwin', 'Eucla', 'Hobart', 'Lindeman', 'Lord Howe', 'Melbourne', 'Perth', 'Sydney'],
bgneal@312 9 ['Atlantic', 'Central', 'Eastern', 'Mountain', 'Newfoundland', 'Pacific'],
bgneal@312 10 ['Amsterdam', 'Andorra', 'Athens', 'Belgrade', 'Berlin', 'Brussels', 'Bucharest', 'Budapest', 'Chisinau', 'Copenhagen', 'Dublin', 'Gibraltar', 'Helsinki', 'Istanbul', 'Kaliningrad', 'Kiev', 'Lisbon', 'London', 'Luxembourg', 'Madrid', 'Malta', 'Minsk', 'Monaco', 'Moscow', 'Oslo', 'Paris', 'Prague', 'Riga', 'Rome', 'Samara', 'Simferopol', 'Sofia', 'Stockholm', 'Tallinn', 'Tirane', 'Uzhgorod', 'Vaduz', 'Vienna', 'Vilnius', 'Volgograd', 'Warsaw', 'Zaporozhye', 'Zurich'],
bgneal@312 11 ['Antananarivo', 'Chagos', 'Christmas', 'Cocos', 'Comoro', 'Kerguelen', 'Mahe', 'Maldives', 'Mauritius', 'Mayotte', 'Reunion'],
bgneal@312 12 ['Apia', 'Auckland', 'Chatham', 'Easter', 'Efate', 'Enderbury', 'Fakaofo', 'Fiji', 'Funafuti', 'Galapagos', 'Gambier', 'Guadalcanal', 'Guam', 'Honolulu', 'Johnston', 'Kiritimati', 'Kosrae', 'Kwajalein', 'Majuro', 'Marquesas', 'Midway', 'Nauru', 'Niue', 'Norfolk', 'Noumea', 'Pago Pago', 'Palau', 'Pitcairn', 'Ponape', 'Port Moresby', 'Rarotonga', 'Saipan', 'Tahiti', 'Tarawa', 'Tongatapu', 'Truk', 'Wake', 'Wallis'],
bgneal@312 13 ['Alaska', 'Arizona', 'Central', 'Eastern', 'Hawaii', 'Mountain', 'Pacific']],
bgneal@312 14 default_area: 10,
bgneal@312 15 default_location: 6
bgneal@312 16 };
bgneal@312 17
bgneal@312 18 $(document).ready(function() {
bgneal@312 19 var $tz_area = $('#id_tz_area');
bgneal@312 20 var $tz_loc = $('#id_tz_location');
bgneal@312 21 var tz_area = $tz_area[0];
bgneal@312 22 var tz_loc = $tz_loc[0];
bgneal@312 23 tz_area.options.length = 0;
bgneal@312 24 for (var i = 0; i < gcalTzInfo.areas.length; ++i)
bgneal@312 25 {
bgneal@312 26 tz_area.options[i] = new Option(gcalTzInfo.areas[i]);
bgneal@312 27 }
bgneal@312 28 var tz = $('#id_time_zone').val();
bgneal@312 29 if (tz == '')
bgneal@312 30 {
bgneal@312 31 tz_area.options.selectedIndex = gcalTzInfo.default_area;
bgneal@312 32 }
bgneal@312 33 else
bgneal@312 34 {
bgneal@312 35 var area_match = tz.match(/^(\w+)\/.*$/);
bgneal@312 36 if (area_match != null)
bgneal@312 37 {
bgneal@312 38 var i = $.inArray(area_match[1], gcalTzInfo.areas);
bgneal@312 39 tz_area.options.selectedIndex = (i != -1) ? i : gcalTzInfo.default_area;
bgneal@312 40 }
bgneal@312 41 else
bgneal@312 42 {
bgneal@312 43 tz_area.options.selectedIndex = gcalTzInfo.default_area;
bgneal@312 44 }
bgneal@312 45 }
bgneal@312 46
bgneal@312 47 $tz_area.change(function () {
bgneal@312 48 tz_loc.options.length = 0;
bgneal@312 49 var area = tz_area.options.selectedIndex;
bgneal@312 50 for (var i = 0; i < gcalTzInfo.locations[area].length; ++i)
bgneal@312 51 {
bgneal@312 52 tz_loc.options[i] = new Option(gcalTzInfo.locations[area][i]);
bgneal@312 53 }
bgneal@312 54 }).change();
bgneal@312 55
bgneal@312 56 if (tz == '')
bgneal@312 57 {
bgneal@312 58 tz_loc.options.selectedIndex = gcalTzInfo.default_location;
bgneal@312 59 }
bgneal@312 60 else
bgneal@312 61 {
bgneal@312 62 var loc_match = tz.match(/^[^\/]+\/(.*)$/);
bgneal@312 63 if (loc_match != null)
bgneal@312 64 {
bgneal@312 65 var loc = loc_match[1].replace(/_/g, ' ');
bgneal@312 66 var i = $.inArray(loc, gcalTzInfo.locations[tz_area.options.selectedIndex]);
bgneal@312 67 tz_loc.options.selectedIndex = (i != -1) ? i : gcalTzInfo.default_location;
bgneal@312 68 }
bgneal@312 69 else
bgneal@312 70 {
bgneal@312 71 tz_loc.options.selectedIndex = gcalTzInfo.default_location;
bgneal@312 72 }
bgneal@312 73 }
bgneal@312 74
bgneal@312 75 $tz_area.parents('form').submit(function () {
bgneal@312 76 var area = $tz_area.val();
bgneal@312 77 var loc = $tz_loc.val();
bgneal@312 78 var tz = area + '/' + loc.replace(/ /g, '_');
bgneal@312 79 $('#id_time_zone').val(tz);
bgneal@312 80 return true;
bgneal@312 81 });
bgneal@312 82 });