";
for(var k = 0; k < a_data.object.attachments.length; k++) {
if (a_data.object.attachments[k].objectType == "photo") {
g_attachments = "
" + g_attachments;
} else if (a_data.object.attachments[k].objectType == "video") {
g_attachments = "
";
} else if (a_data.object.attachments[k].objectType == "article") {
g_attachments += "
";
}
trace(a_data.object.attachments[k]);
}
g_attachments = "
";
mediaElem = "
" + g_content + g_attachments + "
";
mediaElem += "
";
VMM.attachElement("#googleplus_" + gplus.activity, mediaElem);
});
break;
}
}
})
.error(function(jqXHR, textStatus, errorThrown) {
var error_obj = VMM.parseJSON(jqXHR.responseText);
trace(error_obj.error.message);
VMM.attachElement("#googleplus_" + gplus.activity, VMM.MediaElement.loadingmessage("
ERROR LOADING GOOGLE+
" + error_obj.error.message + "
"));
})
.success(function(d) {
clearTimeout(googleplus_timeout);
clearTimeout(callback_timeout);
callback();
});
},
pushQue: function() {
if (VMM.master_config.googleplus.que.length > 0) {
VMM.ExternalAPI.googleplus.create(VMM.master_config.googleplus.que[0], VMM.ExternalAPI.googleplus.pushQue);
VMM.master_config.googleplus.que.remove(0);
}
/*
for(var i = 0; i < VMM.master_config.googleplus.que.length; i++) {
VMM.ExternalAPI.googleplus.create(VMM.master_config.googleplus.que[i]);
}
VMM.master_config.googleplus.que = [];
*/
},
errorTimeOut: function(gplus) {
trace("GOOGLE+ JSON ERROR TIMEOUT " + gplus.activity);
VMM.attachElement("#googleplus_" + gplus.activity, VMM.MediaElement.loadingmessage("
Still waiting on GOOGLE+
" + gplus.activity + "
"));
}
},
googledocs: {
get: function(m) {
var doc = {url: m.id, id: m.uid};
VMM.master_config.googledocs.que.push(doc);
VMM.master_config.googledocs.active = true;
},
create: function(doc) {
var mediaElem = "";
if (doc.url.match(/docs.google.com/i)) {
mediaElem = "
";
} else {
mediaElem = "
";
}
VMM.attachElement("#"+doc.id, mediaElem);
},
pushQue: function() {
for(var i = 0; i < VMM.master_config.googledocs.que.length; i++) {
VMM.ExternalAPI.googledocs.create(VMM.master_config.googledocs.que[i]);
}
VMM.master_config.googledocs.que = [];
}
},
flickr: {
get: function(m) {
var flick = {mid: m.id, id: m.uid, link: m.link};
VMM.master_config.flickr.que.push(flick);
VMM.master_config.flickr.active = true;
},
create: function(flick, callback) {
var api_key,
callback_timeout= setTimeout(callback, VMM.master_config.timers.api, flick);
if (typeof VMM.master_config.Timeline != 'undefined' && VMM.master_config.Timeline.api_keys.flickr != "") {
api_key = VMM.master_config.Timeline.api_keys.flickr;
} else {
api_key = Aes.Ctr.decrypt(VMM.master_config.api_keys_master.flickr, VMM.master_config.vp, 256)
}
var the_url = "http://api.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + api_key + "&photo_id=" + flick.mid + "&format=json&jsoncallback=?";
VMM.getJSON(the_url, function(d) {
var flickr_id = d.sizes.size[0].url.split("photos\/")[1].split("/")[1];
var flickr_large_id = "#" + flick.id,
flickr_thumb_id = "#" + flick.id + "_thumb";
//flickr_thumb_id = "flickr_" + uid + "_thumb";
var flickr_img_size,
flickr_img_thumb,
flickr_size_found = false,
flickr_best_size = "Large";
flickr_best_size = VMM.ExternalAPI.flickr.sizes(VMM.master_config.sizes.api.height);
for(var i = 0; i < d.sizes.size.length; i++) {
if (d.sizes.size[i].label == flickr_best_size) {
flickr_size_found = true;
flickr_img_size = d.sizes.size[i].source;
}
}
if (!flickr_size_found) {
flickr_img_size = d.sizes.size[d.sizes.size.length - 1].source;
}
flickr_img_thumb = d.sizes.size[0].source;
VMM.Lib.attr(flickr_large_id, "src", flickr_img_size);
//VMM.attachElement(flickr_large_id, "
");
VMM.attachElement(flickr_thumb_id, "
");
})
.error(function(jqXHR, textStatus, errorThrown) {
trace("FLICKR error");
trace("FLICKR ERROR: " + textStatus + " " + jqXHR.responseText);
})
.success(function(d) {
clearTimeout(callback_timeout);
callback();
});
},
pushQue: function() {
if (VMM.master_config.flickr.que.length > 0) {
VMM.ExternalAPI.flickr.create(VMM.master_config.flickr.que[0], VMM.ExternalAPI.flickr.pushQue);
VMM.master_config.flickr.que.remove(0);
}
},
sizes: function(s) {
var _size = "";
if (s <= 75) {
_size = "Thumbnail";
} else if (s <= 180) {
_size = "Small";
} else if (s <= 240) {
_size = "Small 320";
} else if (s <= 375) {
_size = "Medium";
} else if (s <= 480) {
_size = "Medium 640";
} else if (s <= 600) {
_size = "Medium 800";
} else {
_size = "Large";
}
return _size;
}
},
instagram: {
get: function(mid, thumb) {
if (thumb) {
return "http://instagr.am/p/" + mid + "/media/?size=t";
} else {
return "http://instagr.am/p/" + mid + "/media/?size=" + VMM.ExternalAPI.instagram.sizes(VMM.master_config.sizes.api.height);
}
},
sizes: function(s) {
var _size = "";
if (s <= 150) {
_size = "t";
} else if (s <= 306) {
_size = "m";
} else {
_size = "l";
}
return _size;
}
},
soundcloud: {
get: function(m) {
var sound = {mid: m.id, id: m.uid};
VMM.master_config.soundcloud.que.push(sound);
VMM.master_config.soundcloud.active = true;
},
create: function(sound, callback) {
var the_url = "http://soundcloud.com/oembed?url=" + sound.mid + "&format=js&callback=?";
VMM.getJSON(the_url, function(d) {
VMM.attachElement("#"+sound.id, d.html);
callback();
});
},
pushQue: function() {
if (VMM.master_config.soundcloud.que.length > 0) {
VMM.ExternalAPI.soundcloud.create(VMM.master_config.soundcloud.que[0], VMM.ExternalAPI.soundcloud.pushQue);
VMM.master_config.soundcloud.que.remove(0);
}
}
},
wikipedia: {
get: function(m) {
var api_obj = {url: m.id, id: m.uid, lang: m.lang};
VMM.master_config.wikipedia.que.push(api_obj);
VMM.master_config.wikipedia.active = true;
},
create: function(api_obj, callback) {
var the_url = "http://" + api_obj.lang + ".wikipedia.org/w/api.php?action=query&prop=extracts&redirects=&titles=" + api_obj.url + "&exintro=1&format=json&callback=?";
callback_timeout= setTimeout(callback, VMM.master_config.timers.api, api_obj);
if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7 && window.XDomainRequest) {
var temp_text = "
";
temp_text += "
" + VMM.master_config.language.messages.wikipedia + "";
temp_text += "
Wikipedia entry unable to load using Internet Explorer 8 or below.
";
VMM.attachElement("#"+api_obj.id, temp_text );
}
VMM.getJSON(the_url, function(d) {
if (d.query) {
var wiki_extract,
wiki_title,
_wiki = "",
wiki_text = "",
wiki_number_of_paragraphs = 1,
wiki_text_array = [];
wiki_extract = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).extract;
wiki_title = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).title;
if (wiki_extract.match("
")) {
wiki_text_array = wiki_extract.split("
");
} else {
wiki_text_array.push(wiki_extract);
}
for(var i = 0; i < wiki_text_array.length; i++) {
if (i+1 <= wiki_number_of_paragraphs && i+1 < wiki_text_array.length) {
wiki_text += "
" + wiki_text_array[i+1];
}
}
_wiki = "
";
_wiki += "
" + VMM.master_config.language.messages.wikipedia + "";
_wiki += VMM.Util.linkify_wikipedia(wiki_text);
if (wiki_extract.match("REDIRECT")) {
} else {
VMM.attachElement("#"+api_obj.id, _wiki );
}
}
//callback();
})
.error(function(jqXHR, textStatus, errorThrown) {
trace("WIKIPEDIA error");
trace("WIKIPEDIA ERROR: " + textStatus + " " + jqXHR.responseText);
trace(errorThrown);
VMM.attachElement("#"+api_obj.id, VMM.MediaElement.loadingmessage("
Wikipedia is not responding
"));
// TRY AGAIN?
clearTimeout(callback_timeout);
if (VMM.master_config.wikipedia.tries < 4) {
trace("WIKIPEDIA ATTEMPT " + VMM.master_config.wikipedia.tries);
trace(api_obj);
VMM.master_config.wikipedia.tries++;
VMM.ExternalAPI.wikipedia.create(api_obj, callback);
} else {
callback();
}
})
.success(function(d) {
VMM.master_config.wikipedia.tries = 0;
clearTimeout(callback_timeout);
callback();
});
},
pushQue: function() {
if (VMM.master_config.wikipedia.que.length > 0) {
trace("WIKIPEDIA PUSH QUE " + VMM.master_config.wikipedia.que.length);
VMM.ExternalAPI.wikipedia.create(VMM.master_config.wikipedia.que[0], VMM.ExternalAPI.wikipedia.pushQue);
VMM.master_config.wikipedia.que.remove(0);
}
}
},
youtube: {
get: function(m) {
var the_url = "http://gdata.youtube.com/feeds/api/videos/" + m.id + "?v=2&alt=jsonc&callback=?",
vid = {mid: m.id, id: m.uid, start: m.start, hd: m.hd};
VMM.master_config.youtube.que.push(vid);
if (!VMM.master_config.youtube.active) {
if (!VMM.master_config.youtube.api_loaded) {
VMM.LoadLib.js('http://www.youtube.com/player_api', function() {
trace("YouTube API Library Loaded");
});
}
}
// THUMBNAIL
VMM.getJSON(the_url, function(d) {
VMM.ExternalAPI.youtube.createThumb(d, vid)
});
},
create: function(vid) {
if (typeof(vid.start) != 'undefined') {
var vidstart = vid.start.toString(),
vid_start_minutes = 0,
vid_start_seconds = 0;
if (vidstart.match('m')) {
vid_start_minutes = parseInt(vidstart.split("m")[0], 10);
vid_start_seconds = parseInt(vidstart.split("m")[1].split("s")[0], 10);
vid.start = (vid_start_minutes * 60) + vid_start_seconds;
} else {
vid.start = 0;
}
} else {
vid.start = 0;
}
var p = {
active: false,
player: {},
name: vid.id,
playing: false,
hd: false
};
if (typeof(vid.hd) != 'undefined') {
p.hd = true;
}
p.player[vid.id] = new YT.Player(vid.id, {
height: '390',
width: '640',
playerVars: {
enablejsapi: 1,
color: 'white',
showinfo: 0,
theme: 'light',
start: vid.start,
rel: 0
},
videoId: vid.mid,
events: {
'onReady': VMM.ExternalAPI.youtube.onPlayerReady,
'onStateChange': VMM.ExternalAPI.youtube.onStateChange
}
});
VMM.master_config.youtube.array.push(p);
},
createThumb: function(d, vid) {
trace("CREATE THUMB");
trace(d);
trace(vid);
if (typeof d.data != 'undefined') {
var thumb_id = "#" + vid.id + "_thumb";
VMM.attachElement(thumb_id, "
");
}
},
pushQue: function() {
for(var i = 0; i < VMM.master_config.youtube.que.length; i++) {
VMM.ExternalAPI.youtube.create(VMM.master_config.youtube.que[i]);
}
VMM.master_config.youtube.que = [];
},
onAPIReady: function() {
VMM.master_config.youtube.active = true;
VMM.ExternalAPI.youtube.pushQue();
},
stopPlayers: function() {
for(var i = 0; i < VMM.master_config.youtube.array.length; i++) {
if (VMM.master_config.youtube.array[i].playing) {
var the_name = VMM.master_config.youtube.array[i].name;
VMM.master_config.youtube.array[i].player[the_name].stopVideo();
}
}
},
onStateChange: function(e) {
for(var i = 0; i < VMM.master_config.youtube.array.length; i++) {
var the_name = VMM.master_config.youtube.array[i].name;
if (VMM.master_config.youtube.array[i].player[the_name] == e.target) {
if (e.data == YT.PlayerState.PLAYING) {
VMM.master_config.youtube.array[i].playing = true;
trace(VMM.master_config.youtube.array[i].hd)
if (VMM.master_config.youtube.array[i].hd) {
// SET TO HD
// DOESN'T WORK AS OF NOW
//VMM.master_config.youtube.array[i].player.setPlaybackQuality("hd720");
}
}
}
}
},
onPlayerReady: function(e) {
}
},
vimeo: {
get: function(m) {
var vid = {mid: m.id, id: m.uid};
VMM.master_config.vimeo.que.push(vid);
VMM.master_config.vimeo.active = true;
},
create: function(vid, callback) {
trace("VIMEO CREATE");
// THUMBNAIL
var the_url = "http://vimeo.com/api/v2/video/" + vid.mid + ".json";
VMM.getJSON(the_url, function(d) {
VMM.ExternalAPI.vimeo.createThumb(d, vid);
callback();
});
},
createThumb: function(d, vid) {
trace("VIMEO CREATE THUMB");
var thumb_id = "#" + vid.id + "_thumb";
VMM.attachElement(thumb_id, "
");
},
pushQue: function() {
if (VMM.master_config.vimeo.que.length > 0) {
VMM.ExternalAPI.vimeo.create(VMM.master_config.vimeo.que[0], VMM.ExternalAPI.vimeo.pushQue);
VMM.master_config.vimeo.que.remove(0);
}
/*
for(var i = 0; i < VMM.master_config.vimeo.que.length; i++) {
VMM.ExternalAPI.vimeo.create(VMM.master_config.vimeo.que[i]);
}
VMM.master_config.vimeo.que = [];
*/
}
}
}).init();
}
/* YOUTUBE API READY
Can't find a way to customize this callback and keep it in the VMM namespace
Youtube wants it to be this function.
================================================== */
function onYouTubePlayerAPIReady() {
trace("GLOBAL YOUTUBE API CALLED")
VMM.ExternalAPI.youtube.onAPIReady();
}
/***********************************************
Begin VMM.MediaElement.js
***********************************************/
/* MediaElement
================================================== */
if(typeof VMM != 'undefined' && typeof VMM.MediaElement == 'undefined') {
VMM.MediaElement = ({
init: function() {
return this;
},
loadingmessage: function(m) {
return "
";
},
thumbnail: function(data, w, h, uid) {
var _w = 16,
_h = 24,
_uid = "";
if (w != null && w != "") {_w = w};
if (h != null && h != "") {_h = h};
if (uid != null && uid != "") {_uid = uid};
if (data.media != null && data.media != "") {
var _valid = true,
mediaElem = "",
m = VMM.MediaType(data.media); //returns an object with .type and .id
// DETERMINE THUMBNAIL OR ICON
if (data.thumbnail != null && data.thumbnail != "") {
trace("CUSTOM THUMB");
mediaElem = "
";
return mediaElem;
} else if (m.type == "image") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "flickr") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "instagram") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "youtube") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "googledoc") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "vimeo") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "dailymotion") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "twitter"){
mediaElem = "";
return mediaElem;
} else if (m.type == "twitter-ready") {
mediaElem = "";
return mediaElem;
} else if (m.type == "soundcloud") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "google-map") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "googleplus") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "wikipedia") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "storify") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "quote") {
mediaElem = "
";
return mediaElem;
} else if (m.type == "unknown") {
if (m.id.match("blockquote")) {
mediaElem = "
";
} else {
mediaElem = "
";
}
return mediaElem;
} else if (m.type == "website") {
mediaElem = "
";
return mediaElem;
} else {
mediaElem = "
";
return mediaElem;
}
}
},
create: function(data, uid) {
var _valid = false,
//loading_messege = "
" + VMM.master_config.language.messages.loading + "
";
loading_messege = VMM.MediaElement.loadingmessage(VMM.master_config.language.messages.loading + "...");
if (data.media != null && data.media != "") {
var mediaElem = "", captionElem = "", creditElem = "", _id = "", isTextMedia = false, m;
m = VMM.MediaType(data.media); //returns an object with .type and .id
m.uid = uid;
_valid = true;
// CREDIT
if (data.credit != null && data.credit != "") {
creditElem = "
" + VMM.Util.linkify_with_twitter(data.credit, "_blank") + "
";
}
// CAPTION
if (data.caption != null && data.caption != "") {
captionElem = "
" + VMM.Util.linkify_with_twitter(data.caption, "_blank") + "
";
}
// IMAGE
if (m.type == "image") {
mediaElem = "
";
// FLICKR
} else if (m.type == "flickr") {
//mediaElem = "
" + loading_messege + "
";
mediaElem = "
";
VMM.ExternalAPI.flickr.get(m);
// INSTAGRAM
} else if (m.type == "instagram") {
mediaElem = "
";
//VMM.ExternalAPI.instagram.get(m.id, uid);
// GOOGLE DOCS
} else if (m.type == "googledoc") {
mediaElem = "
" + loading_messege + "
";
VMM.ExternalAPI.googledocs.get(m);
// YOUTUBE
} else if (m.type == "youtube") {
mediaElem = "
";
VMM.ExternalAPI.youtube.get(m);
// VIMEO
} else if (m.type == "vimeo") {
mediaElem = "
";
VMM.ExternalAPI.vimeo.get(m);
// DAILYMOTION
} else if (m.type == "dailymotion") {
mediaElem = "
";
// TWITTER
} else if (m.type == "twitter"){
mediaElem = "";
isTextMedia = true;
VMM.ExternalAPI.twitter.get(m);
// TWITTER
} else if (m.type == "twitter-ready") {
isTextMedia = true;
mediaElem = m.id;
// SOUNDCLOUD
} else if (m.type == "soundcloud") {
mediaElem = "
" + loading_messege + "
";
VMM.ExternalAPI.soundcloud.get(m);
// GOOGLE MAPS
} else if (m.type == "google-map") {
mediaElem = "
" + loading_messege + "
";
VMM.ExternalAPI.googlemaps.get(m);
// GOOGLE PLUS
} else if (m.type == "googleplus") {
_id = "googleplus_" + m.id;
mediaElem = "
" + loading_messege + "
";
isTextMedia = true;
VMM.ExternalAPI.googleplus.get(m);
// WIKIPEDIA
} else if (m.type == "wikipedia") {
mediaElem = "
" + loading_messege + "
";
isTextMedia = true;
VMM.ExternalAPI.wikipedia.get(m);
// STORIFY
} else if (m.type == "storify") {
isTextMedia = true;
mediaElem = "
" + m.id + "
";
// QUOTE
} else if (m.type == "quote") {
isTextMedia = true;
mediaElem = "
" + m.id + "
";
// UNKNOWN
} else if (m.type == "unknown") {
trace("NO KNOWN MEDIA TYPE FOUND TRYING TO JUST PLACE THE HTML");
isTextMedia = true;
mediaElem = "
" + VMM.Util.properQuotes(m.id) + "
";
// WEBSITE
} else if (m.type == "website") {
//mediaElem = "
";
//mediaElem = "
" + "";
mediaElem = "
";
// NO MATCH
} else {
trace("NO KNOWN MEDIA TYPE FOUND");
trace(m.type);
}
// WRAP THE MEDIA ELEMENT
mediaElem = "
" + mediaElem + creditElem + captionElem + "
";
// RETURN
if (isTextMedia) {
return "
";
} else {
return "
" + mediaElem + "
";
}
};
}
}).init();
}
/***********************************************
Begin VMM.MediaType.js
***********************************************/
/* MediaType
Determines the type of media the url string is.
returns an object with .type and .id
the id is a key piece of information needed to make
the request of the api.
================================================== */
if(typeof VMM != 'undefined' && typeof VMM.MediaType == 'undefined') {
VMM.MediaType = function(_d) {
var d = _d.replace(/^\s\s*/, '').replace(/\s\s*$/, ''),
success = false,
media = {
type: "unknown",
id: "",
start: 0,
hd: false,
link: "",
lang: "",
uniqueid: VMM.Util.unique_ID(6)
};
if (d.match("div class='twitter'")) {
media.type = "twitter-ready";
media.id = d;
success = true;
} else if (d.match('(www.)?youtube|youtu\.be')) {
if (d.match('v=')) {
media.id = VMM.Util.getUrlVars(d)["v"];
} else if (d.match('\/embed\/')) {
media.id = d.split("embed\/")[1].split(/[?&]/)[0];
} else {
media.id = d.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
}
media.start = VMM.Util.getUrlVars(d)["t"];
media.hd = VMM.Util.getUrlVars(d)["hd"];
media.type = "youtube";
success = true;
} else if (d.match('(player.)?vimeo\.com')) {
media.type = "vimeo";
media.id = d.split(/video\/|\/\/vimeo\.com\//)[1].split(/[?&]/)[0];;
success = true;
} else if (d.match('(www.)?dailymotion\.com')) {
media.id = d.split(/video\/|\/\/dailymotion\.com\//)[1];
media.type = "dailymotion";
success = true;
} else if (d.match('(player.)?soundcloud\.com')) {
media.type = "soundcloud";
media.id = d;
success = true;
} else if (d.match('(www.)?twitter\.com') && d.match('status') ) {
if (d.match("status\/")) {
media.id = d.split("status\/")[1];
} else if (d.match("statuses\/")) {
media.id = d.split("statuses\/")[1];
} else {
media.id = "";
}
media.type = "twitter";
success = true;
} else if (d.match("maps.google") && !d.match("staticmap")) {
media.type = "google-map";
media.id = d.split(/src=['|"][^'|"]*?['|"]/gi);
success = true;
} else if (d.match("plus.google")) {
media.type = "googleplus";
media.id = d.split("/posts/")[1];
//https://plus.google.com/u/0/112374836634096795698/posts/bRJSvCb5mUU
//https://plus.google.com/107096716333816995401/posts/J5iMpEDHWNL
if (d.split("/posts/")[0].match("u/0/")) {
media.user = d.split("u/0/")[1].split("/posts")[0];
} else {
media.user = d.split("google.com/")[1].split("/posts/")[0];
}
success = true;
} else if (d.match("flickr.com/photos")) {
media.type = "flickr";
media.id = d.split("photos\/")[1].split("/")[1];
media.link = d;
success = true;
} else if (d.match("instagr.am/p/")) {
media.type = "instagram";
media.link = d;
media.id = d.split("\/p\/")[1].split("/")[0];
success = true;
} else if (d.match(/jpg|jpeg|png|gif/i) || d.match("staticmap") || d.match("yfrog.com") || d.match("twitpic.com")) {
media.type = "image";
media.id = d;
success = true;
} else if (VMM.FileExtention.googleDocType(d)) {
media.type = "googledoc";
media.id = d;
success = true;
} else if (d.match('(www.)?wikipedia\.org')) {
media.type = "wikipedia";
//media.id = d.split("wiki\/")[1];
var wiki_id = d.split("wiki\/")[1].split("#")[0].replace("_", " ");
media.id = wiki_id.replace(" ", "%20");
media.lang = d.split("//")[1].split(".wikipedia")[0];
success = true;
} else if (d.indexOf('http://') == 0) {
media.type = "website";
media.id = d;
success = true;
} else if (d.match('storify')) {
media.type = "storify";
media.id = d;
success = true;
} else if (d.match('blockquote')) {
media.type = "quote";
media.id = d;
success = true;
} else {
trace("unknown media");
media.type = "unknown";
media.id = d;
success = true;
}
if (success) {
return media;
} else {
trace("No valid media id detected");
trace(d);
}
return false;
}
}
/***********************************************
Begin VMM.TextElement.js
***********************************************/
/* TextElement
================================================== */
if(typeof VMM != 'undefined' && typeof VMM.TextElement == 'undefined') {
VMM.TextElement = ({
init: function() {
return this;
},
create: function(data) {
return data;
}
}).init();
}
/***********************************************
Begin VMM.Media.js
***********************************************/
/* Media
================================================== */
/* * CodeKit Import
* http://incident57.com/codekit/
================================================== */
// @codekit-prepend "VMM.ExternalAPI.js";
// @codekit-prepend "VMM.MediaElement.js";
// @codekit-prepend "VMM.MediaType.js";
// @codekit-prepend "VMM.TextElement.js";
/***********************************************
Begin VMM.DragSlider.js
***********************************************/
/* DRAG SLIDER
================================================== */
if(typeof VMM != 'undefined' && typeof VMM.DragSlider == 'undefined') {
// VMM.DragSlider.createSlidePanel(drag_object, move_object, w, padding, sticky);
// VMM.DragSlider.cancelSlide();
VMM.DragSlider = function() {
var drag = {
element: "",
element_move: "",
constraint: "",
sliding: false,
pagex: {
start: 0,
end: 0
},
left: {
start: 0,
end: 0
},
time: {
start: 0,
end: 0
},
touch: false,
ease: "easeOutExpo"
},
dragevent = {
down: "mousedown",
up: "mouseup",
leave: "mouseleave",
move: "mousemove"
},
mousedrag = {
down: "mousedown",
up: "mouseup",
leave: "mouseleave",
move: "mousemove"
},
touchdrag = {
down: "touchstart",
up: "touchend",
leave: "mouseleave",
move: "touchmove"
};
this.createPanel = function(drag_object, move_object, constraint, touch) {
drag.element = drag_object;
drag.element_move = move_object;
if ( constraint != null && constraint != "") {
drag.constraint = constraint;
} else {
drag.constraint = false;
}
if ( touch) {
drag.touch = touch;
} else {
drag.touch = false;
}
trace("TOUCH" + drag.touch);
if (drag.touch) {
dragevent = touchdrag;
} else {
dragevent = mousedrag;
}
makeDraggable(drag.element, drag.element_move);
}
this.updateConstraint = function(constraint) {
trace("updateConstraint");
drag.constraint = constraint;
}
var makeDraggable = function(drag_object, move_object) {
VMM.bindEvent(drag_object, onDragStart, dragevent.down, {element: move_object, delement: drag_object});
VMM.bindEvent(drag_object, onDragEnd, dragevent.up, {element: move_object, delement: drag_object});
VMM.bindEvent(drag_object, onDragLeave, dragevent.leave, {element: move_object, delement: drag_object});
}
this.cancelSlide = function(e) {
VMM.unbindEvent(drag.element, onDragMove, dragevent.move);
return true;
}
var onDragLeave = function(e) {
VMM.unbindEvent(e.data.delement, onDragMove, dragevent.move);
if (!drag.touch) {
e.preventDefault();
}
e.stopPropagation();
if (drag.sliding) {
drag.sliding = false;
dragEnd(e.data.element, e.data.delement, e);
return false;
} else {
return true;
}
}
var onDragStart = function(e) {
dragStart(e.data.element, e.data.delement, e);
if (!drag.touch) {
e.preventDefault();
}
e.stopPropagation();
return true;
}
var onDragEnd = function(e) {
if (!drag.touch) {
e.preventDefault();
}
e.stopPropagation();
if (drag.sliding) {
drag.sliding = false;
dragEnd(e.data.element, e.data.delement, e);
return false;
} else {
return true;
}
}
var onDragMove = function(e) {
dragMove(e.data.element, e);
e.preventDefault();
e.stopPropagation();
return false;
}
var dragStart = function(elem, delem, e) {
if (drag.touch) {
trace("IS TOUCH")
VMM.Lib.css(elem, '-webkit-transition-duration', '0');
drag.pagex.start = e.originalEvent.touches[0].screenX;
} else {
drag.pagex.start = e.pageX;
}
drag.left.start = getLeft(elem);
drag.time.start = new Date().getTime();
VMM.Lib.stop(elem);
VMM.bindEvent(delem, onDragMove, dragevent.move, {element: elem});
}
var dragEnd = function(elem, delem, e) {
VMM.unbindEvent(delem, onDragMove, dragevent.move);
dragMomentum(elem, e);
}
var dragMove = function(elem, e) {
drag.sliding = true;
if (drag.touch) {
drag.pagex.end = e.originalEvent.touches[0].screenX;
} else {
drag.pagex.end = e.pageX;
}
drag.left.end = getLeft(elem);
VMM.Lib.css(elem, 'left', -(drag.pagex.start - drag.pagex.end - drag.left.start));
}
var dragMomentum = function(elem, e) {
var drag_info = {
left: drag.left.end,
left_adjust: 0,
change: {
x: 0
},
time: (new Date().getTime() - drag.time.start) * 10,
time_adjust: (new Date().getTime() - drag.time.start) * 10
},
multiplier = 3000;
if (drag.touch) {
multiplier = 6000;
}
drag_info.change.x = multiplier * (Math.abs(drag.pagex.end) - Math.abs(drag.pagex.start));
drag_info.left_adjust = Math.round(drag_info.change.x / drag_info.time);
drag_info.left = Math.min(drag_info.left + drag_info.left_adjust);
if (drag.constraint) {
if (drag_info.left > drag.constraint.left) {
drag_info.left = drag.constraint.left;
if (drag_info.time > 5000) {
drag_info.time = 5000;
}
} else if (drag_info.left < drag.constraint.right) {
drag_info.left = drag.constraint.right;
if (drag_info.time > 5000) {
drag_info.time = 5000;
}
}
}
VMM.fireEvent(elem, "DRAGUPDATE", [drag_info]);
if (drag_info.time > 0) {
if (drag.touch) {
//VMM.Lib.css(elem, '-webkit-transition-property', 'left');
//VMM.Lib.css(elem, '-webkit-transition-duration', drag_info.time);
//VMM.Lib.css(elem, 'left', drag_info.left);
//VMM.Lib.animate(elem, drag_info.time, "easeOutQuad", {"left": drag_info.left});
VMM.Lib.animate(elem, drag_info.time, "easeOutCirc", {"left": drag_info.left});
//VMM.Lib.css(elem, 'webkitTransition', '');
//VMM.Lib.css(elem, 'webkitTransition', '-webkit-transform ' + drag_info.time + 'ms cubic-bezier(0.33, 0.66, 0.66, 1)');
//VMM.Lib.css(elem, 'webkitTransform', 'translate3d(' + drag_info.left + 'px, 0, 0)');
} else {
VMM.Lib.animate(elem, drag_info.time, drag.ease, {"left": drag_info.left});
}
}
}
var getLeft = function(elem) {
return parseInt(VMM.Lib.css(elem, 'left').substring(0, VMM.Lib.css(elem, 'left').length - 2), 10);
}
}
}
/***********************************************
Begin VMM.Slider.js
***********************************************/
/* Slider
================================================== */
/* * CodeKit Import
* http://incident57.com/codekit/
================================================== */
// @codekit-append "VMM.Slider.Slide.js";
if(typeof VMM != 'undefined' && typeof VMM.Slider == 'undefined') {
VMM.Slider = function(parent, parent_config) {
var config,
timer,
$slider,
$slider_mask,
$slider_container,
$slides_items,
events = {},
data = [],
slides = [],
slide_positions = [],
slides_content = "",
current_slide = 0,
current_width = 960,
touch = {
move: false,
x: 10,
y: 0,
off: 0,
dampen: 48
},
content = "",
_active = false,
layout = parent,
navigation = {
nextBtn: "",
prevBtn: "",
nextDate: "",
prevDate: "",
nextTitle: "",
prevTitle: ""
};
// CONFIG
if(typeof parent_config != 'undefined') {
config = parent_config;
} else {
config = {
preload: 4,
current_slide: 0,
interval: 10,
something: 0,
width: 720,
height: 400,
ease: "easeInOutExpo",
duration: 1000,
timeline: false,
spacing: 15,
slider: {
width: 720,
height: 400,
content: {
width: 720,
height: 400,
padding: 130
},
nav: {
width: 100,
height: 200
}
}
};
}
/* PUBLIC VARS
================================================== */
this.ver = "0.6";
config.slider.width = config.width;
config.slider.height = config.height;
/* PUBLIC FUNCTIONS
================================================== */
this.init = function(d) {
slides = [];
slide_positions = [];
if(typeof d != 'undefined') {
this.setData(d);
} else {
trace("WAITING ON DATA");
}
};
this.width = function(w) {
if (w != null && w != "") {
config.slider.width = w;
reSize();
} else {
return config.slider.width;
}
}
this.height = function(h) {
if (h != null && h != "") {
config.slider.height = h;
reSize();
} else {
return config.slider.height;
}
}
/* GETTERS AND SETTERS
================================================== */
this.setData = function(d) {
if(typeof d != 'undefined') {
data = d;
build();
} else{
trace("NO DATA");
}
};
this.getData = function() {
return data;
};
this.setConfig = function(d) {
if(typeof d != 'undefined') {
config = d;
} else{
trace("NO CONFIG DATA");
}
}
this.getConfig = function() {
return config;
};
this.setSize = function(w, h) {
if (w != null) {config.slider.width = w};
if (h != null) {config.slider.height = h};
if (_active) {
reSize();
}
}
this.active = function() {
return _active;
};
this.getCurrentNumber = function() {
return current_slide;
};
this.setSlide = function(n) {
goToSlide(n);
};
/* ON EVENT
================================================== */
function onConfigSet() {
trace("onConfigSet");
};
function reSize(go_to_slide, from_start) {
var _go_to_slide = true,
_from_start = false;
if (go_to_slide != null) {_go_to_slide = go_to_slide};
if (from_start != null) {_from_start = from_start};
current_width = config.slider.width;
config.slider.nav.height = VMM.Lib.height(navigation.prevBtnContainer);
config.slider.content.width = current_width - (config.slider.content.padding *2);
VMM.Lib.width($slides_items, (slides.length * config.slider.content.width));
if (_from_start) {
VMM.Lib.css($slider_container, "left", slides[current_slide].leftpos());
}
// RESIZE SLIDES
sizeSlides();
// POSITION SLIDES
positionSlides();
// POSITION NAV
VMM.Lib.css(navigation.nextBtn, "left", (current_width - config.slider.nav.width));
VMM.Lib.height(navigation.prevBtn, config.slider.height);
VMM.Lib.height(navigation.nextBtn, config.slider.height);
VMM.Lib.css(navigation.nextBtnContainer, "top", ( (config.slider.height/2) - (config.slider.nav.height/2) ) + 10 );
VMM.Lib.css(navigation.prevBtnContainer, "top", ( (config.slider.height/2) - (config.slider.nav.height/2) ) + 10 );
// Animate Changes
VMM.Lib.height($slider_mask, config.slider.height);
VMM.Lib.width($slider_mask, current_width);
if (_go_to_slide) {
goToSlide(current_slide, "linear", 1);
};
if (current_slide == 0) {
VMM.Lib.visible(navigation.prevBtn, false);
}
}
/* NAVIGATION
================================================== */
function onNextClick(e) {
if (current_slide == slides.length - 1) {
VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": -(slides[current_slide].leftpos()) } );
} else {
goToSlide(current_slide+1);
upDate();
}
}
function onPrevClick(e) {
if (current_slide == 0) {
goToSlide(current_slide);
} else {
goToSlide(current_slide-1);
upDate();
}
}
function onKeypressNav(e) {
switch(e.keyCode) {
case 39:
// RIGHT ARROW
onNextClick(e);
break;
case 37:
// LEFT ARROW
onPrevClick(e);
break;
}
}
function onTouchUpdate(e, b) {
if (slide_positions.length == 0) {
for(var i = 0; i < slides.length; i++) {
slide_positions.push( slides[i].leftpos() );
}
}
if (typeof b.left == "number") {
var _pos = b.left;
var _slide_pos = -(slides[current_slide].leftpos());
if (_pos < _slide_pos - (config.slider_width/3)) {
onNextClick();
} else if (_pos > _slide_pos + (config.slider_width/3)) {
onPrevClick();
} else {
VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": _slide_pos });
}
} else {
VMM.Lib.animate($slider_container, config.duration, config.ease, {"left": _slide_pos });
}
if (typeof b.top == "number") {
VMM.Lib.animate($slider_container, config.duration, config.ease, {"top": -b.top});
} else {
}
};
/* UPDATE
================================================== */
function upDate() {
config.current_slide = current_slide;
VMM.fireEvent(layout, "UPDATE");
};
/* GET DATA
================================================== */
var getData = function(d) {
data = d;
};
/* BUILD SLIDES
================================================== */
var buildSlides = function(d) {
var i = 0;
VMM.attachElement($slides_items, "");
slides = [];
for(i = 0; i < d.length; i++) {
var _slide = new VMM.Slider.Slide(d[i], $slides_items);
//_slide.show();
slides.push(_slide);
}
}
var preloadSlides = function(skip) {
var i = 0;
if (skip) {
preloadTimeOutSlides();
} else {
for(i = 0; i < slides.length; i++) {
slides[i].clearTimers();
}
timer = setTimeout(preloadTimeOutSlides, config.duration);
}
}
var preloadTimeOutSlides = function() {
var i = 0;
for(i = 0; i < slides.length; i++) {
slides[i].enqueue = true;
}
for(i = 0; i < config.preload; i++) {
if ( !((current_slide + i) > slides.length - 1)) {
slides[current_slide + i].show();
slides[current_slide + i].enqueue = false;
}
if ( !( (current_slide - i) < 0 ) ) {
slides[current_slide - i].show();
slides[current_slide - i].enqueue = false;
}
}
if (slides.length > 50) {
for(i = 0; i < slides.length; i++) {
if (slides[i].enqueue) {
slides[i].hide();
}
}
}
sizeSlides();
}
var sizeSlide = function(slide_id) {
}
/* SIZE SLIDES
================================================== */
var sizeSlides = function() {
var i = 0,
layout_text_media = ".slider-item .layout-text-media .media .media-container ",
layout_media = ".slider-item .layout-media .media .media-container ",
layout_both = ".slider-item .media .media-container",
layout_caption = ".slider-item .media .media-container .media-shadow .caption",
mediasize = {
text_media: {
width: (config.slider.content.width/100) * 60,
height: config.slider.height - 60,
video: {
width: 0,
height: 0
},
text: {
width: ((config.slider.content.width/100) * 40) - 30,
height: config.slider.height
}
},
media: {
width: config.slider.content.width,
height: config.slider.height - 110,
video: {
width: 0,
height: 0
}
}
};
VMM.master_config.sizes.api.width = mediasize.media.width;
VMM.master_config.sizes.api.height = mediasize.media.height;
mediasize.text_media.video = VMM.Util.ratio.fit(mediasize.text_media.width, mediasize.text_media.height, 16, 9);
mediasize.media.video = VMM.Util.ratio.fit(mediasize.media.width, mediasize.media.height, 16, 9);
VMM.Lib.css(".slider-item", "width", config.slider.content.width );
VMM.Lib.height(".slider-item", config.slider.height);
// HANDLE SMALLER SIZES
var is_skinny = false;
if (current_width <= 640) {
is_skinny = true;
} else if (VMM.Browser.device == "mobile" && VMM.Browser.orientation == "portrait") {
is_skinny = true;
} else if (VMM.Browser.device == "tablet" && VMM.Browser.orientation == "portrait") {
//is_skinny = true;
}
if (is_skinny) {
mediasize.text_media.width = config.slider.content.width;
mediasize.text_media.height = ((config.slider.height/100) * 50 ) - 50;
mediasize.media.height = ((config.slider.height/100) * 70 ) - 40;
mediasize.text_media.video = VMM.Util.ratio.fit(mediasize.text_media.width, mediasize.text_media.height, 16, 9);
mediasize.media.video = VMM.Util.ratio.fit(mediasize.media.width, mediasize.media.height, 16, 9);
VMM.Lib.css(".slider-item .layout-text-media .text", "width", "100%" );
VMM.Lib.css(".slider-item .layout-text-media .text", "display", "block" );
VMM.Lib.css(".slider-item .layout-text-media .text .container", "display", "block" );
VMM.Lib.css(".slider-item .layout-text-media .text .container", "width", config.slider.content.width );
VMM.Lib.css(".slider-item .layout-text-media .media", "float", "none" );
VMM.Lib.addClass(".slider-item .content-container", "pad-top");
VMM.Lib.css(".slider-item .media blockquote p", "line-height", "18px" );
VMM.Lib.css(".slider-item .media blockquote p", "font-size", "16px" );
VMM.Lib.css(".slider-item", "overflow-y", "auto" );
} else {
VMM.Lib.css(".slider-item .layout-text-media .text", "width", "40%" );
VMM.Lib.css(".slider-item .layout-text-media .text", "display", "table-cell" );
VMM.Lib.css(".slider-item .layout-text-media .text .container", "display", "table-cell" );
VMM.Lib.css(".slider-item .layout-text-media .text .container", "width", "auto" );
VMM.Lib.css(".slider-item .layout-text-media .text .container .start", "width", mediasize.text_media.text.width );
//VMM.Lib.addClass(".slider-item .content-container", "pad-left");
VMM.Lib.removeClass(".slider-item .content-container", "pad-top");
VMM.Lib.css(".slider-item .layout-text-media .media", "float", "left" );
VMM.Lib.css(".slider-item .layout-text-media", "display", "table" );
VMM.Lib.css(".slider-item .media blockquote p", "line-height", "36px" );
VMM.Lib.css(".slider-item .media blockquote p", "font-size", "28px" );
VMM.Lib.css(".slider-item", "display", "table" );
VMM.Lib.css(".slider-item", "overflow-y", "auto" );
}
// MEDIA FRAME
VMM.Lib.css( layout_text_media + ".media-frame", "max-width", mediasize.text_media.width);
VMM.Lib.height( layout_text_media + ".media-frame", mediasize.text_media.height);
VMM.Lib.width( layout_text_media + ".media-frame", mediasize.text_media.width);
// WEBSITES
//VMM.Lib.css( layout_both + ".website", "max-width", 300 );
// IMAGES
VMM.Lib.css( layout_text_media + "img", "max-height", mediasize.text_media.height );
VMM.Lib.css( layout_media + "img", "max-height", mediasize.media.height );
// FIX FOR NON-WEBKIT BROWSERS
VMM.Lib.css( layout_text_media + "img", "max-width", mediasize.text_media.width );
VMM.Lib.css( layout_text_media + ".avatar img", "max-width", 32 );
VMM.Lib.css( layout_text_media + ".avatar img", "max-height", 32 );
VMM.Lib.css( layout_media + ".avatar img", "max-width", 32 );
VMM.Lib.css( layout_media + ".avatar img", "max-height", 32 );
VMM.Lib.css( layout_text_media + ".article-thumb", "max-width", "50%" );
//VMM.Lib.css( layout_text_media + ".article-thumb", "max-height", 100 );
VMM.Lib.css( layout_media + ".article-thumb", "max-width", 200 );
//VMM.Lib.css( layout_media + ".article-thumb", "max-height", 100 );
// IFRAME FULL SIZE VIDEO
VMM.Lib.width( layout_text_media + ".media-frame", mediasize.text_media.video.width);
VMM.Lib.height( layout_text_media + ".media-frame", mediasize.text_media.video.height);
VMM.Lib.width( layout_media + ".media-frame", mediasize.media.video.width);
VMM.Lib.height( layout_media + ".media-frame", mediasize.media.video.height);
VMM.Lib.css( layout_media + ".media-frame", "max-height", mediasize.media.video.height);
VMM.Lib.css( layout_media + ".media-frame", "max-width", mediasize.media.video.width);
// SOUNDCLOUD
VMM.Lib.height( layout_media + ".soundcloud", 168);
VMM.Lib.height( layout_text_media + ".soundcloud", 168);
VMM.Lib.width( layout_media + ".soundcloud", mediasize.media.width);
VMM.Lib.width( layout_text_media + ".soundcloud", mediasize.text_media.width);
VMM.Lib.css( layout_both + ".soundcloud", "max-height", 168 );
// MAPS
VMM.Lib.height( layout_text_media + ".map", mediasize.text_media.height);
VMM.Lib.css( layout_media + ".map", "max-height", mediasize.media.height);
VMM.Lib.width( layout_media + ".map", mediasize.media.width);
// DOCS
VMM.Lib.height( layout_text_media + ".doc", mediasize.text_media.height);
VMM.Lib.height( layout_media + ".doc", mediasize.media.height);
// IE8 NEEDS THIS
VMM.Lib.width( layout_media + ".wikipedia", mediasize.media.width);
VMM.Lib.width( layout_media + ".twitter", mediasize.media.width);
VMM.Lib.width( layout_media + ".plain-text-quote", mediasize.media.width);
VMM.Lib.width( layout_media + ".plain-text", mediasize.media.width);
// CAPTION WIDTH
VMM.Lib.css( layout_text_media + ".caption", "max-width", mediasize.text_media.video.width);
VMM.Lib.css( layout_media + ".caption", "max-width", mediasize.media.video.width);
// MAINTAINS VERTICAL CENTER IF IT CAN
for(i = 0; i < slides.length; i++) {
slides[i].layout(is_skinny);
if (slides[i].content_height() > config.slider.height + 20) {
slides[i].css("display", "block");
} else {
slides[i].css("display", "table");
}
}
}
/* POSITION SLIDES
================================================== */
var positionSlides = function() {
var pos = 0,
i = 0;
for(i = 0; i < slides.length; i++) {
pos = i * (config.slider.width+config.spacing);
slides[i].leftpos(pos);
}
}
/* OPACITY SLIDES
================================================== */
var opacitySlides = function(n) {
var _ease = "linear",
i = 0;
for(i = 0; i < slides.length; i++) {
if (i == current_slide) {
slides[i].animate(config.duration, _ease, {"opacity": 1});
} else if (i == current_slide - 1 || i == current_slide + 1) {
slides[i].animate(config.duration, _ease, {"opacity": 0.1});
} else {
slides[i].opacity(n);
}
}
}
/* GO TO SLIDE
goToSlide(n, ease, duration);
================================================== */
var goToSlide = function(n, ease, duration, fast, firstrun) {
var _ease = config.ease,
_duration = config.duration,
is_last = false,
is_first = false,
_title = "",
_pos;
/* STOP ANY VIDEO PLAYERS ACTIVE
================================================== */
VMM.ExternalAPI.youtube.stopPlayers();
// Set current slide
current_slide = n;
_pos = slides[current_slide].leftpos();
if (current_slide == 0) {is_first = true};
if (current_slide +1 >= slides.length) {is_last = true};
if (ease != null && ease != "") {_ease = ease};
if (duration != null && duration != "") {_duration = duration};
/* set proper nav titles and dates etc.
================================================== */
if (is_first) {
VMM.Lib.visible(navigation.prevBtn, false);
} else {
VMM.Lib.visible(navigation.prevBtn, true);
_title = VMM.Util.unlinkify(data[current_slide - 1].title)
if (config.type == "timeline") {
if(typeof data[current_slide - 1].date === "undefined") {
VMM.attachElement(navigation.prevDate, _title);
VMM.attachElement(navigation.prevTitle, "");
} else {
VMM.attachElement(navigation.prevDate, VMM.Date.prettyDate(data[current_slide - 1].startdate));
VMM.attachElement(navigation.prevTitle, _title);
}
} else {
VMM.attachElement(navigation.prevTitle, _title);
}
}
if (is_last) {
VMM.Lib.visible(navigation.nextBtn, false);
} else {
VMM.Lib.visible(navigation.nextBtn, true);
_title = VMM.Util.unlinkify(data[current_slide + 1].title);
if (config.type == "timeline") {
if(typeof data[current_slide + 1].date === "undefined") {
VMM.attachElement(navigation.nextDate, _title);
VMM.attachElement(navigation.nextTitle, "");
} else {
VMM.attachElement(navigation.nextDate, VMM.Date.prettyDate(data[current_slide + 1].startdate) );
VMM.attachElement(navigation.nextTitle, _title);
}
} else {
VMM.attachElement(navigation.nextTitle, _title);
}
}
/* ANIMATE SLIDE
================================================== */
if (fast) {
VMM.Lib.css($slider_container, "left", -(_pos - config.slider.content.padding));
} else{
VMM.Lib.stop($slider_container);
VMM.Lib.animate($slider_container, _duration, _ease, {"left": -(_pos - config.slider.content.padding)});
}
if (firstrun) {
VMM.fireEvent(layout, "LOADED");
}
/* SET Vertical Scoll
================================================== */
if (slides[current_slide].height() > config.slider_height) {
VMM.Lib.css(".slider", "overflow-y", "scroll" );
} else {
VMM.Lib.css(layout, "overflow-y", "hidden" );
var scroll_height = 0;
try {
scroll_height = VMM.Lib.prop(layout, "scrollHeight");
VMM.Lib.animate(layout, _duration, _ease, {scrollTop: scroll_height - VMM.Lib.height(layout) });
}
catch(err) {
scroll_height = VMM.Lib.height(layout);
}
}
preloadSlides();
}
/* BUILD NAVIGATION
================================================== */
var buildNavigation = function() {
var temp_icon = "
";
navigation.nextBtn = VMM.appendAndGetElement($slider, "
", "nav-next");
navigation.prevBtn = VMM.appendAndGetElement($slider, "
", "nav-previous");
navigation.nextBtnContainer = VMM.appendAndGetElement(navigation.nextBtn, "
", "nav-container", temp_icon);
navigation.prevBtnContainer = VMM.appendAndGetElement(navigation.prevBtn, "
", "nav-container", temp_icon);
if (config.type == "timeline") {
navigation.nextDate = VMM.appendAndGetElement(navigation.nextBtnContainer, "
", "date", "");
navigation.prevDate = VMM.appendAndGetElement(navigation.prevBtnContainer, "
", "date", "");
}
navigation.nextTitle = VMM.appendAndGetElement(navigation.nextBtnContainer, "
", "title", "");
navigation.prevTitle = VMM.appendAndGetElement(navigation.prevBtnContainer, "
", "title", "");
VMM.bindEvent(".nav-next", onNextClick);
VMM.bindEvent(".nav-previous", onPrevClick);
VMM.bindEvent(window, onKeypressNav, 'keydown');
}
/* BUILD
================================================== */
var build = function() {
var __duration = 3000;
// Clear out existing content
VMM.attachElement(layout, "");
// Get DOM Objects to local objects
$slider = VMM.getElement(layout);
$slider_mask = VMM.appendAndGetElement($slider, "
", "slider-container-mask");
$slider_container = VMM.appendAndGetElement($slider_mask, "
", "slider-container");
$slides_items = VMM.appendAndGetElement($slider_container, "
", "slider-item-container");
// BUILD NAVIGATION
buildNavigation();
// ATTACH SLIDES
buildSlides(data);
/* MAKE SLIDER TOUCHABLE
================================================== */
if (VMM.Browser.device == "tablet" || VMM.Browser.device == "mobile") {
config.duration = 500;
__duration = 1000;
//VMM.TouchSlider.createPanel($slider_container, $slider_container, VMM.Lib.width(slides[0]), config.spacing, true);
//VMM.TouchSlider.createPanel($slider_container, $slider_container, slides[0].width(), config.spacing, true);
//VMM.bindEvent($slider_container, onTouchUpdate, "TOUCHUPDATE");
} else if (VMM.Browser.device == "mobile") {
} else {
//VMM.DragSlider.createPanel($slider_container, $slider_container, VMM.Lib.width(slides[0]), config.spacing, true);
}
reSize(false, true);
VMM.Lib.visible(navigation.prevBtn, false);
goToSlide(config.current_slide, "easeOutExpo", __duration, true, true);
_active = true;
};
};
}
/***********************************************
Begin VMM.Slider.Slide.js
***********************************************/
/* Slider Slide
================================================== */
if (typeof VMM.Slider != 'undefined') {
VMM.Slider.Slide = function(d, _parent) {
var $media, $text, $slide, $wrap, element, c,
data = d,
slide = {},
element = "",
media = "",
loaded = false,
preloaded = false,
is_skinny = false,
_enqueue = true,
_removeque = false,
_id = "slide_",
timer = {pushque:"", render:"", relayout:"", remove:"", skinny:false},
times = {pushque:500, render:100, relayout:100, remove:30000};
_id = _id + data.uniqueid;
this.enqueue = _enqueue;
this.id = _id;
element = VMM.appendAndGetElement(_parent, "
", "slider-item");
c = {slide:"", text: "", media: "", media_element: "", layout: "content-container layout", has: { headline: false, text: false, media: false }};
/* PUBLIC
================================================== */
this.show = function(skinny) {
_enqueue = false;
timer.skinny = skinny;
_removeque = false;
clearTimeout(timer.remove);
if (!loaded) {
if (preloaded) {
clearTimeout(timer.relayout);
timer.relayout = setTimeout(reloadLayout, times.relayout);
} else {
render(skinny);
}
}
};
this.hide = function() {
if (loaded && !_removeque) {
_removeque = true;
clearTimeout(timer.remove);
timer.remove = setTimeout(removeSlide, times.remove);
}
};
this.clearTimers = function() {
//clearTimeout(timer.remove);
clearTimeout(timer.relayout);
clearTimeout(timer.pushque);
clearTimeout(timer.render);
};
this.layout = function(skinny) {
if (loaded && preloaded) {
reLayout(skinny);
}
};
this.elem = function() {
return element;
};
this.position = function() {
return VMM.Lib.position(element);
};
this.leftpos = function(p) {
if(typeof p != 'undefined') {
VMM.Lib.css(element, "left", p);
} else {
return VMM.Lib.position(element).left
}
};
this.animate = function(d, e, p) {
VMM.Lib.animate(element, d, e, p);
};
this.css = function(p, v) {
VMM.Lib.css(element, p, v );
}
this.opacity = function(p) {
VMM.Lib.css(element, "opacity", p);
}
this.width = function() {
return VMM.Lib.width(element);
};
this.height = function() {
return VMM.Lib.height(element);
};
this.content_height = function () {
var ch = VMM.Lib.find( element, ".content")[0];
if (ch != 'undefined' && ch != null) {
return VMM.Lib.height(ch);
} else {
return 0;
}
}
/* PRIVATE
================================================== */
var render = function(skinny) {
trace("RENDER " + _id);
loaded = true;
preloaded = true;
timer.skinny = skinny;
buildSlide();
clearTimeout(timer.pushque);
clearTimeout(timer.render);
timer.pushque = setTimeout(VMM.ExternalAPI.pushQues, times.pushque);
};
var removeSlide = function() {
//VMM.attachElement(element, "");
trace("REMOVE SLIDE TIMER FINISHED");
loaded = false;
VMM.Lib.detach($text);
VMM.Lib.detach($media);
};
var reloadLayout = function() {
loaded = true;
reLayout(timer.skinny, true);
};
var reLayout = function(skinny, reload) {
if (c.has.text) {
if (skinny) {
if (!is_skinny || reload) {
VMM.Lib.removeClass($slide, "pad-left");
VMM.Lib.detach($text);
VMM.Lib.detach($media);
VMM.Lib.append($slide, $text);
VMM.Lib.append($slide, $media);
is_skinny = true;
}
} else {
if (is_skinny || reload) {
VMM.Lib.addClass($slide, "pad-left");
VMM.Lib.detach($text);
VMM.Lib.detach($media);
VMM.Lib.append($slide, $media);
VMM.Lib.append($slide, $text);
is_skinny = false;
}
}
} else if (reload) {
if (c.has.headline) {
VMM.Lib.detach($text);
VMM.Lib.append($slide, $text);
}
VMM.Lib.detach($media);
VMM.Lib.append($slide, $media);
}
}
var buildSlide = function() {
trace("BUILDSLIDE");
$wrap = VMM.appendAndGetElement(element, "
", "content");
$slide = VMM.appendAndGetElement($wrap, "
");
/* DATE
================================================== */
if (data.startdate != null && data.startdate != "") {
if (type.of(data.startdate) == "date") {
if (data.type != "start") {
var st = VMM.Date.prettyDate(data.startdate);
var en = VMM.Date.prettyDate(data.enddate);
var tag = "";
/* TAG / CATEGORY
================================================== */
if (data.tag != null && data.tag != "") {
tag = VMM.createElement("span", data.tag, "slide-tag");
}
if (st != en) {
c.text += VMM.createElement("h2", st + " — " + en + tag, "date");
} else {
c.text += VMM.createElement("h2", st + tag, "date");
}
}
}
}
/* HEADLINE
================================================== */
if (data.headline != null && data.headline != "") {
c.has.headline = true;
if (data.type == "start") {
c.text += VMM.createElement("h2", VMM.Util.linkify_with_twitter(data.headline, "_blank"), "start");
} else {
c.text += VMM.createElement("h3", VMM.Util.linkify_with_twitter(data.headline, "_blank"));
}
}
/* TEXT
================================================== */
if (data.text != null && data.text != "") {
c.has.text = true;
c.text += VMM.createElement("p", VMM.Util.linkify_with_twitter(data.text, "_blank"));
}
if (c.has.text || c.has.headline) {
c.text = VMM.createElement("div", c.text, "container");
//$text = VMM.appendAndGetElement($slide, "
", "text", c.text);
$text = VMM.appendAndGetElement($slide, "
", "text", VMM.TextElement.create(c.text));
}
/* SLUG
================================================== */
if (data.needs_slug) {
}
/* MEDIA
================================================== */
if (data.asset != null && data.asset != "") {
if (data.asset.media != null && data.asset.media != "") {
c.has.media = true;
$media = VMM.appendAndGetElement($slide, "
", "media", VMM.MediaElement.create(data.asset, data.uniqueid));
}
}
/* COMBINE
================================================== */
if (c.has.text) { c.layout += "-text" };
if (c.has.media){ c.layout += "-media" };
if (c.has.text) {
if (timer.skinny) {
VMM.Lib.addClass($slide, c.layout);
is_skinny = true;
} else {
VMM.Lib.addClass($slide, c.layout);
VMM.Lib.addClass($slide, "pad-left");
VMM.Lib.detach($text);
VMM.Lib.append($slide, $text);
}
} else {
VMM.Lib.addClass($slide, c.layout);
}
};
}
};
/***********************************************
Begin AES.js
***********************************************/
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* AES implementation in JavaScript (c) Chris Veness 2005-2011 */
/* - see http://csrc.nist.gov/publications/PubsFIPS.html#197 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var Aes = {}; // Aes namespace
/**
* AES Cipher function: encrypt 'input' state with Rijndael algorithm
* applies Nr rounds (10/12/14) using key schedule w for 'add round key' stage
*
* @param {Number[]} input 16-byte (128-bit) input state array
* @param {Number[][]} w Key schedule as 2D byte-array (Nr+1 x Nb bytes)
* @returns {Number[]} Encrypted output state array
*/
Aes.cipher = function(input, w) { // main Cipher function [§5.1]
var Nb = 4; // block size (in words): no of columns in state (fixed at 4 for AES)
var Nr = w.length/Nb - 1; // no of rounds: 10/12/14 for 128/192/256-bit keys
var state = [[],[],[],[]]; // initialise 4xNb byte-array 'state' with input [§3.4]
for (var i=0; i<4*Nb; i++) state[i%4][Math.floor(i/4)] = input[i];
state = Aes.addRoundKey(state, w, 0, Nb);
for (var round=1; round
6 && i%Nk == 4) {
temp = Aes.subWord(temp);
}
for (var t=0; t<4; t++) w[i][t] = w[i-Nk][t] ^ temp[t];
}
return w;
}
/*
* ---- remaining routines are private, not called externally ----
*/
Aes.subBytes = function(s, Nb) { // apply SBox to state S [§5.1.1]
for (var r=0; r<4; r++) {
for (var c=0; c>> i*8) & 0xff;
for (var i=0; i<2; i++) counterBlock[i+2] = (nonceRnd >>> i*8) & 0xff;
for (var i=0; i<4; i++) counterBlock[i+4] = (nonceSec >>> i*8) & 0xff;
// and convert it to a string to go on the front of the ciphertext
var ctrTxt = '';
for (var i=0; i<8; i++) ctrTxt += String.fromCharCode(counterBlock[i]);
// generate key schedule - an expansion of the key into distinct Key Rounds for each round
var keySchedule = Aes.keyExpansion(key);
var blockCount = Math.ceil(plaintext.length/blockSize);
var ciphertxt = new Array(blockCount); // ciphertext as array of strings
for (var b=0; b>> c*8) & 0xff;
for (var c=0; c<4; c++) counterBlock[15-c-4] = (b/0x100000000 >>> c*8)
var cipherCntr = Aes.cipher(counterBlock, keySchedule); // -- encrypt counter block --
// block size is reduced on final block
var blockLength = b>> c*8) & 0xff;
for (var c=0; c<4; c++) counterBlock[15-c-4] = (((b+1)/0x100000000-1) >>> c*8) & 0xff;
var cipherCntr = Aes.cipher(counterBlock, keySchedule); // encrypt counter block
var plaintxtByte = new Array(ciphertext[b].length);
for (var i=0; i 0) { while (c++ < 3) { pad += '='; plain += '\0'; } }
// note: doing padding here saves us doing special-case packing for trailing 1 or 2 chars
for (c=0; c>18 & 0x3f;
h2 = bits>>12 & 0x3f;
h3 = bits>>6 & 0x3f;
h4 = bits & 0x3f;
// use hextets to index into code string
e[c/3] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
}
coded = e.join(''); // join() is far faster than repeated string concatenation in IE
// replace 'A's from padded nulls with '='s
coded = coded.slice(0, coded.length-pad.length) + pad;
return coded;
}
/**
* Decode string from Base64, as defined by RFC 4648 [http://tools.ietf.org/html/rfc4648]
* (instance method extending String object). As per RFC 4648, newlines are not catered for.
*
* @param {String} str The string to be decoded from base-64
* @param {Boolean} [utf8decode=false] Flag to indicate whether str is Unicode string to be decoded
* from UTF8 after conversion from base64
* @returns {String} decoded string
*/
Base64.decode = function(str, utf8decode) {
utf8decode = (typeof utf8decode == 'undefined') ? false : utf8decode;
var o1, o2, o3, h1, h2, h3, h4, bits, d=[], plain, coded;
var b64 = Base64.code;
coded = utf8decode ? str.decodeUTF8() : str;
for (var c=0; c>>16 & 0xff;
o2 = bits>>>8 & 0xff;
o3 = bits & 0xff;
d[c/4] = String.fromCharCode(o1, o2, o3);
// check for padding
if (h4 == 0x40) d[c/4] = String.fromCharCode(o1, o2);
if (h3 == 0x40) d[c/4] = String.fromCharCode(o1);
}
plain = d.join(''); // join() is far faster than repeated string concatenation in IE
return utf8decode ? plain.decodeUTF8() : plain;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Utf8 class: encode / decode between multi-byte Unicode characters and UTF-8 multiple */
/* single-byte character encoding (c) Chris Veness 2002-2011 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
var Utf8 = {}; // Utf8 namespace
/**
* Encode multi-byte Unicode string into utf-8 multiple single-byte characters
* (BMP / basic multilingual plane only)
*
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars
*
* @param {String} strUni Unicode string to be encoded as UTF-8
* @returns {String} encoded string
*/
Utf8.encode = function(strUni) {
// use regular expressions & String.replace callback function for better efficiency
// than procedural approaches
var strUtf = strUni.replace(
/[\u0080-\u07ff]/g, // U+0080 - U+07FF => 2 bytes 110yyyyy, 10zzzzzz
function(c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xc0 | cc>>6, 0x80 | cc&0x3f); }
);
strUtf = strUtf.replace(
/[\u0800-\uffff]/g, // U+0800 - U+FFFF => 3 bytes 1110xxxx, 10yyyyyy, 10zzzzzz
function(c) {
var cc = c.charCodeAt(0);
return String.fromCharCode(0xe0 | cc>>12, 0x80 | cc>>6&0x3F, 0x80 | cc&0x3f); }
);
return strUtf;
}
/**
* Decode utf-8 encoded string back into multi-byte Unicode characters
*
* @param {String} strUtf UTF-8 string to be decoded back to Unicode
* @returns {String} decoded string
*/
Utf8.decode = function(strUtf) {
// note: decode 3-byte chars first as decoded 2-byte strings could appear to be 3-byte char!
var strUni = strUtf.replace(
/[\u00e0-\u00ef][\u0080-\u00bf][\u0080-\u00bf]/g, // 3-byte chars
function(c) { // (note parentheses for precence)
var cc = ((c.charCodeAt(0)&0x0f)<<12) | ((c.charCodeAt(1)&0x3f)<<6) | ( c.charCodeAt(2)&0x3f);
return String.fromCharCode(cc); }
);
strUni = strUni.replace(
/[\u00c0-\u00df][\u0080-\u00bf]/g, // 2-byte chars
function(c) { // (note parentheses for precence)
var cc = (c.charCodeAt(0)&0x1f)<<6 | c.charCodeAt(1)&0x3f;
return String.fromCharCode(cc); }
);
return strUni;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/***********************************************
Begin bootstrap-tooltip.js
***********************************************/
/* ===========================================================
* bootstrap-tooltip.js v2.0.1
* http://twitter.github.com/bootstrap/javascript.html#tooltips
* Inspired by the original jQuery.tipsy by Jason Frame
* ===========================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */
!function( $ ) {
"use strict"
/* TOOLTIP PUBLIC CLASS DEFINITION
* =============================== */
var Tooltip = function ( element, options ) {
this.init('tooltip', element, options)
}
Tooltip.prototype = {
constructor: Tooltip
, init: function ( type, element, options ) {
var eventIn
, eventOut
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.enabled = true
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
}
this.options.selector ?
(this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
this.fixTitle()
}
, getOptions: function ( options ) {
options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
if (options.delay && typeof options.delay == 'number') {
options.delay = {
show: options.delay
, hide: options.delay
}
}
return options
}
, enter: function ( e ) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
if (!self.options.delay || !self.options.delay.show) {
self.show()
} else {
self.hoverState = 'in'
setTimeout(function() {
if (self.hoverState == 'in') {
self.show()
}
}, self.options.delay.show)
}
}
, leave: function ( e ) {
var self = $(e.currentTarget)[this.type](this._options).data(this.type)
if (!self.options.delay || !self.options.delay.hide) {
self.hide()
} else {
self.hoverState = 'out'
setTimeout(function() {
if (self.hoverState == 'out') {
self.hide()
}
}, self.options.delay.hide)
}
}
, show: function () {
var $tip
, inside
, pos
, actualWidth
, actualHeight
, placement
, tp
if (this.hasContent() && this.enabled) {
$tip = this.tip()
this.setContent()
if (this.options.animation) {
$tip.addClass('fade')
}
placement = typeof this.options.placement == 'function' ?
this.options.placement.call(this, $tip[0], this.$element[0]) :
this.options.placement
inside = /in/.test(placement)
$tip
.remove()
.css({ top: 0, left: 0, display: 'block' })
.appendTo(inside ? this.$element : document.body)
pos = this.getPosition(inside)
actualWidth = $tip[0].offsetWidth
actualHeight = $tip[0].offsetHeight
switch (inside ? placement.split(' ')[1] : placement) {
case 'bottom':
tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
break
case 'top':
tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
break
case 'left':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
break
case 'right':
tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
break
}
$tip
.css(tp)
.addClass(placement)
.addClass('in')
}
}
, setContent: function () {
var $tip = this.tip()
$tip.find('.tooltip-inner').html(this.getTitle())
$tip.removeClass('fade in top bottom left right')
}
, hide: function () {
var that = this
, $tip = this.tip()
$tip.removeClass('in')
function removeWithAnimation() {
var timeout = setTimeout(function () {
$tip.off($.support.transition.end).remove()
}, 500)
$tip.one($.support.transition.end, function () {
clearTimeout(timeout)
$tip.remove()
})
}
$.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() :
$tip.remove()
}
, fixTitle: function () {
var $e = this.$element
if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
$e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
}
}
, hasContent: function () {
return this.getTitle()
}
, getPosition: function (inside) {
return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
width: this.$element[0].offsetWidth
, height: this.$element[0].offsetHeight
})
}
, getTitle: function () {
var title
, $e = this.$element
, o = this.options
title = $e.attr('data-original-title')
|| (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
title = title.toString().replace(/(^\s*|\s*$)/, "")
return title
}
, tip: function () {
return this.$tip = this.$tip || $(this.options.template)
}
, validate: function () {
if (!this.$element[0].parentNode) {
this.hide()
this.$element = null
this.options = null
}
}
, enable: function () {
this.enabled = true
}
, disable: function () {
this.enabled = false
}
, toggleEnabled: function () {
this.enabled = !this.enabled
}
, toggle: function () {
this[this.tip().hasClass('in') ? 'hide' : 'show']()
}
}
/* TOOLTIP PLUGIN DEFINITION
* ========================= */
$.fn.tooltip = function ( option ) {
return this.each(function () {
var $this = $(this)
, data = $this.data('tooltip')
, options = typeof option == 'object' && option
if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
if (typeof option == 'string') data[option]()
})
}
$.fn.tooltip.Constructor = Tooltip
$.fn.tooltip.defaults = {
animation: true
, delay: 0
, selector: false
, placement: 'top'
, trigger: 'hover'
, title: ''
, template: ''
}
}( window.jQuery );
/***********************************************
Begin VMM.StoryJS.js
***********************************************/
/* VeriteCo StoryJS
================================================== */
/* * CodeKit Import
* http://incident57.com/codekit/
================================================== */
// @codekit-prepend "VMM.StoryJS.License.js";
// @codekit-prepend "Core/VMM.Core.js";
// @codekit-prepend "Language/VMM.Language.js";
// @codekit-prepend "Media/VMM.Media.js";
// @codekit-prepend "Slider/VMM.DragSlider.js";
// @codekit-prepend "Slider/VMM.Slider.js";
// @codekit-prepend "Library/AES.js";
// @codekit-prepend "Library/bootstrap-tooltip.js";
if(typeof VMM != 'undefined' && typeof VMM.StoryJS == 'undefined') {
VMM.StoryJS = function() {
/* PRIVATE VARS
================================================== */
/* PUBLIC FUNCTIONS
================================================== */
this.init = function(d) {
};
}
}
/***********************************************
Begin VMM.Timeline.js
***********************************************/
/**
* TimelineJS
* Designed and built by Zach Wise at VéritéCo
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* http://www.gnu.org/licenses/
*/
/* * CodeKit Import
* http://incident57.com/codekit/
================================================== */
// @codekit-prepend "VMM.Timeline.License.js";
// @codekit-prepend "Core/VMM.StoryJS.js";
// @codekit-append "VMM.Timeline.TimeNav.js";
// @codekit-append "VMM.Timeline.DataObj.js";
/* Timeline
================================================== */
if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
VMM.Timeline = function(_timeline_id, w, h) {
var $timeline,
$container,
$feature,
$feedback,
$slider,
$navigation,
slider,
timenav,
version = "1.70",
timeline_id = "#timelinejs",
events = {},
data = {},
_dates = [],
config = {},
has_width = false,
has_height = false,
ie7 = false,
is_moving = false;
if (type.of(_timeline_id) == "string") {
if (_timeline_id.match("#")) {
timeline_id = _timeline_id;
} else {
timeline_id = "#" + _timeline_id;
}
} else {
timeline_id = "#timelinejs";
}
trace("VERSION " + version);
/* CONFIG
================================================== */
config = {
embed: false,
events: {
data_ready: "DATAREADY",
messege: "MESSEGE",
headline: "HEADLINE",
slide_change: "SLIDE_CHANGE",
resize: "resize"
},
id: timeline_id,
source: "nothing",
type: "timeline",
touch: false,
maptype: "toner",
preload: 4,
current_slide: 0,
hash_bookmark: false,
start_at_end: false,
start_at_slide: 0,
start_zoom_adjust: 0,
start_page: false,
api_keys: {
google: "",
flickr: "",
twitter: ""
},
interval: 10,
something: 0,
width: 960,
height: 540,
spacing: 15,
loaded: {
slider: false,
timenav: false,
percentloaded: 0
},
nav: {
start_page: false,
interval_width: 200,
density: 4,
minor_width: 0,
minor_left: 0,
constraint: {
left: 0,
right: 0,
right_min: 0,
right_max: 0
},
zoom: {
adjust: 0
},
multiplier: {
current: 6,
min: .1,
max: 50
},
rows: [1, 1, 1],
width: 960,
height: 200,
marker: {
width: 150,
height: 50
}
},
feature: {
width: 960,
height: 540
},
slider: {
width: 720,
height: 400,
content: {
width: 720,
height: 400,
padding: 130
},
nav: {
width: 100,
height: 200
}
},
ease: "easeInOutExpo",
duration: 1000,
language: VMM.Language
};
if ( w != null && w != "") {
config.width = w;
has_width = true;
}
if ( h != null && h != "") {
config.height = h;
has_height = true;
}
if(window.location.hash) {
var hash = window.location.hash.substring(1);
if (!isNaN(hash)) {
config.current_slide = parseInt(hash);
}
}
window.onhashchange = function () {
var hash = window.location.hash.substring(1);
if (config.hash_bookmark) {
if (is_moving) {
goToEvent(parseInt(hash));
} else {
is_moving = false;
}
} else {
goToEvent(parseInt(hash));
}
}
/* CREATE CONFIG
================================================== */
function createConfig(conf) {
// APPLY SUPPLIED CONFIG TO TIMELINE CONFIG
if (typeof embed_config == 'object') {
timeline_config = embed_config;
}
if (typeof timeline_config == 'object') {
trace("HAS TIMELINE CONFIG");
config = VMM.Util.mergeConfig(config, timeline_config);
} else if (typeof conf == 'object') {
config = VMM.Util.mergeConfig(config, conf);
}
if (VMM.Browser.device == "mobile" || VMM.Browser.device == "tablet") {
config.touch = true;
}
config.nav.width = config.width;
config.nav.height = 200;
config.feature.width = config.width;
config.feature.height = config.height - config.nav.height;
config.nav.zoom.adjust = parseInt(config.start_zoom_adjust, 10);
VMM.Timeline.Config = config;
VMM.master_config.Timeline = VMM.Timeline.Config;
this.events = config.events;
}
/* CREATE TIMELINE STRUCTURE
================================================== */
function createStructure() {
// CREATE DOM STRUCTURE
$timeline = VMM.getElement(timeline_id);
VMM.Lib.addClass($timeline, "vco-timeline");
VMM.Lib.addClass($timeline, "vco-storyjs");
$container = VMM.appendAndGetElement($timeline, "", "vco-container vco-main");
$feature = VMM.appendAndGetElement($container, "
", "vco-feature");
$slider = VMM.appendAndGetElement($feature, "
", "vco-slider");
$navigation = VMM.appendAndGetElement($container, "
", "vco-navigation");
$feedback = VMM.appendAndGetElement($timeline, "
", "vco-feedback", "");
if (config.touch) {
VMM.Lib.addClass($timeline, "vco-touch");
} else {
VMM.Lib.addClass($timeline, "vco-notouch");
}
if (typeof config.language.right_to_left != 'undefined') {
VMM.Lib.addClass($timeline, "vco-right-to-left");
}
slider = new VMM.Slider($slider, config);
timenav = new VMM.Timeline.TimeNav($navigation);
if (!has_width) {
config.width = VMM.Lib.width($timeline);
} else {
VMM.Lib.width($timeline, config.width);
}
if (!has_height) {
config.height = VMM.Lib.height($timeline);
} else {
VMM.Lib.height($timeline, config.height);
}
}
/* ON EVENT
================================================== */
function onDataReady(e, d) {
trace("onDataReady");
trace(d);
data = d.timeline;
if (type.of(data.era) != "array") {
data.era = [];
}
buildDates();
};
function onDatesProcessed() {
build();
}
function reSize() {
updateSize();
slider.setSize(config.feature.width, config.feature.height);
timenav.setSize(config.width, config.height);
};
function onSliderLoaded(e) {
config.loaded.slider = true;
onComponentLoaded();
};
function onComponentLoaded(e) {
config.loaded.percentloaded = config.loaded.percentloaded + 25;
if (config.loaded.slider && config.loaded.timenav) {
hideMessege();
}
}
function onTimeNavLoaded(e) {
config.loaded.timenav = true;
onComponentLoaded();
}
function onSlideUpdate(e) {
is_moving = true;
config.current_slide = slider.getCurrentNumber();
setHash(config.current_slide);
timenav.setMarker(config.current_slide, config.ease,config.duration);
};
function onMarkerUpdate(e) {
is_moving = true;
config.current_slide = timenav.getCurrentNumber();
setHash(config.current_slide);
slider.setSlide(config.current_slide);
};
function goToEvent(n) {
if (n <= _dates.length - 1 && n >= 0) {
config.current_slide = n;
slider.setSlide(config.current_slide);
timenav.setMarker(config.current_slide, config.ease,config.duration);
}
}
function setHash(n) {
if (config.hash_bookmark) {
window.location.hash = "#" + n.toString();
}
}
/* PUBLIC FUNCTIONS
================================================== */
this.init = function(c, _data) {
trace('INIT');
createConfig(c);
createStructure();
if (type.of(_data) == "string") {
config.source = _data;
}
// LANGUAGE
VMM.Date.setLanguage(config.language);
VMM.master_config.language = config.language;
// EXTERNAL API
VMM.ExternalAPI.setKeys(config.api_keys);
VMM.ExternalAPI.googlemaps.setMapType(config.maptype);
// EVENTS
VMM.bindEvent(global, onDataReady, config.events.data_ready);
VMM.bindEvent(global, showMessege, config.events.messege);
VMM.fireEvent(global, config.events.messege, config.language.messages.loading_timeline);
/* GET DATA
================================================== */
if (VMM.Browser.browser == "Explorer" || VMM.Browser.browser == "MSIE") {
if ( parseInt(VMM.Browser.version, 10) <= 7 ) {
ie7 = true;
}
}
if (type.of(config.source) == "string" || type.of(config.source) == "object") {
VMM.Timeline.DataObj.getData(config.source);
} else {
VMM.Timeline.DataObj.getData(VMM.getElement(timeline_id));
}
};
this.iframeLoaded = function() {
trace("iframeLoaded");
};
this.reload = function(_d) {
trace("loadNewDates" + _d);
VMM.fireEvent(global, config.events.messege, config.language.messages.loading_timeline);
data = {};
VMM.Timeline.DataObj.getData(_d);
};
/* DATA
================================================== */
function getData(url) {
VMM.getJSON(url, function(d) {
data = VMM.Timeline.DataObj.getData(d);
VMM.fireEvent(global, config.events.data_ready);
});
};
/* MESSEGES
================================================== */
function showMessege(e, msg) {
trace("showMessege " + msg);
//VMM.attachElement($messege, msg);
VMM.attachElement($feedback, VMM.MediaElement.loadingmessage(msg));
};
function hideMessege() {
VMM.Lib.animate($feedback, config.duration, config.ease*4, {"opacity": 0}, detachMessege);
};
function detachMessege() {
VMM.Lib.detach($feedback);
}
/* BUILD DISPLAY
================================================== */
function build() {
// START AT SLIDE
if (parseInt(config.start_at_slide) > 0 && config.current_slide == 0) {
config.current_slide = parseInt(config.start_at_slide);
}
// START AT END
if (config.start_at_end && config.current_slide == 0) {
config.current_slide = _dates.length - 1;
}
// IE7
if (ie7) {
ie7 = true;
VMM.fireEvent(global, config.events.messege, "Internet Explorer " + VMM.Browser.version + " is not supported by TimelineJS. Please update your browser to version 8 or higher.");
} else {
detachMessege();
reSize();
// EVENT LISTENERS
VMM.bindEvent($slider, onSliderLoaded, "LOADED");
VMM.bindEvent($navigation, onTimeNavLoaded, "LOADED");
VMM.bindEvent($slider, onSlideUpdate, "UPDATE");
VMM.bindEvent($navigation, onMarkerUpdate, "UPDATE");
// INITIALIZE COMPONENTS
slider.init(_dates);
timenav.init(_dates, data.era);
// RESIZE EVENT LISTENERS
VMM.bindEvent(global, reSize, config.events.resize);
}
};
function ie7Build() {
trace("IE7 or lower");
for(var i = 0; i < _dates.length; i++) {
trace(_dates[i]);
/*
var st = VMM.Date.prettyDate(data.startdate);
var en = VMM.Date.prettyDate(data.enddate);
var tag = "";
if (data.tag != null && data.tag != "") {
tag = VMM.createElement("span", data.tag, "slide-tag");
}
if (st != en) {
c.text += VMM.createElement("h2", st + " — " + en + tag, "date");
} else {
c.text += VMM.createElement("h2", st + tag, "date");
}
*/
}
};
function updateSize() {
trace("UPDATE SIZE");
config.width = VMM.Lib.width($timeline);
config.height = VMM.Lib.height($timeline);
config.nav.width = config.width;
config.feature.width = config.width;
if (VMM.Browser.device == "mobile") {
//config.feature.height = config.height;
} else {
//config.feature.height = config.height - config.nav.height - 3;
}
config.feature.height = config.height - config.nav.height - 3;
};
// BUILD DATE OBJECTS
function buildDates() {
_dates = [];
VMM.fireEvent(global, config.events.messege, "Building Dates");
updateSize();
for(var i = 0; i < data.date.length; i++) {
if (data.date[i].startDate != null && data.date[i].startDate != "") {
var _date = {};
// START DATE
if (data.date[i].type == "tweets") {
_date.startdate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].startDate);
} else {
_date.startdate = VMM.Date.parse(data.date[i].startDate);
}
if (!isNaN(_date.startdate)) {
// END DATE
if (data.date[i].endDate != null && data.date[i].endDate != "") {
if (data.date[i].type == "tweets") {
_date.enddate = VMM.ExternalAPI.twitter.parseTwitterDate(data.date[i].endDate);
} else {
_date.enddate = VMM.Date.parse(data.date[i].endDate);
}
} else {
_date.enddate = _date.startdate;
}
_date.needs_slug = false;
if (data.date[i].headline == "") {
if (data.date[i].slug != null && data.date[i].slug != "") {
_date.needs_slug = true;
}
}
_date.title = data.date[i].headline;
_date.headline = data.date[i].headline;
_date.type = data.date[i].type;
_date.date = VMM.Date.prettyDate(_date.startdate);
_date.asset = data.date[i].asset;
_date.fulldate = _date.startdate.getTime();
_date.text = data.date[i].text;
_date.content = "";
_date.tag = data.date[i].tag;
_date.slug = data.date[i].slug;
_date.uniqueid = VMM.Util.unique_ID(7);
_dates.push(_date);
}
}
};
/* CUSTOM SORT
================================================== */
if (data.type != "storify") {
_dates.sort(function(a, b){
return a.fulldate - b.fulldate
});
}
/* CREATE START PAGE IF AVAILABLE
================================================== */
if (data.headline != null && data.headline != "" && data.text != null && data.text != "") {
trace("HAS STARTPAGE");
var _date = {}, td_num = 0, td;
td = _dates[0].startdate;
_date.startdate = new Date(_dates[0].startdate);
if (td.getMonth() === 0 && td.getDate() == 1 && td.getHours() === 0 && td.getMinutes() === 0 ) {
// trace("YEAR ONLY");
_date.startdate.setFullYear(td.getFullYear() - 1);
} else if (td.getDate() <= 1 && td.getHours() === 0 && td.getMinutes() === 0) {
// trace("YEAR MONTH");
_date.startdate.setMonth(td.getMonth() - 1);
} else if (td.getHours() === 0 && td.getMinutes() === 0) {
// trace("YEAR MONTH DAY");
_date.startdate.setDate(td.getDate() - 1);
} else if (td.getMinutes() === 0) {
// trace("YEAR MONTH DAY HOUR");
_date.startdate.setHours(td.getHours() - 1);
} else {
// trace("YEAR MONTH DAY HOUR MINUTE");
_date.startdate.setMinutes(td.getMinutes() - 1);
}
_date.uniqueid = VMM.Util.unique_ID(7);
_date.enddate = _date.startdate;
_date.title = data.headline;
_date.headline = data.headline;
_date.text = data.text;
_date.type = "start";
_date.date = VMM.Date.prettyDate(data.startDate);
_date.asset = data.asset;
_date.slug = false;
_date.needs_slug = false;
_date.fulldate = _date.startdate.getTime();
if (config.embed) {
VMM.fireEvent(global, config.events.headline, _date.headline);
}
_dates.unshift(_date);
}
/* CUSTOM SORT
================================================== */
if (data.type != "storify") {
_dates.sort(function(a, b){
return a.fulldate - b.fulldate
});
}
onDatesProcessed();
}
};
VMM.Timeline.Config = {};
};
/***********************************************
Begin VMM.Timeline.TimeNav.js
***********************************************/
/* TimeNav
This class handles the bottom timeline navigation.
It requires the VMM.Util class and VMM.Date class
================================================== */
if(typeof VMM.Timeline != 'undefined' && typeof VMM.Timeline.TimeNav == 'undefined') {
VMM.Timeline.TimeNav = function(parent, content_width, content_height) {
trace("VMM.Timeline.TimeNav");
var $timenav, $content, $time, $timeintervalminor, $timeinterval, $timeintervalmajor, $timebackground,
$timeintervalbackground, $timenavline, $timenavindicator, $timeintervalminor_minor, $toolbar, $zoomin, $zoomout, $dragslide,
config = VMM.Timeline.Config,
row_height,
events = {},
timespan = {},
layout = parent,
data = [],
era_markers = [],
markers = [],
interval_array = [],
interval_major_array = [],
tags = [],
current_marker = 0,
_active = false,
eras,
content,
timeouts = {
interval_position: ""
},
timenav_pos = {
left: "",
visible: {
left: "",
right: ""
}
},
timelookup = {
day: 24,
month: 12,
year: 10,
hour: 60,
minute: 60,
second: 1000,
decade: 10,
century: 100,
millenium: 1000,
age: 1000000,
epoch: 10000000,
era: 100000000,
eon: 500000000,
week: 4.34812141,
days_in_month: 30.4368499,
days_in_week: 7,
weeks_in_month: 4.34812141,
weeks_in_year: 52.177457,
days_in_year: 365.242199,
hours_in_day: 24
},
dateFractionBrowser = {
day: 86400000,
week: 7,
month: 30.4166666667,
year: 12,
hour: 24,
minute: 1440,
second: 86400,
decade: 10,
century: 100,
millenium: 1000,
age: 1000000,
epoch: 10000000,
era: 100000000,
eon: 500000000
},
interval = {
type: "year",
number: 10,
first: 1970,
last: 2011,
multiplier: 100,
classname: "_idd",
interval_type: "interval"
},
interval_major = {
type: "year",
number: 10,
first: 1970,
last: 2011,
multiplier: 100,
classname: "major",
interval_type: "interval major"
},
interval_macro = {
type: "year",
number: 10,
first: 1970,
last: 2011,
multiplier: 100,
classname: "_dd_minor",
interval_type: "interval minor"
},
interval_calc = {
day: {},
month: {},
year: {},
hour: {},
minute: {},
second: {},
decade: {},
century: {},
millenium: {},
week: {},
age: {},
epoch: {},
era: {},
eon: {}
};
/* ADD to Config
================================================== */
row_height = config.nav.marker.height/2;
config.nav.rows = {
full: [1, row_height*2, row_height*4],
half: [1, row_height, row_height*2, row_height*3, row_height*4, row_height*5],
current: []
}
if (content_width != null && content_width != "") {
config.nav.width = content_width;
}
if (content_height != null && content_height != "") {
config.nav.height = content_height;
}
/* INIT
================================================== */
this.init = function(d,e) {
trace('VMM.Timeline.TimeNav init');
// need to evaluate d
// some function to determine type of data and prepare it
if(typeof d != 'undefined') {
this.setData(d, e);
} else {
trace("WAITING ON DATA");
}
};
/* GETTERS AND SETTERS
================================================== */
this.setData = function(d,e) {
if(typeof d != 'undefined') {
data = {};
data = d;
eras = e;
build();
} else{
trace("NO DATA");
}
};
this.setSize = function(w, h) {
if (w != null) {config.width = w};
if (h != null) {config.height = h};
if (_active) {
reSize();
}
}
this.setMarker = function(n, ease, duration, fast) {
goToMarker(n, ease, duration);
}
this.getCurrentNumber = function() {
return current_marker;
}
/* ON EVENT
================================================== */
function onConfigSet() {
trace("onConfigSet");
};
function reSize(firstrun) {
config.nav.constraint.left = (config.width/2);
config.nav.constraint.right = config.nav.constraint.right_min - (config.width/2);
$dragslide.updateConstraint(config.nav.constraint);
VMM.Lib.css($timenavline, "left", Math.round(config.width/2)+2);
VMM.Lib.css($timenavindicator, "left", Math.round(config.width/2)-8);
goToMarker(config.current_slide, config.ease, config.duration, true, firstrun);
};
function upDate() {
VMM.fireEvent(layout, "UPDATE");
}
function onZoomIn() {
$dragslide.cancelSlide();
if (config.nav.multiplier.current > config.nav.multiplier.min) {
if (config.nav.multiplier.current <= 1) {
config.nav.multiplier.current = config.nav.multiplier.current - .25;
} else {
if (config.nav.multiplier.current > 5) {
if (config.nav.multiplier.current > 16) {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 10);
} else {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 4);
}
} else {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current - 1);
}
}
if (config.nav.multiplier.current <= 0) {
config.nav.multiplier.current = config.nav.multiplier.min;
}
refreshTimeline();
}
}
function onZoomOut() {
$dragslide.cancelSlide();
if (config.nav.multiplier.current < config.nav.multiplier.max) {
if (config.nav.multiplier.current > 4) {
if (config.nav.multiplier.current > 16) {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 10);
} else {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 4);
}
} else {
config.nav.multiplier.current = Math.round(config.nav.multiplier.current + 1);
}
if (config.nav.multiplier.current >= config.nav.multiplier.max) {
config.nav.multiplier.current = config.nav.multiplier.max;
}
refreshTimeline();
}
}
function onBackHome(e) {
$dragslide.cancelSlide();
goToMarker(0);
upDate();
}
function onMouseScroll(e) {
var delta = 0,
scroll_to = 0;
if (!e) {
e = window.event;
}
if (e.originalEvent) {
e = e.originalEvent;
}
if (e.wheelDelta) {
delta = e.wheelDelta/6;
} else if (e.detail) {
delta = -e.detail*12;
}
if (delta) {
if (e.preventDefault) {
e.preventDefault();
}
e.returnValue = false;
}
// Webkit
if (typeof e.wheelDeltaX != 'undefined' ) {
delta = e.wheelDeltaY/6;
if (Math.abs(e.wheelDeltaX) > Math.abs(e.wheelDeltaY)) {
delta = e.wheelDeltaX/6;
} else {
delta = e.wheelDeltaY/6;
}
}
// Stop from scrolling too far
scroll_to = VMM.Lib.position($timenav).left + delta;
if (scroll_to > config.nav.constraint.left) {
scroll_to = config.width/2;
} else if (scroll_to < config.nav.constraint.right) {
scroll_to = config.nav.constraint.right;
}
VMM.Lib.stop($timenav);
//VMM.Lib.animate($timenav, config.duration/2, "linear", {"left": scroll_to});
VMM.Lib.css($timenav, "left", scroll_to);
}
var refreshTimeline = function() {
trace("config.nav.multiplier " + config.nav.multiplier.current);
positionMarkers(true);
positionEras(true);
positionInterval($timeinterval, interval_array, true, true);
positionInterval($timeintervalmajor, interval_major_array, true);
config.nav.constraint.left = (config.width/2);
config.nav.constraint.right = config.nav.constraint.right_min - (config.width/2);
$dragslide.updateConstraint(config.nav.constraint);
};
/* MARKER EVENTS
================================================== */
function onMarkerClick(e) {
$dragslide.cancelSlide();
goToMarker(e.data.number);
upDate();
};
function onMarkerHover(e) {
VMM.Lib.toggleClass(e.data.elem, "zFront");
};
var goToMarker = function(n, ease, duration, fast, firstrun) {
var _ease = config.ease,
_duration = config.duration,
is_last = false,
is_first = false;
current_marker = n;
timenav_pos.left = (config.width/2) - VMM.Lib.position(markers[current_marker].marker).left;
timenav_pos.visible.left = Math.abs(timenav_pos.left) - 100;
timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width + 100;
if (current_marker == 0) {
is_first = true;
}
if (current_marker +1 == markers.length) {
is_last = true
}
if (ease != null && ease != "") {_ease = ease};
if (duration != null && duration != "") {_duration = duration};
// set marker style
for(var i = 0; i < markers.length; i++) {
VMM.Lib.removeClass(markers[i].marker, "active");
}
if (config.start_page && markers[0].type == "start") {
VMM.Lib.visible(markers[0].marker, false);
VMM.Lib.addClass(markers[0].marker, "start");
}
VMM.Lib.addClass(markers[current_marker].marker, "active");
// ANIMATE MARKER
VMM.Lib.stop($timenav);
VMM.Lib.animate($timenav, _duration, _ease, {"left": timenav_pos.left});
}
/* TOUCH EVENTS
================================================== */
function onTouchUpdate(e, b) {
VMM.Lib.animate($timenav, b.time/2, config.ease, {"left": b.left});
};
/* CALCULATIONS
================================================== */
var averageMarkerPositionDistance = function() {
var last_pos = 0,
pos = 0,
pos_dif = 0,
mp_diff = [],
i = 0;
for(i = 0; i < markers.length; i++) {
if (data[i].type == "start") {
} else {
var _pos = positionOnTimeline(interval, markers[i].relative_pos),
last_pos = pos;
pos = _pos.begin;
pos_dif = pos - last_pos;
mp_diff.push(pos_dif);
}
}
return VMM.Util.average(mp_diff).mean;
}
var averageDateDistance = function() {
var last_dd = 0,
dd = 0,
_dd = "",
date_dif = 0,
date_diffs = [],
is_first_date = true,
i = 0;
for(i = 0; i < data.length; i++) {
if (data[i].type == "start") {
trace("DATA DATE IS START")
} else {
_dd = data[i].startdate;
last_dd = dd;
dd = _dd;
date_dif = dd - last_dd;
date_diffs.push(date_dif);
}
}
return VMM.Util.average(date_diffs);
}
var calculateMultiplier = function() {
var temp_multiplier = config.nav.multiplier.current,
i = 0;
for(i = 0; i < temp_multiplier; i++) {
if (averageMarkerPositionDistance() < 75) {
if (config.nav.multiplier.current > 1) {
config.nav.multiplier.current = (config.nav.multiplier.current - 1);
}
}
}
}
var calculateInterval = function() {
// NEED TO REWRITE ALL OF THIS
var _first = getDateFractions(data[0].startdate),
_last = getDateFractions(data[data.length - 1].enddate);
// EON
interval_calc.eon.type = "eon";
interval_calc.eon.first = _first.eons;
interval_calc.eon.base = Math.floor(_first.eons);
interval_calc.eon.last = _last.eons;
interval_calc.eon.number = timespan.eons;
interval_calc.eon.multiplier = timelookup.eons;
interval_calc.eon.minor = timelookup.eons;
// ERA
interval_calc.era.type = "era";
interval_calc.era.first = _first.eras;
interval_calc.era.base = Math.floor(_first.eras);
interval_calc.era.last = _last.eras;
interval_calc.era.number = timespan.eras;
interval_calc.era.multiplier = timelookup.eras;
interval_calc.era.minor = timelookup.eras;
// EPOCH
interval_calc.epoch.type = "epoch";
interval_calc.epoch.first = _first.epochs;
interval_calc.epoch.base = Math.floor(_first.epochs);
interval_calc.epoch.last = _last.epochs;
interval_calc.epoch.number = timespan.epochs;
interval_calc.epoch.multiplier = timelookup.epochs;
interval_calc.epoch.minor = timelookup.epochs;
// AGE
interval_calc.age.type = "age";
interval_calc.age.first = _first.ages;
interval_calc.age.base = Math.floor(_first.ages);
interval_calc.age.last = _last.ages;
interval_calc.age.number = timespan.ages;
interval_calc.age.multiplier = timelookup.ages;
interval_calc.age.minor = timelookup.ages;
// MILLENIUM
interval_calc.millenium.type = "millenium";
interval_calc.millenium.first = _first.milleniums;
interval_calc.millenium.base = Math.floor(_first.milleniums);
interval_calc.millenium.last = _last.milleniums;
interval_calc.millenium.number = timespan.milleniums;
interval_calc.millenium.multiplier = timelookup.millenium;
interval_calc.millenium.minor = timelookup.millenium;
// CENTURY
interval_calc.century.type = "century";
interval_calc.century.first = _first.centuries;
interval_calc.century.base = Math.floor(_first.centuries);
interval_calc.century.last = _last.centuries;
interval_calc.century.number = timespan.centuries;
interval_calc.century.multiplier = timelookup.century;
interval_calc.century.minor = timelookup.century;
// DECADE
interval_calc.decade.type = "decade";
interval_calc.decade.first = _first.decades;
interval_calc.decade.base = Math.floor(_first.decades);
interval_calc.decade.last = _last.decades;
interval_calc.decade.number = timespan.decades;
interval_calc.decade.multiplier = timelookup.decade;
interval_calc.decade.minor = timelookup.decade;
// YEAR
interval_calc.year.type = "year";
interval_calc.year.first = _first.years;
interval_calc.year.base = Math.floor(_first.years);
interval_calc.year.last = _last.years;
interval_calc.year.number = timespan.years;
interval_calc.year.multiplier = 1;
interval_calc.year.minor = timelookup.month;
// MONTH
interval_calc.month.type = "month";
interval_calc.month.first = _first.months;
interval_calc.month.base = Math.floor(_first.months);
interval_calc.month.last = _last.months;
interval_calc.month.number = timespan.months;
interval_calc.month.multiplier = 1;
interval_calc.month.minor = Math.round(timelookup.week);
// WEEK
// NOT DONE
interval_calc.week.type = "week";
interval_calc.week.first = _first.weeks;
interval_calc.week.base = Math.floor(_first.weeks);
interval_calc.week.last = _last.weeks;
interval_calc.week.number = timespan.weeks;
interval_calc.week.multiplier = 1;
interval_calc.week.minor = 7;
// DAY
interval_calc.day.type = "day";
interval_calc.day.first = _first.days;
interval_calc.day.base = Math.floor(_first.days);
interval_calc.day.last = _last.days;
interval_calc.day.number = timespan.days;
interval_calc.day.multiplier = 1;
interval_calc.day.minor = 24;
// HOUR
interval_calc.hour.type = "hour";
interval_calc.hour.first = _first.hours;
interval_calc.hour.base = Math.floor(_first.hours);
interval_calc.hour.last = _last.hours;
interval_calc.hour.number = timespan.hours;
interval_calc.hour.multiplier = 1;
interval_calc.hour.minor = 60;
// MINUTE
interval_calc.minute.type = "minute";
interval_calc.minute.first = _first.minutes;
interval_calc.minute.base = Math.floor(_first.minutes);
interval_calc.minute.last = _last.minutes;
interval_calc.minute.number = timespan.minutes;
interval_calc.minute.multiplier = 1;
interval_calc.minute.minor = 60;
// SECOND
interval_calc.second.type = "decade";
interval_calc.second.first = _first.seconds;
interval_calc.second.base = Math.floor(_first.seconds);
interval_calc.second.last = _last.seconds;
interval_calc.second.number = timespan.seconds;
interval_calc.second.multiplier = 1;
interval_calc.second.minor = 10;
}
var getDateFractions = function(the_date, is_utc) {
var _time = {};
_time.days = the_date / dateFractionBrowser.day;
_time.weeks = _time.days / dateFractionBrowser.week;
_time.months = _time.days / dateFractionBrowser.month;
_time.years = _time.months / dateFractionBrowser.year;
_time.hours = _time.days * dateFractionBrowser.hour;
_time.minutes = _time.days * dateFractionBrowser.minute;
_time.seconds = _time.days * dateFractionBrowser.second;
_time.decades = _time.years / dateFractionBrowser.decade;
_time.centuries = _time.years / dateFractionBrowser.century;
_time.milleniums = _time.years / dateFractionBrowser.millenium;
_time.ages = _time.years / dateFractionBrowser.age;
_time.epochs = _time.years / dateFractionBrowser.epoch;
_time.eras = _time.years / dateFractionBrowser.era;
_time.eons = _time.years / dateFractionBrowser.eon;
/*
trace("AGES " + _time.ages);
trace("EPOCHS " + _time.epochs);
trace("MILLENIUMS " + _time.milleniums);
trace("CENTURIES " + _time.centuries);
trace("DECADES " + _time.decades);
trace("YEARS " + _time.years);
trace("MONTHS " + _time.months);
trace("WEEKS " + _time.weeks);
trace("DAYS " + _time.days);
trace("HOURS " + _time.hours);
trace("MINUTES " + _time.minutes);
trace("SECONDS " + _time.seconds);
*/
return _time;
}
/* POSITION
Positions elements on the timeline based on date
relative to the calculated interval
================================================== */
var positionRelative = function(_interval, first, last) {
var _first,
_last,
_type = _interval.type,
timerelative = {
start: "",
end: "",
type: _type
};
/* FIRST
================================================== */
_first = getDateFractions(first);
timerelative.start = first.months;
if (_type == "eon") {
timerelative.start = _first.eons;
} else if (_type == "era") {
timerelative.start = _first.eras;
} else if (_type == "epoch") {
timerelative.start = _first.epochs;
} else if (_type == "age") {
timerelative.start = _first.ages;
} else if (_type == "millenium") {
timerelative.start = first.milleniums;
} else if (_type == "century") {
timerelative.start = _first.centuries;
} else if (_type == "decade") {
timerelative.start = _first.decades;
} else if (_type == "year") {
timerelative.start = _first.years;
} else if (_type == "month") {
timerelative.start = _first.months;
} else if (_type == "week") {
timerelative.start = _first.weeks;
} else if (_type == "day") {
timerelative.start = _first.days;
} else if (_type == "hour") {
timerelative.start = _first.hours;
} else if (_type == "minute") {
timerelative.start = _first.minutes;
}
/* LAST
================================================== */
if (type.of(last) == "date") {
_last = getDateFractions(last);
timerelative.end = last.months;
if (_type == "eon") {
timerelative.end = _last.eons;
} else if (_type == "era") {
timerelative.end = _last.eras;
} else if (_type == "epoch") {
timerelative.end = _last.epochs;
} else if (_type == "age") {
timerelative.end = _last.ages;
} else if (_type == "millenium") {
timerelative.end = last.milleniums;
} else if (_type == "century") {
timerelative.end = _last.centuries;
} else if (_type == "decade") {
timerelative.end = _last.decades;
} else if (_type == "year") {
timerelative.end = _last.years;
} else if (_type == "month") {
timerelative.end = _last.months;
} else if (_type == "week") {
timerelative.end = _last.weeks;
} else if (_type == "day") {
timerelative.end = _last.days;
} else if (_type == "hour") {
timerelative.end = _last.hours;
} else if (_type == "minute") {
timerelative.end = _last.minutes;
}
} else {
timerelative.end = timerelative.start;
}
return timerelative
}
var positionOnTimeline = function(the_interval, timerelative) {
return {
begin: (timerelative.start - interval.base) * (config.nav.interval_width / config.nav.multiplier.current),
end: (timerelative.end - interval.base) * (config.nav.interval_width / config.nav.multiplier.current)
};
}
var positionMarkers = function(is_animated) {
var row = 2,
previous_pos = 0,
pos_offset = -2,
row_depth = 0,
row_depth_sub = 0,
line_last_height_pos = 150,
line_height = 6,
cur_mark = 0,
in_view_margin = config.width,
pos_cache_array = [],
pos_cache_max = 6,
in_view = {
left: timenav_pos.visible.left - in_view_margin,
right: timenav_pos.visible.right + in_view_margin
},
i = 0,
k = 0;
config.nav.minor_width = config.width;
VMM.Lib.removeClass(".flag", "row1");
VMM.Lib.removeClass(".flag", "row2");
VMM.Lib.removeClass(".flag", "row3");
for(i = 0; i < markers.length; i++) {
var line,
marker = markers[i],
pos = positionOnTimeline(interval, markers[i].relative_pos),
row_pos = 0,
is_in_view = false,
pos_cache_obj = {id: i, pos: 0, row: 0},
pos_cache_close = 0;
// COMPENSATE FOR DATES BEING POITIONED IN THE MIDDLE
pos.begin = Math.round(pos.begin + pos_offset);
pos.end = Math.round(pos.end + pos_offset);
line = Math.round(pos.end - pos.begin);
if (current_marker == i) {
timenav_pos.left = (config.width/2) - pos;
timenav_pos.visible.left = Math.abs(timenav_pos.left);
timenav_pos.visible.right = Math.abs(timenav_pos.left) + config.width;
in_view.left = timenav_pos.visible.left - in_view_margin;
in_view.right = timenav_pos.visible.right + in_view_margin;
}
if (Math.abs(pos.begin) >= in_view.left && Math.abs(pos.begin) <= in_view.right ) {
is_in_view = true;
}
// APPLY POSITION TO MARKER
if (is_animated) {
VMM.Lib.stop(marker.marker);
VMM.Lib.animate(marker.marker, config.duration/2, config.ease, {"left": pos.begin});
} else {
VMM.Lib.stop(marker.marker);
VMM.Lib.css(marker.marker, "left", pos.begin);
}
if (i == current_marker) {
cur_mark = pos.begin;
}
// EVENT LENGTH LINE
if (line > 5) {
VMM.Lib.css(marker.lineevent, "height", line_height);
VMM.Lib.css(marker.lineevent, "top", line_last_height_pos);
if (is_animated) {
VMM.Lib.animate(marker.lineevent, config.duration/2, config.ease, {"width": line});
} else {
VMM.Lib.css(marker.lineevent, "width", line);
}
}
// CONTROL ROW POSITION
if (tags.length > 0) {
for (k = 0; k < tags.length; k++) {
if (k < config.nav.rows.current.length) {
if (marker.tag == tags[k]) {
row = k;
if (k == config.nav.rows.current.length - 1) {
trace("ON LAST ROW");
VMM.Lib.addClass(marker.flag, "flag-small-last");
}
}
}
}
row_pos = config.nav.rows.current[row];
} else {
if (pos.begin - previous_pos.begin < (config.nav.marker.width + config.spacing)) {
if (row < config.nav.rows.current.length - 1) {
row ++;
} else {
row = 0;
row_depth ++;
}
} else {
row_depth = 1;
row = 1;
}
row_pos = config.nav.rows.current[row];
}
// SET LAST MARKER POSITION
previous_pos = pos;
// POSITION CACHE
pos_cache_obj.pos = pos;
pos_cache_obj.row = row;
pos_cache_array.push(pos_cache_obj);
if (pos_cache_array.length > pos_cache_max) {
pos_cache_array.remove(0);
}
//if (is_animated && is_in_view) {
if (is_animated) {
VMM.Lib.stop(marker.flag);
VMM.Lib.animate(marker.flag, config.duration, config.ease, {"top": row_pos});
} else {
VMM.Lib.stop(marker.flag);
VMM.Lib.css(marker.flag, "top", row_pos);
}
// IS THE MARKER A REPRESENTATION OF A START SCREEN?
if (config.start_page && markers[i].type == "start") {
VMM.Lib.visible(marker.marker, false);
}
if (pos > config.nav.minor_width) {
config.nav.minor_width = pos;
}
if (pos < config.nav.minor_left) {
config.nav.minor_left = pos;
}
}
// ANIMATE THE TIMELINE TO ADJUST TO CHANGES
VMM.Lib.stop($timenav);
VMM.Lib.animate($timenav, config.duration/2, config.ease, {"left": (config.width/2) - (cur_mark)});
//VMM.Lib.delay_animate(config.duration, $timenav, config.duration/2, config.ease, {"left": (config.width/2) - (cur_mark)});
}
var positionEras = function(is_animated) {
var i = 0,
p = 0;
for(i = 0; i < era_markers.length; i++) {
var era = era_markers[i],
pos = positionOnTimeline(interval, era.relative_pos),
row_pos = 0,
era_height = config.nav.marker.height * config.nav.rows.full.length,
era_length = pos.end - pos.begin;
// CONTROL ROW POSITION
if (era.tag != "") {
era_height = (config.nav.marker.height * config.nav.rows.full.length) / config.nav.rows.current.length;
for (p = 0; p < tags.length; p++) {
if (p < config.nav.rows.current.length) {
if (era.tag == tags[p]) {
row = p;
}
}
}
row_pos = config.nav.rows.current[row];
} else {
row_pos = -1;
}
// APPLY POSITION TO MARKER
if (is_animated) {
VMM.Lib.stop(era.content);
VMM.Lib.stop(era.text_content);
VMM.Lib.animate(era.content, config.duration/2, config.ease, {"top": row_pos, "left": pos.begin, "width": era_length, "height":era_height});
VMM.Lib.animate(era.text_content, config.duration/2, config.ease, {"left": pos.begin});
} else {
VMM.Lib.stop(era.content);
VMM.Lib.stop(era.text_content);
VMM.Lib.css(era.content, "left", pos.begin);
VMM.Lib.css(era.content, "width", era_length);
VMM.Lib.css(era.content, "height", era_height);
VMM.Lib.css(era.content, "top", row_pos);
VMM.Lib.css(era.text_content, "left", pos.begin);
}
}
}
var positionInterval = function(the_main_element, the_intervals, is_animated, is_minor) {
var last_position = 0,
last_position_major = 0,
//in_view_margin = (config.nav.minor_width/config.nav.multiplier.current)/2,
in_view_margin = config.width,
in_view = {
left: timenav_pos.visible.left - in_view_margin,
right: timenav_pos.visible.right + in_view_margin
}
not_too_many = true,
i = 0;
config.nav.minor_left = 0;
if (the_intervals.length > 100) {
not_too_many = false;
trace("TOO MANY " + the_intervals.length);
}
for(i = 0; i < the_intervals.length; i++) {
var _interval = the_intervals[i].element,
_interval_date = the_intervals[i].date,
_interval_visible = the_intervals[i].visible,
_pos = positionOnTimeline(interval, the_intervals[i].relative_pos),
pos = _pos.begin,
_animation = the_intervals[i].animation,
is_visible = true,
is_in_view = false,
pos_offset = 50;
_animation.pos = pos;
_animation.animate = false;
if (Math.abs(pos) >= in_view.left && Math.abs(pos) <= in_view.right ) {
is_in_view = true;
}
if (true) {
// CONDENSE WHAT IS DISPLAYED
if (config.nav.multiplier.current > 16 && is_minor) {
is_visible = false;
} else {
if ((pos - last_position) < 65 ) {
if ((pos - last_position) < 35 ) {
if (i%4 == 0) {
if (pos == 0) {
is_visible = false;
}
} else {
is_visible = false;
}
} else {
if (!VMM.Util.isEven(i)) {
is_visible = false;
}
}
}
}
if (is_visible) {
if (the_intervals[i].is_detached) {
VMM.Lib.append(the_main_element, _interval);
the_intervals[i].is_detached = false;
}
} else {
the_intervals[i].is_detached = true;
VMM.Lib.detach(_interval);
}
if (_interval_visible) {
if (!is_visible) {
_animation.opacity = "0";
if (is_animated && not_too_many) {
_animation.animate = true;
}
the_intervals[i].interval_visible = false;
} else {
_animation.opacity = "100";
if (is_animated && is_in_view) {
_animation.animate = true;
}
}
} else {
_animation.opacity = "100";
if (is_visible) {
if (is_animated && not_too_many) {
_animation.animate = true;
} else {
if (is_animated && is_in_view) {
_animation.animate = true;
}
}
the_intervals[i].interval_visible = true;
} else {
if (is_animated && not_too_many) {
_animation.animate = true;
}
}
}
last_position = pos;
if (pos > config.nav.minor_width) {
config.nav.minor_width = pos;
}
if (pos < config.nav.minor_left) {
config.nav.minor_left = pos;
}
}
if (_animation.animate) {
VMM.Lib.animate(_interval, config.duration/2, config.ease, {opacity: _animation.opacity, left: _animation.pos});
} else {
VMM.Lib.css(_interval, "opacity", _animation.opacity);
VMM.Lib.css(_interval, "left", pos);
}
}
config.nav.constraint.right_min = -(config.nav.minor_width)+(config.width);
config.nav.constraint.right = config.nav.constraint.right_min + (config.width/2);
VMM.Lib.css($timeintervalminor_minor, "left", config.nav.minor_left - (config.width)/2);
VMM.Lib.width($timeintervalminor_minor, (config.nav.minor_width)+(config.width) + Math.abs(config.nav.minor_left) );
}
/* Interval Elements
================================================== */
var createIntervalElements = function(_interval, _array, _element_parent) {
var inc_time = 0,
_first_run = true,
_last_pos = 0,
_largest_pos = 0,
_timezone_offset,
_first_date,
_last_date,
int_number = Math.ceil(_interval.number) + 2,
firefox = {
flag: false,
offset: 0
},
i = 0;
VMM.attachElement(_element_parent, "");
_interval.date = new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0);
_timezone_offset = _interval.date.getTimezoneOffset();
for(i = 0; i < int_number; i++) {
trace(_interval.type);
var _is_year = false,
int_obj = {
element: VMM.appendAndGetElement(_element_parent, "
", _interval.classname),
date: new Date(data[0].startdate.getFullYear(), 0, 1, 0,0,0),
visible: false,
date_string: "",
type: _interval.interval_type,
relative_pos: 0,
is_detached: false,
animation: {
animate: false,
pos: "",
opacity: "100"
}
};
if (_interval.type == "eon") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 500000000) * 500000000;
}
int_obj.date.setFullYear(_first_date + (inc_time * 500000000));
_is_year = true;
} else if (_interval.type == "era") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 100000000) * 100000000;
}
int_obj.date.setFullYear(_first_date + (inc_time * 100000000));
_is_year = true;
} else if (_interval.type == "epoch") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 10000000) * 10000000
}
int_obj.date.setFullYear(_first_date + (inc_time * 10000000));
_is_year = true;
} else if (_interval.type == "age") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 1000000) * 1000000
}
int_obj.date.setFullYear(_first_date + (inc_time * 1000000));
_is_year = true;
} else if (_interval.type == "millenium") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 1000) * 1000;
}
int_obj.date.setFullYear(_first_date + (inc_time * 1000));
_is_year = true;
} else if (_interval.type == "century") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 100) * 100
}
int_obj.date.setFullYear(_first_date + (inc_time * 100));
_is_year = true;
} else if (_interval.type == "decade") {
if (_first_run) {
_first_date = Math.floor(data[0].startdate.getFullYear() / 10) * 10;
}
int_obj.date.setFullYear(_first_date + (inc_time * 10));
_is_year = true;
} else if (_interval.type == "year") {
if (_first_run) {
_first_date = data[0].startdate.getFullYear();
}
int_obj.date.setFullYear(_first_date + inc_time);
_is_year = true;
} else if (_interval.type == "month") {
if (_first_run) {
_first_date = data[0].startdate.getMonth();
}
int_obj.date.setMonth(_first_date + inc_time);
} else if (_interval.type == "week") {
if (_first_run) {
_first_date = data[0].startdate.getMonth();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(_first_date + (inc_time * 7) );
} else if (_interval.type == "day") {
if (_first_run) {
_first_date = data[0].startdate.getDate();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(_first_date + inc_time);
} else if (_interval.type == "hour") {
if (_first_run) {
_first_date = data[0].startdate.getHours();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(data[0].startdate.getDate());
int_obj.date.setHours(_first_date + inc_time);
} else if (_interval.type == "minute") {
if (_first_run) {
_first_date = data[0].startdate.getMinutes();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(data[0].startdate.getDate());
int_obj.date.setHours(data[0].startdate.getHours());
int_obj.date.setMinutes(_first_date + inc_time);
} else if (_interval.type == "second") {
if (_first_run) {
_first_date = data[0].startdate.getSeconds();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(data[0].startdate.getDate());
int_obj.date.setHours(data[0].startdate.getHours());
int_obj.date.setMinutes(data[0].startdate.getMinutes());
int_obj.date.setSeconds(_first_date + inc_time);
} else if (_interval.type == "millisecond") {
if (_first_run) {
_first_date = data[0].startdate.getMilliseconds();
}
int_obj.date.setMonth(data[0].startdate.getMonth());
int_obj.date.setDate(data[0].startdate.getDate());
int_obj.date.setHours(data[0].startdate.getHours());
int_obj.date.setMinutes(data[0].startdate.getMinutes());
int_obj.date.setSeconds(data[0].startdate.getSeconds());
int_obj.date.setMilliseconds(_first_date + inc_time);
}
// FIX WEIRD FIREFOX BUG FOR GMT TIME FORMATTING
if (VMM.Browser.browser == "Firefox") {
if (int_obj.date.getFullYear() == "1970" && int_obj.date.getTimezoneOffset() != _timezone_offset) {
trace("FIREFOX 1970 TIMEZONE OFFSET " + int_obj.date.getTimezoneOffset() + " SHOULD BE " + _timezone_offset);
trace(_interval.type + " " + _interval.date);
// try and fix firefox bug, if not the flag will catch it
firefox.offset = (int_obj.date.getTimezoneOffset()/60);
firefox.flag = true;
int_obj.date.setHours(int_obj.date.getHours() + firefox.offset );
} else if (firefox.flag) {
// catch the bug the second time around
firefox.flag = false;
int_obj.date.setHours(int_obj.date.getHours() + firefox.offset );
if (_is_year) {
firefox.flag = true;
}
}
}
if (_is_year) {
if ( int_obj.date.getFullYear() < 0 ) {
int_obj.date_string = Math.abs( int_obj.date.getFullYear() ).toString() + " B.C.";
} else {
int_obj.date_string = int_obj.date.getFullYear();
}
} else {
int_obj.date_string = VMM.Date.prettyDate(int_obj.date, true);
}
// Increment Time
inc_time = inc_time + 1;
// No longer first run
_first_run = false;
int_obj.relative_pos = positionRelative(interval, int_obj.date);
_last_pos = int_obj.relative_pos.begin;
if (int_obj.relative_pos.begin > _largest_pos) {
_largest_pos = int_obj.relative_pos.begin;
}
// Add the time string to the element and position it.
VMM.appendElement(int_obj.element, int_obj.date_string);
VMM.Lib.css(int_obj.element, "text-indent", -(VMM.Lib.width(int_obj.element)/2));
VMM.Lib.css(int_obj.element, "opacity", "0");
// add the interval element to the array
_array.push(int_obj);
}
VMM.Lib.width($timeintervalminor_minor, _largest_pos);
positionInterval(_element_parent, _array);
}
/* BUILD
================================================== */
var build = function() {
var i = 0,
j = 0;
VMM.attachElement(layout, "");
$timenav = VMM.appendAndGetElement(layout, "
", "timenav");
$content = VMM.appendAndGetElement($timenav, "
", "content");
$time = VMM.appendAndGetElement($timenav, "
", "time");
$timeintervalminor = VMM.appendAndGetElement($time, "
", "time-interval-minor");
$timeintervalminor_minor = VMM.appendAndGetElement($timeintervalminor, "
", "minor");
$timeintervalmajor = VMM.appendAndGetElement($time, "
", "time-interval-major");
$timeinterval = VMM.appendAndGetElement($time, "
", "time-interval");
$timebackground = VMM.appendAndGetElement(layout, "
", "timenav-background");
$timenavline = VMM.appendAndGetElement($timebackground, "
", "timenav-line");
$timenavindicator = VMM.appendAndGetElement($timebackground, "
", "timenav-indicator");
$timeintervalbackground = VMM.appendAndGetElement($timebackground, "
", "timenav-interval-background", "
");
$toolbar = VMM.appendAndGetElement(layout, "
", "toolbar");
buildInterval();
buildMarkers();
buildEras();
calculateMultiplier();
positionMarkers();
positionEras();
positionInterval($timeinterval, interval_array, false, true);
positionInterval($timeintervalmajor, interval_major_array);
if (config.start_page) {
$backhome = VMM.appendAndGetElement($toolbar, "
", "back-home", "
");
VMM.bindEvent(".back-home", onBackHome, "click");
VMM.Lib.css($toolbar, "top", 27);
VMM.Lib.attribute($backhome, "title", VMM.master_config.language.messages.return_to_title);
VMM.Lib.attribute($backhome, "rel", "tooltip");
}
$zoomin = VMM.appendAndGetElement($toolbar, "
", "zoom-in", "
");
$zoomout = VMM.appendAndGetElement($toolbar, "
", "zoom-out", "
");
// MAKE TIMELINE DRAGGABLE/TOUCHABLE
$dragslide = new VMM.DragSlider;
$dragslide.createPanel(layout, $timenav, config.nav.constraint, config.touch);
// ZOOM EVENTS
VMM.bindEvent($zoomin, onZoomIn, "click");
VMM.bindEvent($zoomout, onZoomOut, "click");
if (!config.touch) {
// TOOLTIP
VMM.Lib.attribute($zoomin, "title", VMM.master_config.language.messages.expand_timeline);
VMM.Lib.attribute($zoomin, "rel", "tooltip");
VMM.Lib.attribute($zoomout, "title", VMM.master_config.language.messages.contract_timeline);
VMM.Lib.attribute($zoomout, "rel", "tooltip");
$toolbar.tooltip({selector: "div[rel=tooltip]", placement: "right"});
// MOUSE EVENTS
VMM.bindEvent(layout, onMouseScroll, 'DOMMouseScroll');
VMM.bindEvent(layout, onMouseScroll, 'mousewheel');
}
VMM.fireEvent(layout, "LOADED");
_active = true;
reSize(true);
// USER CONFIGURABLE ADJUSTMENT TO DEFAULT ZOOM
if (config.nav.zoom.adjust != 0) {
if (config.nav.zoom.adjust < 0) {
for(i = 0; i < Math.abs(config.nav.zoom.adjust); i++) {
onZoomOut();
}
} else {
for(j = 0; j < config.nav.zoom.adjust; j++) {
onZoomIn();
}
}
}
};
var buildInterval = function() {
var i = 0,
j = 0;
// CALCULATE INTERVAL
timespan = getDateFractions((data[data.length - 1].enddate) - (data[0].startdate), true);
trace(timespan);
calculateInterval();
/* DETERMINE DEFAULT INTERVAL TYPE
millenium, ages, epoch, era and eon are not working yet
================================================== */
/*
if (timespan.eons > data.length / config.nav.density) {
interval = interval_calc.eon;
interval_major = interval_calc.eon;
interval_macro = interval_calc.era;
} else if (timespan.eras > data.length / config.nav.density) {
interval = interval_calc.era;
interval_major = interval_calc.eon;
interval_macro = interval_calc.epoch;
} else if (timespan.epochs > data.length / config.nav.density) {
interval = interval_calc.epoch;
interval_major = interval_calc.era;
interval_macro = interval_calc.age;
} else if (timespan.ages > data.length / config.nav.density) {
interval = interval_calc.ages;
interval_major = interval_calc.epoch;
interval_macro = interval_calc.millenium;
} else if (timespan.milleniums > data.length / config.nav.density) {
interval = interval_calc.millenium;
interval_major = interval_calc.age;
interval_macro = interval_calc.century;
} else
*/
if (timespan.centuries > data.length / config.nav.density) {
interval = interval_calc.century;
interval_major = interval_calc.millenium;
interval_macro = interval_calc.decade;
} else if (timespan.decades > data.length / config.nav.density) {
interval = interval_calc.decade;
interval_major = interval_calc.century;
interval_macro = interval_calc.year;
} else if (timespan.years > data.length / config.nav.density) {
interval = interval_calc.year;
interval_major = interval_calc.decade;
interval_macro = interval_calc.month;
} else if (timespan.months > data.length / config.nav.density) {
interval = interval_calc.month;
interval_major = interval_calc.year;
interval_macro = interval_calc.day;
} else if (timespan.days > data.length / config.nav.density) {
interval = interval_calc.day;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
} else if (timespan.hours > data.length / config.nav.density) {
interval = interval_calc.hour;
interval_major = interval_calc.day;
interval_macro = interval_calc.minute;
} else if (timespan.minutes > data.length / config.nav.density) {
interval = interval_calc.minute;
interval_major = interval_calc.hour;
interval_macro = interval_calc.second;
} else if (timespan.seconds > data.length / config.nav.density) {
interval = interval_calc.second;
interval_major = interval_calc.minute;
interval_macro = interval_calc.second;
} else {
trace("NO IDEA WHAT THE TYPE SHOULD BE");
interval = interval_calc.day;
interval_major = interval_calc.month;
interval_macro = interval_calc.hour;
}
trace("INTERVAL TYPE: " + interval.type);
trace("INTERVAL MAJOR TYPE: " + interval_major.type);
createIntervalElements(interval, interval_array, $timeinterval);
createIntervalElements(interval_major, interval_major_array, $timeintervalmajor);
// Cleanup duplicate interval elements between normal and major
for(i = 0; i < interval_array.length; i++) {
for(j = 0; j < interval_major_array.length; j++) {
if (interval_array[i].date_string == interval_major_array[j].date_string) {
VMM.attachElement(interval_array[i].element, "");
}
}
}
}
var buildMarkers = function() {
var row = 2,
lpos = 0,
row_depth = 0,
i = 0,
k = 0,
l = 0;
markers = [];
era_markers = [];
for(i = 0; i < data.length; i++) {
var _marker,
_marker_flag,
_marker_content,
_marker_dot,
_marker_line,
_marker_line_event,
_marker_obj,
_marker_title = "",
has_title = false;
_marker = VMM.appendAndGetElement($content, "
", "marker");
_marker_flag = VMM.appendAndGetElement(_marker, "
", "flag");
_marker_content = VMM.appendAndGetElement(_marker_flag, "
", "flag-content");
_marker_dot = VMM.appendAndGetElement(_marker, "
", "dot");
_marker_line = VMM.appendAndGetElement(_marker, "
", "line");
_marker_line_event = VMM.appendAndGetElement(_marker_line, "
", "event-line");
_marker_relative_pos = positionRelative(interval, data[i].startdate, data[i].enddate);
_marker_thumb = "";
// THUMBNAIL
if (data[i].asset != null && data[i].asset != "") {
VMM.appendElement(_marker_content, VMM.MediaElement.thumbnail(data[i].asset, 24, 24, data[i].uniqueid));
} else {
VMM.appendElement(_marker_content, "
");
}
// ADD DATE AND TITLE
if (data[i].title == "" || data[i].title == " " ) {
trace("TITLE NOTHING")
if (typeof data[i].slug != 'undefined' && data[i].slug != "") {
trace("SLUG")
_marker_title = VMM.Util.untagify(data[i].slug);
has_title = true;
} else {
var m = VMM.MediaType(data[i].asset.media);
if (m.type == "quote" || m.type == "unknown") {
_marker_title = VMM.Util.untagify(m.id);
has_title = true;
} else if (m.type == "twitter") {
has_title = false;
VMM.appendElement(_marker_content, "
" + _marker_title + "
");
} else {
has_title = false;
}
}
} else if (data[i].title != "" || data[i].title != " ") {
trace(data[i].title)
_marker_title = VMM.Util.untagify(data[i].title);
has_title = true;
} else {
trace("TITLE SLUG NOT FOUND " + data[i].slug)
}
if (has_title) {
VMM.appendElement(_marker_content, "
" + _marker_title + "
");
}
// ADD ID
VMM.Lib.attr(_marker, "id", ( "marker_" + data[i].uniqueid).toString() );
// MARKER CLICK
VMM.bindEvent(_marker_flag, onMarkerClick, "", {number: i});
VMM.bindEvent(_marker_flag, onMarkerHover, "mouseenter mouseleave", {number: i, elem:_marker_flag});
_marker_obj = {
marker: _marker,
flag: _marker_flag,
lineevent: _marker_line_event,
type: "marker",
full: true,
relative_pos: _marker_relative_pos,
tag: data[i].tag
};
if (data[i].type == "start") {
trace("BUILD MARKER HAS START PAGE");
config.start_page = true;
_marker_obj.type = "start";
}
if (data[i].type == "storify") {
_marker_obj.type = "storify";
}
if (data[i].tag) {
tags.push(data[i].tag);
}
markers.push(_marker_obj);
}
// CREATE TAGS
tags = VMM.Util.deDupeArray(tags);
if (tags.length > 3) {
config.nav.rows.current = config.nav.rows.half;
} else {
config.nav.rows.current = config.nav.rows.full;
}
for(k = 0; k < tags.length; k++) {
if (k < config.nav.rows.current.length) {
var tag_element = VMM.appendAndGetElement($timebackground, "
", "timenav-tag");
VMM.Lib.addClass(tag_element, "timenav-tag-row-" + (k+1));
if (tags.length > 3) {
VMM.Lib.addClass(tag_element, "timenav-tag-size-half");
} else {
VMM.Lib.addClass(tag_element, "timenav-tag-size-full");
}
VMM.appendElement(tag_element, "
" + tags[k] + "
");
}
}
// RESIZE FLAGS IF NEEDED
if (tags.length > 3) {
for(l = 0; l < markers.length; l++) {
VMM.Lib.addClass(markers[l].flag, "flag-small");
markers[l].full = false;
}
}
}
var buildEras = function() {
var number_of_colors = 6,
current_color = 0,
j = 0;
// CREATE ERAS
for(j = 0; j < eras.length; j++) {
var era = {
content: VMM.appendAndGetElement($content, "
", "era"),
text_content: VMM.appendAndGetElement($timeinterval, "
", "era"),
startdate: VMM.Date.parse(eras[j].startDate),
enddate: VMM.Date.parse(eras[j].endDate),
title: eras[j].headline,
uniqueid: VMM.Util.unique_ID(6),
tag: "",
relative_pos: ""
},
st = VMM.Date.prettyDate(era.startdate),
en = VMM.Date.prettyDate(era.enddate),
era_text = "
";
if (typeof eras[j].tag != "undefined") {
era.tag = eras[j].tag;
}
era.relative_pos = positionRelative(interval, era.startdate, era.enddate);
VMM.Lib.attr(era.content, "id", era.uniqueid);
VMM.Lib.attr(era.text_content, "id", era.uniqueid + "_text");
// Background Color
VMM.Lib.addClass(era.content, "era"+(current_color+1));
VMM.Lib.addClass(era.text_content, "era"+(current_color+1));
if (current_color < number_of_colors) {
current_color++;
} else {
current_color = 0;
}
VMM.appendElement(era.content, era_text);
VMM.appendElement(era.text_content, VMM.Util.unlinkify(era.title));
era_markers.push(era);
}
}
};
}
/***********************************************
Begin VMM.Timeline.DataObj.js
***********************************************/
/* 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 {
trace("DATA SOURCE: JSON");
VMM.getJSON(raw_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");
}
},
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 = VMM.Util.getUrlVars(raw)["key"];
var _url = "https://spreadsheets.google.com/feeds/list/" + _key + "/od6/public/values?alt=json";
VMM.getJSON(_url, VMM.Timeline.DataObj.model.googlespreadsheet.buildData);
},
buildData: function(d) {
VMM.fireEvent(global, VMM.Timeline.Config.events.messege, "Parsing Data");
var _data_obj = VMM.Timeline.DataObj.data_template_obj;
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 = dd.gsx$startdate.$t;
_data_obj.timeline.headline = dd.gsx$headline.$t;
_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.text = dd.gsx$text.$t;
_data_obj.timeline.type = "google spreadsheet";
} else if (dd_type.match("era")) {
var _era = {
"startDate": dd.gsx$startdate.$t,
"endDate": dd.gsx$enddate.$t,
"headline": dd.gsx$headline.$t,
"text": dd.gsx$text.$t,
"tag": ""
};
if (typeof dd.gsx$tag != 'undefined') {
_era.tag = dd.gsx$tag.$t;
}
_data_obj.timeline.era.push(_era);
} else {
var _date = {
"type": "google spreadsheet",
"startDate": dd.gsx$startdate.$t,
"endDate": dd.gsx$enddate.$t,
"headline": dd.gsx$headline.$t,
"text": dd.gsx$text.$t,
"asset": {
"media": dd.gsx$media.$t,
"credit": dd.gsx$mediacredit.$t,
"caption": dd.gsx$mediacaption.$t
},
"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);
}
};
VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj);
}
},
storify: {
getData: function(raw) {
//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...");
var _key = raw.split("storify.com\/")[1];
var _url = "http://api.storify.com/v1/stories/" + _key + "?per_page=300&callback=?";
var 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 += "
";
_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": ""
}
};
/* MEDIA
================================================== */
if (dd.type == "image") {
if (typeof dd.source.name != 'undefined') {
if (dd.source.name == "flickr") {
_date.asset.media = "http://flickr.com/photos/" + dd.meta.pathalias + "/" + dd.meta.id + "/";
_date.asset.credit = "
" + dd.attribution.name + "";
_date.asset.credit += " on
" + dd.source.name + "";
} else if (dd.source.name == "instagram") {
_date.asset.media = dd.permalink;
_date.asset.credit = "
" + dd.attribution.name + "";
_date.asset.credit += " on
" + dd.source.name + "";
} else {
_date.asset.credit = "
" + dd.attribution.name + "";
if (typeof dd.source.href != 'undefined') {
_date.asset.credit += " on
" + dd.source.name + "";
}
_date.asset.media = dd.data.image.src;
}
} else {
_date.asset.credit = "
" + dd.attribution.name + "";
_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 = "
" + 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 += "
" + dd.data.text.replace(/<\s*\/?\s*b\s*.*?>/g,"") + "
";
//asset_text += "
" + "" + " ";
asset_text += "
";
_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 + " (
" + "@" + d.tweetdata[i].raw.from_user + ")" ;
} else {
_date.headline = d.tweetdata[i].raw.user.name + " (
" + "@" + d.tweetdata[i].raw.user.screen_name + ")" ;
}
_date.asset.media = d.tweetdata[i].content;
_data_obj.timeline.date.push(_date);
};
VMM.fireEvent(global, VMM.Timeline.Config.events.data_ready, _data_obj);
}
}
},
/* TEMPLATE OBJECTS
================================================== */
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"}
};
}