From d265bcd8988ae9e83b84b375a58e074e5ffa5656 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 30 Sep 2015 11:51:59 +0200 Subject: Make file input look more consistent across browsers --- modules/backup.inc.php | 1 + modules/sysconfig/addmodule_branding.inc.php | 1 + modules/sysconfig/addmodule_custommodule.inc.php | 1 + script/fileselect.js | 26 ++++++++++++++++++++++++ style/default.css | 26 ++++++++++++++++++++++++ templates/backup/_page.html | 10 ++++++--- templates/backup/restore.html | 1 - templates/sysconfig/branding-start.html | 9 +++++++- templates/sysconfig/custom-upload.html | 12 +++++++---- 9 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 script/fileselect.js diff --git a/modules/backup.inc.php b/modules/backup.inc.php index 8cc0502f..d152c03f 100644 --- a/modules/backup.inc.php +++ b/modules/backup.inc.php @@ -27,6 +27,7 @@ class Page_Backup extends Page if ($this->action === 'restore') { Render::addTemplate('backup/restore', $this->templateData); } else { + Render::addScriptBottom('fileselect'); Render::addTemplate('backup/_page'); } } diff --git a/modules/sysconfig/addmodule_branding.inc.php b/modules/sysconfig/addmodule_branding.inc.php index c659a007..336e2a77 100644 --- a/modules/sysconfig/addmodule_branding.inc.php +++ b/modules/sysconfig/addmodule_branding.inc.php @@ -9,6 +9,7 @@ class Branding_Start extends AddModule_Base protected function renderInternal() { + Render::addScriptBottom('fileselect'); Render::addDialog(Dictionary::translate('config-module', 'branding_title'), false, 'sysconfig/branding-start', array( 'step' => 'Branding_ProcessFile', 'edit' => $this->edit ? $this->edit->id() : false diff --git a/modules/sysconfig/addmodule_custommodule.inc.php b/modules/sysconfig/addmodule_custommodule.inc.php index e3ddeca8..f7342b7b 100644 --- a/modules/sysconfig/addmodule_custommodule.inc.php +++ b/modules/sysconfig/addmodule_custommodule.inc.php @@ -12,6 +12,7 @@ class CustomModule_Start extends AddModule_Base protected function renderInternal() { Session::set('mod_temp', false); + Render::addScriptBottom('fileselect'); Render::addDialog(Dictionary::translate('config-module', 'custom_title'), false, 'sysconfig/custom-upload', array( 'step' => 'CustomModule_ProcessUpload', 'edit' => $this->edit ? $this->edit->id() : false diff --git a/script/fileselect.js b/script/fileselect.js new file mode 100644 index 00000000..df4ff7b9 --- /dev/null +++ b/script/fileselect.js @@ -0,0 +1,26 @@ +$(document).on('change', '.btn-file :file', function() { + var input = $(this); + var numFiles = input.get(0).files ? input.get(0).files.length : 1; + var label = input.val().replace(/\\/g, '/').replace(/.*\//, ''); + input.trigger('fileselect', [numFiles, label]); +}); + +$(document).ready(function() { + $('.btn-file :file').on('fileselect', function(event, numFiles, label) { + + var input = $(this).parents('.upload-ex').find(':text'); + var log = numFiles > 1 ? numFiles + ' files selected' : label; + + if (input.length) { + input.val(log); + } else { + if (log) + alert(log); + } + + }); +}); + +$('.upload-ex :text').click(function () { + $(this).parents('.upload-ex').find(':file').click(); +}); \ No newline at end of file diff --git a/style/default.css b/style/default.css index 69a12699..9e430b73 100644 --- a/style/default.css +++ b/style/default.css @@ -187,3 +187,29 @@ body { .slx-strike { text-decoration: line-through; } + +/* File upload */ + +.btn-file { + position: relative; + overflow: hidden; +} +.btn-file input[type=file] { + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + filter: alpha(opacity=0); + opacity: 0; + background: red; + cursor: inherit; + display: block; + cursor: pointer; +} +input[readonly] { + background-color: white !important; + cursor: text !important; +} \ No newline at end of file diff --git a/templates/backup/_page.html b/templates/backup/_page.html index 0c4429e2..47b5a174 100644 --- a/templates/backup/_page.html +++ b/templates/backup/_page.html @@ -19,9 +19,13 @@
{{lang_restore}}

{{lang_restoreDescription}}

-
- {{lang_file}} - +
+ + + + {{lang_browseForFile}}… + +
diff --git a/templates/backup/restore.html b/templates/backup/restore.html index c5d9ba13..42580647 100644 --- a/templates/backup/restore.html +++ b/templates/backup/restore.html @@ -2,7 +2,6 @@
{{lang_backup}}
-
{{lang_stopping}} syncdaemon
{{lang_stopping}} dmsd
{{lang_stopping}} ldadp
{{lang_stopping}} vmstore
diff --git a/templates/sysconfig/branding-start.html b/templates/sysconfig/branding-start.html index 1470929f..09b9ca27 100644 --- a/templates/sysconfig/branding-start.html +++ b/templates/sysconfig/branding-start.html @@ -11,7 +11,14 @@ {{lang_or}}
- +
+ + + + {{lang_browseForFile}}… + + +
diff --git a/templates/sysconfig/custom-upload.html b/templates/sysconfig/custom-upload.html index 02f813f6..c453a97d 100644 --- a/templates/sysconfig/custom-upload.html +++ b/templates/sysconfig/custom-upload.html @@ -5,10 +5,14 @@
-
- {{lang_file}} - -
+
+ + + + {{lang_browseForFile}}… + + +

{{lang_supportedFiles}}: .tar.gz, .tar.bz2, .zip

-- cgit v1.2.3-55-g7522