mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-21 13:00:10 +01:00
Fixes problems with file type recognition.
This commit is contained in:
parent
cc06b07d52
commit
e67c854cb5
@ -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 _.extend({}, defaults, config.options);
|
||||
});
|
||||
|
||||
|
||||
module.define('core/types', [H5AI_CONFIG], function (config) {
|
||||
|
||||
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;
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
getType = function (sequence) {
|
||||
|
||||
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 {
|
||||
settings: _.extend({}, defaults, config.options),
|
||||
types: _.extend({}, config.types),
|
||||
langs: _.extend({}, config.langs)
|
||||
getType: getType
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
module.define('core/settings', ['core/config'], function (config) {
|
||||
module.define('core/langs', [H5AI_CONFIG], function (config) {
|
||||
|
||||
return config.settings;
|
||||
});
|
||||
|
||||
|
||||
module.define('core/types', ['core/config'], function (config) {
|
||||
|
||||
return config.types;
|
||||
});
|
||||
|
||||
|
||||
module.define('core/langs', ['core/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 () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user