Browse Source

Made changes to make loading from Google Spreadsheet more reliable and prevent parsing errors should help with issue #183

pull/197/head
Zach Wise 12 years ago
parent
commit
ade91daf75
  1. 79
      source/js/VMM.Timeline.DataObj.js

79
source/js/VMM.Timeline.DataObj.js

@ -172,8 +172,17 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef
}, },
buildData: function(d) { buildData: function(d) {
var data_obj = VMM.Timeline.DataObj.data_template_obj;
VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data"); VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data");
var _data_obj = VMM.Timeline.DataObj.data_template_obj;
function getGVar(v) {
if (typeof v != 'undefined') {
return v.$t;
} else {
return "";
}
}
for(var i = 0; i < d.feed.entry.length; i++) { for(var i = 0; i < d.feed.entry.length; i++) {
var dd = d.feed.entry[i], var dd = d.feed.entry[i],
@ -186,52 +195,44 @@ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undef
} }
if (dd_type.match("start") || dd_type.match("title") ) { if (dd_type.match("start") || dd_type.match("title") ) {
_data_obj.timeline.startDate = dd.gsx$startdate.$t; data_obj.timeline.startDate = getGVar(dd.gsx$startdate);
_data_obj.timeline.headline = dd.gsx$headline.$t; data_obj.timeline.headline = getGVar(dd.gsx$headline);
_data_obj.timeline.asset.media = dd.gsx$media.$t; data_obj.timeline.asset.media = getGVar(dd.gsx$media);
_data_obj.timeline.asset.caption = dd.gsx$mediacaption.$t; data_obj.timeline.asset.caption = getGVar(dd.gsx$mediacaption);
_data_obj.timeline.asset.credit = dd.gsx$mediacredit.$t; data_obj.timeline.asset.credit = getGVar(dd.gsx$mediacredit);
_data_obj.timeline.text = dd.gsx$text.$t; data_obj.timeline.text = getGVar(dd.gsx$text);
_data_obj.timeline.type = "google spreadsheet"; data_obj.timeline.type = "google spreadsheet";
} else if (dd_type.match("era")) { } else if (dd_type.match("era")) {
var _era = { var era = {
"startDate": dd.gsx$startdate.$t, startDate: getGVar(dd.gsx$startdate),
"endDate": dd.gsx$enddate.$t, endDate: getGVar(dd.gsx$enddate),
"headline": dd.gsx$headline.$t, headline: getGVar(dd.gsx$headline),
"text": dd.gsx$text.$t, text: getGVar(dd.gsx$text),
"tag": "" tag: getGVar(dd.gsx$tag)
};
if (typeof dd.gsx$tag != 'undefined') {
_era.tag = dd.gsx$tag.$t;
} }
_data_obj.timeline.era.push(_era); data_obj.timeline.era.push(era);
} else { } else {
var _date = { var date = {
"type": "google spreadsheet", type: "google spreadsheet",
"startDate": dd.gsx$startdate.$t, startDate: getGVar(dd.gsx$startdate),
"endDate": dd.gsx$enddate.$t, endDate: getGVar(dd.gsx$enddate),
"headline": dd.gsx$headline.$t, headline: getGVar(dd.gsx$headline),
"text": dd.gsx$text.$t, tag: getGVar(dd.gsx$tag),
"asset": { asset: {
"media": dd.gsx$media.$t, media: getGVar(dd.gsx$media),
"credit": dd.gsx$mediacredit.$t, credit: getGVar(dd.gsx$mediacredit),
"caption": dd.gsx$mediacaption.$t caption: getGVar(dd.gsx$mediacaption),
}, thumbnail: getGVar(dd.gsx$mediathumbnail)
"tag": "" }
}; };
if (typeof dd.gsx$tag != 'undefined') {
_date.tag = dd.gsx$tag.$t;
}
if (typeof dd.gsx$mediathumbnail != 'undefined') {
_date.asset.thumbnail = dd.gsx$mediathumbnail.$t;
}
_data_obj.timeline.date.push(_date); data_obj.timeline.date.push(date);
} }
}; };
VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj); VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Finished Parsing Data");
VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, data_obj);
} }
}, },

Loading…
Cancel
Save