MediaWiki:Deduster.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// User interface for marking dustspots to be processed by [[Commons:Deduster]]

$(function(){
  var spots = [], aButton, zoom=null, px=0, py=0, dx, dy;
  function startMark(){
    if(!zoom) {
      var link = $('#file').find('a').eq(0);
      zoom = 
      zoom = $('<img/>')
        .attr('src', link.attr('href') )
        .mousedown(function(e){
          dx=e.pageX; dy=e.pageY;
          // check target
          $(document)
            .on('mousemove.deduster',function(e){
              //console.log('-'+px+'px -'+py+'px');
            })
            .on('mouseup.deduster',function(){
              $(document).off('mousemove.deduster').off('mouseup.deduster');
            });
        });
      link.replaceWith($('<div></div>').css( { 
        width:'100%',height:'600px',
        overflow:'scroll',
      }).append(zoom) );
      px=0; py=0;
    }
  }
  function addUI() {
    aButton = $('<button>Mark dust spots</button>').click(startMark).insertAfter($('#file'));
  }
  if( mw.config.get('wgNamespaceNumber') == 6 ) {
    if( mw.config.get('wgAction') == 'view' ) addUI();
    if( mw.config.get('wgAction') == 'edit' ) {
      var data = mw.util.getParamValue('dedusteradd');
      if( data ) {
        // validate data 
        // add to text area
        // submit
      }
    }
  }
});