From ea8471781ee26f79c3835e68b31353601e78d0a8 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Mon, 23 Feb 2015 11:26:14 +0100 Subject: upload_form: Support multiple textareas/files at the same time Signed-off-by: Florian Pritz --- data/js/script.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'data') diff --git a/data/js/script.js b/data/js/script.js index ee8ba9e3c..c96bdb5b7 100644 --- a/data/js/script.js +++ b/data/js/script.js @@ -155,7 +155,7 @@ function fixedEncodeURIComponent (str) { document.getElementById('upload_button').innerHTML = "File(s) too big"; document.getElementById('upload_button').disabled = true; } else { - document.getElementById('upload_button').innerHTML = "Upload it!"; + document.getElementById('upload_button').innerHTML = "Upload/Paste it!"; document.getElementById('upload_button').disabled = false; } } @@ -179,6 +179,43 @@ function fixedEncodeURIComponent (str) { }); + $(document).on("input propertychange", '.text-upload', function() { + var need_new = true; + + $('.text-upload').each(function() { + if (!$(this).val()) { + need_new = false; + return; + } + }); + + if (need_new) { + var i = $('#textboxes .tab-content .tab-pane').length + 1; + var new_tab = $('#text-upload-tab-1') + .clone() + .attr("id", "text-upload-tab-"+i) + .toggleClass("active", false) + .appendTo('#textboxes .tab-content'); + new_tab.find("[name^=filename]").attr("name", "filename["+i+"]").val(""); + new_tab.find("[name^=content]").attr("name", "content["+i+"]").val(""); + $('#textboxes ul.nav') + .append('
  • Paste '+i+'
  • '); + } + }); + + $(document).on("input propertychange", '#textboxes input[name^=filename]', function() { + var name = $(this).val(); + var tabId = $(this).closest("[id^=text-upload-tab-]").attr("id"); + var id = tabId.match(/-(\d)$/)[1]; + var tab = $('#textboxes .nav a[href="#'+tabId+'"]'); + + if (name != "") { + tab.text(name); + } else { + tab.text("Paste " + id); + } + }); + if (typeof $.tablesorter !== 'undefined') { // source: https://projects.archlinux.org/archweb.git/tree/sitestatic/archweb.js $.tablesorter.addParser({ -- cgit v1.2.3-24-g4f1b