$('#timeline-embed').html('');
var timeline_config = { width: '100%', height: '600', source: '{{ URL::to("timeline/town") }}/' + townId, embed_id: 'timeline-embed', //OPTIONAL USE A DIFFERENT DIV ID FOR EMBED start_at_end: false, //OPTIONAL START AT LATEST DATE start_zoom_adjust: '1', //OPTIONAL TWEAK THE DEFAULT ZOOM LEVEL hash_bookmark: true, //OPTIONAL LOCATION BAR HASHES font: 'Bevan-PotanoSans', //OPTIONAL FONT debug: true, //OPTIONAL DEBUG TO CONSOLE lang: 'fr', //OPTIONAL LANGUAGE maptype: 'watercolor' //OPTIONAL MAP STYLE }
createStoryJS(timeline_config); var timeline_config = { width: '100%', height: '600', source: '{{ URL::to("timeline/index/town") }}/' + townId, embed_id: 'timeline-embed', //OPTIONAL USE A DIFFERENT DIV ID FOR EMBED start_at_end: false, //OPTIONAL START AT LATEST DATE start_zoom_adjust: '1', //OPTIONAL TWEAK THE DEFAULT ZOOM LEVEL hash_bookmark: true, //OPTIONAL LOCATION BAR HASHES font: 'Bevan-PotanoSans', //OPTIONAL FONT debug: true, //OPTIONAL DEBUG TO CONSOLE lang: 'fr', //OPTIONAL LANGUAGE maptype: 'watercolor' //OPTIONAL MAP STYLE }
storyjs_embedjs = new VMM.Timeline('timeline-embed'); storyjs_embedjs.init(timeline_config); $(document).ready(function() {
// Global for the timeline object so I can reset it (not sure if this is really required)
var gTimeLine = "";
$('#survey_start_date').datepicker({
dateFormat: "dd/mm/yy",
onSelect: function(dateText, inst) {
//Update startdate in system
var fetch_url = "myURL?method=setStartDate&startdate="+ escape(dateText);
$.get(fetch_url,function(response){
if (response == 'true') {
//We have changed the start date in the system so re-load the timeline
gTimeLine = null;
$('##timeline-embed').html("");
initTimeline ();
}
});
}
});
// Initialise timeline on page load
initTimeline ();
});
function initTimeline () {
// Get data from JSON source (also calculates slide to show and returns in structure
var fetch_url = "myURL?method=getDates";
$.get(fetch_url,function(response){
var objdata2load = JSON.parse(response);
var slide=0;
// Initialise timeline with loaded JSON data
gTimeLine = createStoryJS({
type: 'timeline',
embed_id: 'timeline-embed',
width: "100%",
height: "100%",
start_zoom_adjust:0,
start_at_slide: objdata2load.timeline.defaultslide,
source: objdata2load
});
});
}
Hope that helps.
I have two buttons
that load a different source data
My problem is that events from
both source data get mixed. Every time I press a button, instead of
reloading with only the new data, the new data get appended to the
existing data.
Please, could you help me? A working example will be very helpful, too!
My code:
$(window).load(function() {
var sourceNews = 'https://docs.google.com/spreadsheet/pub?key=0Aly6bWUDjwazdG1UN2p3YkJ6Tk15UDN6RnpQd2hOaGc&single=true&gid=0&output=html';
var idDestinationNews = '#news';
var _idDestinationNews = 'news';
var sourceHistory = 'https://docs.google.com/spreadsheet/pub?key=0Aly6bWUDjwazdEllTHBSRDlBcDQ4MlFqSVp4ZEpZYWc&output=html';
var idDestinationHistory = '#history';
var _idDestinationHistory = 'history';
var timeline = null;
$(idDestinationNews).show();
$(idDestinationHistory).hide();
createTimeline(_idDestinationNews, sourceNews);
/*
* <button id="btNews">News</button>
* <button id="btHistory">History</button>
*/
$('#btNews').on('click', function() {
$(idDestinationNews).empty();
$(idDestinationNews).html("");
$(idDestinationNews).unbind();
timeline = null;
createTimeline(_idDestinationNews, sourceNews);
$(idDestinationNews).show();
});
$('#btHistory').on('click', function() {
$(idDestinationNews).empty();
$(idDestinationNews).html("");
$(idDestinationNews).unbind();
timeline = null;
createTimeline(_idDestinationNews, sourceHistory);
$(idDestinationNews).show();
});
});
function createTimeline(id_destination, source) {
timeline = createStoryJS({
type: 'timeline',
width: '100%',
height: '100%',
start_at_slide: 0,
source: source,
embed_id: id_destination,
css: 'js/timeline/css/timeline.css', //OPTIONAL PATH TO CSS
js: 'js/timeline/js/timeline.js' //OPTIONAL PATH TO JS
});
}