7 0, 1, 10, 100, 1000, 10000, 0.1, 0.12, 0.123, 0.1234, 0.12345, 1000.123, 10000.12345,
8 -1, -10, -100, -1000, -10000, -0.1, -0.12, -0.123, -0.1234, -0.12345, -1000.123, -10000.12345
11 "n", "n1", "n3", "d", "d2", "d3", "p", "p1", "p3", "c", "c0"
13 window.dates = $.map([
14 "Jan 1, 1970 1:34 PM", "Dec 31, 1970 1:34 PM", "Apr 1, 1999 1:34 PM", "Dec 31, 1999 1:34 PM", "Jan 1, 2000 1:34 PM", "Nov 5, 1955 1:34 PM"
15 ], function(d) { return d instanceof Date ? d : new Date(Date.parse(d)); } );
17 window.dateFormats = [
18 "d", "D", "f", "F", "M", "S", "t", "T", "Y"
21 // add template extensions to format numbers and dates declaratively
22 $.extend( $.tmplcmd, {
25 prefix: "_.push(Globalize.format(numbers[$2],formats[$1]));"
29 prefix: "_.push(Globalize.format(dates[$2],typeof $1 === 'number' ? dateFormats[$1] : $1));"
34 $(".tab").click(function() {
35 $(".active").removeClass("active").addClass("inactive");
36 $("#" + this.id + "content").removeClass("inactive").addClass("active");
37 $(this).removeClass("inactive").addClass("active");
40 // fill cultures dropdown with the available cultures
41 $.each(sortByName(Globalize.cultures), function(i, culture) {
44 text: culture.name + ": " + culture.englishName + " (" + culture.nativeName + ")"
45 }).appendTo("#cultures");
48 // re-render templates after selecting a culture
49 $("#cultures").bind("change keyup", selectCulture)
50 // set default culture to Japanese in Japan
53 // re-render templates after selecting a calendar
54 var calendars = $("#calendars").bind("change keyup", function() {
55 Globalize.culture().calendar = Globalize.culture().calendars[calendars.val()] || Globalize.culture().calendars.standard;
59 $("#parseDate").change(function() {
60 $("#parseDateResult").text(Globalize.parseDate($(this).val()).toString());
62 $("#parseNumber").change(function() {
63 $("#parseNumberResult").text(Globalize.parseFloat($(this).val()).toString());
66 function sortByName(map) {
67 // converts a dictionary into a sorted dictionary based on obj.name
69 $.each(map, function(name, value) {
72 arr.sort(function(a, b) {
73 return a.name < b.name ? -1 : 1;
78 function selectCulture() {
79 // sets the current culture to the value specified in the cultures dropdown,
80 // populates the calendars dropdown with that cultures calendars,
81 // and renders the formatting templates.
82 Globalize.culture($("#cultures").val());
85 $.each(sortByName(Globalize.culture().calendars), function(i, cal) {
86 $("<option/>", { value: cal.name, text: cal.name }).appendTo(calendars);
88 calendars.val(Globalize.culture().calendar.name);
94 $("#dateformat").empty();
95 $("#dateformattmpl").render({}).appendTo("#dateformat");
98 $("#formattmpl").render({}).appendTo("#format");
100 $("#englishName").text(Globalize.culture().englishName);
101 $("#nativeName").text(Globalize.culture().nativeName);
102 $("#isRTL").text(Globalize.culture().isRTL ? "YES" : "no");
104 $("#infonumber").empty();
105 $("#infonumbertmpl").render(Globalize.culture().numberFormat).appendTo("#infonumber");
107 $("#infodate").empty();
108 $("#infodatetmpl").render(Globalize.culture().calendar).appendTo("#infodate");