diff --git a/source/js/VMM.js b/source/js/VMM.js index 6ec4060..f28f30a 100644 --- a/source/js/VMM.js +++ b/source/js/VMM.js @@ -296,7 +296,7 @@ if (typeof VMM == 'undefined') { }; // VMM.getJSON(url, the_function); - VMM.getJSON = function(url, the_function) { + VMM.getJSON = function(url, data, callback) { if( typeof( jQuery ) != 'undefined' ){ /* CHECK FOR IE AND USE Use Microsoft XDR @@ -307,7 +307,7 @@ if (typeof VMM == 'undefined') { if (ie_url.match('^http://')){ //ie_url = ie_url.replace("http://","//"); - $.getJSON(url, the_function); + $.getJSON(url, data); } else if (ie_url.match('^https://')) { ie_url = ie_url.replace("https://","http://"); var xdr = new XDomainRequest(); @@ -319,7 +319,9 @@ if (typeof VMM == 'undefined') { xdr.send(); } } else { - $.getJSON(url, the_function); + //$.getJSON(url, data); + return jQuery.getJSON(url, data, callback); + } } @@ -1295,11 +1297,11 @@ if (typeof VMM == 'undefined') { // CREDIT if (data.credit != null && data.credit != "") { - creditElem = "
"; - var td = VMM.Util.linkify(d.text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); - //twit += VMM.Util.linkify(d.text); + var td = VMM.Util.linkify_with_twitter(d.text, "_blank"); twit += td; twit += "
"; @@ -1582,7 +1574,10 @@ if (typeof VMM == 'undefined') { var the_tweets = {tweetdata: tweetArray} VMM.fireEvent(global, "TWEETSLOADED", the_tweets); } - }); + }) + .success(function() { trace("second success"); }) + .error(function() { trace("error"); }) + .complete(function() { trace("complete"); }); } @@ -1591,8 +1586,6 @@ if (typeof VMM == 'undefined') { // VMM.ExternalAPI.twitter.getTweetSearch(search string); getTweetSearch: function(tweets, number_of_tweets) { - - var _number_of_tweets = 40; if (number_of_tweets != null && number_of_tweets != "") { _number_of_tweets = number_of_tweets; @@ -1607,9 +1600,7 @@ if (typeof VMM == 'undefined') { for(var i = 0; i < d.results.length; i++) { var tweet = {} var twit = ""; @@ -1624,32 +1615,51 @@ if (typeof VMM == 'undefined') { }, // VMM.ExternalAPI.twitter.prettyHTML(id); prettyHTML: function(id) { - - // https://api.twitter.com/1/statuses/show.json?id=164165553810976768&include_entities=true&callback=? + var id = id.toString(); + var error_obj = { + twitterid: id + }; var the_url = "http://api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?"; - VMM.getJSON(the_url, VMM.ExternalAPI.twitter.formatJSON); + trace("id " + id); + var twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.notFoundError, 4000, id); + VMM.getJSON(the_url, VMM.ExternalAPI.twitter.formatJSON) + .error(function(jqXHR, textStatus, errorThrown) { + trace("TWITTER error"); + trace("TWITTER ERROR: " + textStatus + " " + qXHR.responseText); + VMM.attachElement("#twitter_"+id, ""; - var td = VMM.Util.linkify(d.results[i].text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); + 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() { + clearTimeout(twitter_timeout); + }); + + }, + + notFoundError: function(id) { + trace("TWITTER JSON ERROR TIMEOUT " + id); + VMM.attachElement("#twitter_" + id, "TWEET NOT FOUND " + id + "
" ); }, formatJSON: function(d) { trace("TWITTER JSON LOADED F"); + trace(d); var id = d.id_str; var twit = ""; - twit += " " + "" + " "; + twit += " " + "" + " "; twit += " "; - VMM.attachElement("#"+id, twit ); + VMM.attachElement("#twitter_"+id.toString(), twit ); } diff --git a/source/js/timeline.js b/source/js/timeline.js index 34cdc55..7801628 100755 --- a/source/js/timeline.js +++ b/source/js/timeline.js @@ -1,5 +1,5 @@ /*! - Verite Timeline 0.88 + Open Timeline 0.88 Designed and built by Zach Wise digitalartwork.net Date: April 8, 2012 @@ -40,7 +40,7 @@ // @codekit-prepend "VMM.LoadLib.js"; // @codekit-prepend "bootstrap-tooltip.js"; -/* Timeline Class contained in VMM (verite) namespace +/* Open Timeline Class contained in VMM (verite) namespace ================================================== */ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { @@ -333,14 +333,14 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if (d.type == "tweets") { } else if (dd.type == "start") { - c._text += VMM.createElement("h2", d.headline, "start"); + c._text += VMM.createElement("h2", VMM.Util.linkify_with_twitter(d.headline, "_blank"), "start"); } else { - c._text += VMM.createElement("h3", d.headline); + c._text += VMM.createElement("h3", VMM.Util.linkify_with_twitter(d.headline, "_blank")); } } if (d.text != null && d.text != "") { _hastext = true; - c._text += VMM.createElement("p", d.text); + c._text += VMM.createElement("p", VMM.Util.linkify_with_twitter(d.text, "_blank")); } c._text = VMM.createElement("div", c._text, "container"); diff --git a/timeline.js b/timeline.js index d62f060..b9f22fe 100644 --- a/timeline.js +++ b/timeline.js @@ -296,7 +296,7 @@ if (typeof VMM == 'undefined') { }; // VMM.getJSON(url, the_function); - VMM.getJSON = function(url, the_function) { + VMM.getJSON = function(url, data, callback) { if( typeof( jQuery ) != 'undefined' ){ /* CHECK FOR IE AND USE Use Microsoft XDR @@ -307,7 +307,7 @@ if (typeof VMM == 'undefined') { if (ie_url.match('^http://')){ //ie_url = ie_url.replace("http://","//"); - $.getJSON(url, the_function); + $.getJSON(url, data); } else if (ie_url.match('^https://')) { ie_url = ie_url.replace("https://","http://"); var xdr = new XDomainRequest(); @@ -319,7 +319,9 @@ if (typeof VMM == 'undefined') { xdr.send(); } } else { - $.getJSON(url, the_function); + //$.getJSON(url, data); + return jQuery.getJSON(url, data, callback); + } } @@ -1295,11 +1297,11 @@ if (typeof VMM == 'undefined') { // CREDIT if (data.credit != null && data.credit != "") { - creditElem = ""; - var td = VMM.Util.linkify(d.text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); + 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 += "
" + data.credit + ""; + creditElem = "" + VMM.Util.linkify_with_twitter(data.credit, "_blank") + ""; } // CAPTION if (data.caption != null && data.caption != "") { - captionElem = " "; + captionElem = " "; } // MEDIA TYPE @@ -1327,7 +1329,7 @@ if (typeof VMM == 'undefined') { } else if (m.type == "vimeo") { mediaElem = ""; } else if (m.type == "twitter"){ - mediaElem = "Loading Tweet"; + mediaElem = "Loading Tweet"; //VMM.ExternalAPI.twitter.getHTML(m.id); trace("TWITTER"); VMM.ExternalAPI.twitter.prettyHTML(m.id); @@ -1505,16 +1507,9 @@ if (typeof VMM == 'undefined') { onJSONLoaded: function(d) { trace("TWITTER JSON LOADED"); var id = 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.attachElement("#"+id, VMM.Util.linkify_with_twitter(d.html) ); }, + // VMM.ExternalAPI.twitter.parseTwitterDate(date); parseTwitterDate: function(d) { var date = new Date(Date.parse(d)); @@ -1561,10 +1556,7 @@ if (typeof VMM == 'undefined') { /* FORMAT RESPONSE ================================================== */ var twit = ""; - var td = VMM.Util.linkify(d.text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); - //twit += VMM.Util.linkify(d.text); + var td = VMM.Util.linkify_with_twitter(d.text, "_blank"); twit += td; twit += "
"; @@ -1582,7 +1574,10 @@ if (typeof VMM == 'undefined') { var the_tweets = {tweetdata: tweetArray} VMM.fireEvent(global, "TWEETSLOADED", the_tweets); } - }); + }) + .success(function() { trace("second success"); }) + .error(function() { trace("error"); }) + .complete(function() { trace("complete"); }); } @@ -1591,8 +1586,6 @@ if (typeof VMM == 'undefined') { // VMM.ExternalAPI.twitter.getTweetSearch(search string); getTweetSearch: function(tweets, number_of_tweets) { - - var _number_of_tweets = 40; if (number_of_tweets != null && number_of_tweets != "") { _number_of_tweets = number_of_tweets; @@ -1607,9 +1600,7 @@ if (typeof VMM == 'undefined') { for(var i = 0; i < d.results.length; i++) { var tweet = {} var twit = ""; @@ -1624,32 +1615,51 @@ if (typeof VMM == 'undefined') { }, // VMM.ExternalAPI.twitter.prettyHTML(id); prettyHTML: function(id) { - - // https://api.twitter.com/1/statuses/show.json?id=164165553810976768&include_entities=true&callback=? + var id = id.toString(); + var error_obj = { + twitterid: id + }; var the_url = "http://api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?"; - VMM.getJSON(the_url, VMM.ExternalAPI.twitter.formatJSON); + trace("id " + id); + var twitter_timeout = setTimeout(VMM.ExternalAPI.twitter.notFoundError, 4000, id); + VMM.getJSON(the_url, VMM.ExternalAPI.twitter.formatJSON) + .error(function(jqXHR, textStatus, errorThrown) { + trace("TWITTER error"); + trace("TWITTER ERROR: " + textStatus + " " + qXHR.responseText); + VMM.attachElement("#twitter_"+id, ""; - var td = VMM.Util.linkify(d.results[i].text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); + 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() { + clearTimeout(twitter_timeout); + }); + + }, + + notFoundError: function(id) { + trace("TWITTER JSON ERROR TIMEOUT " + id); + VMM.attachElement("#twitter_" + id, "TWEET NOT FOUND " + id + "
" ); }, formatJSON: function(d) { trace("TWITTER JSON LOADED F"); + trace(d); var id = d.id_str; var twit = ""; - twit += " " + "" + " "; + twit += " " + "" + " "; twit += " "; - VMM.attachElement("#"+id, twit ); + VMM.attachElement("#twitter_"+id.toString(), twit ); } @@ -3238,25 +3248,45 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { // VMM.Util.linkify(); linkify: function(text,targets,is_touch) { - if(!text) return text; + // http://, https://, ftp:// + var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim; + + // www. sans http:// or https:// + var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim; + + // Email addresses + var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim; - text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url) { - var nice = url; - var _touch = ""; - if(url.search('^https?:\/\/') < 0) url = 'http://'+url; - _touch = "onclick = 'void(0)'"; - if(is_touch) { - _touch = "onclick = 'void(0)'"; - } - - onclick = "void(0)"; - if(targets === null || targets === "") return ''+ url +''; - else return "'" + url + "" ; - }); + return text + .replace(urlPattern, "$&") + .replace(pseudoUrlPattern, "$1$2") + .replace(emailAddressPattern, "$1"); + }, + + linkify_with_twitter: function(text,targets,is_touch) { - return text; + // http://, https://, ftp:// + var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim; + + // www. sans http:// or https:// + var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim; + + // Email addresses + var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim; + + var twitterHandlePattern = /(@([\w]+))/g; + + var twitterSearchPattern = /(#([\w]+))/g; + + return text + .replace(urlPattern, "$&") + .replace(pseudoUrlPattern, "$1$2") + .replace(emailAddressPattern, "$1") + .replace(twitterHandlePattern, "$1") + .replace(twitterSearchPattern, "$1"); }, + /* Turns plain text links into real links ================================================== */ // VMM.Util.unlinkify(); @@ -3449,6 +3479,32 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') { }).init(); + //'string'.linkify(); + if(!String.linkify) { + String.prototype.linkify = function() { + + // http://, https://, ftp:// + var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim; + + // www. sans http:// or https:// + var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim; + + // Email addresses + var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim; + + var twitterHandlePattern = /(@([\w]+))/g; + + var twitterSearchPattern = /(#([\w]+))/g; + + return this + .replace(urlPattern, '$&') + .replace(pseudoUrlPattern, '$1$2') + .replace(emailAddressPattern, '$1') + .replace(twitterHandlePattern, "$1") + .replace(twitterSearchPattern, "$1"); + }; + } + } /*********************************************** @@ -3984,7 +4040,7 @@ if(typeof VMM != 'undefined' && typeof VMM.LoadLib == 'undefined') { ***********************************************/ /*! - Verite Timeline 0.88 + Open Timeline 0.88 Designed and built by Zach Wise digitalartwork.net Date: April 8, 2012 @@ -4025,7 +4081,7 @@ if(typeof VMM != 'undefined' && typeof VMM.LoadLib == 'undefined') { // @codekit-prepend "VMM.LoadLib.js"; // @codekit-prepend "bootstrap-tooltip.js"; -/* Timeline Class contained in VMM (verite) namespace +/* Open Timeline Class contained in VMM (verite) namespace ================================================== */ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { @@ -4318,14 +4374,14 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') { if (d.type == "tweets") { } else if (dd.type == "start") { - c._text += VMM.createElement("h2", d.headline, "start"); + c._text += VMM.createElement("h2", VMM.Util.linkify_with_twitter(d.headline, "_blank"), "start"); } else { - c._text += VMM.createElement("h3", d.headline); + c._text += VMM.createElement("h3", VMM.Util.linkify_with_twitter(d.headline, "_blank")); } } if (d.text != null && d.text != "") { _hastext = true; - c._text += VMM.createElement("p", d.text); + c._text += VMM.createElement("p", VMM.Util.linkify_with_twitter(d.text, "_blank")); } c._text = VMM.createElement("div", c._text, "container");"; - var td = VMM.Util.linkify(d.text); - td = td.replace(/(@([\w]+))/g,"$1"); - td = td.replace(/(#([\w]+))/g,"$1"); + 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 += "