Jump to content

User:Magnus Manske/sifter.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Magnus Manske (talk | contribs) at 22:22, 8 December 2010. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
var sifter_html ;
var sifter_old_content ;

$(document).ready( function(){
  var url = "http://toolserver.org/~magnus/sifter_api.php?query=wikipage&page=" + wgPageName + "&format=json&callback=?" ;
  $.getJSON ( url , function (data) {
    if ( data.length > 0 ) create_sifter_menu ( data ) ;
  } ) ;
}) ;

function create_sifter_menu ( data ) {
  var html = "<li id='sifter_menu'><a href='#' onclick='show_sifter_dialog(1);return false'><span>Sifter</span></a><div class='menu><ul><li>Test</li></ul></div></li>" ;
  $('#p-views ul').prepend ( html ) ;

  sifter_html = '<h1>Sifter</h1><table border='1'>' ;
  sifter_html += "<tr><th>Partner</th><th>Partner page</th><th>Wikipedia revision</th><th>Reviewer</th><th>Reviewed</th></tr>" ;
  $.each ( data , function ( k , v ) {
    sifter_html += "<tr>" ;
    sifter_html += "<td>" + v.partner_name + "</td>" ;
    sifter_html += "</tr>" ;
  } ) ;
  sifter_html += "<div><a href='#' onclick='show_sifter_dialog(2);return false'>Restore page</a></div>" ;
}

function show_sifter_dialog ( mode ) {
  if ( mode == 1 ) {
    sifter_old_content = $('#content').html();
    $('#content').html(sifter_html);
  }
  if ( mode == 2 ) {
    $('#content').html(sifter_old_content);
  }
  return false ;
}