-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Show images from subcategories" link to category pages
- Loading branch information
1 parent
495a7dc
commit ab96272
Showing
5 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
Script for [[Category:Something]] pages. | ||
*/ | ||
|
||
$( function () { | ||
if ( !$( '#mw-subcategories' ).length ) { | ||
// No subcategories. | ||
return; | ||
} | ||
|
||
var $gallery = $( '.gallery' ); | ||
if ( !$gallery.length ) { | ||
// No images in this category, | ||
// it's very likely that subcategores won't have them either. | ||
return; | ||
} | ||
|
||
var $loading = $( '<div>' ) | ||
.attr( 'class', 'mw-subcatimagesgallery-loading' ) | ||
.append( mw.msg( 'subcatimagesgallery-link-loading' ) ); | ||
|
||
function onfail() { | ||
$loading.html( mw.msg( 'subcatimagesgallery-empty' ) ); | ||
} | ||
|
||
$gallery.after( $( '<a>' ) | ||
.append( mw.msg( 'subcatimagesgallery-link' ) ) | ||
.click( function () { | ||
$( this ).remove(); | ||
$gallery.after( $loading ); | ||
|
||
var url = new mw.Title( 'Special:SubcatImagesGallery/' + mw.config.get( 'wgTitle' ) ).getUrl(); | ||
$.get( url ).done( function ( res ) { | ||
var $newgallery = $( '<div>' ).append( res ).find( '.gallery' ); | ||
if ( !$newgallery.length ) { | ||
return onfail(); | ||
} | ||
|
||
$loading.replaceWith( $newgallery ); | ||
$newgallery[ 0 ].scrollIntoView( { behavior: 'smooth' } ); | ||
} ).fail( onfail ); | ||
} ) | ||
); | ||
} ); |