From 591b383f2dd1601009382152079e004034c4258d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Friedrich=20Dreyer?= Date: Mon, 13 May 2013 15:54:45 +0200 Subject: [PATCH] peselect filename without extension on rename --- apps/files/js/filelist.js | 7 +++++++ core/js/js.js | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index b1e9a88506..c24d1fd824 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -191,6 +191,13 @@ var FileList={ td.children('a.name').hide(); td.append(form); input.focus(); + //preselect input + var len = input.val().lastIndexOf('.'); + if (len === -1) { + len = input.val().length; + } + input.selectRange(0,len); + form.submit(function(event){ event.stopPropagation(); event.preventDefault(); diff --git a/core/js/js.js b/core/js/js.js index d85e6d88f8..3cb4d3dd15 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -767,6 +767,26 @@ OC.set=function(name, value) { context[tail]=value; }; +/** + * select a range in an input field + * @link http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area + * @param {type} start + * @param {type} end + */ +$.fn.selectRange = function(start, end) { + return this.each(function() { + if (this.setSelectionRange) { + this.focus(); + this.setSelectionRange(start, end); + } else if (this.createTextRange) { + var range = this.createTextRange(); + range.collapse(true); + range.moveEnd('character', end); + range.moveStart('character', start); + range.select(); + } + }); +}; /** * Calls the server periodically every 15 mins to ensure that session doesnt