Browse Source

Wikipedia will now load the article extract based on the language of the link in the media field instead of the language localization from Timeline closes #109

pull/127/head
Zach Wise 13 years ago
parent
commit
1a429557e8
  1. 32
      source/js/Media/VMM.ExternalAPI.js
  2. 2
      source/js/Media/VMM.MediaElement.js
  3. 3
      source/js/Media/VMM.MediaType.js

32
source/js/Media/VMM.ExternalAPI.js

@ -194,13 +194,13 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
//td = td.replace(/(#([\w]+))/g,"<a href='http://twitter.com/#search?q=%23$2' target='_blank'>$1</a>");
twit += td;
twit += "</p></blockquote>";
twit += " <a href='https://twitter.com/" + d.user.screen_name + "/status/" + d.id_str + "' target='_blank' 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_str + "' target='_blank' alt='link to original tweet' title='link to original tweet'>" + "<span class='created-at'></span>" + " </a>";
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 + "' target='_blank'>";
twit += "<span class='avatar'><img src=' " + d.user.profile_image_url + "' alt=''></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 class='thumbnail-inline'></span></span>";
twit += "</a>";
twit += "</div>";
@ -619,14 +619,15 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
wikipedia: {
get: function(url, id) {
var api_obj = {url: url, id: id};
get: function(url, id, lang) {
var api_obj = {url: url, id: id, lang: lang};
VMM.master_config.wikipedia.que.push(api_obj);
VMM.master_config.wikipedia.active = true;
},
create: function(api_obj) {
var the_url = "http://" + VMM.master_config.language.api.wikipedia + ".wikipedia.org/w/api.php?action=query&prop=extracts&redirects=&titles=" + api_obj.url + "&exintro=1&format=json&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=?";
if ( VMM.Browser.browser == "Explorer" && parseInt(VMM.Browser.version, 10) >= 7 && window.XDomainRequest) {
var temp_text = "<h4><a href='http://" + VMM.master_config.language.api.wikipedia + ".wikipedia.org/wiki/" + api_obj.url + "' target='_blank'>" + api_obj.url + "</a></h4>";
temp_text += "<span class='wiki-source'>" + VMM.master_config.language.messages.wikipedia + "</span>";
@ -636,12 +637,21 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') {
VMM.getJSON(the_url, function(d) {
if (d.query) {
var wiki_extract = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).extract;
var wiki_title = VMM.Util.getObjectAttributeByIndex(d.query.pages, 0).title;
var _wiki = "";
var wiki_text = "";
var wiki_text_array = wiki_extract.split("<p>");
var wiki_number_of_paragraphs = 1;
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("<p>")) {
wiki_text_array = wiki_extract.split("<p>");
} 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) {

2
source/js/Media/VMM.MediaElement.js

@ -149,7 +149,7 @@ if(typeof VMM != 'undefined' && typeof VMM.MediaElement == 'undefined') {
_id = "wikipedia_" + VMM.Util.unique_ID(7);
mediaElem = "<div class='wikipedia' id='" + _id + "'><span class='messege'><p>Loading Wikipedia</p></span></div>";
isTextMedia = true;
VMM.ExternalAPI.wikipedia.get(m.id, _id);
VMM.ExternalAPI.wikipedia.get(m.id, _id, m.lang);
// STORIFY
} else if (m.type == "storify") {
isTextMedia = true;

3
source/js/Media/VMM.MediaType.js

@ -71,7 +71,8 @@ if(typeof VMM != 'undefined' && typeof VMM.MediaType == 'undefined') {
media.type = "wikipedia";
//media.id = d.split("wiki\/")[1];
var wiki_id = d.split("wiki\/")[1].split("#")[0].replace("_", " ");
media.id = VMM.Util.toTitleCase(wiki_id).replace(" ", "%20");
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";

Loading…
Cancel
Save