Difference between revisions of "MediaWiki:Common.js"

Line 7: Line 7:
 
console.log('q', query);
 
console.log('q', query);
 
   $.getJSON(query, function(data) {
 
   $.getJSON(query, function(data) {
     console.log('data', data);
+
     try {
window.d = data;
+
      var val = d.query.results[basePage].printouts['Scenario Task Description'];
 +
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').text(val);
 +
    } catch (e) {
 +
      console.log("failed parsing", datda);
 +
    }
 
   });
 
   });
 
}
 
}

Revision as of 00:45, 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 (basePage && $('textarea[name="Scenario Task Translation[Scenario Task Description]"]')) {
  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) {
    try {
      var val = d.query.results[basePage].printouts['Scenario Task Description'];
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').text(val);
    } catch (e) {
      console.log("failed parsing", datda);
    }
  });
}

function getParameterByName(name) {
  if (window.location.search.indexOf(name) > -1) {
    value = window.location.search.split('&')[1].split('=')[1];
    return value;
  }
}