From 0005f11098890ad76c1b9963792cd686493649a9 Mon Sep 17 00:00:00 2001 From: marktaiwan Date: Wed, 18 Mar 2015 21:35:58 +0800 Subject: [PATCH] initialize file selector soon as it's loaded Conflicts: templates/post_form.html --- js/file-selector.js | 42 ++++++++++++++++++------------------------ templates/post_form.html | 2 ++ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/js/file-selector.js b/js/file-selector.js index ddae2d09..b4589706 100644 --- a/js/file-selector.js +++ b/js/file-selector.js @@ -5,34 +5,29 @@ * $config['additional_javascript'][] = 'js/jquery.min.js'; * $config['additional_javascript'][] = 'js/file-selector.js'; */ +function init_file_selector() { -if (active_page == 'index' || active_page == 'thread') { $(document).ready(function () { + // add options panel item + if (window.Options && Options.get_tab('general')) { + Options.extend_tab('general', ''); -// 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'; + } + }); - $('#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); -} + 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. -// fallback to old -if (localStorage.file_dragdrop == 'false' || !(window.FileReader && window.File)) { - $('.dropzone-wrap').remove(); - $('#upload_file').show(); - +if (localStorage.file_dragdrop == 'false' || !(window.FileReader && window.File)) return; -} // multipost not enabled if (typeof max_images == 'undefined') { @@ -40,6 +35,8 @@ if (typeof max_images == 'undefined') { } 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) @@ -140,8 +137,6 @@ var dropHandlers = { } }; -$('#upload input[type=file]').hide(); // hide the original file selector -$('.dropzone-wrap').css('user-select', 'none').show(); // let jquery add browser specific prefix // attach handlers $(document).on(dropHandlers, '.dropzone'); @@ -184,5 +179,4 @@ $(document).on('paste', function (e) { } }); -}); } diff --git a/templates/post_form.html b/templates/post_form.html index 9596ee6b..809230f0 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -106,6 +106,8 @@ + + {% if config.allow_upload_by_url %}
: