Difference between revisions of "MediaWiki:Common.js"
Line 3: | Line 3: | ||
var basePage = getParameterByName('Scenario_Task_Translation[Base+Page]'); | var basePage = getParameterByName('Scenario_Task_Translation[Base+Page]'); | ||
− | if ($('textarea[name="Scenario Task Translation[Scenario Task Description]"]') && | + | if ($('textarea[name="Scenario Task Translation[Scenario Task Description]"]') && basePage) { // |
var query = 'https://learn.equalit.ie/mw/api.php?action=ask&query=[[' + basePage + ']]|?Scenario Task Description&format=json'; | var query = 'https://learn.equalit.ie/mw/api.php?action=ask&query=[[' + basePage + ']]|?Scenario Task Description&format=json'; | ||
console.log('q', query); | console.log('q', query); | ||
Line 9: | Line 9: | ||
var val; | var val; | ||
try { | try { | ||
− | var val = data.query.results[basePage].printouts['Scenario Task Description']; | + | var val = data.query.results[basePage.replace(/\+/g, ' ')].printouts['Scenario Task Description']; |
$('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div>' + val + '</div>'); | $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div>' + val + '</div>'); | ||
} catch (e) { | } catch (e) { |
Revision as of 01:01, 17 November 2015
/* Any JavaScript here will be loaded for all users on every page load. */ var basePage = getParameterByName('Scenario_Task_Translation[Base+Page]'); if ($('textarea[name="Scenario Task Translation[Scenario Task Description]"]') && basePage) { // var query = 'https://learn.equalit.ie/mw/api.php?action=ask&query=[[' + basePage + ']]|?Scenario Task Description&format=json'; console.log('q', query); $.getJSON(query, function(data) { var val; try { var val = data.query.results[basePage.replace(/\+/g, ' ')].printouts['Scenario Task Description']; $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div>' + val + '</div>'); } catch (e) { window.d = data; console.log("failed parsing", e, 'data', data, 'val', val); } }); } function getParameterByName(name) { if (window.location.search.indexOf(name) > -1) { value = window.location.search.split('&')[1].split('=')[1]; return value; } }