From 24a08c686df393e41fca251776ce0a414d75976f Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Thu, 28 Nov 2013 10:17:01 +0100 Subject: [PATCH] New file box now has default file name + extension Whenever a user creates a file or folder in the web UI, the input field will contain a default file name, pre-selected up to the extension for easier typing. The purpose is mostly to prevent users creating text files without an extension. Fixes #6045 --- apps/files/js/file-upload.js | 16 +++++++++++++--- apps/files/templates/index.php | 4 ++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js index bc1244a1e6..e9663353f7 100644 --- a/apps/files/js/file-upload.js +++ b/apps/files/js/file-upload.js @@ -508,11 +508,15 @@ $(document).ready(function() { $(this).children('p').remove(); // add input field - var form=$('
'); - var input=$(''); + var form = $('
'); + var input = $(''); + var newName = $(this).attr('data-newname') || ''; + if (newName) { + input.val(newName); + } form.append(input); $(this).append(form); - + var lastPos; var checkInput = function () { var filename = input.val(); if (type === 'web' && filename.length === 0) { @@ -543,6 +547,12 @@ $(document).ready(function() { }); input.focus(); + // pre select name up to the extension + lastPos = newName.lastIndexOf('.'); + if (lastPos === -1) { + lastPos = newName.length; + } + input.selectRange(0, lastPos); form.submit(function(event) { event.stopPropagation(); event.preventDefault(); diff --git a/apps/files/templates/index.php b/apps/files/templates/index.php index 4f8623573c..bb46086a4d 100644 --- a/apps/files/templates/index.php +++ b/apps/files/templates/index.php @@ -5,9 +5,9 @@ t('New'));?>