Browse Source

Twitter API Error handling and better linkification.

pull/33/merge
Zach Wise 13 years ago
parent
commit
994e8fc3db
  1. 76
      source/js/VMM.js
  2. 10
      source/js/timeline.js
  3. 160
      timeline.js

76
source/js/VMM.js

@ -296,7 +296,7 @@ if (typeof VMM == 'undefined') {
}; };
// VMM.getJSON(url, the_function); // VMM.getJSON(url, the_function);
VMM.getJSON = function(url, the_function) { VMM.getJSON = function(url, data, callback) {
if( typeof( jQuery ) != 'undefined' ){ if( typeof( jQuery ) != 'undefined' ){
/* CHECK FOR IE AND USE Use Microsoft XDR /* CHECK FOR IE AND USE Use Microsoft XDR
@ -307,7 +307,7 @@ if (typeof VMM == 'undefined') {
if (ie_url.match('^http://')){ if (ie_url.match('^http://')){
//ie_url = ie_url.replace("http://","//"); //ie_url = ie_url.replace("http://","//");
$.getJSON(url, the_function); $.getJSON(url, data);
} else if (ie_url.match('^https://')) { } else if (ie_url.match('^https://')) {
ie_url = ie_url.replace("https://","http://"); ie_url = ie_url.replace("https://","http://");
var xdr = new XDomainRequest(); var xdr = new XDomainRequest();
@ -319,7 +319,9 @@ if (typeof VMM == 'undefined') {
xdr.send(); xdr.send();
} }
} else { } else {
$.getJSON(url, the_function); //$.getJSON(url, data);
return jQuery.getJSON(url, data, callback);
} }
} }
@ -1295,11 +1297,11 @@ if (typeof VMM == 'undefined') {
// CREDIT // CREDIT
if (data.credit != null && data.credit != "") { if (data.credit != null && data.credit != "") {
creditElem = "<div class='credit'>" + data.credit + "</div>"; creditElem = "<div class='credit'>" + VMM.Util.linkify_with_twitter(data.credit, "_blank") + "</div>";
} }
// CAPTION // CAPTION
if (data.caption != null && data.caption != "") { if (data.caption != null && data.caption != "") {
captionElem = "<div class='caption'>" + data.caption + "</div>"; captionElem = "<div class='caption'>" + VMM.Util.linkify_with_twitter(data.caption, "_blank") + "</div>";
} }
// MEDIA TYPE // MEDIA TYPE
@ -1327,7 +1329,7 @@ if (typeof VMM == 'undefined') {
} else if (m.type == "vimeo") { } else if (m.type == "vimeo") {
mediaElem = "<iframe class='media-frame video vimeo' frameborder='0' width='100%' height='100%' src='http://player.vimeo.com/video/" + m.id + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff'></iframe>"; mediaElem = "<iframe class='media-frame video vimeo' frameborder='0' width='100%' height='100%' src='http://player.vimeo.com/video/" + m.id + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff'></iframe>";
} else if (m.type == "twitter"){ } else if (m.type == "twitter"){
mediaElem = "<div class='twitter' id='" + m.id + "'>Loading Tweet</div>"; mediaElem = "<div class='twitter' id='" + "twitter_" + m.id + "'>Loading Tweet</div>";
//VMM.ExternalAPI.twitter.getHTML(m.id); //VMM.ExternalAPI.twitter.getHTML(m.id);
trace("TWITTER"); trace("TWITTER");
VMM.ExternalAPI.twitter.prettyHTML(m.id); VMM.ExternalAPI.twitter.prettyHTML(m.id);
@ -1505,16 +1507,9 @@ if (typeof VMM == 'undefined') {
onJSONLoaded: function(d) { onJSONLoaded: function(d) {
trace("TWITTER JSON LOADED"); trace("TWITTER JSON LOADED");
var id = d.id; var id = d.id;
VMM.attachElement("#"+id, VMM.ExternalAPI.twitter.linkify(d.html) ); VMM.attachElement("#"+id, VMM.Util.linkify_with_twitter(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); // VMM.ExternalAPI.twitter.parseTwitterDate(date);
parseTwitterDate: function(d) { parseTwitterDate: function(d) {
var date = new Date(Date.parse(d)); var date = new Date(Date.parse(d));
@ -1561,10 +1556,7 @@ if (typeof VMM == 'undefined') {
/* FORMAT RESPONSE /* FORMAT RESPONSE
================================================== */ ================================================== */
var twit = "<div class='twitter'><blockquote><p>"; var twit = "<div class='twitter'><blockquote><p>";
var td = VMM.Util.linkify(d.text); var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>");
//twit += VMM.Util.linkify(d.text);
twit += td; twit += td;
twit += "</p>"; twit += "</p>";
@ -1582,7 +1574,10 @@ if (typeof VMM == 'undefined') {
var the_tweets = {tweetdata: tweetArray} var the_tweets = {tweetdata: tweetArray}
VMM.fireEvent(global, "TWEETSLOADED", the_tweets); 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); // VMM.ExternalAPI.twitter.getTweetSearch(search string);
getTweetSearch: function(tweets, number_of_tweets) { getTweetSearch: function(tweets, number_of_tweets) {
var _number_of_tweets = 40; var _number_of_tweets = 40;
if (number_of_tweets != null && number_of_tweets != "") { if (number_of_tweets != null && number_of_tweets != "") {
_number_of_tweets = 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++) { for(var i = 0; i < d.results.length; i++) {
var tweet = {} var tweet = {}
var twit = "<div class='twitter'><blockquote><p>"; var twit = "<div class='twitter'><blockquote><p>";
var td = VMM.Util.linkify(d.results[i].text); var td = VMM.Util.linkify_with_twitter(d.results[i].text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>");
twit += td; twit += td;
twit += "</p>"; twit += "</p>";
twit += "— " + d.results[i].from_user_name + " (<a href='https://twitter.com/" + d.results[i].from_user + "'>@" + d.results[i].from_user + "</a>) <a href='https://twitter.com/" + d.results[i].from_user + "/status/" + d.id + "'>" + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.results[i].created_at) + " </a></blockquote></div>"; twit += "— " + d.results[i].from_user_name + " (<a href='https://twitter.com/" + d.results[i].from_user + "'>@" + d.results[i].from_user + "</a>) <a href='https://twitter.com/" + d.results[i].from_user + "/status/" + d.id + "'>" + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.results[i].created_at) + " </a></blockquote></div>";
@ -1624,32 +1615,51 @@ if (typeof VMM == 'undefined') {
}, },
// VMM.ExternalAPI.twitter.prettyHTML(id); // VMM.ExternalAPI.twitter.prettyHTML(id);
prettyHTML: function(id) { prettyHTML: function(id) {
var id = id.toString();
// https://api.twitter.com/1/statuses/show.json?id=164165553810976768&include_entities=true&callback=? var error_obj = {
twitterid: id
};
var the_url = "http://api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?"; 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, "<p>ERROR LOADING TWEET " + id + "</p>" );
})
.success(function() {
clearTimeout(twitter_timeout);
});
},
notFoundError: function(id) {
trace("TWITTER JSON ERROR TIMEOUT " + id);
VMM.attachElement("#twitter_" + id, "<p>TWEET NOT FOUND " + id + "</p>" );
}, },
formatJSON: function(d) { formatJSON: function(d) {
trace("TWITTER JSON LOADED F"); trace("TWITTER JSON LOADED F");
trace(d);
var id = d.id_str; var id = d.id_str;
var twit = "<blockquote><p>"; var twit = "<blockquote><p>";
var td = VMM.Util.linkify(d.text); var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>"); //td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2' target='_blank'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>"); //td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
twit += td; twit += td;
twit += "</p></blockquote>"; twit += "</p></blockquote>";
twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id + "' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>"; twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id + "' target='_blank' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>";
twit += "<div class='vcard author'>"; twit += "<div class='vcard author'>";
twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "'>"; twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "' target='_blank'>";
twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>"; twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>";
twit += "<span class='fn'>" + d.user.name + "</span>"; twit += "<span class='fn'>" + d.user.name + "</span>";
twit += "<span class='nickname'>@" + d.user.screen_name + "</span>"; twit += "<span class='nickname'>@" + d.user.screen_name + "</span>";
twit += "</a>"; twit += "</a>";
twit += "</div>"; twit += "</div>";
VMM.attachElement("#"+id, twit ); VMM.attachElement("#twitter_"+id.toString(), twit );
} }

10
source/js/timeline.js

@ -1,5 +1,5 @@
/*! /*!
Verite Timeline 0.88 Open Timeline 0.88
Designed and built by Zach Wise digitalartwork.net Designed and built by Zach Wise digitalartwork.net
Date: April 8, 2012 Date: April 8, 2012
@ -40,7 +40,7 @@
// @codekit-prepend "VMM.LoadLib.js"; // @codekit-prepend "VMM.LoadLib.js";
// @codekit-prepend "bootstrap-tooltip.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') { if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
@ -333,14 +333,14 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
if (d.type == "tweets") { if (d.type == "tweets") {
} else if (dd.type == "start") { } 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 { } 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 != "") { if (d.text != null && d.text != "") {
_hastext = true; _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"); c._text = VMM.createElement("div", c._text, "container");

160
timeline.js

@ -296,7 +296,7 @@ if (typeof VMM == 'undefined') {
}; };
// VMM.getJSON(url, the_function); // VMM.getJSON(url, the_function);
VMM.getJSON = function(url, the_function) { VMM.getJSON = function(url, data, callback) {
if( typeof( jQuery ) != 'undefined' ){ if( typeof( jQuery ) != 'undefined' ){
/* CHECK FOR IE AND USE Use Microsoft XDR /* CHECK FOR IE AND USE Use Microsoft XDR
@ -307,7 +307,7 @@ if (typeof VMM == 'undefined') {
if (ie_url.match('^http://')){ if (ie_url.match('^http://')){
//ie_url = ie_url.replace("http://","//"); //ie_url = ie_url.replace("http://","//");
$.getJSON(url, the_function); $.getJSON(url, data);
} else if (ie_url.match('^https://')) { } else if (ie_url.match('^https://')) {
ie_url = ie_url.replace("https://","http://"); ie_url = ie_url.replace("https://","http://");
var xdr = new XDomainRequest(); var xdr = new XDomainRequest();
@ -319,7 +319,9 @@ if (typeof VMM == 'undefined') {
xdr.send(); xdr.send();
} }
} else { } else {
$.getJSON(url, the_function); //$.getJSON(url, data);
return jQuery.getJSON(url, data, callback);
} }
} }
@ -1295,11 +1297,11 @@ if (typeof VMM == 'undefined') {
// CREDIT // CREDIT
if (data.credit != null && data.credit != "") { if (data.credit != null && data.credit != "") {
creditElem = "<div class='credit'>" + data.credit + "</div>"; creditElem = "<div class='credit'>" + VMM.Util.linkify_with_twitter(data.credit, "_blank") + "</div>";
} }
// CAPTION // CAPTION
if (data.caption != null && data.caption != "") { if (data.caption != null && data.caption != "") {
captionElem = "<div class='caption'>" + data.caption + "</div>"; captionElem = "<div class='caption'>" + VMM.Util.linkify_with_twitter(data.caption, "_blank") + "</div>";
} }
// MEDIA TYPE // MEDIA TYPE
@ -1327,7 +1329,7 @@ if (typeof VMM == 'undefined') {
} else if (m.type == "vimeo") { } else if (m.type == "vimeo") {
mediaElem = "<iframe class='media-frame video vimeo' frameborder='0' width='100%' height='100%' src='http://player.vimeo.com/video/" + m.id + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff'></iframe>"; mediaElem = "<iframe class='media-frame video vimeo' frameborder='0' width='100%' height='100%' src='http://player.vimeo.com/video/" + m.id + "?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff'></iframe>";
} else if (m.type == "twitter"){ } else if (m.type == "twitter"){
mediaElem = "<div class='twitter' id='" + m.id + "'>Loading Tweet</div>"; mediaElem = "<div class='twitter' id='" + "twitter_" + m.id + "'>Loading Tweet</div>";
//VMM.ExternalAPI.twitter.getHTML(m.id); //VMM.ExternalAPI.twitter.getHTML(m.id);
trace("TWITTER"); trace("TWITTER");
VMM.ExternalAPI.twitter.prettyHTML(m.id); VMM.ExternalAPI.twitter.prettyHTML(m.id);
@ -1505,16 +1507,9 @@ if (typeof VMM == 'undefined') {
onJSONLoaded: function(d) { onJSONLoaded: function(d) {
trace("TWITTER JSON LOADED"); trace("TWITTER JSON LOADED");
var id = d.id; var id = d.id;
VMM.attachElement("#"+id, VMM.ExternalAPI.twitter.linkify(d.html) ); VMM.attachElement("#"+id, VMM.Util.linkify_with_twitter(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); // VMM.ExternalAPI.twitter.parseTwitterDate(date);
parseTwitterDate: function(d) { parseTwitterDate: function(d) {
var date = new Date(Date.parse(d)); var date = new Date(Date.parse(d));
@ -1561,10 +1556,7 @@ if (typeof VMM == 'undefined') {
/* FORMAT RESPONSE /* FORMAT RESPONSE
================================================== */ ================================================== */
var twit = "<div class='twitter'><blockquote><p>"; var twit = "<div class='twitter'><blockquote><p>";
var td = VMM.Util.linkify(d.text); var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>");
//twit += VMM.Util.linkify(d.text);
twit += td; twit += td;
twit += "</p>"; twit += "</p>";
@ -1582,7 +1574,10 @@ if (typeof VMM == 'undefined') {
var the_tweets = {tweetdata: tweetArray} var the_tweets = {tweetdata: tweetArray}
VMM.fireEvent(global, "TWEETSLOADED", the_tweets); 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); // VMM.ExternalAPI.twitter.getTweetSearch(search string);
getTweetSearch: function(tweets, number_of_tweets) { getTweetSearch: function(tweets, number_of_tweets) {
var _number_of_tweets = 40; var _number_of_tweets = 40;
if (number_of_tweets != null && number_of_tweets != "") { if (number_of_tweets != null && number_of_tweets != "") {
_number_of_tweets = 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++) { for(var i = 0; i < d.results.length; i++) {
var tweet = {} var tweet = {}
var twit = "<div class='twitter'><blockquote><p>"; var twit = "<div class='twitter'><blockquote><p>";
var td = VMM.Util.linkify(d.results[i].text); var td = VMM.Util.linkify_with_twitter(d.results[i].text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>");
twit += td; twit += td;
twit += "</p>"; twit += "</p>";
twit += "— " + d.results[i].from_user_name + " (<a href='https://twitter.com/" + d.results[i].from_user + "'>@" + d.results[i].from_user + "</a>) <a href='https://twitter.com/" + d.results[i].from_user + "/status/" + d.id + "'>" + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.results[i].created_at) + " </a></blockquote></div>"; twit += "— " + d.results[i].from_user_name + " (<a href='https://twitter.com/" + d.results[i].from_user + "'>@" + d.results[i].from_user + "</a>) <a href='https://twitter.com/" + d.results[i].from_user + "/status/" + d.id + "'>" + VMM.ExternalAPI.twitter.prettyParseTwitterDate(d.results[i].created_at) + " </a></blockquote></div>";
@ -1624,32 +1615,51 @@ if (typeof VMM == 'undefined') {
}, },
// VMM.ExternalAPI.twitter.prettyHTML(id); // VMM.ExternalAPI.twitter.prettyHTML(id);
prettyHTML: function(id) { prettyHTML: function(id) {
var id = id.toString();
// https://api.twitter.com/1/statuses/show.json?id=164165553810976768&include_entities=true&callback=? var error_obj = {
twitterid: id
};
var the_url = "http://api.twitter.com/1/statuses/show.json?id=" + id + "&include_entities=true&callback=?"; 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, "<p>ERROR LOADING TWEET " + id + "</p>" );
})
.success(function() {
clearTimeout(twitter_timeout);
});
},
notFoundError: function(id) {
trace("TWITTER JSON ERROR TIMEOUT " + id);
VMM.attachElement("#twitter_" + id, "<p>TWEET NOT FOUND " + id + "</p>" );
}, },
formatJSON: function(d) { formatJSON: function(d) {
trace("TWITTER JSON LOADED F"); trace("TWITTER JSON LOADED F");
trace(d);
var id = d.id_str; var id = d.id_str;
var twit = "<blockquote><p>"; var twit = "<blockquote><p>";
var td = VMM.Util.linkify(d.text); var td = VMM.Util.linkify_with_twitter(d.text, "_blank");
td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2'>$1</a>"); //td = td.replace(/(@([\w]+))/g,"<a href='http://twitter.com/$2' target='_blank'>$1</a>");
td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2'>$1</a>"); //td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
twit += td; twit += td;
twit += "</p></blockquote>"; twit += "</p></blockquote>";
twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id + "' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>"; twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id + "' target='_blank' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>";
twit += "<div class='vcard author'>"; twit += "<div class='vcard author'>";
twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "'>"; twit += "<a class='screen-name url' href='https://twitter.com/" + d.user.screen_name + "' data-screen-name='" + d.user.screen_name + "' target='_blank'>";
twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>"; twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></span>";
twit += "<span class='fn'>" + d.user.name + "</span>"; twit += "<span class='fn'>" + d.user.name + "</span>";
twit += "<span class='nickname'>@" + d.user.screen_name + "</span>"; twit += "<span class='nickname'>@" + d.user.screen_name + "</span>";
twit += "</a>"; twit += "</a>";
twit += "</div>"; twit += "</div>";
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(); // VMM.Util.linkify();
linkify: function(text,targets,is_touch) { 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;
text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi, function(url) { // www. sans http:// or https://
var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
var nice = url; // Email addresses
var _touch = ""; var emailAddressPattern = /(([a-zA-Z0-9_\-\.]+)@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6}))+/gim;
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 '<a href="'+ url + " " + _touch + '">'+ url +'</a>';
else return "<a href='"+ url + " " + _touch + " target='" +targets+"'>'" + url + "</a>" ;
});
return text; return text
.replace(urlPattern, "<a target='_blank' href='$&' onclick='void(0)'>$&</a>")
.replace(pseudoUrlPattern, "$1<a target='_blank' onclick='void(0)' href='http://$2'>$2</a>")
.replace(emailAddressPattern, "<a target='_blank' onclick='void(0)' href='mailto:$1'>$1</a>");
}, },
linkify_with_twitter: function(text,targets,is_touch) {
// 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, "<a target='_blank' href='$&' onclick='void(0)'>$&</a>")
.replace(pseudoUrlPattern, "$1<a target='_blank' onclick='void(0)' href='http://$2'>$2</a>")
.replace(emailAddressPattern, "<a target='_blank' onclick='void(0)' href='mailto:$1'>$1</a>")
.replace(twitterHandlePattern, "<a href='http://twitter.com/$2' target='_blank' onclick='void(0)'>$1</a>")
.replace(twitterSearchPattern, "<a href='http://twitter.com/#search?q=%23$2' target='_blank' 'void(0)'>$1</a>");
},
/* Turns plain text links into real links /* Turns plain text links into real links
================================================== */ ================================================== */
// VMM.Util.unlinkify(); // VMM.Util.unlinkify();
@ -3449,6 +3479,32 @@ if(typeof VMM != 'undefined' && typeof VMM.Util == 'undefined') {
}).init(); }).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, '<a target="_blank" href="$&">$&</a>')
.replace(pseudoUrlPattern, '$1<a target="_blank" href="http://$2">$2</a>')
.replace(emailAddressPattern, '<a target="_blank" href="mailto:$1">$1</a>')
.replace(twitterHandlePattern, "<a href='http://twitter.com/$2' target='_blank'>$1</a>")
.replace(twitterSearchPattern, "<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
};
}
} }
/*********************************************** /***********************************************
@ -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 Designed and built by Zach Wise digitalartwork.net
Date: April 8, 2012 Date: April 8, 2012
@ -4025,7 +4081,7 @@ if(typeof VMM != 'undefined' && typeof VMM.LoadLib == 'undefined') {
// @codekit-prepend "VMM.LoadLib.js"; // @codekit-prepend "VMM.LoadLib.js";
// @codekit-prepend "bootstrap-tooltip.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') { if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
@ -4318,14 +4374,14 @@ if(typeof VMM != 'undefined' && typeof VMM.Timeline == 'undefined') {
if (d.type == "tweets") { if (d.type == "tweets") {
} else if (dd.type == "start") { } 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 { } 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 != "") { if (d.text != null && d.text != "") {
_hastext = true; _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"); c._text = VMM.createElement("div", c._text, "container");

Loading…
Cancel
Save