User:Husky/cycler.js
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.
![]() |
Documentation for this user script can be added at User:Husky/cycler. |
- Report page listing warnings and errors.
var cyclebox_start = 0 ;
var cyclebox_row = 10 ;
var cyclebox_thumbsize = 120 ;
var cyclebox_data ;
var cyclebox_initial_load = true ;
var cyclebox_mouse_inside = false ;
jQuery(document).ready ( function () {
if ( wgNamespaceNumber != 0 || wgPageName != "Main_Page" ) return ;
jQuery("#mainpage-welcome-box").after ( "<div id='cyclebox_container'><div style='background:#faecc8; border-bottom:1px solid #fad67d; padding:0.2em 0.5em; font-size:125%; font-weight:bold;'>Other featured contents</div><div id='cyclebox' style='position:relative;overflow:hidden;max-height:"+cyclebox_thumbsize+"px;width:100%;margin-top:2px'><div id='cyclebox1' style='display:inline;width:500px'></div></div></div>" ) ;
var w = parseInt ( ( parseInt ( jQuery('#cyclebox_container').width() ) - ( cyclebox_row * cyclebox_thumbsize ) ) / 2 ) ;
jQuery('#cyclebox').height ( cyclebox_thumbsize + 4 ) ;
jQuery('#cyclebox').css ( 'margin-left' , w ) ;
jQuery('#cyclebox_container').mouseenter ( function() { cyclebox_mouse_inside = true ; } ) ;
jQuery('#cyclebox_container').mouseleave ( function() { cyclebox_mouse_inside = false ; } ) ;
initialize_cyclebox () ;
} ) ;
function iterate_cyclebox () {
if ( !cyclebox_initial_load && cyclebox_mouse_inside ) {
setTimeout('iterate_cyclebox()', 2000);
return ;
}
var h = "<div id='cyclebox2' style='position:relative;display:inline'>";
if ( cyclebox_start + cyclebox_row >= cyclebox_data.length ) cyclebox_start = 0 ;
var titles = '' ;
for ( var i = 0 ; i < cyclebox_row ; i++ ) {
var d = cyclebox_data[i + cyclebox_start] ;
if ( titles != '' ) titles += "|" ;
titles += escape ( d.title ) ;
}
var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php' ;
url += "?action=query&titles=" + titles + "&prop=imageinfo&iiprop=url&iiurlwidth="+cyclebox_thumbsize+"&iiurlheight="+cyclebox_thumbsize+"&format=json&callback=?" ;
jQuery.getJSON ( url , function ( data ) {
jQuery.each(data.query.pages, function ( idx , elm ) {
var n = "<a href='" + wgArticlePath.replace("$1", escape(elm.title)) + "'><img border='0' src='" ;
jQuery.each(jQuery(elm.imageinfo),function ( i2 , e2 ) {
jQuery.each ( jQuery(e2) , function ( i3 , e3 ) { n += e3.thumburl ; } ) ;
} ) ;
n += "'/></a>" ;
h += "<div style='display:inline'>" + n + "</div>" ;
} ) ;
h += "</div>" ;
jQuery("#cyclebox1").after ( h ) ;
cyclebox_start += cyclebox_row ;
var w = parseInt ( jQuery('#cyclebox1').width() ) ;
jQuery('#cyclebox2').animate( { left : "-="+w+"px" } , 'slow' ) ;
jQuery('#cyclebox1').animate( { left : "-="+w+"px" } , 'slow' , function () {
jQuery('#cyclebox2').css('left','0px') ;
jQuery('#cyclebox1').remove() ;
jQuery('#cyclebox2').attr('id','cyclebox1') ;
cyclebox_initial_load = false ;
setTimeout('iterate_cyclebox()', 5000);
} ) ;
} ) ;
}
function initialize_cyclebox () {
var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=json&action=query&list=categorymembers&cmnamespace=6&cmsort=timestamp&cmdir=desc&cmlimit=500&cmtitle=Category:Featured_pictures_on_Wikimedia_Commons&callback=?' ;
jQuery.getJSON ( url , function ( data ) {
cyclebox_data = data.query.categorymembers ;
iterate_cyclebox () ;
} ) ;
}