User:WikiDwarf/ArticleInfo.js: Difference between revisions

Undo revision 304214 by WikiDwarf (talk)
No edit summary
Tag: Reverted
(Undo revision 304214 by WikiDwarf (talk))
Tag: Undo
 
Line 1: Line 1:
var xpagehistory = {
/**
  loadinganimation : 0,
* XTools ArticleInfo gadget
  execute : function () {
* Based on meta.wikimedia.org/wiki/User:Hedonil/XTools
  if (mw.config.get('wgArticleId') === 0) return; // no deleted articles, no special pages
* Documentation: mediawiki.org/wiki/XTools/ArticleInfo_gadget
  if (mw.config.get('wgCurRevisionId') != mw.config.get('wgRevisionId')) return; // only current revision
* Released under GPL 3.0+ license
  $("<div id='xtools' style='font-size:84%; line-height:1.2em; margin:0 0 0.4em 0.2em; width:auto;'><span id='xtoolsresult'></span><span id='xtoolsloading'>.</span></div>").insertBefore("#contentSub");
* For updates, please copy and paste from https://xtools.wmflabs.org/articleinfo-gadget.js
  loadinganimation = window.setInterval( function() { if ($("#xtoolsloading").html() == ".&nbsp;&nbsp;") $("#xtoolsloading").html("&nbsp;.&nbsp;"); else if ($("#xtoolsloading").html() == "&nbsp;.&nbsp;") $("#xtoolsloading").html("&nbsp;&nbsp;."); else $("#xtoolsloading").html(".&nbsp;&nbsp;"); }, 300);
*/
  mw.loader.load("//tools.wmflabs.org/xtools/api.php?pageid=" + mw.config.get('wgArticleId') + "&pagetitle=" + mw.config.get('wgPageName') + "&project=" + mw.config.get('wgServer').slice(2) + "&uselang=" + mw.config.get('wgContentLanguage') );
$(function () {
  },
    if (mw.config.get('wgArticleId') === 0 || // no deleted articles, no special pages
  resultloaded : function( res ) {
            mw.config.get('wgCurRevisionId') !== mw.config.get('wgRevisionId') || // only current revision
  $("#xtoolsresult").html(res);
            mw.config.get('wgAction') !== 'view') { // only when viewing a page, not editing
  this.stoploading();
        return;
  },
    }
  stoploading : function() {
 
  clearInterval(loadinganimation);
    var $result,
  $('#xtoolsloading').remove();
        markup = "<div id='xtools' style='font-size:84%; line-height:1.2em;" +
  }
        "width:auto;'><span id='xtools_result'>.</span></div>";
};
    $(markup).insertBefore('#contentSub');
if ( (mw.config.get('wgAction') == "view") ) $( xpagehistory.execute );
    $result = $('#xtools_result');
 
    var loadinganimation = window.setInterval(function () {
        if ($result.html() === '.&nbsp;&nbsp;') {
            $result.html('&nbsp;.&nbsp;');
        } else if ($result.html() === '&nbsp;.&nbsp;') {
            $result.html('&nbsp;&nbsp;.');
        } else {
            $result.html('.&nbsp;&nbsp;');
        }
    }, 300);
 
    $.get(
        'https://xtools.wmflabs.org/api/page/articleinfo/' +
        mw.config.get('wgServerName') + '/' +
        mw.config.get('wgPageName').replace(/["?%&+]/g, escape) + '?format=html' +
        '&uselang=' + mw.config.get('wgUserLanguage')
    ).done(function (result) {
        $result.html(result);
        clearInterval(loadinganimation);
    });
});