From f9751b013bfb0f1ef990f7676426eef0d04e02e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 12 Feb 2019 15:50:19 +0100 Subject: [PATCH] misc: refactor (a bit) file upload javascript code (#30566) --- wcs/qommon/static/js/qommon.fileupload.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/wcs/qommon/static/js/qommon.fileupload.js b/wcs/qommon/static/js/qommon.fileupload.js index b8febec26..13868e25f 100644 --- a/wcs/qommon/static/js/qommon.fileupload.js +++ b/wcs/qommon/static/js/qommon.fileupload.js @@ -1,13 +1,13 @@ -$(function() { - $('.file-upload-widget').each(function() { +$.WcsFileUpload = { + prepare: function() { var base_widget = $(this); if ($(base_widget).find('input[type=hidden]').val()) { $(base_widget).find('input[type=file]').hide(); $(base_widget).find('.use-file-from-fargo').hide(); - $(this).addClass('has-file'); + $(base_widget).addClass('has-file'); } else { $(base_widget).find('.fileinfo').hide(); - $(this).addClass('has-no-file'); + $(base_widget).addClass('has-no-file'); } $(this).find('input[type=file]').fileupload({ dropZone: base_widget, @@ -57,5 +57,9 @@ $(function() { $(base_widget).find('input[type=file]').click(); return false; }); - }); + } +} + +$(function() { + $('.file-upload-widget').each($.WcsFileUpload.prepare); });