152 lines
6.3 KiB
JavaScript
152 lines
6.3 KiB
JavaScript
//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 = "";
|
|
//this.container = t.timelineHtml.find("#t_container");
|
|
this.events = new Array;
|
|
this.monthList = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
|
|
this.dt = new Date();
|
|
this.fromdate = [t.dt.getFullYear(),t.dt.getMonth()+1];
|
|
this.ajaxload = true;
|
|
this.initialize = function(){
|
|
t.dom.html(t.timelineHtml);
|
|
$("div.scrollbar").hide();
|
|
t.constructTimeScale(function(timelineScale){
|
|
$("#timeline_scale").html(timelineScale);
|
|
var totalyearwidth =timelineScale.find(".year").length * 200;
|
|
var totalul = 0;
|
|
$(".t_scale").css({"min-width":$(".tinycanvas .viewport").width()+200 + "px"})
|
|
for(eve in t.events){
|
|
t.makeBubble(t.events[eve]);
|
|
totalul = $("#scale_wrapper ul").length
|
|
$(".t_scale").width((totalul*350) + totalyearwidth);
|
|
}
|
|
|
|
$('.tinycanvas').tinyscrollbar({
|
|
axis: 'x',
|
|
onMove: function(x){
|
|
var limit = $("#timeline_scale").width() - $(".tinycanvas .scrollbar").width();
|
|
if(t.ajaxload){
|
|
if((limit - x) < 10){
|
|
t.eventAjaxLoad(function(){
|
|
var totalul = 0;
|
|
for(eve in t.events){
|
|
t.makeBubble(t.events[eve]);
|
|
totalul = $("#scale_wrapper ul").length
|
|
$(".t_scale").width((totalul*350) + totalyearwidth);
|
|
}
|
|
$('.tinycanvas').tinyscrollbar_update(x);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
this.constructTimeScale = function(callbackFn){
|
|
var mon ="",year="",formname;
|
|
var scale = $("<div id='scale_wrapper'></div>");
|
|
$.getJSON("desktop_orbit/eventajaxload",{"event":"papers","from":t.fromdate},function(papersArray){
|
|
$.each(papersArray,function(i,pa){
|
|
$.each(pa.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("-","");
|
|
formname = (cur_mon.charAt(0) == "0"?cur_mon.charAt(1) : cur_mon)
|
|
var bubbleData = {"fulldate" : t.monthList[parseInt(formname)] +", " + dt.getDate() + ", " + cur_year,"title":paper.title,"jtitle":"Harry","coauthors":paper.coauthors,"abstract":paper.abstract,"timestamp":cdt}
|
|
t.events.push(bubbleData);
|
|
if(cur_year != year){
|
|
year = cur_year;
|
|
scale.append($("<div class='group year w1 h1 hp vp thmtxt thmc1'>"+(year+1)+"</div><div data-content='"+year+"'></div>"));
|
|
}
|
|
if(cur_mon != mon){
|
|
mon = cur_mon;
|
|
var yr = scale.find("div[data-content="+year+"]");
|
|
yr.append($("<div class='group month' data-content='"+cdt+"'><div class='month_heading'>"+t.monthList[parseInt(formname)]+"</div><div class='bubble_list'></div></div>"))
|
|
}
|
|
});
|
|
});
|
|
scale.append($("<div class='group year w1 h1 thmtxt thmc1'>"+year+"</div><div data-content='"+(year-1)+"'></div>"));
|
|
t.fromdate = [year,formname-1];
|
|
if(typeof callbackFn == "function"){
|
|
callbackFn.call(this,scale);
|
|
}
|
|
})
|
|
|
|
}
|
|
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);
|
|
if(totalul == 0){
|
|
var ul = $("<ul></ul>");
|
|
$("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
|
|
targetul = ul;
|
|
}else{
|
|
var totalli = targetul.find("li").length;
|
|
if(totalli >= 5){
|
|
var ul = $("<ul></ul>");
|
|
$("#scale_wrapper").find("div[data-content="+bubbleData.timestamp+"] div.bubble_list").append(ul);
|
|
targetul = ul;
|
|
}
|
|
}
|
|
var bt = (bubbleData.title.length > 70? bubbleData.title.substr(0,70) + "..." : bubbleData.title);
|
|
var bubble = $("<li class='bubble hh3 admbg vp hp'>"+bt+"<span class='date'>"+bubbleData.fulldate+"</span></li>");
|
|
targetul.prepend(bubble);
|
|
bubble.show();
|
|
bubble.click(function(){
|
|
o.toolPopup({
|
|
parent: $(this),
|
|
html : "<div><h3>"+bubbleData.jtitle+"</h3><span><h2>Co-Authors: </h2>"+bubbleData.coauthors+"</span><span><h2>Abstract: </h2>"+bubbleData.abstract+"</span></div>",
|
|
height: "auto",
|
|
width:"300px"
|
|
});
|
|
})//.mouseout(function(){t.oapi.toolPopup("destroy");})
|
|
}
|
|
this.eventAjaxLoad = function(callbackFn){
|
|
t.events = [];
|
|
var mon ="",year="",formname;
|
|
var scale = $("#scale_wrapper");
|
|
|
|
t.ajaxload = false;
|
|
$.getJSON("desktop_orbit/eventajaxload",{"from":t.fromdate},function(papersArray){
|
|
$.each(papersArray,function(i,pa){
|
|
$.each(pa.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("-","");
|
|
formname = (cur_mon.charAt(0) == "0"?cur_mon.charAt(1) : cur_mon)
|
|
var bubbleData = {"fulldate" : t.monthList[parseInt(formname)] +", " + dt.getDate() + ", " + cur_year,"title":paper.title,"jtitle":"Harry","coauthors":paper.coauthors,"abstract":paper.abstract,"timestamp":cdt}
|
|
t.events.push(bubbleData);
|
|
if(cur_year != year){
|
|
year = cur_year;
|
|
if(scale.find("div[data-content="+year+"]").length == 0){
|
|
scale.append($("<div class='scale_region year'>"+(year+1)+"</div><div data-content='"+year+"'></div>"));
|
|
}
|
|
}
|
|
if(cur_mon != mon){
|
|
mon = cur_mon;
|
|
var yr = scale.find("div[data-content="+year+"]");
|
|
yr.append($("<div class='scale_region month' data-content='"+cdt+"'><div class='month_heading'>"+t.monthList[parseInt(formname)]+"</div><div class='bubble_list'></div></div>"))
|
|
}
|
|
});
|
|
});
|
|
if(papersArray.length != 0){
|
|
if(scale.find("div[data-content="+(year-1)+"]").length == 0)
|
|
scale.append($("<div class='scale_region year'>"+year+"</div><div data-content='"+(year-1)+"'></div>"));
|
|
t.ajaxload = true;
|
|
t.fromdate = [year,formname-1];
|
|
}
|
|
if(typeof callbackFn == "function"){
|
|
callbackFn.call(this,scale);
|
|
}
|
|
})
|
|
|
|
}
|
|
} |