diff --git a/compiled/js/timeline.js b/compiled/js/timeline.js index e5b943f8f..d668acb41 100644 --- a/compiled/js/timeline.js +++ b/compiled/js/timeline.js @@ -673,9 +673,9 @@ if(typeof VMM != 'undefined') { if (show != null) { if( typeof( jQuery ) != 'undefined' ){ if (show) { - jQuery(element).show(0); + jQuery(element).show(); } else { - jQuery(element).hide(0); + jQuery(element).hide(); } } } else { @@ -4346,19 +4346,37 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { /* NAVIGATION ================================================== */ function onNextClick(e) { - if (current_slide == slides.length - 1) { + var next; + var last; + if (config.reverse) { + next = -1; + last = 0; + } else { + next = 1; + last = slides.length - 1; + } + if (current_slide == last) { VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": -(slides[current_slide].leftpos()) } ); } else { - goToSlide(current_slide+1); + goToSlide(current_slide+next); upDate(); } } function onPrevClick(e) { - if (current_slide == 0) { + var prev; + var first; + if (config.reverse) { + prev = 1; + first = slides.length - 1; + } else { + prev = -1; + first = 0; + } + if (current_slide == first) { goToSlide(current_slide); } else { - goToSlide(current_slide-1); + goToSlide(current_slide+prev); upDate(); } } @@ -4642,7 +4660,11 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { var positionSlides = function() { var pos = 0; for(var i = 0; i < slides.length; i++) { - pos = i * (config.slider.width+config.spacing); + if (config.reverse) { + pos = -i * (config.slider.width+config.spacing); + } else { + pos = i * (config.slider.width+config.spacing); + } slides[i].leftpos(pos); } } @@ -4681,8 +4703,19 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { var _pos = slides[current_slide].leftpos(); var _title = ""; - if (current_slide == 0) {is_first = true}; - if (current_slide +1 >= slides.length) {is_last = true}; + var next, prev; + + if (config.reverse) { + if (current_slide == 0) {is_last = true}; + if (current_slide +1 >= slides.length) {is_first = true}; + next = -1; + prev = 1; + } else { + if (current_slide == 0) {is_first = true}; + if (current_slide +1 >= slides.length) {is_last = true}; + next = 1; + prev = -1; + } if (ease != null && ease != "") {_ease = ease}; if (duration != null && duration != "") {_duration = duration}; @@ -4692,13 +4725,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { VMM.Lib.visible(navigation.prevBtn, false); } else { VMM.Lib.visible(navigation.prevBtn, true); - _title = VMM.Util.unlinkify(data[current_slide - 1].title) + _title = VMM.Util.unlinkify(data[current_slide + prev].title) if (config.type == "timeline") { - if(typeof data[current_slide - 1].date === "undefined") { + if(typeof data[current_slide + prev].date === "undefined") { VMM.attachElement(navigation.prevDate, _title); VMM.attachElement(navigation.prevTitle, ""); } else { - VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide - 1].startdate)); + VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide + prev].startdate)); VMM.attachElement(navigation.prevTitle, _title); } } else { @@ -4710,13 +4743,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { VMM.Lib.visible(navigation.nextBtn, false); } else { VMM.Lib.visible(navigation.nextBtn, true); - _title = VMM.Util.unlinkify(data[current_slide + 1].title); + _title = VMM.Util.unlinkify(data[current_slide + next].title); if (config.type == "timeline") { - if(typeof data[current_slide + 1].date === "undefined") { + if(typeof data[current_slide + next].date === "undefined") { VMM.attachElement(navigation.nextDate, _title); VMM.attachElement(navigation.nextTitle, ""); } else { - VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + 1].startdate) ); + VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + next].startdate) ); VMM.attachElement(navigation.nextTitle, _title); } } else { @@ -6731,25 +6764,33 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if (data.headline != null && data.headline != "" && data.text != null && data.text != "") { trace("HAS STARTPAGE"); var _date = {}, td_num = 0, td; + var offset; - td = _dates[0].startdate; - _date.startdate = new Date(_dates[0].startdate); + if (config.start_at_end) { + td = _dates[_dates.length - 1].enddate; + _date.startdate = new Date(_dates[_dates.length - 1].enddate); + offset = 1; + } else { + td = _dates[0].startdate; + _date.startdate = new Date(_dates[0].startdate); + offset = -1; + } if (td.getMonth() === 0 && td.getDate() == 1 && td.getHours() === 0 && td.getMinutes() === 0 ) { // trace("YEAR ONLY"); - _date.startdate.setFullYear(td.getFullYear() - 1); + _date.startdate.setFullYear(td.getFullYear() + offset); } else if (td.getDate() <= 1 && td.getHours() === 0 && td.getMinutes() === 0) { // trace("YEAR MONTH"); - _date.startdate.setMonth(td.getMonth() - 1); + _date.startdate.setMonth(td.getMonth() + offset); } else if (td.getHours() === 0 && td.getMinutes() === 0) { // trace("YEAR MONTH DAY"); - _date.startdate.setDate(td.getDate() - 1); + _date.startdate.setDate(td.getDate() + offset); } else if (td.getMinutes() === 0) { // trace("YEAR MONTH DAY HOUR"); - _date.startdate.setHours(td.getHours() - 1); + _date.startdate.setHours(td.getHours() + offset); } else { // trace("YEAR MONTH DAY HOUR MINUTE"); - _date.startdate.setMinutes(td.getMinutes() - 1); + _date.startdate.setMinutes(td.getMinutes() + offset); } _date.uniqueid = VMM.Util.unique_ID(7); @@ -6978,7 +7019,11 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin function onBackHome(e) { $dragslide.cancelSlide(); - goToMarker(0); + if (config.start_at_end) { + goToMarker(markers.length - 1); + } else { + goToMarker(0); + } upDate(); } @@ -7054,19 +7099,34 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin _duration = config.duration, is_last = false, is_first = false; + var start_page_index = 0; current_marker = n; + if (config.reverse) { + if (current_marker == 0) { + is_last = true; + } + if (current_marker +1 == markers.length) { + is_first = true; + } + } else { + if (current_marker == 0) { + is_first = true; + } + if (current_marker +1 == markers.length) { + is_last = true; + } + } + if (is_last) { + VMM.Lib.visible(markers[current_marker].marker, true); + } + timenav_pos.left = (config.width/2) - VMM.Lib.position(markers[current_marker].marker).left; timenav_pos.visible.left = Math.abs(timenav_pos.left) - 100; timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width + 100; - if (current_marker == 0) { - is_first = true; - } - if (current_marker +1 == markers.length) { - is_last = true - } + if (ease != null && ease != "") {_ease = ease}; if (duration != null && duration != "") {_duration = duration}; @@ -7075,9 +7135,14 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin VMM.Lib.removeClass(markers[i].marker, "active"); } - if (config.start_page && markers[0].type == "start") { - VMM.Lib.visible(markers[0].marker, false); - VMM.Lib.addClass(markers[0].marker, "start"); + if (config.start_at_end) { + start_page_index = markers.length - 1; + } else { + start_page_index = 0; + } + if (config.start_page && markers[start_page_index].type == "start") { + VMM.Lib.visible(markers[start_page_index].marker, false); + VMM.Lib.addClass(markers[start_page_index].marker, "start"); } VMM.Lib.addClass(markers[current_marker].marker, "active"); @@ -7102,6 +7167,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin pos_dif = 0, mp_diff = []; + if (markers.length > 0) { + pos = positionOnTimeline(interval, markers[0].relative_pos).begin; + } for(var i = 0; i < markers.length; i++) { if (data[i].type == "start") { @@ -7109,7 +7177,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin var _pos = positionOnTimeline(interval, markers[i].relative_pos), last_pos = pos; pos = _pos.begin; - pos_dif = pos - last_pos; + pos_dif = Math.abs(pos - last_pos); mp_diff.push(pos_dif); } } @@ -7155,10 +7223,17 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin var _first = getDateFractions(data[0].startdate); var _last = getDateFractions(data[data.length - 1].enddate); + var _base; + if (config.reverse) { + _base = _last; + } else { + _base = _first; + } + // EON interval_calc.eon.type = "eon"; interval_calc.eon.first = _first.eons; - interval_calc.eon.base = Math.floor(_first.eons); + interval_calc.eon.base = Math.floor(_base.eons); interval_calc.eon.last = _last.eons; interval_calc.eon.number = timespan.eons; interval_calc.eon.multiplier = timelookup.eons; @@ -7167,7 +7242,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // ERA interval_calc.era.type = "era"; interval_calc.era.first = _first.eras; - interval_calc.era.base = Math.floor(_first.eras); + interval_calc.era.base = Math.floor(_base.eras); interval_calc.era.last = _last.eras; interval_calc.era.number = timespan.eras; interval_calc.era.multiplier = timelookup.eras; @@ -7176,7 +7251,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // EPOCH interval_calc.epoch.type = "epoch"; interval_calc.epoch.first = _first.epochs; - interval_calc.epoch.base = Math.floor(_first.epochs); + interval_calc.epoch.base = Math.floor(_base.epochs); interval_calc.epoch.last = _last.epochs; interval_calc.epoch.number = timespan.epochs; interval_calc.epoch.multiplier = timelookup.epochs; @@ -7185,7 +7260,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // AGE interval_calc.age.type = "age"; interval_calc.age.first = _first.ages; - interval_calc.age.base = Math.floor(_first.ages); + interval_calc.age.base = Math.floor(_base.ages); interval_calc.age.last = _last.ages; interval_calc.age.number = timespan.ages; interval_calc.age.multiplier = timelookup.ages; @@ -7194,7 +7269,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MILLENIUM interval_calc.millenium.type = "millenium"; interval_calc.millenium.first = _first.milleniums; - interval_calc.millenium.base = Math.floor(_first.milleniums); + interval_calc.millenium.base = Math.floor(_base.milleniums); interval_calc.millenium.last = _last.milleniums; interval_calc.millenium.number = timespan.milleniums; interval_calc.millenium.multiplier = timelookup.millenium; @@ -7203,7 +7278,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // CENTURY interval_calc.century.type = "century"; interval_calc.century.first = _first.centuries; - interval_calc.century.base = Math.floor(_first.centuries); + interval_calc.century.base = Math.floor(_base.centuries); interval_calc.century.last = _last.centuries; interval_calc.century.number = timespan.centuries; interval_calc.century.multiplier = timelookup.century; @@ -7212,7 +7287,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // DECADE interval_calc.decade.type = "decade"; interval_calc.decade.first = _first.decades; - interval_calc.decade.base = Math.floor(_first.decades); + interval_calc.decade.base = Math.floor(_base.decades); interval_calc.decade.last = _last.decades; interval_calc.decade.number = timespan.decades; interval_calc.decade.multiplier = timelookup.decade; @@ -7221,7 +7296,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // YEAR interval_calc.year.type = "year"; interval_calc.year.first = _first.years; - interval_calc.year.base = Math.floor(_first.years); + interval_calc.year.base = Math.floor(_base.years); interval_calc.year.last = _last.years; interval_calc.year.number = timespan.years; interval_calc.year.multiplier = 1; @@ -7230,7 +7305,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MONTH interval_calc.month.type = "month"; interval_calc.month.first = _first.months; - interval_calc.month.base = Math.floor(_first.months); + interval_calc.month.base = Math.floor(_base.months); interval_calc.month.last = _last.months; interval_calc.month.number = timespan.months; interval_calc.month.multiplier = 1; @@ -7240,7 +7315,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // NOT DONE interval_calc.week.type = "week"; interval_calc.week.first = _first.weeks; - interval_calc.week.base = Math.floor(_first.weeks); + interval_calc.week.base = Math.floor(_base.weeks); interval_calc.week.last = _last.weeks; interval_calc.week.number = timespan.weeks; interval_calc.week.multiplier = 1; @@ -7249,7 +7324,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // DAY interval_calc.day.type = "day"; interval_calc.day.first = _first.days; - interval_calc.day.base = Math.floor(_first.days); + interval_calc.day.base = Math.floor(_base.days); interval_calc.day.last = _last.days; interval_calc.day.number = timespan.days; interval_calc.day.multiplier = 1; @@ -7258,7 +7333,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // HOUR interval_calc.hour.type = "hour"; interval_calc.hour.first = _first.hours; - interval_calc.hour.base = Math.floor(_first.hours); + interval_calc.hour.base = Math.floor(_base.hours); interval_calc.hour.last = _last.hours; interval_calc.hour.number = timespan.hours; interval_calc.hour.multiplier = 1; @@ -7267,7 +7342,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MINUTE interval_calc.minute.type = "minute"; interval_calc.minute.first = _first.minutes; - interval_calc.minute.base = Math.floor(_first.minutes); + interval_calc.minute.base = Math.floor(_base.minutes); interval_calc.minute.last = _last.minutes; interval_calc.minute.number = timespan.minutes; interval_calc.minute.multiplier = 1; @@ -7276,7 +7351,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // SECOND interval_calc.second.type = "decade"; interval_calc.second.first = _first.seconds; - interval_calc.second.base = Math.floor(_first.seconds); + interval_calc.second.base = Math.floor(_base.seconds); interval_calc.second.last = _last.seconds; interval_calc.second.number = timespan.seconds; interval_calc.second.multiplier = 1; @@ -7406,10 +7481,17 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin } var positionOnTimeline = function(the_interval, timerelative) { - return { - begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current), - end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current) - }; + if (config.reverse) { + return { + begin: (interval.base - timerelative.end) * (config.nav.interval_width / config.nav.multiplier.current), + end: (interval.base - timerelative.start) * (config.nav.interval_width / config.nav.multiplier.current) + }; + } else { + return { + begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current), + end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current) + }; + } } var positionMarkers = function(is_animated) { @@ -7729,8 +7811,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin if (config.nav.multiplier.current > 16 && is_minor) { is_visible = false; } else { - if ((pos - last_position) < 65 ) { - if ((pos - last_position) < 35 ) { + if (Math.abs(pos - last_position) < 65 ) { + if (Math.abs(pos - last_position) < 35 ) { if (i%4 == 0) { if (pos == 0) { is_visible = false; diff --git a/examples/example_reverse_json.html b/examples/example_reverse_json.html new file mode 100644 index 000000000..5bab9ba3d --- /dev/null +++ b/examples/example_reverse_json.html @@ -0,0 +1,48 @@ + + + + + JSON Example Timeline + + + + + + + + +
+ + + + + diff --git a/source/js/Core/VMM.Library.js b/source/js/Core/VMM.Library.js index 1d0e977c0..4df65acae 100644 --- a/source/js/Core/VMM.Library.js +++ b/source/js/Core/VMM.Library.js @@ -280,9 +280,9 @@ if(typeof VMM != 'undefined') { if (show != null) { if( typeof( jQuery ) != 'undefined' ){ if (show) { - jQuery(element).show(0); + jQuery(element).show(); } else { - jQuery(element).hide(0); + jQuery(element).hide(); } } } else { diff --git a/source/js/Slider/VMM.Slider.js b/source/js/Slider/VMM.Slider.js index f0dff931f..b461face5 100644 --- a/source/js/Slider/VMM.Slider.js +++ b/source/js/Slider/VMM.Slider.js @@ -192,19 +192,37 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { /* NAVIGATION ================================================== */ function onNextClick(e) { - if (current_slide == slides.length - 1) { + var next; + var last; + if (config.reverse) { + next = -1; + last = 0; + } else { + next = 1; + last = slides.length - 1; + } + if (current_slide == last) { VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": -(slides[current_slide].leftpos()) } ); } else { - goToSlide(current_slide+1); + goToSlide(current_slide+next); upDate(); } } function onPrevClick(e) { - if (current_slide == 0) { + var prev; + var first; + if (config.reverse) { + prev = 1; + first = slides.length - 1; + } else { + prev = -1; + first = 0; + } + if (current_slide == first) { goToSlide(current_slide); } else { - goToSlide(current_slide-1); + goToSlide(current_slide+prev); upDate(); } } @@ -488,7 +506,11 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { var positionSlides = function() { var pos = 0; for(var i = 0; i < slides.length; i++) { - pos = i * (config.slider.width+config.spacing); + if (config.reverse) { + pos = -i * (config.slider.width+config.spacing); + } else { + pos = i * (config.slider.width+config.spacing); + } slides[i].leftpos(pos); } } @@ -527,8 +549,19 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { var _pos = slides[current_slide].leftpos(); var _title = ""; - if (current_slide == 0) {is_first = true}; - if (current_slide +1 >= slides.length) {is_last = true}; + var next, prev; + + if (config.reverse) { + if (current_slide == 0) {is_last = true}; + if (current_slide +1 >= slides.length) {is_first = true}; + next = -1; + prev = 1; + } else { + if (current_slide == 0) {is_first = true}; + if (current_slide +1 >= slides.length) {is_last = true}; + next = 1; + prev = -1; + } if (ease != null && ease != "") {_ease = ease}; if (duration != null && duration != "") {_duration = duration}; @@ -538,13 +571,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { VMM.Lib.visible(navigation.prevBtn, false); } else { VMM.Lib.visible(navigation.prevBtn, true); - _title = VMM.Util.unlinkify(data[current_slide - 1].title) + _title = VMM.Util.unlinkify(data[current_slide + prev].title) if (config.type == "timeline") { - if(typeof data[current_slide - 1].date === "undefined") { + if(typeof data[current_slide + prev].date === "undefined") { VMM.attachElement(navigation.prevDate, _title); VMM.attachElement(navigation.prevTitle, ""); } else { - VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide - 1].startdate)); + VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide + prev].startdate)); VMM.attachElement(navigation.prevTitle, _title); } } else { @@ -556,13 +589,13 @@ if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') { VMM.Lib.visible(navigation.nextBtn, false); } else { VMM.Lib.visible(navigation.nextBtn, true); - _title = VMM.Util.unlinkify(data[current_slide + 1].title); + _title = VMM.Util.unlinkify(data[current_slide + next].title); if (config.type == "timeline") { - if(typeof data[current_slide + 1].date === "undefined") { + if(typeof data[current_slide + next].date === "undefined") { VMM.attachElement(navigation.nextDate, _title); VMM.attachElement(navigation.nextTitle, ""); } else { - VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + 1].startdate) ); + VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + next].startdate) ); VMM.attachElement(navigation.nextTitle, _title); } } else { diff --git a/source/js/VMM.Timeline.TimeNav.js b/source/js/VMM.Timeline.TimeNav.js index 8dbdda872..f9d1609b2 100644 --- a/source/js/VMM.Timeline.TimeNav.js +++ b/source/js/VMM.Timeline.TimeNav.js @@ -184,7 +184,20 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin function onBackHome(e) { $dragslide.cancelSlide(); - goToMarker(0); + if (config.start_at_end) { + if (config.reverse) { + goToMarker(0); + } else { + goToMarker(markers.length - 1); + } + + } else { + if (config.reverse) { + goToMarker(markers.length - 1); + } else { + goToMarker(0); + } + } upDate(); } @@ -260,19 +273,34 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin _duration = config.duration, is_last = false, is_first = false; + var start_page_index = 0; current_marker = n; + if (config.reverse) { + if (current_marker == 0) { + is_last = true; + } + if (current_marker +1 == markers.length) { + is_first = true; + } + } else { + if (current_marker == 0) { + is_first = true; + } + if (current_marker +1 == markers.length) { + is_last = true; + } + } + if (is_last) { + VMM.Lib.visible(markers[current_marker].marker, true); + } + timenav_pos.left = (config.width/2) - VMM.Lib.position(markers[current_marker].marker).left; timenav_pos.visible.left = Math.abs(timenav_pos.left) - 100; timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width + 100; - if (current_marker == 0) { - is_first = true; - } - if (current_marker +1 == markers.length) { - is_last = true - } + if (ease != null && ease != "") {_ease = ease}; if (duration != null && duration != "") {_duration = duration}; @@ -281,9 +309,14 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin VMM.Lib.removeClass(markers[i].marker, "active"); } - if (config.start_page && markers[0].type == "start") { - VMM.Lib.visible(markers[0].marker, false); - VMM.Lib.addClass(markers[0].marker, "start"); + if (config.start_at_end) { + start_page_index = markers.length - 1; + } else { + start_page_index = 0; + } + if (config.start_page && markers[start_page_index].type == "start") { + VMM.Lib.visible(markers[start_page_index].marker, false); + VMM.Lib.addClass(markers[start_page_index].marker, "start"); } VMM.Lib.addClass(markers[current_marker].marker, "active"); @@ -308,6 +341,9 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin pos_dif = 0, mp_diff = []; + if (markers.length > 0) { + pos = positionOnTimeline(interval, markers[0].relative_pos).begin; + } for(var i = 0; i < markers.length; i++) { if (data[i].type == "start") { @@ -315,7 +351,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin var _pos = positionOnTimeline(interval, markers[i].relative_pos), last_pos = pos; pos = _pos.begin; - pos_dif = pos - last_pos; + pos_dif = Math.abs(pos - last_pos); mp_diff.push(pos_dif); } } @@ -361,10 +397,17 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin var _first = getDateFractions(data[0].startdate); var _last = getDateFractions(data[data.length - 1].enddate); + var _base; + if (config.reverse) { + _base = _last; + } else { + _base = _first; + } + // EON interval_calc.eon.type = "eon"; interval_calc.eon.first = _first.eons; - interval_calc.eon.base = Math.floor(_first.eons); + interval_calc.eon.base = Math.floor(_base.eons); interval_calc.eon.last = _last.eons; interval_calc.eon.number = timespan.eons; interval_calc.eon.multiplier = timelookup.eons; @@ -373,7 +416,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // ERA interval_calc.era.type = "era"; interval_calc.era.first = _first.eras; - interval_calc.era.base = Math.floor(_first.eras); + interval_calc.era.base = Math.floor(_base.eras); interval_calc.era.last = _last.eras; interval_calc.era.number = timespan.eras; interval_calc.era.multiplier = timelookup.eras; @@ -382,7 +425,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // EPOCH interval_calc.epoch.type = "epoch"; interval_calc.epoch.first = _first.epochs; - interval_calc.epoch.base = Math.floor(_first.epochs); + interval_calc.epoch.base = Math.floor(_base.epochs); interval_calc.epoch.last = _last.epochs; interval_calc.epoch.number = timespan.epochs; interval_calc.epoch.multiplier = timelookup.epochs; @@ -391,7 +434,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // AGE interval_calc.age.type = "age"; interval_calc.age.first = _first.ages; - interval_calc.age.base = Math.floor(_first.ages); + interval_calc.age.base = Math.floor(_base.ages); interval_calc.age.last = _last.ages; interval_calc.age.number = timespan.ages; interval_calc.age.multiplier = timelookup.ages; @@ -400,7 +443,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MILLENIUM interval_calc.millenium.type = "millenium"; interval_calc.millenium.first = _first.milleniums; - interval_calc.millenium.base = Math.floor(_first.milleniums); + interval_calc.millenium.base = Math.floor(_base.milleniums); interval_calc.millenium.last = _last.milleniums; interval_calc.millenium.number = timespan.milleniums; interval_calc.millenium.multiplier = timelookup.millenium; @@ -409,7 +452,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // CENTURY interval_calc.century.type = "century"; interval_calc.century.first = _first.centuries; - interval_calc.century.base = Math.floor(_first.centuries); + interval_calc.century.base = Math.floor(_base.centuries); interval_calc.century.last = _last.centuries; interval_calc.century.number = timespan.centuries; interval_calc.century.multiplier = timelookup.century; @@ -418,7 +461,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // DECADE interval_calc.decade.type = "decade"; interval_calc.decade.first = _first.decades; - interval_calc.decade.base = Math.floor(_first.decades); + interval_calc.decade.base = Math.floor(_base.decades); interval_calc.decade.last = _last.decades; interval_calc.decade.number = timespan.decades; interval_calc.decade.multiplier = timelookup.decade; @@ -427,7 +470,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // YEAR interval_calc.year.type = "year"; interval_calc.year.first = _first.years; - interval_calc.year.base = Math.floor(_first.years); + interval_calc.year.base = Math.floor(_base.years); interval_calc.year.last = _last.years; interval_calc.year.number = timespan.years; interval_calc.year.multiplier = 1; @@ -436,7 +479,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MONTH interval_calc.month.type = "month"; interval_calc.month.first = _first.months; - interval_calc.month.base = Math.floor(_first.months); + interval_calc.month.base = Math.floor(_base.months); interval_calc.month.last = _last.months; interval_calc.month.number = timespan.months; interval_calc.month.multiplier = 1; @@ -446,7 +489,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // NOT DONE interval_calc.week.type = "week"; interval_calc.week.first = _first.weeks; - interval_calc.week.base = Math.floor(_first.weeks); + interval_calc.week.base = Math.floor(_base.weeks); interval_calc.week.last = _last.weeks; interval_calc.week.number = timespan.weeks; interval_calc.week.multiplier = 1; @@ -455,7 +498,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // DAY interval_calc.day.type = "day"; interval_calc.day.first = _first.days; - interval_calc.day.base = Math.floor(_first.days); + interval_calc.day.base = Math.floor(_base.days); interval_calc.day.last = _last.days; interval_calc.day.number = timespan.days; interval_calc.day.multiplier = 1; @@ -464,7 +507,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // HOUR interval_calc.hour.type = "hour"; interval_calc.hour.first = _first.hours; - interval_calc.hour.base = Math.floor(_first.hours); + interval_calc.hour.base = Math.floor(_base.hours); interval_calc.hour.last = _last.hours; interval_calc.hour.number = timespan.hours; interval_calc.hour.multiplier = 1; @@ -473,7 +516,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // MINUTE interval_calc.minute.type = "minute"; interval_calc.minute.first = _first.minutes; - interval_calc.minute.base = Math.floor(_first.minutes); + interval_calc.minute.base = Math.floor(_base.minutes); interval_calc.minute.last = _last.minutes; interval_calc.minute.number = timespan.minutes; interval_calc.minute.multiplier = 1; @@ -482,7 +525,7 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin // SECOND interval_calc.second.type = "decade"; interval_calc.second.first = _first.seconds; - interval_calc.second.base = Math.floor(_first.seconds); + interval_calc.second.base = Math.floor(_base.seconds); interval_calc.second.last = _last.seconds; interval_calc.second.number = timespan.seconds; interval_calc.second.multiplier = 1; @@ -612,10 +655,17 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin } var positionOnTimeline = function(the_interval, timerelative) { - return { - begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current), - end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current) - }; + if (config.reverse) { + return { + begin: (interval.base - timerelative.end) * (config.nav.interval_width / config.nav.multiplier.current), + end: (interval.base - timerelative.start) * (config.nav.interval_width / config.nav.multiplier.current) + }; + } else { + return { + begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current), + end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current) + }; + } } var positionMarkers = function(is_animated) { @@ -935,8 +985,8 @@ if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefin if (config.nav.multiplier.current > 16 && is_minor) { is_visible = false; } else { - if ((pos - last_position) < 65 ) { - if ((pos - last_position) < 35 ) { + if (Math.abs(pos - last_position) < 65 ) { + if (Math.abs(pos - last_position) < 35 ) { if (i%4 == 0) { if (pos == 0) { is_visible = false; diff --git a/source/js/VMM.Timeline.js b/source/js/VMM.Timeline.js index ae8ba7ed4..96796e2f8 100755 --- a/source/js/VMM.Timeline.js +++ b/source/js/VMM.Timeline.js @@ -559,25 +559,33 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if (data.headline != null && data.headline != "" && data.text != null && data.text != "") { trace("HAS STARTPAGE"); var _date = {}, td_num = 0, td; + var offset; - td = _dates[0].startdate; - _date.startdate = new Date(_dates[0].startdate); + if (config.start_at_end) { + td = _dates[_dates.length - 1].enddate; + _date.startdate = new Date(_dates[_dates.length - 1].enddate); + offset = 1; + } else { + td = _dates[0].startdate; + _date.startdate = new Date(_dates[0].startdate); + offset = -1; + } if (td.getMonth() === 0 && td.getDate() == 1 && td.getHours() === 0 && td.getMinutes() === 0 ) { // trace("YEAR ONLY"); - _date.startdate.setFullYear(td.getFullYear() - 1); + _date.startdate.setFullYear(td.getFullYear() + offset); } else if (td.getDate() <= 1 && td.getHours() === 0 && td.getMinutes() === 0) { // trace("YEAR MONTH"); - _date.startdate.setMonth(td.getMonth() - 1); + _date.startdate.setMonth(td.getMonth() + offset); } else if (td.getHours() === 0 && td.getMinutes() === 0) { // trace("YEAR MONTH DAY"); - _date.startdate.setDate(td.getDate() - 1); + _date.startdate.setDate(td.getDate() + offset); } else if (td.getMinutes() === 0) { // trace("YEAR MONTH DAY HOUR"); - _date.startdate.setHours(td.getHours() - 1); + _date.startdate.setHours(td.getHours() + offset); } else { // trace("YEAR MONTH DAY HOUR MINUTE"); - _date.startdate.setMinutes(td.getMinutes() - 1); + _date.startdate.setMinutes(td.getMinutes() + offset); } _date.uniqueid = VMM.Util.unique_ID(7); @@ -614,4 +622,4 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { VMM.Timeline.Config = {}; -}; \ No newline at end of file +};