-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeline.min.js
executable file
·18 lines (18 loc) · 8.39 KB
/
Timeline.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
jQuery(document).ready(function(a){function e(){var c=a(this).attr("id").substring(14);a("#modal").css("display","block");a("#shade").css("display","block");var b=null;if(0!=c)for(var e=0;e<ursTimelineEvents.length;e++){var d=ursTimelineEvents[e];if(d.id==c){b=d;break}}else b={id:0,start_year:ursSelectedYear,end_year:ursSelectedYear,show_filter_only:0,planets:[],categories:[]};b&&(a("#edit_id").val(b.id),a("#edit_start_year").val(b.start_year),a("#edit_end_year").val(b.end_year),a("#edit_title").val(b.title),
a("#edit_caption").val(b.caption),a("#edit_notes").val(b.notes),a("#edit_image").val(b.image_url),a("#edit_icon").val(b.icon_url),1==b.show_filter_only&&a("#edit_private").attr("checked","checked"),a("#edit_text_color").val(b.text_color),a("#edit_planets").importTags(b.planets.join(",")),a("#edit_categories").importTags(b.categories.join(",")))}function n(){a("#modal").css("display","none");a("#shade").css("display","none")}function l(){var c=a(this).attr("id").substring(16);a.ajax({url:wgScriptPath+
"/index.php?action=ajax",type:"POST",data:{rs:"ursDeleteTimelineEvent",rsrnd:(new Date).getTime(),rsargs:[{id:c}]},success:function(b){JSON.parse(b).status&&(a("#timeline-row-"+c).remove(),a("#timeline-spacer-"+c).remove())}})}a("#timeline_view_list").click(function(){a("#dynamic_timeline").css("display","none");a("#timeline_view_key").css("display","none");a("#timeline_view_list").css("display","none");a("div.printfooter").before(a("#list_timeline").text())});a.getJSON("/wiki/extensions/Timeline/planets.json",
function(c){a("#edit_planets").tagsInput({autocomplete_url:c,autocomplete:{selectFirst:!1,autoFill:!0,autoFocus:!0},width:"565px",height:"10px",defaultText:"Add a planet"})});a.getJSON("/wiki/api.php?action=query&format=json&list=allpages&aplimit=max&apnamespace=14&apfilterredir=nonredirects",function(c){c=c.query.allpages;var b=[];for(i=0;i<c.length;i++){var e={value:c[i].title.substring(9)};b.push(e)}a("#edit_categories").tagsInput({autocomplete_url:b,autocomplete:{selectFirst:!1,autoFill:!0,autoFocus:!0},
width:"565px",height:"10px",defaultText:"Add a category"})});a("[id^='edit-timeline-']").click(e);a("[id^='edit-timeline-']").css("cursor","pointer");a("#edit_save").click(function(){var c=a("#edit_id").val(),b=a("#edit_start_year").val(),q=a("#edit_end_year").val(),d=a("#edit_title").val(),f=a("#edit_caption").val(),j=a("#edit_notes").val(),p=a("#edit_image").val(),g=a("#edit_icon").val(),m=a("#edit_text_color").val(),h=0;a("#edit_private").attr("checked")&&(h=1);var k=a("#edit_categories").val(),
r=a("#edit_planets").val(),s={id:c,start_year:b,end_year:q,title:d,caption:f,notes:j,image_url:p,icon_url:g,text_color:m,show_filter_only:h,categories:k,planets:r};a.ajax({url:wgScriptPath+"/index.php?action=ajax&rs=ursUpdateTimelineEvent&rsrnd="+(new Date).getTime(),type:"POST",data:{rs:"ursUpdateTimelineEvent",rsrnd:(new Date).getTime(),rsargs:[s]},success:function(b){b=JSON.parse(b);if(b.status){var d=b.event.title;0==b.event.title.length&&0<b.event.caption.length?d=b.event.caption:0==b.event.title.length&&
0==b.event.caption.length&&(d=b.event.notes);if(0==c)c=b.event.id,s.id=c,j=b.event.notes,s.notes=j,b='<tr id="timeline-row-'+c+'"><td id="timeline-title-'+c+'">'+d+'</td><td id="edit-timeline-'+c+'">Edit</td><td id="delete-timeline-'+c+'">Delete</td></tr><tr id="timeline-spacer-'+c+'"><td colspan="3"> </td></tr>',a("#timeline-events").append(b),a("#edit-timeline-"+c).click(e),a("#delete-timeline-"+c).click(l),ursTimelineEvents.push(s);else{a("#timeline-title-"+b.event.id).html(d);for(var d=[],
f=0;f<ursTimelineEvents.length;f++){var g=ursTimelineEvents[f];g.id==c?d.push(b.event):d.push(g)}ursTimelineEvents=d}}}});n()});a("#close").click(n);a("[id^='delete-timeline-']").css("cursor","pointer");a("[id^='delete-timeline-']").click(l)});
jQuery(window).load(function(){$("#dynamic_timeline").length&&(console.log("Loading timeline "+window.location.hash.substring(1)),window.location.hash?timelineLoad(new Date(window.location.hash.substring(1))):timelineLoad(new Date("2085")));wgIsArticle&&0==$("#dynamic_timeline").length?($("div.entry-content").before('<div id="timeline-modal-shade" style="display:none;"></div><div id="timeline-modal" style="display:none;"><button id="timeline-modal-close">X</button><div id="dynamic_timeline" class="timeline-default" style="height: 600px; margin-top: 20px; margin-bottom: 50px;" data-planets="" data-categories=""></div></div>'),
$("<link>").attr("rel","stylesheet").attr("type","text/css").attr("href",wgScriptPath+"/extensions/Timeline/timeline_ajax/styles/modal-graphics.css").appendTo("head"),$("div.entry-content a").click(function(){var a=$(this).attr("href"),e=a.indexOf("Timeline");$("#timeline-modal-close").click(hideTimelineModal);$("#timeline-modal-shade").click(hideTimelineModal);console.log("Timeline Index: "+e);$(document).keyup(function(a){27==a.keyCode&&"block"==$("#timeline-modal").css("display")&&hideTimelineModal()});
if("Timeline"==$(this).attr("title")&&0<e){a=a.substring(e+8+1);console.log("Timeline Year: "+a);$("#timeline-modal").css("display","block");$("#timeline-modal-shade").css("display","block");if($("#dynamic_timeline").length&&$("#dynamic_timeline").children().length){e=(new Date(a)).getFullYear()+2;e=new Date(""+e+"");dynamicTimeline.getBand(0).setCenterVisibleDate(new Date(a));dynamicTimeline.getBand(0)._decorators[3]._startDate=new Date(a);dynamicTimeline.getBand(0)._decorators[3]._endDate=new Date(e);
dynamicTimeline.getBand(1)._decorators[3]._startDate=new Date(a);dynamicTimeline.getBand(1)._decorators[3]._endDate=new Date(e);dynamicTimeline.paint();try{_gaq.push(["_trackEvent","timeline","viewed",""+a+""])}catch(n){}}else{try{_gaq.push(["_trackEvent","timeline","loaded",""+a+""])}catch(l){}timelineLoad(new Date(a))}return!1}})):wgIsArticle&&0<$("#dynamic_timeline").length&&$("div.entry-content a").click(function(){var a=$(this).attr("href"),e=a.indexOf("Timeline");return"Timeline"==$(this).attr("title")&&
0<e?($("html, body").animate({scrollTop:$("#dynamic_timeline").offset().top-20},1E3),a=a.substring(e+8+1),console.log("Timeline Year: "+a),dynamicTimeline.getBand(0).setCenterVisibleDate(new Date(a)),!1):!0})});function hideTimelineModal(){console.log("Hiding Timeline Modal");$("#timeline-modal").css("display","none");$("#timeline-modal-shade").css("display","none")}var dynamicTimeline;
function timelineLoad(a){var e=$("#dynamic_timeline").data("planets"),n=$("#dynamic_timeline").data("categories"),l="/wiki/api.php?action=timeline&format=json";e.length&&(l+="&tlplanets="+e);n.length&&(l+="&tlcategories="+n);$.getJSON(l,function(c){for(var b=c.events,q=b.length,d=[],f=[],j=0,p=0,g=0,m=0,h=0;h<q;h++){var k=b[h],r=parseInt(k.start.substring(0,4));r!=g&&(3<=p&&(0==d.length||d[j-1].end<g?(console.log("Adding hotzone for years "+g+"-"+m+", number of events: "+p),d[j]={start:g,end:m,magnify:5,
unit:SimileAjax.DateTime.MONTH},f[j]={start:g,end:m,magnify:35,unit:SimileAjax.DateTime.MONTH},j++):0<d.length&&d[j-1].end==g&&(console.log("Edtending hotzone to include year "+m),d[j-1].end=m,f[j-1].end=m)),g=r,m=g+1,p=0);if(k.durrationEvent||4<k.start.length)k.durrationEvent?(k=parseInt(k.end.substring(0,4)),k<g+3&&(p++,k!=g&&(m=k+1))):p++}console.log("Number of Hot Zones: "+d.length);b=new Timeline.DefaultEventSource;d=[Timeline.createHotZoneBandInfo({zones:d,eventSource:b,date:"Jan 01 2035 00:00:00 GMT",
width:"85%",intervalUnit:SimileAjax.DateTime.YEAR,intervalPixels:100}),Timeline.createHotZoneBandInfo({zones:f,overview:!0,eventSource:b,date:"Jan 01 2035 00:00:00 GMT",width:"15%",intervalUnit:SimileAjax.DateTime.DECADE,intervalPixels:100})];for(h=0;h<d.length;h++)f="#FFFFFF",q="transparent",0<h&&(q=f="transparent"),d[h].decorators=[new Timeline.SpanHighlightDecorator({startDate:"2086",endDate:"2088",color:"transparent",opacity:35,endLabel:"Age of Colonization"}),new Timeline.SpanHighlightDecorator({startDate:"2088",
endDate:"2210",color:f,opacity:65,endLabel:"Age of War"}),new Timeline.SpanHighlightDecorator({startDate:"2210",endDate:"2360",color:q,opacity:35,endLabel:"Age of Betrayal"})],!n&&!e&&(f=a.getFullYear()+2,f=new Date(""+f+""),console.log("Adding Year decorator: "+f),d[h].decorators[3]=new Timeline.SpanHighlightDecorator({startDate:a,endDate:f,color:"#B2B2B2",opacity:65}));d[1].syncWith=0;d[1].highlight=!0;dynamicTimeline=Timeline.create(document.getElementById("dynamic_timeline"),d);a&&dynamicTimeline.getBand(0).setCenterVisibleDate(a);
b.loadJSON(c,l);(n.length||e.length)&&dynamicTimeline.getBand(0).setCenterVisibleDate(new Date(c.events[0].start))})};