From 1a429557e8ee91a10788754912278881032f35f3 Mon Sep 17 00:00:00 2001 From: Zach Wise Date: Wed, 23 May 2012 20:43:57 -0500 Subject: [PATCH] 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 --- source/js/Media/VMM.ExternalAPI.js | 32 +++++++++++++++++++---------- source/js/Media/VMM.MediaElement.js | 2 +- source/js/Media/VMM.MediaType.js | 3 ++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/source/js/Media/VMM.ExternalAPI.js b/source/js/Media/VMM.ExternalAPI.js index c4efb82..b365786 100644 --- a/source/js/Media/VMM.ExternalAPI.js +++ b/source/js/Media/VMM.ExternalAPI.js @@ -194,13 +194,13 @@ if(typeof VMM != 'undefined' && typeof VMM.ExternalAPI == 'undefined') { //td = td.replace(/(#([\w]+))/g,"$1"); twit += td; twit += "

"; - twit += " " + "" + " "; + //twit += " " + "" + " "; twit += "
"; twit += ""; twit += ""; twit += "" + d.user.name + ""; - twit += "@" + d.user.screen_name + ""; + twit += "@" + d.user.screen_name + ""; twit += ""; twit += "
"; @@ -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 = "

" + api_obj.url + "

"; temp_text += "" + VMM.master_config.language.messages.wikipedia + ""; @@ -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("

"); - 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("

")) { + 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) { diff --git a/source/js/Media/VMM.MediaElement.js b/source/js/Media/VMM.MediaElement.js index 568f67d..e49b7e9 100644 --- a/source/js/Media/VMM.MediaElement.js +++ b/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 = "

Loading Wikipedia

"; 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; diff --git a/source/js/Media/VMM.MediaType.js b/source/js/Media/VMM.MediaType.js index 6bf1e04..a0de4f1 100644 --- a/source/js/Media/VMM.MediaType.js +++ b/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";