/*!
Verite Timeline 0.85
Designed and built by Zach Wise digitalartwork.net
Date: March 30, 2012
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/
*/
/*!
TODO
-
-
FUTURE PLANS
- Better iPhone usability
- Support feeds from popular sources
- Storify integration
- Code optimization
- Clean up config flow
- Possible tagging of events (depends on usability factors)
*/
/* CodeKit Import
================================================== */
/* 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;
};
})();
/* CLASS EXTEND EXAMPLE
================================================== */
/*
var Person = Class.extend({
init: function(isDancing){
this.dancing = isDancing;
},
dance: function(){
return this.dancing;
}
});
var Ninja = Person.extend({
init: function(){
this._super( false );
},
dance: function(){
// Call the inherited version of dance()
return this._super();
},
swingSword: function(){
return true;
}
});
var p = new Person(true);
p.dance(); // => true
var n = new Ninja();
n.dance(); // => false
n.swingSword(); // => true
// Should all be true
p instanceof Person && p instanceof Class &&
n instanceof Ninja && n instanceof Person && n instanceof 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({
});
/* Master Config
================================================== */
//VMM.master_config.youtube_array
VMM.master_config = ({
init: function() {
return this;
},
youtube: {
active: false,
array: [],
api_loaded:false
},
}).init();
VMM.master_config = ({
init: function() {
return this;
},
youtube: {
active: false,
array: [],
api_loaded:false,
que: []
},
}).init();
/* Abstract out DOM element creation to make independent of library
================================================== */
//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 += " " + 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 += "
";
if (media != null && media != "") {
valid = true;
ce += "";
// CREDIT
if (credit != null && credit != "") {
ce += VMM.createElement("div", credit, "credit");
}
// CAPTION
if (caption != null && caption != "") {
ce += VMM.createElement("div", caption, "caption");
}
}
ce += "
";
VMM.ExternalAPI.soundcloud.getSound(m.id, soundcloud_id)
} else if (m.type == "google-map") {
mediaElem = ""
} else if (m.type == "unknown") {
trace("NO KNOWN MEDIA TYPE FOUND TRYING TO JUST PLACE THE HTML");
mediaElem = VMM.Util.properQuotes(m.id);
} else if (m.type == "website") {
mediaElem = ""
} else {
trace("NO KNOWN MEDIA TYPE FOUND");
trace(m.type);
}
// WRAP THE MEDIA ELEMENT
mediaElem = "
" + mediaElem + creditElem + captionElem + "
";
if (_return) {
if (isTextMedia) {
return "
" + mediaElem + "
";
} else {
return "
" + mediaElem + "
";
}
} else {
VMM.appendElement($mediacontainer, mediaElem);
VMM.appendElement($mediacontainer, creditElem);
VMM.appendElement($mediacontainer, captionElem);
}
};
},
}).init();
//VMM.mediaType.youtube(d); //should return a true or false
// VMM.MediaType(url); //returns an object with .type and .id
VMM.MediaType = function(d) {
var success = false;
var media = {};
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('embed')) {
youtube_id = d.split(/embed\//)[1].split('"')[0];
} else {
youtube_id = d.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
}
//youtube_id = d.split(/v\/|v=|youtu\.be\//)[1].split(/[?&]/)[0];
media.type = "youtube";
media.id = youtube_id;
success = true;
} else if (d.match('(player.)?vimeo\.com')) {
//vimeo_id = d.split(/video\/|http:\/\/vimeo\.com\//)[1].split(/[?&]/)[0];
vimeo_id = d.split(/video\/|\/\/vimeo\.com\//)[1].split(/[?&]/)[0];
media.type = "vimeo";
media.id = vimeo_id;
success = true;
} else if (d.match('(player.)?soundcloud\.com')) {
//soundcloud_url = unescape(d.split(/value="/)[1].split(/["]/)[0]);
//soundcloud_id = soundcloud_url.split(/tracks\//)[1].split(/[&"]/)[0];
media.type = "soundcloud";
media.id = d;
success = true;
} else if (d.match('(www.)?twitter\.com')) {
trace("TWITTER MATCH");
// https://twitter.com/#!/twitterapi/statuses/133640144317198338
// https://twitter.com/#!/DeliciousHot/status/23189589820702720
if (d.match("status\/")) {
twitter_id = d.split("status\/")[1];
} else if (d.match("statuses\/")) {
twitter_id = d.split("statuses\/")[1];
} else {
twitter_id = "";
}
media.type = "twitter";
media.id = twitter_id;
success = true;
} else if (d.match("maps.google.com")) {
//maps.google.com
media.type = "google-map";
media.id = d.split(/src=['|"][^'|"]*?['|"]/gi);
trace("google map " + media.id);
success = true;
} else if (d.match("flickr.com/photos")) {
media.type = "flickr";
//media.id = d.split('/photos/[^/]+/([0-9]+)/gi');
media.id = d.split("photos\/")[1].split("/")[1];
//media.id = media.id.split("/")[1];
trace("FLICKR " + media.id);
success = true;
} else if (d.match(/jpg|jpeg|png|gif/i)) {
media.type = "image";
media.id = d;
success = true;
} else if (d.indexOf('http://') == 0) {
media.type = "website";
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;
}
VMM.Keys = {
flickr: "6d6f59d8d30d79f4f402a7644d5073e3",
}
VMM.ExternalAPI = {
twitter: {
tweetArray: [],
// VMM.ExternalAPI.twitter.getHTML(id);
getHTML: function(id) {
var the_url = "https://api.twitter.com/1/statuses/oembed.json?id=" + id+ "&callback=?";
VMM.getJSON(the_url, function(d) {
VMM.ExternalAPI.twitter.onJSONLoaded(d, id);
});
},
onJSONLoaded: function(d, id) {
VMM.attachElement("#"+id, VMM.ExternalAPI.twitter.linkify(d.html) );
},
//somestring = VMM.ExternalAPI.twitter.linkify(d);
linkify: function(d) {
return d.replace(/[@]+[A-Za-z0-9-_]+/g, function(u) {
var username = u.replace("@","");
return u.link("http://twitter.com/"+username);
});
},
// VMM.ExternalAPI.twitter.parseTwitterDate(date);
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.Util.date.prettyDate(date, true);
},
// VMM.ExternalAPI.twitter.getTweets(tweets_array);
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 = "https://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 = "
", "media-container");
if (data.media != null && data.media != "") {
_valid = true;
var m = {};
m = VMM.MediaType(data.media); //returns an object with .type and .id
if (m.type == "image") {
VMM.appendElement($mediacontainer, "");
} else if (m.type == "youtube") {
VMM.appendElement($mediacontainer, "