MediaWiki:Gadget-fileDownload.js: Difference between revisions

From Old School Near-Reality Wiki
Jump to navigation Jump to search
(Created page with "→‎* * Adds a download link to file pages * * @author Gaz Lloyd: $(function(){ if (!(mw.config.get('wgNamespaceNumber') === 6 && $('.fullMedia, .filehistory').length > 0)) { return; } function addLinks() { // underneath image - also replace filename with page title $('.fullMedia a.internal').after( ' (', $('<a>') .text('download') .addClass('fileDownload') .attr({ href: $('.fullMedia a.internal').attr('href'), download: mw.conf...")
 
(No difference)

Latest revision as of 19:15, 3 October 2022

 1 /**
 2  * Adds a download link to file pages
 3  * 
 4  * @author Gaz Lloyd
 5  */
 6 $(function(){
 7 	if (!(mw.config.get('wgNamespaceNumber') === 6  && $('.fullMedia, .filehistory').length > 0)) {
 8 		return;
 9 	}
10 	function addLinks() {
11 		// underneath image - also replace filename with page title
12 		$('.fullMedia a.internal').after(
13 			' (',
14 			$('<a>')
15 				.text('download')
16 				.addClass('fileDownload')
17 				.attr({
18 					href: $('.fullMedia a.internal').attr('href'),
19 					download: mw.config.get('wgTitle').replace('_', ' '),
20 					title: 'Download this file'
21 				}),
22 			')'
23 		);
24 		
25 		// file history - leave numbers in file name
26 		$('.filehistory tr td[style]').each(function() {
27 			var $this = $(this);
28 			$this.append(
29 				$('<br />'),
30 				$('<a>')
31 					.text('Download')
32 					.addClass('fileDownload')
33 					.attr({
34 						download: '',
35 						href: $this.find('a').attr('href'),
36 						title: 'Download this version of this file'
37 					})
38 			);
39 		});
40 	}
41 	addLinks()
42 })