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.
// recuGall2.js. // adds a button for showing subcat images// adds a button for opening up subcatsvarmaxImgPerCat=50;// never load more from each subcatvarhideImages=true;// whether to hide images (or not)functionextractImages(response){vart="";// to returnif(response.query===undefined){return"(no images)";}// skip if emptyvarsubpages=response.query.pages;// when using generator=varimgcount=0;for(varxinsubpages){varpage=subpages[x];if(page.ns!=6){continue;}// only interested in images (ns 6)varimgtitle=page.title;//mylog (imgtitle ); mylog (page);if(page.imageinfo===undefined){continue;}// old images cant be scaled so imageinfo is not included in repy ...imgcount++;if(imgcount>maxImgPerCat){break;}// stop adding images, so break (not continue))varimgthumb=page.imageinfo[0].thumburl;t+="<img src='"+imgthumb+"'/>";// " (Image:" + imgtitle + ")";// mylog (imgtitle + ": " + imgthumb);}returnt;}functiongetImages(title,place){varurlprefix="https://commons.wikimedia.org";varajaxcall=$.ajax({// url: urlprefix + "/w/api.php?action=query&list=categorymembers&cmtitle=" + encodeURI(title) + "&cmlimit=500&cmnamespace=6&format=json", //ns=6 for imagecontext:{"title":title,"place":place},// becomes "this" when response has arrived (in the "success" function, see below)//url: urlprefix + "/w/api.php?action=query&generator=categorymembers&gcmtitle=" + encodeURI(title) + "&gcmlimit=500&prop=imageinfo&iiprop=url&iiurlheight=120&format=json", url:urlprefix+"/w/api.php?action=query&generator=categorymembers&gcmtitle="+title+"&gcmlimit=500&prop=imageinfo&iiprop=url&iiurlheight=80&format=json",success:function(response){console.log("getImages done for: "+this.title);this.place.html(extractImages(response));// this.place.toggle();}});}varmyName="recuGall";varmyPlace='#'+myName;varmyButton=myName+'ToggleBtn';varmyClass="catImages";varsubcatPlace="#mw-subcategories";// where WP puts all subcategories in the documentfunctioncheckGallery(){$(".CategoryTreeSection:not([hasimages])").each(function(index){$(this).attr("hasImages","yes");$(this).after("<div style='border: thin solid black' class='"+myClass+"'>"+"(waiting for images...)"+"</div>");// make a place for the imagesgetImages("Category:"+$(this).find("a").text(),$(this).next());// get category images into this new place (next)});}functiontoggleGallery(){checkGallery();// will initiate data collection for subcategories without imagesif(hideImages)$("."+myClass).show();// if first time, this toggle() will run BEFORE any of the images are collectedelse$("."+myClass).hide();hideImages=!hideImages;}functionopenallCats(){$('.CategoryTreeToggle').click();// the clickable arrow has class "CategoryTreeToggle"}functioninsertButtons(){// set where buttons will appear:$("#mw-subcategories p").append("<span id='myButtons'/>");// add (append) two buttons to button place$("#myButtons").append("<button id='"+myButton+"' onclick='toggleGallery()'>Images on/off</button>");$("#myButtons").append("<button id='openallCatsButton' onclick='openallCats()'>Open subcats</button>");// unsuccessful attempt to let user regulate #images shown://$("#myButtons").append('<input type="range" min="1" max="10" value="' + maxImgPerCat + '" class="slider" data-show-value="true" id="myMaxCnt">');//$("#myMaxCnt").oninput=function() { maxImgPerCat=this.value; this.text=maxImgPerCat; } // react to changes in the maxImgPerCat slider}mw.loader.using('oojs-ui-core').done(function(){$(function(){// when document has finished loadinginsertButtons();});// var button = new OO.ui.ButtonWidget( { // label: 'Click mex!' // } );// button.on( 'click', function () {// alert( 'You clicked the button!' );// } );// $( '#mw-content-text' ).append( button.$element );});