Browse Source

added rudimentary i18n support by adding date.format.js and adding an i18n object to VMM.master_config

pull/12/head
Martin Widmann 13 years ago
parent
commit
4ffa82df2a
  1. 1
      date.format.min.js
  2. 93
      source/js/VMM.Util.js
  3. 28
      source/js/VMM.js
  4. 16
      source/js/timeline.js

1
date.format.min.js vendored

@ -0,0 +1 @@
var dateFormat=function(){var a=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,b=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,c=/[^-+\dA-Z]/g,d=function(a,b){a=String(a);b=b||2;while(a.length<b)a="0"+a;return a};return function(e,f,g){var h=dateFormat;if(arguments.length==1&&Object.prototype.toString.call(e)=="[object String]"&&!/\d/.test(e)){f=e;e=undefined}e=e?new Date(e):new Date;if(isNaN(e))throw SyntaxError("invalid date");f=String(h.masks[f]||f||h.masks["default"]);if(f.slice(0,4)=="UTC:"){f=f.slice(4);g=true}var i=g?"getUTC":"get",j=e[i+"Date"](),k=e[i+"Day"](),l=e[i+"Month"](),m=e[i+"FullYear"](),n=e[i+"Hours"](),o=e[i+"Minutes"](),p=e[i+"Seconds"](),q=e[i+"Milliseconds"](),r=g?0:e.getTimezoneOffset(),s={d:j,dd:d(j),ddd:h.i18n.dayNames[k],dddd:h.i18n.dayNames[k+7],m:l+1,mm:d(l+1),mmm:h.i18n.monthNames[l],mmmm:h.i18n.monthNames[l+12],yy:String(m).slice(2),yyyy:m,h:n%12||12,hh:d(n%12||12),H:n,HH:d(n),M:o,MM:d(o),s:p,ss:d(p),l:d(q,3),L:d(q>99?Math.round(q/10):q),t:n<12?"a":"p",tt:n<12?"am":"pm",T:n<12?"A":"P",TT:n<12?"AM":"PM",Z:g?"UTC":(String(e).match(b)||[""]).pop().replace(c,""),o:(r>0?"-":"+")+d(Math.floor(Math.abs(r)/60)*100+Math.abs(r)%60,4),S:["th","st","nd","rd"][j%10>3?0:(j%100-j%10!=10)*j%10]};return f.replace(a,function(a){return a in s?s[a]:a.slice(1,a.length-1)})}}();dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};dateFormat.i18n={dayNames:["Sun","Mon","Tue","Wed","Thu","Fri","Sat","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],monthNames:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec","January","February","March","April","May","June","July","August","September","October","November","December"]};Date.prototype.format=function(a,b){return dateFormat(this,a,b)}

93
source/js/VMM.Util.js

@ -123,53 +123,47 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
// VMM.Util.date.day[0];
// VMM.Util.date.get12HRTime(time, seconds_true);
date: {
// somestring = VMM.Util.date.month[2]; // Returns March
month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
// somestring = VMM.Util.date.month_abbrev[1]; // Returns Feb.
month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."],
day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
day_abbr: ["Sun.","Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."],
hour: [1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12],
hour_suffix: ["am"],
//VMM.Util.date.prettyDate(d, is_abbr)
prettyDate: function(d, is_abbr, date_type) {
var _date = "";
if (type.of(d) == "date") {
dateFormat.i18n = {
dayNames: VMM.master_config.i18n.date.day_abbr.concat( VMM.master_config.i18n.date.day ),
monthNames: VMM.master_config.i18n.date.month_abbr.concat( VMM.master_config.i18n.date.month ),
};
if (d.getMonth() === 0 && d.getDate() == 1 && d.getHours() === 0 && d.getMinutes() === 0 ) {
// trace("YEAR ONLY");
_date = d.getFullYear();
_date = dateFormat( d, VMM.master_config.i18n.dateformats.year );
} else {
if (d.getDate() <= 1 && d.getHours() === 0 && d.getMinutes() === 0) {
// trace("YEAR MONTH");
if (is_abbr) {
_date = VMM.Util.date.month_abbr[d.getMonth()];
_date = dateFormat( d, VMM.master_config.i18n.dateformats.month_short );
} else {
_date = VMM.Util.date.month[d.getMonth()] + " " + d.getFullYear() ;
_date = dateFormat( d, VMM.master_config.i18n.dateformats.month );
}
} else if (d.getHours() === 0 && d.getMinutes() === 0) {
// trace("YEAR MONTH DAY");
if (is_abbr) {
_date = VMM.Util.date.month_abbr[d.getMonth()] + " " + d.getDate();
_date = dateFormat( d, VMM.master_config.i18n.dateformats.full_short );
} else {
_date = VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() ;
_date = dateFormat( d, VMM.master_config.i18n.dateformats.full );
}
} else if (d.getMinutes() === 0) {
// trace("YEAR MONTH DAY HOUR");
if (is_abbr){
//_date = VMM.Util.date.get12HRTime(d) + " " + (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear() ;
_date = VMM.Util.date.get12HRTime(d);
if (is_abbr) {
_date = dateFormat( d, VMM.master_config.i18n.dateformats.time_no_seconds_short );
} else {
_date = VMM.Util.date.get12HRTime(d) + "<br/><small>" + VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " </small> ";
_date = dateFormat( d, VMM.master_config.i18n.dateformats.time_no_seconds_small_date );
}
} else {
// trace("YEAR MONTH DAY HOUR MINUTE");
if (is_abbr){
_date = VMM.Util.date.day[d.getDay()] + ", " + VMM.Util.date.month_abbr[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " at " + VMM.Util.date.get12HRTime(d);
if (is_abbr) {
_date = dateFormat( d, VMM.master_config.i18n.dateformats.full_long );
} else {
_date = VMM.Util.date.get12HRTime(d) + "<br/><small>" + VMM.Util.date.day[d.getDay()] + ", " + VMM.Util.date.month[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear() + " </small> ";
_date = dateFormat( d, VMM.master_config.i18n.dateformats.full_long );
}
}
@ -184,59 +178,6 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
return _date;
},
prettyMonth: function(m, is_year) {
var _month = "";
if (type.of(t) == "date") {
}
return _month;
},
get12HRTime: function(t, is_seconds) {
var _time = "";
if (type.of(t) == "date") {
_time = VMM.Util.date.theHour(t.getHours()) + ":" + VMM.Util.date.minuteZeroFill(t.getMinutes());
if (is_seconds) {
_time = _time + ":" + VMM.Util.date.minuteZeroFill(t.getSeconds());
}
_time = _time + VMM.Util.date.hourSuffix(t.getHours());
}
return _time;
},
theHour: function(hr) {
if (hr > 0 && hr < 13) {
return (hr);
}
if (hr == "0") {
hr = 12;
return (hr);
}
if (hr === 0) {
return (12);
}
return (hr-12);
},
minuteZeroFill: function(v) {
if (v > 9) {
return "" + v;
}
return "0" + v;
},
hourSuffix: function(t) {
if (t < 12) {
return (" am");
}
return (" pm");
}
},
// VMM.Util.doubledigit(number).

28
source/js/VMM.js

@ -167,6 +167,34 @@ if (typeof VMM == 'undefined') {
que: []
},
i18n: {
date: {
month: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
month_abbr: ["Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec."],
day: ["Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
day_abbr: ["Sun.","Mon.", "Tues.", "Wed.", "Thurs.", "Fri.", "Sat."],
},
dateformats: {
year: "yyyy",
month_short: "mmm",
month: "mmmm yyyy",
full_short: "mmm d",
full: "mmmm d',' yyyy",
time_no_seconds_short: "hh:MM TT",
time_no_seconds_small_date: "hh:MM TT'<br/><small>'mmmm d',' yyyy'</small>'",
full_long: "dddd',' mmm d',' yyyy 'at' hh:MM TT",
full_long_small_date: "hh:MM TT'<br/><small>'dddd',' mmm d',' yyyy'</small>'",
},
messages: {
loading_timeline: "Loading Taimeline",
return_to_title: "Return to Title",
expand_timeline: "Expand Timeline",
contract_timeline: "Contract Timeline"
}
}
}).init();
/* Abstract out DOM element creation to make independent of library

16
source/js/timeline.js

@ -58,7 +58,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
//VMM.attachElement($timeline, "");
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", "Loading Timeline");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", VMM.master_config.i18n.messages.loading_timeline);
//VMM.appendElement($timeline, "<div class='container main'><div class='feature'><div class='slider'></div></div><div class='navigation'></div></div>");
@ -158,7 +158,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
function onComponentLoaded(e) {
config.loaded.percentloaded = config.loaded.percentloaded + 25;
showMessege("Loading Timeline " + config.loaded.percentloaded);
showMessege(VMM.master_config.i18n.messages.loading_timeline + config.loaded.percentloaded);
if (config.loaded.slider && config.loaded.timenav) {
hideMessege();
}
@ -197,7 +197,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
//VMM.attachElement($timeline, "");
$feedback = VMM.appendAndGetElement($timeline, "<div>", "feedback", "");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", "Loading Timeline");
$messege = VMM.appendAndGetElement($feedback, "<div>", "messege", VMM.master_config.i18n.messages.loading_timeline);
};
@ -1538,7 +1538,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
interval = interval_calc.second;
//interval_major = interval_calc.minute;
} else {
trace("NO FUCKING IDEA WHAT THE TYPE SHOULD BE");
trace("NO ******* IDEA WHAT THE TYPE SHOULD BE");
interval.type = "unknown";
}
@ -1566,7 +1566,7 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
} else if (timespan.seconds > 1) {
interval_major = interval_calc.minute;
} else {
trace("NO FUCKING IDEA WHAT THE TYPE SHOULD BE");
trace("NO ******* IDEA WHAT THE TYPE SHOULD BE");
interval_major.type = "unknown";
}
@ -1672,13 +1672,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
$zoomin = VMM.appendAndGetElement($toolbar, "<div>", "zoom-in", "<div class='icon'></div>");
$zoomout = VMM.appendAndGetElement($toolbar, "<div>", "zoom-out", "<div class='icon'></div>");
VMM.Element.attribute($backhome, "title", "Return to Title");
VMM.Element.attribute($backhome, "title", VMM.master_config.i18n.messages.return_to_title);
VMM.Element.attribute($backhome, "rel", "tooltip");
VMM.Element.attribute($zoomin, "title", "Expand Timeline");
VMM.Element.attribute($zoomin, "title", VMM.master_config.i18n.messages.expand_timeline);
VMM.Element.attribute($zoomin, "rel", "tooltip");
VMM.Element.attribute($zoomout, "title", "Contract Timeline");
VMM.Element.attribute($zoomout, "title", VMM.master_config.i18n.messages.contract_timeline);
VMM.Element.attribute($zoomout, "rel", "tooltip");
VMM.bindEvent(".zoom-in", onZoomIn, "click");

Loading…
Cancel
Save