User:Zocky/PicturePopupsVector.js

/*

jquery.event.drag.js ~ v1.5 ~ Copyright (c) 2008, Three Dub Media (http://threedubmedia.com)

Liscensed under the MIT License ~ http://threedubmedia.googlecode.com/files/MIT-LICENSE.txt

  • /

(function(E){E.fn.drag=function(L,K,J){if(K){this.bind("dragstart",L)}if(J){this.bind("dragend",J)}return !L?this.trigger("drag"):this.bind("drag",K?K:L)};var A=E.event,B=A.special,F=B.drag={not:":input",distance:0,which:1,dragging:false,setup:function(J){J=E.extend({distance:F.distance,which:F.which,not:F.not},J||{});J.distance=I(J.distance);A.add(this,"mousedown",H,J);if(this.attachEvent){this.attachEvent("ondragstart",D)}},teardown:function(){A.remove(this,"mousedown",H);if(this===F.dragging){F.dragging=F.proxy=false}G(this,true);if(this.detachEvent){this.detachEvent("ondragstart",D)}}};B.dragstart=B.dragend={setup:function(){},teardown:function(){}};function H(L){var K=this,J,M=L.data||{};if(M.elem){K=L.dragTarget=M.elem;L.dragProxy=F.proxy||K;L.cursorOffsetX=M.pageX-M.left;L.cursorOffsetY=M.pageY-M.top;L.offsetX=L.pageX-L.cursorOffsetX;L.offsetY=L.pageY-L.cursorOffsetY}else{if(F.dragging||(M.which>0&&L.which!=M.which)||E(L.target).is(M.not)){return }}switch(L.type){case"mousedown":E.extend(M,E(K).offset(),{elem:K,target:L.target,pageX:L.pageX,pageY:L.pageY});A.add(document,"mousemove mouseup",H,M);G(K,false);F.dragging=null;return false;case !F.dragging&&"mousemove":if(I(L.pageX-M.pageX)+I(L.pageY-M.pageY)

mw.loader.load('//en.wikipedia.org/w/index.php?action=raw&ctype=text/css&title=User%3AZocky%2FPicturePopups.css', 'text/css');

(function($) {

mw.log.error('This script is incompatible with the latest jquery version and has been disabled.');

return;

var zTop = 10;

var $doc = $(document);

$('.imagenotetoggle').live('click', function(e) {

$(this).closest('.imagenote').toggleClass('imagenoteminimized');

});

$('.imagenoteclose').live('click', function(e) {

$(this).closest('.imagenote').remove();

});

$('#content a.image img').live('click',function(e){

if (e.ctrlKey || e.shiftKey) return;

var $this = $(this);

var $link = $this.closest('a.image');

if (!$link.length) return;

e.preventDefault();

var filename = decodeURIComponent($link.attr('href').match(/(\/wiki\/|title=)[^:]+:([^&]*)/)[2].replace(/_/g," "));

var $thumb = $this.closest('.thumbinner');

var title = '[>] ' + filename;

var caption = $thumb.length ? $thumb.find('.thumbcaption').html() : '';

var content = 'loading...';

var $popup = $('

'

+ '

'

+ '

'

+ '

'

+ '

'

+ '

' + title + ' '

+ '[–] '

+ '[×]'

+ '

'+content+'
'+caption+'
'

);

$popup

.appendTo($('body'))

.css({

top: Math.round(Math.random()*200)+'px',

left: Math.round(Math.random()*200)+'px',

// width:'600px',

zIndex: zTop++

})

.mousedown(function(e) {

$popup.css({

zIndex: zTop++

})

})

.bind('drag', function(e) {

$popup.css({

top: e.offsetY-$doc.scrollTop()+'px',

left: e.offsetX-$doc.scrollLeft()+'px'

});

});

$.getJSON (

'/w/api.php', {

format: 'json',

action: 'query',

prop: 'imageinfo',

titles: 'file:' + filename,

iiprop: 'url|size|dimensions|mime',

iiurlwidth: window.picturePopupsWidth || 800,

iiurlheight: window.picturePopupsHeight || 600

}, function (data) {

var info;

var page;

for (var i in data.query.pages) {

page = data.query.pages[i];

info = data.query.pages[i].imageinfo[0];

}

var content =

''

+ '
'

+ ' full resolution ('+info.width+'×'+info.height+', '+info.mime+')';

$popup.find('.imagenotecontent').html(content);

});

});

})(jQuery);