Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.defaultOptions.js |
— | — | @@ -271,11 +271,9 @@ |
272 | 272 | header: 'A beer for you!', |
273 | 273 | text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // custom text |
274 | 274 | gallery: { |
275 | | - // right now we can only query the local wiki (not e.g. commons) |
276 | | - category: 'Category:Beer', |
277 | | - total: 100, // total number of pictures to retrieve, and to randomise |
278 | | - num: 3, // number of pictures to show from the randomised set |
279 | | - width: 145 // width of each picture in pixels in the interface (not in the template) |
| 275 | + imageList: [ 'Cruzcampo.jpg', 'Glass_of_la_trappe_quadrupel.jpg', 'Hefeweizen.jpg', 'Krušovice_Mušketýr_in_glass.JPG', 'NCI_Visuals_Food_Beer.jpg', 'PintJug.jpg' ], |
| 276 | + width: 145, |
| 277 | + number: 3 |
280 | 278 | }, |
281 | 279 | icon: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/extensions/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-beer.png' // icon for left-side menu |
282 | 280 | }, |
— | — | @@ -285,8 +283,9 @@ |
286 | 284 | header: 'A kitten for you!', |
287 | 285 | text: '[[$3|left|150px]]\n$1\n\n~~~~\n<br style="clear: both"/>', // $3 is the image filename |
288 | 286 | gallery: { |
289 | | - imageList: ['File:Cucciolo gatto Bibo.jpg','File:Kitten (06) by Ron.jpg','File:Kitten-stare.jpg'], |
290 | | - width: 145 |
| 287 | + imageList: [ 'Cucciolo gatto Bibo.jpg','Kitten (06) by Ron.jpg','Kitten-stare.jpg', 'Cat03.jpg', 'Kot_Leon.JPG', 'Greycat.jpg' ], |
| 288 | + width: 145, |
| 289 | + number: 3 |
291 | 290 | }, |
292 | 291 | icon: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/extensions/WikiLove/modules/ext.wikiLove/images/icons/wikilove-icon-kitten.png' // icon for left-side menu |
293 | 292 | }, |
Index: trunk/extensions/WikiLove/modules/ext.wikiLove/ext.wikiLove.core.js |
— | — | @@ -440,60 +440,80 @@ |
441 | 441 | $.wikiLove.gallery = {}; |
442 | 442 | $( '#mw-wikilove-gallery-spinner' ).fadeIn( 200 ); |
443 | 443 | |
444 | | - $.each( $.wikiLove.currentTypeOrSubtype.gallery.imageList, function(index, value) { |
| 444 | + if( typeof $.wikiLove.currentTypeOrSubtype.gallery.number == 'undefined' |
| 445 | + || $.wikiLove.currentTypeOrSubtype.gallery.number <= 0 |
| 446 | + ) { |
| 447 | + $.wikiLove.currentTypeOrSubtype.gallery.number = $.wikiLove.currentTypeOrSubtype.gallery.imageList.length; |
| 448 | + } |
445 | 449 | |
446 | | - $.ajax({ |
447 | | - url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', |
448 | | - data: { |
449 | | - 'action' : 'query', |
450 | | - 'format' : 'json', |
451 | | - 'prop' : 'imageinfo', |
452 | | - 'iiprop' : 'mime|url', |
453 | | - 'titles' : value, |
454 | | - 'iiurlwidth' : $.wikiLove.currentTypeOrSubtype.gallery.width |
455 | | - }, |
456 | | - dataType: 'json', |
457 | | - type: 'POST', |
458 | | - success: function( data ) { |
459 | | - $( '#mw-wikilove-gallery-spinner' ).fadeOut( 200 ); |
460 | | - |
461 | | - if ( !data || !data.query || !data.query.pages ) { |
462 | | - return; |
| 450 | + var titles = ''; |
| 451 | + var imageList = $.wikiLove.currentTypeOrSubtype.gallery.imageList; |
| 452 | + for( var i=0; i<$.wikiLove.currentTypeOrSubtype.gallery.number; i++ ) { |
| 453 | + // get a randomimage |
| 454 | + var id = Math.floor( Math.random() * imageList.length ); |
| 455 | + titles = titles + 'File:' + imageList[id] + '|'; |
| 456 | + |
| 457 | + // remove the random page from the keys array |
| 458 | + imageList.splice(id, 1); |
| 459 | + } |
| 460 | + |
| 461 | + var index = 0; |
| 462 | + $.ajax({ |
| 463 | + url: mw.config.get( 'wgServer' ) + mw.config.get( 'wgScriptPath' ) + '/api.php', |
| 464 | + data: { |
| 465 | + 'action' : 'query', |
| 466 | + 'format' : 'json', |
| 467 | + 'prop' : 'imageinfo', |
| 468 | + 'iiprop' : 'mime|url', |
| 469 | + 'titles' : titles, |
| 470 | + 'iiurlwidth' : $.wikiLove.currentTypeOrSubtype.gallery.width |
| 471 | + }, |
| 472 | + dataType: 'json', |
| 473 | + type: 'POST', |
| 474 | + success: function( data ) { |
| 475 | + $( '#mw-wikilove-gallery-spinner' ).fadeOut( 200 ); |
| 476 | + |
| 477 | + if ( !data || !data.query || !data.query.pages ) { |
| 478 | + return; |
| 479 | + } |
| 480 | + $.each( data.query.pages, function( id, page ) { |
| 481 | + if ( page.imageinfo && page.imageinfo.length ) { |
| 482 | + // build an image tag with the correct url and width |
| 483 | + $img = $( '<img/>' ) |
| 484 | + .attr( 'src', page.imageinfo[0].thumburl ) |
| 485 | + .attr( 'width', $.wikiLove.currentTypeOrSubtype.gallery.width ) |
| 486 | + .hide() |
| 487 | + .load( function() { $( this ).css( 'display', 'inline-block' ); } ); |
| 488 | + $( '#mw-wikilove-gallery-content' ).append( |
| 489 | + $( '<a href="#"></a>' ) |
| 490 | + .attr( 'id', 'mw-wikilove-gallery-img-' + index ) |
| 491 | + .append( $img ) |
| 492 | + .click( function( e ) { |
| 493 | + e.preventDefault(); |
| 494 | + $( '#mw-wikilove-gallery a' ).removeClass( 'selected' ); |
| 495 | + $( this ).addClass( 'selected' ); |
| 496 | + $( '#mw-wikilove-image' ).val( $.wikiLove.gallery[$( this ).attr( 'id' )] ); |
| 497 | + }) |
| 498 | + ); |
| 499 | + $.wikiLove.gallery['mw-wikilove-gallery-img-' + index] = page.title; |
| 500 | + index++; |
463 | 501 | } |
464 | | - $.each( data.query.pages, function( id, page ) { |
465 | | - if ( page.imageinfo && page.imageinfo.length ) { |
466 | | - // build an image tag with the correct url and width |
467 | | - $img = $( '<img/>' ) |
468 | | - .attr( 'src', page.imageinfo[0].thumburl ) |
469 | | - .attr( 'width', $.wikiLove.currentTypeOrSubtype.gallery.width ) |
470 | | - .hide() |
471 | | - .load( function() { $( this ).css( 'display', 'inline-block' ); } ); |
472 | | - $( '#mw-wikilove-gallery-content' ).append( |
473 | | - $( '<a href="#"></a>' ) |
474 | | - .attr( 'id', 'mw-wikilove-gallery-img-' + index ) |
475 | | - .append( $img ) |
476 | | - .click( function( e ) { |
477 | | - e.preventDefault(); |
478 | | - $( '#mw-wikilove-gallery a' ).removeClass( 'selected' ); |
479 | | - $( this ).addClass( 'selected' ); |
480 | | - $( '#mw-wikilove-image' ).val( $.wikiLove.gallery[$( this ).attr( 'id' )] ); |
481 | | - }) |
482 | | - ); |
483 | | - $.wikiLove.gallery['mw-wikilove-gallery-img-' + index] = page.title; |
484 | | - } |
485 | | - } ); |
486 | | - } |
487 | | - }); |
488 | | - |
| 502 | + } ); |
| 503 | + } |
489 | 504 | }); |
490 | | - }, |
| 505 | + } |
491 | 506 | |
492 | 507 | /* |
493 | 508 | * This is a bit of a hack to show some random images. A predefined set of image infos are |
494 | 509 | * retrieved using the API. Then we randomise this set ourselves and select some images to |
495 | 510 | * show. Eventually we probably want to make a custom API call that does this properly and |
496 | 511 | * also allows for using remote galleries such as Commons, which is now prohibited by JS. |
| 512 | + * |
| 513 | + * For now this function is disabled. It also shares code with the current gallery function, |
| 514 | + * so when enabling it again it should be implemented cleaner with a custom API call, and |
| 515 | + * without duplicate code between functions |
497 | 516 | */ |
| 517 | + /* |
498 | 518 | makeGallery: function() { |
499 | 519 | $( '#mw-wikilove-gallery-content' ).html( '' ); |
500 | 520 | $.wikiLove.gallery = {}; |
— | — | @@ -575,6 +595,7 @@ |
576 | 596 | } |
577 | 597 | }); |
578 | 598 | }, |
| 599 | + */ |
579 | 600 | }; |
580 | 601 | } ) ( jQuery ); |
581 | 602 | |