Permalink
Browse files

much better handling of file extensions. defaults attachments to a .j…

…s file if no extension entered.
  • Loading branch information...
1 parent 95376a4 commit dd4085274b29d99fdcb5324ee7862283c3b4285d @seanmonstar seanmonstar committed Feb 9, 2011
Showing with 28 additions and 10 deletions.
  1. +1 −0 .gitignore
  2. +15 −2 media/jetpack/js/FileTree.js
  3. +3 −5 media/jetpack/js/Package.js
  4. +9 −3 media/jetpack/js/Sidebar.js
View
@@ -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) {

0 comments on commit dd40852

Please sign in to comment.