This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
orbit-4-1/app/assets/javascripts/orbitTimeline.js

82 lines
3.4 KiB
JavaScript
Raw Normal View History

2012-06-26 07:59:28 +00:00
//for timeline parent library, will be accessable by main library and API library for other people to use.. default inherits orbitDesktopAPI
// Harry Bomrah
var orbitTimeline = function(dom){
t = this;
this.dom = $("#"+dom);
this.timelineHtml = $("<div class='t_bottom t_scale' id='timeline_scale'></div>");
//this.marker = t.timelineHtml.find("#timline_marker");
this.scale = t.timelineHtml.find("#timeline_scale");
//this.container = t.timelineHtml.find("#t_container");
2012-06-26 13:09:33 +00:00
this.events = new Array;
this.monthList = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
2012-06-26 07:59:28 +00:00
this.initialize = function(){
t.dom.html(t.timelineHtml);
$("div.scrollbar").hide();
2012-06-26 13:09:33 +00:00
t.constructTimeScale(function(timelineScale){
$("#timeline_scale").html(timelineScale);
for(eve in t.events){
t.makeBubble(t.events[eve]);
}
});
2012-06-26 07:59:28 +00:00
}
2012-06-26 13:09:33 +00:00
this.constructTimeScale = function(callbackFn){
var mon ="",year="";
var scale = $("<div id='scale_wrapper'></div>");
$.getJSON("desktop_orbit/getevents",{"event":"papers"},function(journals){
$.each(journals,function(x,journal){
$.each(journal.papers,function(i,paper){
var dt = new Date(paper.created_at);
var cur_mon = paper.created_at.substr(5,2);
var cur_year = dt.getFullYear();
var cdt = paper.created_at.substr(0,7).replace("-","");
var bubbleData = {"fulldate" : t.monthList[parseInt(cur_mon)] +", " + dt.getDate() + ", " + cur_year,"title":paper.title,"jtitle":journal.title,"coauthors":paper.coauthors,"abstract":paper.abstract,"timestamp":cdt}
t.events.push(bubbleData);
if(cur_year != year){
year = cur_year;
scale.append($("<div class='scale_region year'>"+(year+1)+"</div>"));
}
if(cur_mon != mon){
mon = cur_mon;
scale.append($("<div class='scale_region month' data-content='"+cdt+"'><div class='month_heading'>"+t.monthList[parseInt(mon)]+"</div><div class='bubble_list'></div></div>"))
}
});
2012-06-26 07:59:28 +00:00
})
2012-06-26 13:09:33 +00:00
scale.append($("<div class='scale_region year'>"+year+"</div>"));
if(typeof callbackFn == "function"){
callbackFn.call(this,scale);
}
});
2012-06-26 07:59:28 +00:00
}
2012-06-26 13:09:33 +00:00
this.makeBubble = function(bubbleData){
var totalul = $("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] ul").length;
var targetul = $("#scale_wrapper div[data-content="+bubbleData.timestamp+"] div.bubble_list ul").eq(totalul-1);
2012-06-26 07:59:28 +00:00
if(totalul == 0){
var ul = $("<ul></ul>");
2012-06-26 13:09:33 +00:00
$("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
2012-06-26 07:59:28 +00:00
targetul = ul;
}else{
var totalli = targetul.find("li").length;
if(totalli >= 5){
var ul = $("<ul></ul>");
2012-06-26 13:09:33 +00:00
$("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
2012-06-26 07:59:28 +00:00
targetul = ul;
}
}
2012-06-26 13:09:33 +00:00
var bt = (bubbleData.title.length > 70? bubbleData.title.substr(0,70) + "..." : bubbleData.title);
var bubble = $("<li class='bubble'><span>"+bt+"<span class='date'> - "+bubbleData.fulldate+"</span></span></li>");
2012-06-26 07:59:28 +00:00
bubble.css("margin-left","25px");
targetul.prepend(bubble);
2012-06-26 13:09:33 +00:00
bubble.show();
2012-06-26 07:59:28 +00:00
bubble.click(function(){
o.toolPopup({
parent: $(this),
2012-06-26 13:09:33 +00:00
html : "<div><h3>"+bubbleData.jtitle+"</h3><span><h2>Co-Authors: </h2>"+bubbleData.coauthors+"</span><span><h2>Abstract: </h2>"+bubbleData.abstract+"</span></div>",
2012-06-26 07:59:28 +00:00
height: "auto",
width:"300px"
});
})//.mouseout(function(){t.oapi.toolPopup("destroy");})
}
}