Browse Source

Enable download with filename without JavaScript

This enables the functionality of download-original.js for non-JS users.
main
discomrade 3 years ago
parent
commit
6dfedaeb4c
  1. 42
      js/download-original.js
  2. 4
      templates/post/fileinfo.html

42
js/download-original.js

@ -1,42 +0,0 @@
/*
* 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>
*
* Usage:
* $config['additional_javascript'][] = 'js/jquery.min.js';
* $config['additional_javascript'][] = 'js/download-original.js';
*
*/
onready(function(){
var do_original_filename = function() {
var filename, truncated;
if ($(this).attr('title')) {
filename = $(this).attr('title');
truncated = true;
} else {
filename = $(this).text();
}
$(this).replaceWith(
$('<a></a>')
.attr('download', filename)
.append($(this).contents())
.attr('href', $(this).parent().parent().find('a').attr('href'))
.attr('title', _('Save as original filename') + (truncated ? ' (' + filename + ')' : ''))
);
};
$('.postfilename').each(do_original_filename);
$(document).on('new_post', function(e, post) {
$(post).find('.postfilename').each(do_original_filename);
});
});

4
templates/post/fileinfo.html

@ -22,9 +22,9 @@
{% if config.show_filename and file.filename %}
,
{% if file.filename|length > config.max_filename_display %}
<span class="postfilename" title="{{ file.filename|e|bidi_cleanup }}">{{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }}</span>
<a href="{{ config.uri_img }}{{ file.file|e|bidi_cleanup }}" download="{{ file.filename|e|bidi_cleanup }}" title="Save as original filename: {{ file.filename|e|bidi_cleanup }}">{{ file.filename|truncate_filename(config.max_filename_display)|e|bidi_cleanup }}</a>
{% else %}
<span class="postfilename">{{ file.filename|e|bidi_cleanup }}</span>
<a href="{{ config.uri_img }}{{ file.file|e|bidi_cleanup }}" download="{{ file.filename|e|bidi_cleanup }}" title="Save as original filename">{{ file.filename|e|bidi_cleanup }}</a>
{% endif %}
{% endif %}
)

Loading…
Cancel
Save