User:Zocky/PicturePopupsDev.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
// Picture Popups for Mediawiki // (c)2005-2007 [[en:User:Zocky]] // Released under GPL window.onerror=function(a,b,c,d) { alert( a + ", " + b + ", " + c + ", " + d); } document.write('<'+'script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/Tools.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></'+'script>'); document.write('<link rel="stylesheet" type="text/css" href="' + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/PicturePopupsDev.css' + '&action=raw&ctype=text/css&dontcountme=s">'); addOnloadHook(picturePopupInit); function picturePopupInit() { var c; c = window.$('content'); if (!c) c=$('article'); if (c) $E.hook(c,'click',picturePopupImageClick); } //Handle clicks on images function picturePopupImageClick(e) { if ($E.target(e).tagName=='IMG') { $E.cancel(e); var imageTag=$E.target(e); if ($D.a(imageTag,'longdesc')) { var imageName = decodeURI($D.a(imageTag,'longdesc')).replace(/^\/wiki\//,''); var imageLink=$D.parentByTag(imageTag,'A'); var caption=$D.a(imageTag,'alt'); try { var captiondiv=imageLink.nextSibling.nextSibling; if ($D.a(captiondiv,'class')=='thumbcaption') {caption=captiondiv.innerHTML} } catch (er) {} var dragletTitle='<a href="'+imageLink.href+'">[>]</a> '+ imageName; var dragletId = $P.create( dragletTitle,100,100 ); $(dragletId+'_content').innerHTML='<div class="picture_popup"' + 'id="'+dragletId+'_picture_popup">Loading...</div>' + '<div class="picture_popup_caption">'+caption+'</div>'; var cbSuccess=function(t) { c=document.createElement('div'); c.innerHTML=t; $(dragletId+'_picture_popup').innerHTML=''; imageDiv = $D.descendantByID(c,'file'); imageTag = imageDiv.firstChild.firstChild; imageDiv.removeChild(imageDiv.firstChild); imageDiv.insertBefore(imageTag,imageDiv.firstChild); $(dragletId).style.width=imageTag.width+"px"; $(dragletId+'_picture_popup').appendChild(imageDiv) || ($(dragletId+'_picture_popup').innerHTML="Failed. <a>retry</a>"); try { $(dragletId+'_picture_popup_caption').appendChild($D.descendantByID(c,'imageLicense')); } catch(er) {}; return true; }; var cbFailure=function(s) { $(dragletId+'_picture_popup').innerHTML=s; return true; } $X.get(imageLink.href,cbSuccess,cbFailure); } } }

