/* TIMELINE SOURCE DATA PROCESSOR ================================================== */ if (typeof VMM.Timeline !== 'undefined' && typeof VMM.Timeline.DataObj == 'undefined') { VMM.Timeline.DataObj = { data_obj: {}, model_array: [], getData: function (raw_data) { VMM.Timeline.DataObj.data_obj = {}; VMM.fireEvent(global, VMM.Timeline.Config.events.messege, VMM.Timeline.Config.language.messages.loading_timeline); if (type.of(raw_data) == "object") { trace("DATA SOURCE: JSON OBJECT"); VMM.Timeline.DataObj.parseJSON(raw_data); } else if (type.of(raw_data) == "string") { if (raw_data.match("%23")) { trace("DATA SOURCE: TWITTER SEARCH"); VMM.Timeline.DataObj.model.tweets.getData("%23medill"); } else if ( raw_data.match("spreadsheet") ) { trace("DATA SOURCE: GOOGLE SPREADSHEET"); VMM.Timeline.DataObj.model.googlespreadsheet.getData(raw_data); } else if (raw_data.match("storify.com")) { trace("DATA SOURCE: STORIFY"); VMM.Timeline.DataObj.model.storify.getData(raw_data); //http://api.storify.com/v1/stories/number10gov/g8-and-nato-chicago-summit } else if (raw_data.match(".jsonp")) { trace("DATA SOURCE: JSONP"); LoadLib.js(raw_data, VMM.Timeline.DataObj.onJSONPLoaded); } else { trace("DATA SOURCE: JSON"); VMM.getJSON(raw_data + "?callback=onJSONP_Data", VMM.Timeline.DataObj.parseJSON); } } else if (type.of(raw_data) == "html") { trace("DATA SOURCE: HTML"); VMM.Timeline.DataObj.parseHTML(raw_data); } else { trace("DATA SOURCE: UNKNOWN"); } }, onJSONPLoaded: function() { trace("JSONP IS LOADED"); VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, storyjs_jsonp_data); }, parseHTML: function (d) { trace("parseHTML"); trace("WARNING: THIS IS STILL ALPHA AND WILL NOT WORK WITH ID's other than #timeline"); var _data_obj = VMM.Timeline.DataObj.data_template_obj; /* Timeline start slide ================================================== */ if (VMM.Lib.find("#timeline section", "time")[0]) { _data_obj.timeline.startDate = VMM.Lib.html(VMM.Lib.find("#timeline section", "time")[0]); _data_obj.timeline.headline = VMM.Lib.html(VMM.Lib.find("#timeline section", "h2")); _data_obj.timeline.text = VMM.Lib.html(VMM.Lib.find("#timeline section", "article")); var found_main_media = false; if (VMM.Lib.find("#timeline section", "figure img").length != 0) { found_main_media = true; _data_obj.timeline.asset.media = VMM.Lib.attr(VMM.Lib.find("#timeline section", "figure img"), "src"); } else if (VMM.Lib.find("#timeline section", "figure a").length != 0) { found_main_media = true; _data_obj.timeline.asset.media = VMM.Lib.attr(VMM.Lib.find("#timeline section", "figure a"), "href"); } else { //trace("NOT FOUND"); } if (found_main_media) { if (VMM.Lib.find("#timeline section", "cite").length != 0) { _data_obj.timeline.asset.credit = VMM.Lib.html(VMM.Lib.find("#timeline section", "cite")); } if (VMM.Lib.find(this, "figcaption").length != 0) { _data_obj.timeline.asset.caption = VMM.Lib.html(VMM.Lib.find("#timeline section", "figcaption")); } } } /* Timeline Date Slides ================================================== */ VMM.Lib.each("#timeline li", function(i, elem){ var valid_date = false; var _date = { "type":"default", "startDate":"", "headline":"", "text":"", "asset": { "media":"", "credit":"", "caption":"" }, "tags":"Optional" }; if (VMM.Lib.find(this, "time") != 0) { valid_date = true; _date.startDate = VMM.Lib.html(VMM.Lib.find(this, "time")[0]); if (VMM.Lib.find(this, "time")[1]) { _date.endDate = VMM.Lib.html(VMM.Lib.find(this, "time")[1]); } _date.headline = VMM.Lib.html(VMM.Lib.find(this, "h3")); _date.text = VMM.Lib.html(VMM.Lib.find(this, "article")); var found_media = false; if (VMM.Lib.find(this, "figure img").length != 0) { found_media = true; _date.asset.media = VMM.Lib.attr(VMM.Lib.find(this, "figure img"), "src"); } else if (VMM.Lib.find(this, "figure a").length != 0) { found_media = true; _date.asset.media = VMM.Lib.attr(VMM.Lib.find(this, "figure a"), "href"); } else { //trace("NOT FOUND"); } if (found_media) { if (VMM.Lib.find(this, "cite").length != 0) { _date.asset.credit = VMM.Lib.html(VMM.Lib.find(this, "cite")); } if (VMM.Lib.find(this, "figcaption").length != 0) { _date.asset.caption = VMM.Lib.html(VMM.Lib.find(this, "figcaption")); } } trace(_date); _data_obj.timeline.date.push(_date); } }); VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj); }, parseJSON: function(d) { trace("parseJSON"); if (d.timeline.type == "default") { trace("DATA SOURCE: JSON STANDARD TIMELINE"); VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, d); } else if (d.timeline.type == "twitter") { trace("DATA SOURCE: JSON TWEETS"); VMM.Timeline.DataObj.model_Tweets.buildData(d); } else { trace("DATA SOURCE: UNKNOWN JSON"); trace(type.of(d.timeline)); }; }, /* MODEL OBJECTS New Types of Data can be formatted for the timeline here ================================================== */ model: { googlespreadsheet: { getData: function(raw) { var key, url, timeout; key = VMM.Util.getUrlVars(raw)["key"]; url = "https://spreadsheets.google.com/feeds/list/" + key + "/od6/public/values?alt=json"; timeout = setTimeout(function() { trace("Google Docs timeout"); VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Google Docs is not responding"); }, 6000); VMM.getJSON(url, VMM.Timeline.DataObj.model.googlespreadsheet.buildData) .error(function(jqXHR, textStatus, errorThrown) { trace("Google Docs ERROR"); trace("Google Docs ERROR: " + textStatus + " " + jqXHR.responseText); }) .success(function(d) { clearTimeout(timeout); }); }, buildData: function(d) { var data_obj = VMM.Timeline.DataObj.data_template_obj; VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data"); function getGVar(v) { if (typeof v != 'undefined') { return v.$t; } else { return ""; } } for(var i = 0; i < d.feed.entry.length; i++) { var dd = d.feed.entry[i], dd_type = ""; if (typeof dd.gsx$type != 'undefined') { dd_type = dd.gsx$type.$t; } else if (typeof dd.gsx$titleslide != 'undefined') { dd_type = dd.gsx$titleslide.$t; } if (dd_type.match("start") || dd_type.match("title") ) { data_obj.timeline.startDate = getGVar(dd.gsx$startdate); data_obj.timeline.headline = getGVar(dd.gsx$headline); data_obj.timeline.asset.media = getGVar(dd.gsx$media); data_obj.timeline.asset.caption = getGVar(dd.gsx$mediacaption); data_obj.timeline.asset.credit = getGVar(dd.gsx$mediacredit); data_obj.timeline.text = getGVar(dd.gsx$text); data_obj.timeline.type = "google spreadsheet"; } else if (dd_type.match("era")) { var era = { startDate: getGVar(dd.gsx$startdate), endDate: getGVar(dd.gsx$enddate), headline: getGVar(dd.gsx$headline), text: getGVar(dd.gsx$text), tag: getGVar(dd.gsx$tag) } data_obj.timeline.era.push(era); } else { var date = { type: "google spreadsheet", startDate: getGVar(dd.gsx$startdate), endDate: getGVar(dd.gsx$enddate), headline: getGVar(dd.gsx$headline), text: getGVar(dd.gsx$text), tag: getGVar(dd.gsx$tag), asset: { media: getGVar(dd.gsx$media), credit: getGVar(dd.gsx$mediacredit), caption: getGVar(dd.gsx$mediacaption), thumbnail: getGVar(dd.gsx$mediathumbnail) } }; data_obj.timeline.date.push(date); } }; VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Finished Parsing Data"); VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, data_obj); } }, storify: { getData: function(raw) { var key, url, storify_timeout; //http://storify.com/number10gov/g8-and-nato-chicago-summit //http://api.storify.com/v1/stories/number10gov/g8-and-nato-chicago-summit VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Loading Storify..."); key = raw.split("storify.com\/")[1]; url = "http://api.storify.com/v1/stories/" + key + "?per_page=300&callback=?"; storify_timeout = setTimeout(function() { trace("STORIFY timeout"); VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Storify is not responding"); }, 6000); VMM.getJSON(url, VMM.Timeline.DataObj.model.storify.buildData) .error(function(jqXHR, textStatus, errorThrown) { trace("STORIFY error"); trace("STORIFY ERROR: " + textStatus + " " + jqXHR.responseText); }) .success(function(d) { clearTimeout(storify_timeout); }); }, buildData: function(d) { VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data"); var _data_obj = VMM.Timeline.DataObj.data_template_obj; _data_obj.timeline.startDate = new Date(d.content.date.created);; _data_obj.timeline.headline = d.content.title; trace(d); //d.permalink var tt = ""; var t_name = d.content.author.username; var t_nickname = ""; if (typeof d.content.author.name != 'undefined') { t_name = d.content.author.name; t_nickname = d.content.author.username + " "; } if (typeof d.content.description != 'undefined' && d.content.description != null) { tt += d.content.description; } tt += "
" + dd.data.quote.text.replace(/<\s*\/?\s*b\s*.*?>/g,"") + ""; } } else if (dd.type == "link") { _date.headline = dd.data.link.title; _date.text = dd.data.link.description; if (dd.data.link.thumbnail != 'undefined' && dd.data.link.thumbnail != '') { _date.asset.media = dd.data.link.thumbnail; } else { _date.asset.media = dd.permalink; } //_date.asset.media = dd.permalink; _date.asset.caption = "" + dd.data.link.title + "" _date.slug = dd.data.link.title; } else if (dd.type == "text") { if (dd.permalink.match("storify")) { is_text = true; var d_name = d.content.author.username; var d_nickname = ""; if (typeof dd.attribution.name != 'undefined') { t_name = dd.attribution.name; t_nickname = dd.attribution.username + " "; } var asset_text = "
"; //asset_text += " " + "" + " "; asset_text += "" + dd.data.text.replace(/<\s*\/?\s*b\s*.*?>/g,"") + "