3 function itemTemplate( results ) {
5 return results.map( ( result ) => {
6 const imageThumbnailSrc = result.thumbnail ? result.thumbnail.source : '';
8 return $( '<div>' ).addClass( 'iw-result__mini-gallery' ).append(
10 .addClass( 'iw-result__mini-gallery__image' )
12 style: 'background-image: url(' + imageThumbnailSrc + ')',
13 href: new mw.Title( result.title ).getUrl()
15 $( '<span>' ).addClass( 'iw-result__mini-gallery__caption' )
23 function itemWrapperTemplate( pageQuery, itemTemplateOutput ) {
25 return $( '<li>' ).addClass( 'iw-resultset iw-resultset--image' ).attr( 'data-iw-resultset-pos', 0 ).append(
26 $( '<div>' ).addClass( 'iw-result__header' ).append(
27 $( '<strong>' ).text( mw.msg( 'searchprofile-images' ) )
29 $( '<div>' ).addClass( 'iw-result__content' ).append(
32 $( '<div>' ).addClass( 'iw-result__footer' ).append(
34 .attr( 'href', new mw.Title( 'Special:Search' ).getUrl( {
39 .text( mw.msg( 'search-interwiki-more-results' ) )
45 const api = new mw.Api();
46 const pageUrl = new URL( location.href );
51 gsrsearch: pageUrl.searchParams.get( 'search' ),
52 gsrnamespace: mw.config.get( 'wgNamespaceIds' ).file,
59 } ).done( ( resp ) => {
60 const results = resp.query && resp.query.pages || false;
66 results.sort( ( a, b ) => a.index - b.index );
68 const multimediaWidgetTemplate = itemWrapperTemplate(
69 pageUrl.searchParams.get( 'search' ),
70 itemTemplate( results )
72 /* we really only need to wait for document ready for DOM manipulation */
74 $( '.iw-results' ).append( multimediaWidgetTemplate );