зеркало из https://github.com/mozilla/FlightDeck.git
much better handling of file extensions. defaults attachments to a .js file if no extension entered.
This commit is contained in:
Родитель
95376a4d95
Коммит
dd4085274b
|
@ -19,3 +19,4 @@ settings_local.py
|
|||
.coverage
|
||||
.figleaf
|
||||
vendor
|
||||
*.pyc
|
||||
|
|
|
@ -139,12 +139,12 @@ FileTree = new Class({
|
|||
this.renameBranch(element);
|
||||
}.bind(this))
|
||||
|
||||
hasExtension = hasExtension || (text.indexOf('.') >= 0);
|
||||
hasExtension = hasExtension || !!text.getFileExtension();
|
||||
|
||||
var range = document.createRange(),
|
||||
node = label.firstChild;
|
||||
range.setStart(node, 0);
|
||||
range.setEnd(node, hasExtension ? text.split('.')[0].length : text.length);
|
||||
range.setEnd(node, hasExtension ? text.length - text.getFileExtension().length -1 : text.length);
|
||||
sel = window.getSelection();
|
||||
sel.removeAllRanges();
|
||||
sel.addRange(range);
|
||||
|
@ -234,3 +234,16 @@ FileTree.Collapse = new Class({
|
|||
}
|
||||
|
||||
});
|
||||
|
||||
String.implement('getFileExtension', function() {
|
||||
var parts = this.split('.'),
|
||||
ext = parts.pop(),
|
||||
filename = parts.join('.');
|
||||
|
||||
return !!filename && !!ext && !ext.match(/[^a-zA-Z0-9]/) && ext;
|
||||
});
|
||||
|
||||
String.implement('getFileName', function() {
|
||||
var ext = this.getFileExtension();
|
||||
return ext && this.substring(0, this.length - ext.length - 1);
|
||||
});
|
||||
|
|
|
@ -749,11 +749,9 @@ Package.Edit = new Class({
|
|||
var that = this;
|
||||
|
||||
// break off an extension from the filename
|
||||
var ext = newName.match(/\.([^\.]+$)/);
|
||||
if (ext) {
|
||||
ext = ext[1];
|
||||
newName = newName.substring(0, ext.length);
|
||||
}
|
||||
var ext = newName.getFileExtension();
|
||||
newName = newName.getFileName();
|
||||
|
||||
|
||||
|
||||
new Request.JSON({
|
||||
|
|
|
@ -471,10 +471,10 @@ var Sidebar = new Class({
|
|||
}
|
||||
|
||||
for (var f = 0; f < files.length; f++){
|
||||
var fname = files[f].fileName.replace(/\.[^\.]+$/g, ''),
|
||||
ext = files[f].fileName.match(/\.([^\.]+)$/)[1];
|
||||
var fname = files[f].fileName.getFileName(),
|
||||
ex = files[f].fileName.getFileExtension();
|
||||
|
||||
if (Attachment.exists(fname, ext)) {
|
||||
if (Attachment.exists(fname, ex)) {
|
||||
fd.error.alert('Filename has to be unique', 'You already have an attachment with that name.');
|
||||
return;
|
||||
}
|
||||
|
@ -508,6 +508,12 @@ var Sidebar = new Class({
|
|||
filename = filename.replace(/[^a-zA-Z0-9\-_\/\.]+/g, '-');
|
||||
filename = filename.replace(/\/{2,}/g, '/');
|
||||
filename = filename.replace(/\/*$/g, ''); /* */
|
||||
|
||||
|
||||
if (!isFolder && !filename.getFileExtension()) {
|
||||
|
||||
filename = filename.replace(/\./, '') + '.js'; //we're defaulting to .js files if the user doesnt enter an extension
|
||||
}
|
||||
}
|
||||
|
||||
if(files.length) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче