Permalink
Browse files

Fixes problems with file type recognition.

  • Loading branch information...
1 parent cc06b07 commit e67c854cb50cd0769ba9cb26e973d0a25cf0c30f @lrsjng committed Apr 17, 2012
@@ -1,32 +1,65 @@
-module.define('core/config', [H5AI_CONFIG], function (config) {
+module.define('core/settings', [H5AI_CONFIG], function (config) {
var defaults = {
rootAbsHref: '/',
h5aiAbsHref: '/_h5ai/',
};
- return {
- settings: _.extend({}, defaults, config.options),
- types: _.extend({}, config.types),
- langs: _.extend({}, config.langs)
- };
+ return _.extend({}, defaults, config.options);
});
-module.define('core/settings', ['core/config'], function (config) {
+module.define('core/types', [H5AI_CONFIG], function (config) {
- return config.settings;
-});
+ var reEndsWithSlash = /\/$/,
+ reStartsWithDot = /^\./,
+
+ fileExts = {},
+ fileNames = {},
+
+ parse = function (types) {
+
+ _.each(types, function (matches, type) {
+
+ _.each(matches, function (match) {
+
+ match = match.toLowerCase();
+ if (reStartsWithDot.test(match)) {
+ fileExts[match] = type;
+ } else {
+ fileNames[match] = type;
+ }
+ })
+ });
+ },
-module.define('core/types', ['core/config'], function (config) {
+ getType = function (sequence) {
- return config.types;
+ if (reEndsWithSlash.test(sequence)) {
+ return 'folder';
+ }
+
+ sequence = sequence.toLowerCase();
+
+ var slashidx = sequence.lastIndexOf('/'),
+ name = slashidx >= 0 ? sequence.substr(slashidx + 1) : sequence,
+ dotidx = sequence.lastIndexOf('.'),
+ ext = dotidx >= 0 ? sequence.substr(dotidx) : sequence;
+
+ return fileNames[name] || fileExts[ext] || 'unknown';
+ };
+
+ parse(_.extend({}, config.types));
+
+ return {
+ getType: getType
+ };
});
-module.define('core/langs', ['core/config'], function (config) {
+module.define('core/langs', [H5AI_CONFIG], function (config) {
- return config.langs;
+ return _.extend({}, config.langs);
});
@@ -49,7 +49,7 @@ module.define('ext/select', [jQuery, 'core/settings', 'core/event'], function ($
event.preventDefault();
$document.off('mousemove', selectionUpdate);
- $selectionRect.hide().css({left: 0, top: 0, width: 0, height: 0});
+ $selectionRect.fadeOut(300);
$('#extended .entry.selecting.selected').removeClass('selecting').removeClass('selected');
$('#extended .entry.selecting').removeClass('selecting').addClass('selected');
publish();
@@ -100,10 +100,6 @@ module.define('ext/select', [jQuery, 'core/settings', 'core/event'], function ($
$selectionRect.hide().appendTo($('body'));
- // $('#topbar,#bottombar,#tree,input').on('mousedown', noSelection);
- // $('#content').on('mousedown', 'a', noSelectionUnlessCtrl);
- // $document.on('mousedown', selectionStart);
-
$document
.on('mousedown', '.noSelection', noSelection)
.on('mousedown', '.noSelectionUnlessCtrl,input,a', noSelectionUnlessCtrl)
@@ -88,9 +88,9 @@
_.each(definitions, function (def) {
var invDeps = [];
- _.each(allDeps, function (depId, id) {
+ _.each(allDeps, function (depIds, id) {
- if (_.inArray(def.id, depId) >= 0) {
+ if (_.indexOf(depIds, def.id) >= 0) {
invDeps.push(id);
}
});
@@ -9,10 +9,6 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
reEndsWithSlash = /\/$/,
- pathEndsWithSlash = function (sequence) {
-
- return reEndsWithSlash.test(sequence);
- },
createLabel = function (sequence) {
@@ -60,29 +56,6 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
},
- extToFileType = (function (types) {
- var map = {};
- $.each(types, function (type, exts) {
- $.each(exts, function (idx, ext) {
- map[ext] = type;
- });
- });
- return map;
- }(types)),
-
- getFileType = function (sequence) {
-
- if (pathEndsWithSlash(sequence)) {
- return 'folder';
- }
-
- var dotidx = sequence.lastIndexOf('.'),
- ext = dotidx >= 0 ? sequence.substr(dotidx) : sequence;
-
- return extToFileType[ext.toLowerCase()] || 'unknown';
- },
-
-
reContentType = /^text\/html;h5ai=/,
ajaxRequest = function (self, parser, callback) {
@@ -120,7 +93,7 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
cache[absHref] = this;
this.absHref = absHref;
- this.type = getFileType(absHref);
+ this.type = types.getType(absHref);
this.label = createLabel(absHref === '/' ? domain : split.name);
this.time = null;
this.size = null;
@@ -194,7 +167,7 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
isFolder: function () {
- return pathEndsWithSlash(this.absHref);
+ return reEndsWithSlash.test(this.absHref);
},
isCurrentFolder: function () {

0 comments on commit e67c854

Please sign in to comment.