diff --git a/js/file-selector.js b/js/file-selector.js new file mode 100644 index 00000000..b4589706 --- /dev/null +++ b/js/file-selector.js @@ -0,0 +1,182 @@ +/* + * file-selector.js - Add support for drag and drop file selection, and paste from clipbboard on supported browsers. + * + * Usage: + * $config['additional_javascript'][] = 'js/jquery.min.js'; + * $config['additional_javascript'][] = 'js/file-selector.js'; + */ +function init_file_selector() { + +$(document).ready(function () { + // add options panel item + if (window.Options && Options.get_tab('general')) { + Options.extend_tab('general', ''); + + $('#file-drag-drop>input').on('click', function() { + if ($('#file-drag-drop>input').is(':checked')) { + localStorage.file_dragdrop = 'true'; + } else { + localStorage.file_dragdrop = 'false'; + } + }); + + if (localStorage.file_dragdrop === 'undefined') localStorage.file_dragdrop = 'true'; + if (localStorage.file_dragdrop === 'true') $('#file-drag-drop>input').prop('checked', true); + } +}); + +// disabled by user, or incompatible browser. +if (localStorage.file_dragdrop == 'false' || !(window.FileReader && window.File)) + return; + +// multipost not enabled +if (typeof max_images == 'undefined') { + var max_images = 1; +} + +var files = []; +$('#upload_file').hide(); // hide the original file selector +$('.dropzone-wrap').css('user-select', 'none').show(); // let jquery add browser specific prefix + +function addFile(file) { + if (files.length == max_images) + return; + + files.push(file); + addThumb(file); +} + +function removeFile(file) { + files.splice(files.indexOf(file), 1); +} + +function getThumbElement(file) { + return $('.tmb-container').filter(function(){return($(this).data('file-ref')==file);}); +} + +function addThumb(file) { + + var fileName = (file.name.length < 24) ? file.name : file.name.substr(0, 22) + '…'; + var fileType = file.type.split('/')[0]; + var fileExt = file.type.split('/')[1]; + var $fileThumb; + + $('.file-thumbs').append($('
{% trans %}Name{% endtrans %} @@ -91,6 +91,13 @@ |
+
:
@@ -129,7 +136,8 @@
Confused? See the FAQ. |
+
{% if config.allow_upload_by_url %}
---|
+ {% trans %}Do not bump{% endtrans %}
+
{% if config.spoiler_images %}+ {% trans %}(you can also write sage in the email field){% endtrans %}
+ {% trans %}Spoiler images{% endtrans %}
+ {% endif %}
{% if config.allow_no_country and config.country_flags and not config.force_flag %}+ {% trans %}(this replaces the thumbnails of your images with question marks){% endtrans %}
+ {% trans %}Hide country{% endtrans %}
+ {% endif %}
{% if mod %}
@@ -225,7 +239,7 @@
+ {% trans %}(this board displays your country when you post if this is unchecked){% endtrans %} |
-