diff --git a/source/js/Core/VMM.Date.js b/source/js/Core/VMM.Date.js index 4f833f7..f3744ec 100644 --- a/source/js/Core/VMM.Date.js +++ b/source/js/Core/VMM.Date.js @@ -139,7 +139,8 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') { if (d2 != null) { is_pair = true; } - + + if (type.of(d) == "date") { if (d.getMonth() === 0 && d.getDate() == 1 && d.getHours() === 0 && d.getMinutes() === 0 ) { // YEAR ONLY @@ -173,8 +174,8 @@ if(typeof VMM != 'undefined' && typeof VMM.Date == 'undefined') { format = VMM.Date.dateformats.full_long; } } - - _date = dateFormat(d, format); + + _date = dateFormat(d, format, false); bc_check = _date.split(" "); // BC TIME SUPPORT diff --git a/source/js/VMM.Timeline.TimeNav.js b/source/js/VMM.Timeline.TimeNav.js index 600649e..d4af4d5 100644 --- a/source/js/VMM.Timeline.TimeNav.js +++ b/source/js/VMM.Timeline.TimeNav.js @@ -1,4 +1,6 @@ -/* TIMELINE NAVIGATION +/* TimeNav + This class handles the bottom timeline navigation. + It requires the VMM.Util class and VMM.Date class ================================================== */ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefined') { @@ -453,7 +455,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin return _time; } - /* POSITION + /* POSITION + Positions elements on the timeline based on date + relative to the calculated interval ================================================== */ var positionRelative = function(_interval, first, last) { var _first, @@ -714,9 +718,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin for(var i = 0; i < the_intervals.length; i++) { - var _interval = the_intervals[i].interval_element, - _interval_date = the_intervals[i].interval_date, - _interval_visible = the_intervals[i].interval_visible, + var _interval = the_intervals[i].element, + _interval_date = the_intervals[i].date, + _interval_visible = the_intervals[i].visible, _pos = positionOnTimeline(interval, the_intervals[i].relative_pos), pos = _pos.begin, _animation = the_intervals[i].animation, @@ -835,150 +839,206 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin */ } + /* Interval Elements + ================================================== */ var createIntervalElements = function(_interval, _array, _element_parent) { - var inc_time = 0, - _first_run = true, - _last_pos = 0, - _largest_pos = 0; + var inc_time = 0, + _first_run = true, + _last_pos = 0, + _largest_pos = 0, + _timezone_offset, + _first_date, + firefox = { + flag: false, + offset: 0 + }; VMM.attachElement(_element_parent, ""); _interval.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0); - - for(var i = 0; i < Math.ceil(_interval.number) + 1; i++) { - var _idd, - _pos, - pos, - _date, - _visible = false, - _relative_pos, - _element = VMM.appendAndGetElement(_element_parent, "
", _interval.classname); + _timezone_offset = _interval.date.getTimezoneOffset(); + + for(var i = 0; i < Math.ceil(_interval.number) + 2; i++) { + var _is_year = false, + int_obj = { + element: VMM.appendAndGetElement(_element_parent, "
", _interval.classname), + date: new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0), + visible: false, + date_string: "", + type: _interval.interval_type, + relative_pos: 0, + is_detached: false, + animation: { + animate: false, + pos: "", + opacity: "100" + + } + }; + + //int_obj.date.setFullYear( data[0].startdate.getFullYear() ); + //int_obj.date.setMonth( data[0].startdate.getMonth() ); + //int_obj.date.setDate( data[0].startdate.getDate() ); + //int_obj.date.setHours( data[0].startdate.getHours() ); + //int_obj.date.setMinutes( data[0].startdate.getMinutes() ); + //int_obj.date.setSeconds( data[0].startdate.getSeconds() ); + //int_obj.date.setMilliseconds(0); + if (_interval.type == "eon") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 500000000) * 500000000 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 500000000) * 500000000; } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 500000000)); + int_obj.date.setFullYear(_first_date + (inc_time * 500000000)); + _is_year = true; } else if (_interval.type == "era") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 100000000) * 100000000 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 100000000) * 100000000; } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 100000000)); + int_obj.date.setFullYear(_first_date + (inc_time * 100000000)); + _is_year = true; } else if (_interval.type == "epoch") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 10000000) * 10000000 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 10000000) * 10000000 } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 10000000)); + int_obj.date.setFullYear(_first_date + (inc_time * 10000000)); + _is_year = true; } else if (_interval.type == "age") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 1000000) * 1000000 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 1000000) * 1000000 } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 1000000)); + int_obj.date.setFullYear(_first_date + (inc_time * 1000000)); + _is_year = true; } else if (_interval.type == "millenium") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 1000) * 1000 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 1000) * 1000; } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 1000)); + int_obj.date.setFullYear(_first_date + (inc_time * 1000)); + _is_year = true; } else if (_interval.type == "century") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 100) * 100 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 100) * 100 } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 100)); + int_obj.date.setFullYear(_first_date + (inc_time * 100)); + _is_year = true; } else if (_interval.type == "decade") { if (_first_run) { - _interval.date.setFullYear( Math.floor(data[0].startdate.getFullYear() / 10) * 10 ); + _first_date = Math.floor(data[0].startdate.getFullYear() / 10) * 10; } - _interval.date.setFullYear(_interval.date.getFullYear() + (inc_time * 10)); + int_obj.date.setFullYear(_first_date + (inc_time * 10)); + _is_year = true; } else if (interval.type == "year") { if (_first_run) { - + _first_date = data[0].startdate.getFullYear(); } - _interval.date.setFullYear(_interval.date.getFullYear() + inc_time); + int_obj.date.setFullYear(_first_date + inc_time); + _is_year = true; } else if (_interval.type == "month") { if (_first_run) { - _interval.date.setMonth(data[0].startdate.getMonth()); + _first_date = data[0].startdate.getMonth(); } - _interval.date.setMonth(_interval.date.getMonth() + inc_time); + int_obj.date.setMonth(_first_date + inc_time); } else if (_interval.type == "week") { if (_first_run) { - _interval.date.setMonth( data[0].startdate.getMonth() ); - _interval.date.setDate( Math.floor(data[0].startdate.getDate() *7) ); + _first_date = data[0].startdate.getMonth(); } - _interval.date.setDate(_interval.date.getDate() + (inc_time * 7) ); + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(_first_date + (inc_time * 7) ); } else if (_interval.type == "day") { if (_first_run) { - _interval.date.setMonth( data[0].startdate.getMonth() ); - _interval.date.setDate( data[0].startdate.getDate() ); + _first_date = data[0].startdate.getDate(); } - _interval.date.setDate(_interval.date.getDate() + inc_time); + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(_first_date + inc_time); } else if (_interval.type == "hour") { if (_first_run) { - _interval.date.setMonth( data[0].startdate.getMonth() ); - _interval.date.setDate( data[0].startdate.getDate() ); - _interval.date.setHours( data[0].startdate.getHours() ); + _first_date = data[0].startdate.getHours(); } - _interval.date.setHours(_interval.date.getHours() + inc_time); + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(data[0].startdate.getDate()); + int_obj.date.setHours(_first_date + inc_time); } else if (_interval.type == "minute") { if (_first_run) { - _interval.date.setMonth( data[0].startdate.getMonth() ); - _interval.date.setDate( data[0].startdate.getDate() ); - _interval.date.setHours( data[0].startdate.getHours() ); - _interval.date.setMinutes( data[0].startdate.getMinutes() ); + _first_date = data[0].startdate.getMinutes(); } - _interval.date.setMinutes(_interval.date.getMinutes() + inc_time); + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(data[0].startdate.getDate()); + int_obj.date.setHours(data[0].startdate.getHours()); + int_obj.date.setMinutes(_first_date + inc_time); } else if (_interval.type == "second") { if (_first_run) { - _interval.date.setMonth( data[0].startdate.getMonth() ); - _interval.date.setDate( data[0].startdate.getDate() ); - _interval.date.setHours( data[0].startdate.getHours() ); - _interval.date.setMinutes( data[0].startdate.getMinutes() ); - _interval.date.setSeconds( data[0].startdate.getSeconds() ); + _first_date = data[0].startdate.getSeconds(); } - _interval.date.setSeconds(_interval.date.getSeconds() + inc_time); + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(data[0].startdate.getDate()); + int_obj.date.setHours(data[0].startdate.getHours()); + int_obj.date.setMinutes(data[0].startdate.getMinutes()); + int_obj.date.setSeconds(_first_date + inc_time); + } else if (_interval.type == "millisecond") { + if (_first_run) { + _first_date = data[0].startdate.getMilliseconds(); + } + int_obj.date.setMonth(data[0].startdate.getMonth()); + int_obj.date.setDate(data[0].startdate.getDate()); + int_obj.date.setHours(data[0].startdate.getHours()); + int_obj.date.setMinutes(data[0].startdate.getMinutes()); + int_obj.date.setSeconds(data[0].startdate.getSeconds()); + int_obj.date.setMilliseconds(_first_date + inc_time); } - _idd = VMM.Date.prettyDate(_interval.date, true); - - inc_time = 1; - - _first_run = false; - - _relative_pos = positionRelative(interval, _interval.date); + // FIX WEIRD FIREFOX BUG FOR GMT TIME FORMATTING + if (VMM.Browser.browser == "Firefox") { + if (int_obj.date.getFullYear() == "1970" && int_obj.date.getTimezoneOffset() != _timezone_offset) { + + trace("FIREFOX 1970 TIMEZONE OFFSET " + int_obj.date.getTimezoneOffset() + " SHOULD BE " + _timezone_offset); + trace(_interval.type + " " + _interval.date); + + // try and fix firefox bug, if not the flag will catch it + firefox.offset = (int_obj.date.getTimezoneOffset()/60); + firefox.flag = true; + int_obj.date.setHours(int_obj.date.getHours() + firefox.offset ); + + } else if (firefox.flag) { + // catch the bug the second time around + firefox.flag = false; + int_obj.date.setHours(int_obj.date.getHours() + firefox.offset ); + if (_is_year) { + firefox.flag = true; + } + } + + } - //_pos = positionOnTimeline(_interval, _interval.date); - //pos = _pos.begin; - pos = _relative_pos.begin; + if (_is_year) { + if ( int_obj.date.getFullYear() < 0 ) { + int_obj.date_string = Math.abs( int_obj.date.getFullYear() ).toString() + " B.C."; + } else { + int_obj.date_string = int_obj.date.getFullYear(); + } + } else { + int_obj.date_string = VMM.Date.prettyDate(int_obj.date, true); + } - VMM.appendElement(_element, _idd); + // Increment Time + inc_time++; - VMM.Lib.css(_element, "text-indent", -(VMM.Lib.width(_element)/2)); - VMM.Lib.css(_element, "opacity", "0"); - - _last_pos = pos; + // No longer first run + _first_run = false; - if (pos > _largest_pos) { - _largest_pos = pos; + int_obj.relative_pos = positionRelative(interval, int_obj.date); + _last_pos = int_obj.relative_pos.begin; + if (int_obj.relative_pos.begin > _largest_pos) { + _largest_pos = int_obj.relative_pos.begin; } - _date = new Date(_interval.date); - - var _obj = { - interval_element: _element, - interval_date: _date, - interval_visible: _visible, - type: _interval.interval_type, - relative_pos: _relative_pos, - is_detached: false, - animation: { - animate: false, - pos: "", - opacity: "100" - - } - }; + // Add the time string to the element and position it. + VMM.appendElement(int_obj.element, int_obj.date_string); + VMM.Lib.css(int_obj.element, "text-indent", -(VMM.Lib.width(int_obj.element)/2)); + VMM.Lib.css(int_obj.element, "opacity", "0"); - _array.push(_obj); + // add the interval element to the array + _array.push(int_obj); } VMM.Lib.width($timeintervalminor_minor, _largest_pos);