Difference between revisions of "MediaWiki:Common.js"

Vid (Talk | contribs)
Vid (Talk | contribs)
 
(24 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
  
 +
var basePage = getParameterByName('Scenario_Task_Translation[Base+Page]');
  
console.log(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';
   var query = 'http://mywiki/mw/api.php?action=ask&query=[[2 factor authentication]]|?Scenario Task Description&format=json';
+
  console.log('q', query);
 
   $.getJSON(query, function(data) {
 
   $.getJSON(query, function(data) {
     console.log('data', data):
+
     var val;
 +
    try {
 +
      var val = data.query.results[basePage.replace(/\+/g, ' ')].printouts['Scenario Task Description'][0];
 +
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div id="basePageText" style="background-color: #ddd; border: 1px solid grey; font-family: monospace; font-size: 70%">' + val.replace(/\n/g, '<br />') + '</div>');
 +
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').css('height', $('#basePageText').css('height'))
 +
    } catch (e) {
 +
      window.d = data;
 +
      console.log("failed parsing", e, 'data', data, 'val', val);
 +
    }
 
   });
 
   });
 +
}
  
 
function getParameterByName(name) {
 
function getParameterByName(name) {
    var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
+
  if (window.location.search.indexOf(name) > -1) {
     return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
+
     value = window.location.search.split('&')[1].split('=')[1];
 +
    return value;
 +
  }
 
}
 
}

Latest revision as of 01:09, 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'][0];
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').after('<div id="basePageText" style="background-color: #ddd; border: 1px solid grey; font-family: monospace; font-size: 70%">' + val.replace(/\n/g, '<br />') + '</div>');
      $('textarea[name="Scenario Task Translation[Scenario Task Description]"]').css('height', $('#basePageText').css('height'))
    } 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;
  }
}
Last modified on 17 November 2015, at 01:09