1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-27 17:00:52 +01:00
vichan/js/download-original.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2013-08-31 11:49:06 +02:00
/*
* download-original.js
* https://github.com/savetheinternet/Tinyboard/blob/master/js/download-original.js
*
* Makes image filenames clickable, allowing users to download and save files as their original filename.
* Only works in newer browsers. http://caniuse.com/#feat=download
*
* Released under the MIT license
* Copyright (c) 2012-2013 Michael Save <savetheinternet@tinyboard.org>
* Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
2013-08-31 11:49:06 +02:00
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/download-original.js';
*
*/
onready(function(){
2013-12-27 15:28:46 +01:00
var do_original_filename = function() {
2013-08-31 11:59:26 +02:00
var filename, truncated;
if ($(this).attr('title')) {
filename = $(this).attr('title');
truncated = true;
} else {
filename = $(this).text();
}
2013-08-31 11:49:06 +02:00
$(this).replaceWith(
$('<a></a>')
2013-08-31 11:59:26 +02:00
.attr('download', filename)
2013-08-31 11:49:06 +02:00
.append($(this).contents())
.attr('href', $(this).parent().parent().find('a').attr('href'))
2013-08-31 11:59:26 +02:00
.attr('title', _('Save as original filename') + (truncated ? ' (' + filename + ')' : ''))
2013-08-31 11:49:06 +02:00
);
2013-12-27 15:28:46 +01:00
};
$('.postfilename').each(do_original_filename);
$(document).on('new_post', function(e, post) {
2013-12-27 15:28:46 +01:00
$(post).find('.postfilename').each(do_original_filename);
2013-08-31 11:49:06 +02:00
});
});