From 3287e574210fa8531d1ab2d9f658c8dc2cd949e0 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 31 Aug 2013 19:49:06 +1000 Subject: js/download-original.js --- js/download-original.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 js/download-original.js (limited to 'js') diff --git a/js/download-original.js b/js/download-original.js new file mode 100644 index 00000000..673cdf65 --- /dev/null +++ b/js/download-original.js @@ -0,0 +1,27 @@ +/* + * 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 + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/download-original.js'; + * + */ + +onready(function(){ + $('.postfilename').each(function() { + $(this).replaceWith( + $('') + .attr('download', $(this).text()) + .append($(this).contents()) + .attr('href', $(this).parent().parent().find('a').attr('href')) + .attr('title', _('Save as original filename')) + ); + }); +}); -- cgit v1.3 From c567131ca703a8bda0c3b1ca83fa2cae5af863a4 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Sat, 31 Aug 2013 19:59:26 +1000 Subject: bugfix: work with truncated filenames --- js/download-original.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'js') diff --git a/js/download-original.js b/js/download-original.js index 673cdf65..b7c98c35 100644 --- a/js/download-original.js +++ b/js/download-original.js @@ -16,12 +16,20 @@ onready(function(){ $('.postfilename').each(function() { + var filename, truncated; + if ($(this).attr('title')) { + filename = $(this).attr('title'); + truncated = true; + } else { + filename = $(this).text(); + } + $(this).replaceWith( $('') - .attr('download', $(this).text()) + .attr('download', filename) .append($(this).contents()) .attr('href', $(this).parent().parent().find('a').attr('href')) - .attr('title', _('Save as original filename')) + .attr('title', _('Save as original filename') + (truncated ? ' (' + filename + ')' : '')) ); }); }); -- cgit v1.3