/ * V M M . T i m e l i n e . D a t a O b j . j s
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" ) ;
var req = "" ;
if ( raw _data . indexOf ( "?" ) > - 1 ) {
req = raw _data + "&callback=onJSONP_Data" ;
} else {
req = raw _data + "?callback=onJSONP_Data" ;
}
VMM . getJSON ( req , 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 ;
/ * T i m e l i n e s t a r t s l i d e
=== === === === === === === === === === === === === === === === == * /
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" ) ) ;
}
}
}
/ * T i m e l i n e D a t e S l i d e s
=== === === === === === === === === === === === === === === === == * /
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 ) ) ;
} ;
} ,
/ * M O D E L O B J E C T S
New Types of Data can be formatted for the timeline here
=== === === === === === === === === === === === === === === === == * /
model : {
googlespreadsheet : {
getData : function ( raw ) {
var getjsondata , key , worksheet , url , timeout , tries = 0 ;
key = VMM . Util . getUrlVars ( raw ) [ "key" ] ;
worksheet = VMM . Util . getUrlVars ( raw ) [ "worksheet" ] ;
if ( typeof worksheet == "undefined" ) worksheet = "od6" ;
url = "https://spreadsheets.google.com/feeds/list/" + key + "/" + worksheet + "/public/values?alt=json" ;
timeout = setTimeout ( function ( ) {
trace ( "Google Docs timeout " + url ) ;
trace ( url ) ;
if ( tries < 3 ) {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Still waiting on Google Docs, trying again " + tries ) ;
tries ++ ;
getjsondata . abort ( )
requestJsonData ( ) ;
} else {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Google Docs is not responding" ) ;
}
} , 16000 ) ;
function requestJsonData ( ) {
getjsondata = VMM . getJSON ( url , function ( d ) {
clearTimeout ( timeout ) ;
VMM . Timeline . DataObj . model . googlespreadsheet . buildData ( d ) ;
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "Google Docs ERROR" ) ;
trace ( "Google Docs ERROR: " + textStatus + " " + jqXHR . responseText ) ;
} )
. success ( function ( d ) {
clearTimeout ( timeout ) ;
} ) ;
}
requestJsonData ( ) ;
} ,
buildData : function ( d ) {
var data _obj = VMM . Timeline . DataObj . data _template _obj ,
is _valid = false ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Parsing Google Doc Data" ) ;
function getGVar ( v ) {
if ( typeof v != 'undefined' ) {
return v . $t ;
} else {
return "" ;
}
}
if ( typeof d . feed . entry == 'undefined' ) {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Error parsing spreadsheet. Make sure you have no blank rows and that the headers have not been changed." ) ;
} else {
is _valid = true ;
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 ) ;
}
} ;
}
if ( is _valid ) {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Finished Parsing Data" ) ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . data _ready , data _obj ) ;
} else {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , VMM . Language . messages . loading + " Google Doc Data (cells)" ) ;
trace ( "There may be too many entries. Still trying to load data. Now trying to load cells to avoid Googles limitation on cells" ) ;
VMM . Timeline . DataObj . model . googlespreadsheet . getDataCells ( d . feed . link [ 0 ] . href ) ;
}
} ,
getDataCells : function ( raw ) {
var getjsondata , key , url , timeout , tries = 0 ;
key = VMM . Util . getUrlVars ( raw ) [ "key" ] ;
url = "https://spreadsheets.google.com/feeds/cells/" + key + "/od6/public/values?alt=json" ;
timeout = setTimeout ( function ( ) {
trace ( "Google Docs timeout " + url ) ;
trace ( url ) ;
if ( tries < 3 ) {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Still waiting on Google Docs, trying again " + tries ) ;
tries ++ ;
getjsondata . abort ( )
requestJsonData ( ) ;
} else {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Google Docs is not responding" ) ;
}
} , 16000 ) ;
function requestJsonData ( ) {
getjsondata = VMM . getJSON ( url , function ( d ) {
clearTimeout ( timeout ) ;
VMM . Timeline . DataObj . model . googlespreadsheet . buildDataCells ( d ) ;
} )
. error ( function ( jqXHR , textStatus , errorThrown ) {
trace ( "Google Docs ERROR" ) ;
trace ( "Google Docs ERROR: " + textStatus + " " + jqXHR . responseText ) ;
} )
. success ( function ( d ) {
clearTimeout ( timeout ) ;
} ) ;
}
requestJsonData ( ) ;
} ,
buildDataCells : function ( d ) {
var data _obj = VMM . Timeline . DataObj . data _template _obj ,
is _valid = false ,
cellnames = [ "timeline" ] ,
list = [ ] ,
max _row = 0 ,
i = 0 ,
k = 0 ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , VMM . Language . messages . loading _timeline + " Parsing Google Doc Data (cells)" ) ;
function getGVar ( v ) {
if ( typeof v != 'undefined' ) {
return v . $t ;
} else {
return "" ;
}
}
if ( typeof d . feed . entry != 'undefined' ) {
is _valid = true ;
// DETERMINE NUMBER OF ROWS
for ( i = 0 ; i < d . feed . entry . length ; i ++ ) {
var dd = d . feed . entry [ i ] ;
if ( parseInt ( dd . gs$cell . row ) > max _row ) {
max _row = parseInt ( dd . gs$cell . row ) ;
}
}
// CREATE OBJECT FOR EACH ROW
for ( var i = 0 ; i < max _row + 1 ; i ++ ) {
var date = {
type : "" ,
startDate : "" ,
endDate : "" ,
headline : "" ,
text : "" ,
tag : "" ,
asset : {
media : "" ,
credit : "" ,
caption : "" ,
thumbnail : ""
}
} ;
list . push ( date ) ;
}
// PREP GOOGLE DOC CELL DATA TO EVALUATE
for ( i = 0 ; i < d . feed . entry . length ; i ++ ) {
var dd = d . feed . entry [ i ] ,
dd _type = "" ,
column _name = "" ,
cell = {
content : getGVar ( dd . gs$cell ) ,
col : dd . gs$cell . col ,
row : dd . gs$cell . row ,
name : ""
} ;
//trace(cell);
if ( cell . row == 1 ) {
if ( cell . content == "Start Date" ) {
column _name = "startDate" ;
} else if ( cell . content == "End Date" ) {
column _name = "endDate" ;
} else if ( cell . content == "Headline" ) {
column _name = "headline" ;
} else if ( cell . content == "Text" ) {
column _name = "text" ;
} else if ( cell . content == "Media" ) {
column _name = "media" ;
} else if ( cell . content == "Media Credit" ) {
column _name = "credit" ;
} else if ( cell . content == "Media Caption" ) {
column _name = "caption" ;
} else if ( cell . content == "Media Thumbnail" ) {
column _name = "thumbnail" ;
} else if ( cell . content == "Type" ) {
column _name = "type" ;
} else if ( cell . content == "Tag" ) {
column _name = "tag" ;
}
cellnames . push ( column _name ) ;
} else {
cell . name = cellnames [ cell . col ] ;
list [ cell . row ] [ cell . name ] = cell . content ;
}
} ;
for ( i = 0 ; i < list . length ; i ++ ) {
var date = list [ i ] ;
if ( date . type . match ( "start" ) || date . type . match ( "title" ) ) {
data _obj . timeline . startDate = date . startDate ;
data _obj . timeline . headline = date . headline ;
data _obj . timeline . asset . media = date . media ;
data _obj . timeline . asset . caption = date . caption ;
data _obj . timeline . asset . credit = date . credit ;
data _obj . timeline . text = date . text ;
data _obj . timeline . type = "google spreadsheet" ;
} else if ( date . type . match ( "era" ) ) {
var era = {
startDate : date . startDate ,
endDate : date . endDate ,
headline : date . headline ,
text : date . text ,
tag : date . tag
}
data _obj . timeline . era . push ( era ) ;
} else {
if ( date . startDate ) {
var date = {
type : "google spreadsheet" ,
startDate : date . startDate ,
endDate : date . endDate ,
headline : date . headline ,
text : date . text ,
tag : date . tag ,
asset : {
media : date . media ,
credit : date . credit ,
caption : date . caption ,
thumbnail : date . thumbnail
}
} ;
data _obj . timeline . date . push ( date ) ;
} else {
trace ( "Skipping item " + i + " in list: no start date." )
}
}
}
}
is _valid = data _obj . timeline . date . length > 0 ;
if ( is _valid ) {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Finished Parsing Data" ) ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . data _ready , data _obj ) ;
} else {
VMM . fireEvent ( global , VMM . Timeline . Config . events . messege , "Unable to load Google Doc data source. Make sure you have no blank rows and that the headers have not been changed." ) ;
}
}
} ,
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 = "//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 += "<div class='storify'>"
//tt += " <a href='" + d.content.permalink + "' target='_blank' alt='link to original story' title='link to original story'>" + "<span class='created-at'></span>" + " </a>";
tt += "<div class='vcard author'><a class='screen-name url' href='" + d . content . author . permalink + "' target='_blank'>" ;
tt += "<span class='avatar'><img src='" + d . content . author . avatar + "' style='max-width: 32px; max-height: 32px;'></span>"
tt += "<span class='fn'>" + t _name + "</span>" ;
tt += "<span class='nickname'>" + t _nickname + "<span class='thumbnail-inline'></span></span>" ;
tt += "</a>" ;
//tt += "<span class='nickname'>" + d.content.author.stats.stories + " Stories</span>";
//tt += "<span class='nickname'>" + d.content.author.stats.subscribers + " Subscribers</span>";
tt += "</div>"
tt += "</div>" ;
_data _obj . timeline . text = tt ;
_data _obj . timeline . asset . media = d . content . thumbnail ;
//_data_obj.timeline.asset.media = dd.gsx$media.$t;
//_data_obj.timeline.asset.caption = dd.gsx$mediacaption.$t;
//_data_obj.timeline.asset.credit = dd.gsx$mediacredit.$t;
_data _obj . timeline . type = "storify" ;
for ( var i = 0 ; i < d . content . elements . length ; i ++ ) {
var dd = d . content . elements [ i ] ;
var is _text = false ;
var d _date = new Date ( dd . posted _at ) ;
//trace(tempdat);
trace ( dd . type ) ;
//trace(dd);
var _date = {
"type" : "storify" ,
"startDate" : dd . posted _at ,
"endDate" : dd . posted _at ,
"headline" : " " ,
"slug" : "" ,
"text" : "" ,
"asset" : {
"media" : "" ,
"credit" : "" ,
"caption" : ""
}
} ;
/ * M E D I A
=== === === === === === === === === === === === === === === === == * /
if ( dd . type == "image" ) {
if ( typeof dd . source . name != 'undefined' ) {
if ( dd . source . name == "flickr" ) {
_date . asset . media = "//flickr.com/photos/" + dd . meta . pathalias + "/" + dd . meta . id + "/" ;
_date . asset . credit = "<a href='" + _date . asset . media + "'>" + dd . attribution . name + "</a>" ;
_date . asset . credit += " on <a href='" + dd . source . href + "'>" + dd . source . name + "</a>" ;
} else if ( dd . source . name == "instagram" ) {
_date . asset . media = dd . permalink ;
_date . asset . credit = "<a href='" + dd . permalink + "'>" + dd . attribution . name + "</a>" ;
_date . asset . credit += " on <a href='" + dd . source . href + "'>" + dd . source . name + "</a>" ;
} else {
_date . asset . credit = "<a href='" + dd . permalink + "'>" + dd . attribution . name + "</a>" ;
if ( typeof dd . source . href != 'undefined' ) {
_date . asset . credit += " on <a href='" + dd . source . href + "'>" + dd . source . name + "</a>" ;
}
_date . asset . media = dd . data . image . src ;
}
} else {
_date . asset . credit = "<a href='" + dd . permalink + "'>" + dd . attribution . name + "</a>" ;
_date . asset . media = dd . data . image . src ;
}
_date . slug = dd . attribution . name ;
if ( typeof dd . data . image . caption != 'undefined' ) {
if ( dd . data . image . caption != 'undefined' ) {
_date . asset . caption = dd . data . image . caption ;
_date . slug = dd . data . image . caption ;
}
}
} else if ( dd . type == "quote" ) {
if ( dd . permalink . match ( "twitter" ) ) {
_date . asset . media = dd . permalink ;
_date . slug = VMM . Util . untagify ( dd . data . quote . text ) ;
} else if ( dd . permalink . match ( "storify" ) ) {
is _text = true ;
_date . asset . media = "<blockquote>" + dd . data . quote . text . replace ( /<\s*\/?\s*b\s*.*?>/g , "" ) + "</blockquote>" ;
}
} 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 = "<a href='" + dd . permalink + "' target='_blank'>" + dd . data . link . title + "</a>"
_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 = "<div class='storify'>"
asset _text += "<blockquote><p>" + dd . data . text . replace ( /<\s*\/?\s*b\s*.*?>/g , "" ) + "</p></blockquote>" ;
//asset_text += " <a href='" + dd.attribution.href + "' target='_blank' alt='link to author' title='link to author'>" + "<span class='created-at'></span>" + " </a>";
asset _text += "<div class='vcard author'><a class='screen-name url' href='" + dd . attribution . href + "' target='_blank'>" ;
asset _text += "<span class='avatar'><img src='" + dd . attribution . thumbnail + "' style='max-width: 32px; max-height: 32px;'></span>"
asset _text += "<span class='fn'>" + t _name + "</span>" ;
asset _text += "<span class='nickname'>" + t _nickname + "<span class='thumbnail-inline'></span></span>" ;
asset _text += "</a></div></div>" ;
_date . text = asset _text ;
// Try and put it before the element where it is expected on storify
if ( ( i + 1 ) >= d . content . elements . length ) {
_date . startDate = d . content . elements [ i - 1 ] . posted _at ;
} else {
if ( d . content . elements [ i + 1 ] . type == "text" && d . content . elements [ i + 1 ] . permalink . match ( "storify" ) ) {
if ( ( i + 2 ) >= d . content . elements . length ) {
_date . startDate = d . content . elements [ i - 1 ] . posted _at ;
} else {
if ( d . content . elements [ i + 2 ] . type == "text" && d . content . elements [ i + 2 ] . permalink . match ( "storify" ) ) {
if ( ( i + 3 ) >= d . content . elements . length ) {
_date . startDate = d . content . elements [ i - 1 ] . posted _at ;
} else {
if ( d . content . elements [ i + 3 ] . type == "text" && d . content . elements [ i + 3 ] . permalink . match ( "storify" ) ) {
_date . startDate = d . content . elements [ i - 1 ] . posted _at ;
} else {
trace ( "LEVEL 3" ) ;
_date . startDate = d . content . elements [ i + 3 ] . posted _at ;
}
}
} else {
trace ( "LEVEL 2" ) ;
_date . startDate = d . content . elements [ i + 2 ] . posted _at ;
}
}
} else {
trace ( "LEVEL 1" ) ;
_date . startDate = d . content . elements [ i + 1 ] . posted _at ;
}
}
_date . endDate = _date . startDate
}
} else if ( dd . type == "video" ) {
_date . headline = dd . data . video . title ;
_date . asset . caption = dd . data . video . description ;
_date . asset . caption = dd . source . username ;
_date . asset . media = dd . data . video . src ;
} else {
trace ( "NO MATCH " ) ;
trace ( dd ) ;
}
if ( is _text ) {
_date . slug = VMM . Util . untagify ( dd . data . text ) ;
}
_data _obj . timeline . date . push ( _date ) ;
} ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . data _ready , _data _obj ) ;
}
} ,
tweets : {
type : "twitter" ,
buildData : function ( raw _data ) {
VMM . bindEvent ( global , VMM . Timeline . DataObj . model . tweets . onTwitterDataReady , "TWEETSLOADED" ) ;
VMM . ExternalAPI . twitter . getTweets ( raw _data . timeline . tweets ) ;
} ,
getData : function ( raw _data ) {
VMM . bindEvent ( global , VMM . Timeline . DataObj . model . tweets . onTwitterDataReady , "TWEETSLOADED" ) ;
VMM . ExternalAPI . twitter . getTweetSearch ( raw _data ) ;
} ,
onTwitterDataReady : function ( e , d ) {
var _data _obj = VMM . Timeline . DataObj . data _template _obj ;
for ( var i = 0 ; i < d . tweetdata . length ; i ++ ) {
var _date = {
"type" : "tweets" ,
"startDate" : "" ,
"headline" : "" ,
"text" : "" ,
"asset" :
{
"media" : "" ,
"credit" : "" ,
"caption" : ""
} ,
"tags" : "Optional"
} ;
// pass in the 'created_at' string returned from twitter //
// stamp arrives formatted as Tue Apr 07 22:52:51 +0000 2009 //
//var twit_date = VMM.ExternalAPI.twitter.parseTwitterDate(d.tweetdata[i].raw.created_at);
//trace(twit_date);
_date . startDate = d . tweetdata [ i ] . raw . created _at ;
if ( type . of ( d . tweetdata [ i ] . raw . from _user _name ) ) {
_date . headline = d . tweetdata [ i ] . raw . from _user _name + " (<a href='https://twitter.com/" + d . tweetdata [ i ] . raw . from _user + "'>" + "@" + d . tweetdata [ i ] . raw . from _user + "</a>)" ;
} else {
_date . headline = d . tweetdata [ i ] . raw . user . name + " (<a href='https://twitter.com/" + d . tweetdata [ i ] . raw . user . screen _name + "'>" + "@" + d . tweetdata [ i ] . raw . user . screen _name + "</a>)" ;
}
_date . asset . media = d . tweetdata [ i ] . content ;
_data _obj . timeline . date . push ( _date ) ;
} ;
VMM . fireEvent ( global , VMM . Timeline . Config . events . data _ready , _data _obj ) ;
}
}
} ,
/ * T E M P L A T E O B J E C T S
=== === === === === === === === === === === === === === === === == * /
data _template _obj : { "timeline" : { "headline" : "" , "description" : "" , "asset" : { "media" : "" , "credit" : "" , "caption" : "" } , "date" : [ ] , "era" : [ ] } } ,
date _obj : { "startDate" : "2012,2,2,11,30" , "headline" : "" , "text" : "" , "asset" : { "media" : "http://youtu.be/vjVfu8-Wp6s" , "credit" : "" , "caption" : "" } , "tags" : "Optional" }
} ;
}