mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 20:44:53 -04:00
Fixes problems with file type recognition.
This commit is contained in:
parent
cc06b07d52
commit
e67c854cb5
4 changed files with 56 additions and 54 deletions
|
@ -1,32 +1,65 @@
|
||||||
|
|
||||||
module.define('core/config', [H5AI_CONFIG], function (config) {
|
module.define('core/settings', [H5AI_CONFIG], function (config) {
|
||||||
|
|
||||||
var defaults = {
|
var defaults = {
|
||||||
rootAbsHref: '/',
|
rootAbsHref: '/',
|
||||||
h5aiAbsHref: '/_h5ai/',
|
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 {
|
return {
|
||||||
settings: _.extend({}, defaults, config.options),
|
getType: getType
|
||||||
types: _.extend({}, config.types),
|
|
||||||
langs: _.extend({}, config.langs)
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
module.define('core/settings', ['core/config'], function (config) {
|
module.define('core/langs', [H5AI_CONFIG], function (config) {
|
||||||
|
|
||||||
return config.settings;
|
return _.extend({}, config.langs);
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
module.define('core/types', ['core/config'], function (config) {
|
|
||||||
|
|
||||||
return config.types;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
module.define('core/langs', ['core/config'], function (config) {
|
|
||||||
|
|
||||||
return config.langs;
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -49,7 +49,7 @@ module.define('ext/select', [jQuery, 'core/settings', 'core/event'], function ($
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
$document.off('mousemove', selectionUpdate);
|
$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.selected').removeClass('selecting').removeClass('selected');
|
||||||
$('#extended .entry.selecting').removeClass('selecting').addClass('selected');
|
$('#extended .entry.selecting').removeClass('selecting').addClass('selected');
|
||||||
publish();
|
publish();
|
||||||
|
@ -100,10 +100,6 @@ module.define('ext/select', [jQuery, 'core/settings', 'core/event'], function ($
|
||||||
|
|
||||||
$selectionRect.hide().appendTo($('body'));
|
$selectionRect.hide().appendTo($('body'));
|
||||||
|
|
||||||
// $('#topbar,#bottombar,#tree,input').on('mousedown', noSelection);
|
|
||||||
// $('#content').on('mousedown', 'a', noSelectionUnlessCtrl);
|
|
||||||
// $document.on('mousedown', selectionStart);
|
|
||||||
|
|
||||||
$document
|
$document
|
||||||
.on('mousedown', '.noSelection', noSelection)
|
.on('mousedown', '.noSelection', noSelection)
|
||||||
.on('mousedown', '.noSelectionUnlessCtrl,input,a', noSelectionUnlessCtrl)
|
.on('mousedown', '.noSelectionUnlessCtrl,input,a', noSelectionUnlessCtrl)
|
||||||
|
|
|
@ -88,9 +88,9 @@
|
||||||
_.each(definitions, function (def) {
|
_.each(definitions, function (def) {
|
||||||
|
|
||||||
var invDeps = [];
|
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);
|
invDeps.push(id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,10 +9,6 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
|
||||||
|
|
||||||
reEndsWithSlash = /\/$/,
|
reEndsWithSlash = /\/$/,
|
||||||
|
|
||||||
pathEndsWithSlash = function (sequence) {
|
|
||||||
|
|
||||||
return reEndsWithSlash.test(sequence);
|
|
||||||
},
|
|
||||||
|
|
||||||
createLabel = function (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=/,
|
reContentType = /^text\/html;h5ai=/,
|
||||||
|
|
||||||
ajaxRequest = function (self, parser, callback) {
|
ajaxRequest = function (self, parser, callback) {
|
||||||
|
@ -120,7 +93,7 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
|
||||||
cache[absHref] = this;
|
cache[absHref] = this;
|
||||||
|
|
||||||
this.absHref = absHref;
|
this.absHref = absHref;
|
||||||
this.type = getFileType(absHref);
|
this.type = types.getType(absHref);
|
||||||
this.label = createLabel(absHref === '/' ? domain : split.name);
|
this.label = createLabel(absHref === '/' ? domain : split.name);
|
||||||
this.time = null;
|
this.time = null;
|
||||||
this.size = null;
|
this.size = null;
|
||||||
|
@ -194,7 +167,7 @@ module.define('model/entry', [jQuery, 'core/types'], function ($, types) {
|
||||||
|
|
||||||
isFolder: function () {
|
isFolder: function () {
|
||||||
|
|
||||||
return pathEndsWithSlash(this.absHref);
|
return reEndsWithSlash.test(this.absHref);
|
||||||
},
|
},
|
||||||
|
|
||||||
isCurrentFolder: function () {
|
isCurrentFolder: function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue