MediaWiki:Gadget-ZoomViewer.js

From Sarkarverse
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*global $, mw*/
/*jshint curly:false, boss:true */

if ( mw.config.get('wgNamespaceNumber') === 6 && mw.config.get('wgAction') === 'view' && !mw.util.getParamValue('diff')) {
 $(document).ready(
  function () {
   'use strict';
   var m, fileInfo = $(".fileInfo");
   if (!fileInfo) { return; } else // &diff/&oldid also have wgAction=view...
   {
    // check if the image is below 2MP
    var pixel_filter = /([\d,\.\']+) × ([\d,\.\']+) [Pp][íi](?:[kc]s|x)el[ei]?s?/;
    if( m=pixel_filter.exec(fileInfo.text()) ) {
     var p = parseInt(m[1].replace(/[,\.\']/g,''), 10) * parseInt(m[2].replace(/[,\.]/g,''), 10);
     if( p < 2*1024*1024 ) return;
    }
    var links = $("<span>", { id: "ZoomViewerLinks", style: "white-space:nowrap; display:inline-block;" });
    var fileName = mw.config.get('wgPageName').match(/File:(.+\.jpe?g)/i);
    if (!fileName) { return; }
    var url = "//toolserver.org/~dschwen/iip/wip.php?f=" + encodeURIComponent( fileName[1] );
    var link = $("<a>", { href: url, text: "flash" });
    var linkNoFlash = $("<a>", { href: url + "&flash=no", text: "no flash" });
    links.append("; ZoomViewer: ", link, "/", linkNoFlash);
    fileInfo.after(links);
   }
  }
 );
}