/*! 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/ */ /*********************************************** Begin VMM.js ***********************************************/ /* VéritéCo JS Master Version: 0.6 Date: June 19, 2012 Copyright 2012 VéritéCo unless part of TimelineJS, if part of TimelineJS then it inherits TimelineJS's license. Designed and built by Zach Wise digitalartwork.net ================================================== */ /* Simple JavaScript Inheritance By John Resig http://ejohn.org/ MIT Licensed. ================================================== */ (function() { var initializing = false, fnTest = /xyz/.test(function() { xyz; }) ? /\b_super\b/: /.*/; // The base Class implementation (does nothing) this.Class = function() {}; // Create a new Class that inherits from this class Class.extend = function(prop) { var _super = this.prototype; // Instantiate a base class (but only create the instance, // don't run the init constructor) initializing = true; var prototype = new this(); initializing = false; // Copy the properties over onto the new prototype for (var name in prop) { // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { return function() { var tmp = this._super; // Add a new ._super() method that is the same method // but on the super-class this._super = _super[name]; // The method only need to be bound temporarily, so we // remove it when we're done executing var ret = fn.apply(this, arguments); this._super = tmp; return ret; }; })(name, prop[name]) : prop[name]; } // The dummy class constructor function Class() { // All construction is actually done in the init method if (!initializing && this.init) this.init.apply(this, arguments); } // Populate our constructed prototype object Class.prototype = prototype; // Enforce the constructor to be what we expect Class.prototype.constructor = Class; // And make this class extendable Class.extend = arguments.callee; return Class; }; })(); /* Access to the Global Object access the global object without hard-coding the identifier window ================================================== */ var global = (function () { return this || (1,eval)('this'); }()); /* VMM ================================================== */ if (typeof VMM == 'undefined') { /* Main Scope Container ================================================== */ //var VMM = {}; var VMM = Class.extend({}); /* Debug ================================================== */ VMM.debug = true; /* Master Config ================================================== */ VMM.master_config = ({ init: function() { return this; }, sizes: { api: { width: 0, height: 0 } }, vp: "Pellentesque nibh felis, eleifend id, commodo in, interdum vitae, leo", api_keys_master: { flickr: "RAIvxHY4hE/Elm5cieh4X5ptMyDpj7MYIxziGxi0WGCcy1s+yr7rKQ==", google: "jwNGnYw4hE9lmAez4ll0QD+jo6SKBJFknkopLS4FrSAuGfIwyj57AusuR0s8dAo=", twitter: "" }, timers: { api: 7000 }, api: { pushques: [] }, twitter: { active: false, array: [], api_loaded: false, que: [] }, flickr: { active: false, array: [], api_loaded: false, que: [] }, youtube: { active: false, array: [], api_loaded: false, que: [] }, vimeo: { active: false, array: [], api_loaded: false, que: [] }, googlemaps: { active: false, map_active: false, places_active: false, array: [], api_loaded: false, que: [] }, googledocs: { active: false, array: [], api_loaded: false, que: [] }, googleplus: { active: false, array: [], api_loaded: false, que: [] }, wikipedia: { active: false, array: [], api_loaded: false, que: [], tries: 0 }, soundcloud: { active: false, array: [], api_loaded: false, que: [] } }).init(); //VMM.createElement(tag, value, cName, attrs, styles); VMM.createElement = function(tag, value, cName, attrs, styles) { var ce = ""; if (tag != null && tag != "") { // TAG ce += "<" + tag; if (cName != null && cName != "") { ce += " class='" + cName + "'"; }; if (attrs != null && attrs != "") { ce += " " + attrs; }; if (styles != null && styles != "") { ce += " style='" + styles + "'"; }; ce += ">"; if (value != null && value != "") { ce += value; } // CLOSE TAG ce = ce + "" + tag + ">"; } return ce; }; VMM.createMediaElement = function(media, caption, credit) { var ce = ""; var _valid = false; ce += "
"; // TWEET MEDIA if (typeof d.entities.media != 'undefined') { if (d.entities.media[0].type == "photo") { //twit += "", td = VMM.Util.linkify_with_twitter(d.text, "_blank"); // TWEET CONTENT twit += td; twit += "
Still waiting on Twitter: " + tweet.mid + "
" ); // CHECK RATE STATUS VMM.getJSON("http://api.twitter.com/1/account/rate_limit_status.json", function(d) { trace("REMAINING TWITTER API CALLS " + d.remaining_hits); trace("TWITTER RATE LIMIT WILL RESET AT " + d.reset_time); var mes = ""; if (d.remaining_hits == 0) { mes = "You've reached the maximum number of tweets you can load in an hour.
"; mes += "You can view tweets again starting at:
" + d.reset_time + "
Still waiting on Twitter. " + id + "
"; //mes = "Tweet " + id + " was not found.
"; } VMM.attachElement("#twitter_" + id, VMM.MediaElement.loadingmessage(mes) ); }); }, pushQue: function() { if (VMM.master_config.twitter.que.length > 0) { VMM.ExternalAPI.twitter.create(VMM.master_config.twitter.que[0], VMM.ExternalAPI.twitter.pushQue); VMM.master_config.twitter.que.remove(0); } }, getHTML: function(id) { //var the_url = document.location.protocol + "//api.twitter.com/1/statuses/oembed.json?id=" + id+ "&callback=?"; var the_url = "http://api.twitter.com/1/statuses/oembed.json?id=" + id+ "&callback=?"; VMM.getJSON(the_url, VMM.ExternalAPI.twitter.onJSONLoaded); }, onJSONLoaded: function(d) { trace("TWITTER JSON LOADED"); var id = d.id; VMM.attachElement("#"+id, VMM.Util.linkify_with_twitter(d.html) ); }, parseTwitterDate: function(d) { var date = new Date(Date.parse(d)); /* var t = d.replace(/(\d{1,2}[:]\d{2}[:]\d{2}) (.*)/, '$2 $1'); t = t.replace(/(\+\S+) (.*)/, '$2 $1'); var date = new Date(Date.parse(t)).toLocaleDateString(); var time = new Date(Date.parse(t)).toLocaleTimeString(); */ return date; }, prettyParseTwitterDate: function(d) { var date = new Date(Date.parse(d)); return VMM.Date.prettyDate(date, true); }, getTweets: function(tweets) { var tweetArray = []; var number_of_tweets = tweets.length; for(var i = 0; i < tweets.length; i++) { var twitter_id = ""; /* FIND THE TWITTER ID ================================================== */ if (tweets[i].tweet.match("status\/")) { twitter_id = tweets[i].tweet.split("status\/")[1]; } else if (tweets[i].tweet.match("statuses\/")) { twitter_id = tweets[i].tweet.split("statuses\/")[1]; } else { twitter_id = ""; } /* FETCH THE DATA ================================================== */ var the_url = "http://api.twitter.com/1/statuses/show.json?id=" + twitter_id + "&include_entities=true&callback=?"; VMM.getJSON(the_url, function(d) { var tweet = {} /* FORMAT RESPONSE ================================================== */ var twit = ""; var td = VMM.Util.linkify_with_twitter(d.text, "_blank"); twit += td; twit += "
"; twit += "— " + d.user.name + " (@" + d.user.screen_name + ") " + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.created_at) + "
"; var td = VMM.Util.linkify_with_twitter(d.results[i].text, "_blank"); twit += td; twit += "
"; twit += "— " + d.results[i].from_user_name + " (@" + d.results[i].from_user + ") " + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.results[i].created_at) + "
ERROR LOADING TWEET " + id + "
" ); }) .success(function(d) { clearTimeout(twitter_timeout); if (secondary) { VMM.ExternalAPI.twitter.secondaryMedia(d); } }); }, formatJSON: function(d) { var id = d.id_str; var twit = ""; //twit += " " + "" + " "; twit += " "; if (typeof d.entities.media != 'undefined') { if (d.entities.media[0].type == "photo") { twit += ""; var td = VMM.Util.linkify_with_twitter(d.text, "_blank"); //td = td.replace(/(@([\w]+))/g,"$1"); //td = td.replace(/(#([\w]+))/g,"$1"); twit += td; twit += "
" + a_data.object.attachments[k].content + "
"; g_attachments += ""; g_attachments += "" + a_data.object.attachments[k].content + "
"; g_attachments += ""; g_attachments += "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(url, id) { var doc = {url: url, id: id}; 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(mid, id, link) { var flick = {mid: mid, id: id, link: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 (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, "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 = "
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(mid, id) { var the_url = "http://gdata.youtube.com/feeds/api/videos/" + mid + "?v=2&alt=jsonc&callback=?", vid = {mid: mid, id: id}; 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) { var p = { active: false, player: {}, name: vid.id, playing: false }; p.player[vid.id] = new YT.Player(vid.id, { height: '390', width: '640', playerVars: { enablejsapi: 1, color: 'white', showinfo: 0, theme: 'light', 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, "" + 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 _valid = true; // CREDIT if (data.credit != null && data.credit != "") { creditElem = "