mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-06-06 09:41:14 -04:00
More changes. Improves styles.
This commit is contained in:
parent
cb9341451b
commit
d6c5696f96
16 changed files with 130 additions and 151 deletions
|
@ -4,12 +4,7 @@ modulejs.define('core/entry', ['$', 'core/parser', 'model/entry'], function ($,
|
|||
var entry = Entry.get();
|
||||
|
||||
parser.parse(entry.absHref, $('body'));
|
||||
$('#data-apache-autoindex').remove();
|
||||
|
||||
entry.status = 'h5ai';
|
||||
if (entry.parent) {
|
||||
entry.parent.isParentFolder = true;
|
||||
}
|
||||
entry.status = '=h5ai=';
|
||||
|
||||
return entry;
|
||||
});
|
||||
|
|
|
@ -12,6 +12,8 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
|||
k: 1024.0,
|
||||
u: ['B', 'KiB', 'MiB', 'GiB', 'TiB']
|
||||
},
|
||||
defaultMetric = decimalMetric,
|
||||
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
||||
|
||||
parseSize = function (str) {
|
||||
|
||||
|
@ -37,8 +39,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
|||
return val;
|
||||
},
|
||||
|
||||
defaultMetric = decimalMetric,
|
||||
|
||||
setDefaultMetric = function (metric) {
|
||||
|
||||
if (!metric) {
|
||||
|
@ -68,8 +68,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
|
|||
return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i];
|
||||
},
|
||||
|
||||
defaultDateFormat = 'YYYY-MM-DD HH:mm',
|
||||
|
||||
setDefaultDateFormat = function (dateFormat) {
|
||||
|
||||
defaultDateFormat = dateFormat;
|
||||
|
|
52
src/_h5ai/client/js/inc/core/location.js
Normal file
52
src/_h5ai/client/js/inc/core/location.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
|
||||
modulejs.define('core/location', ['$', 'core/event'], function ($, event) {
|
||||
|
||||
var doc = document,
|
||||
|
||||
forceEncoding = function (href) {
|
||||
|
||||
return href
|
||||
.replace(/\/+/g, '/')
|
||||
.replace(/ /g, '%20')
|
||||
.replace(/'/g, '%27')
|
||||
.replace(/\[/g, '%5B')
|
||||
.replace(/\]/g, '%5D')
|
||||
.replace(/\(/g, '%28')
|
||||
.replace(/\)/g, '%29')
|
||||
.replace(/\+/g, '%2B')
|
||||
.replace(/\=/g, '%3D');
|
||||
},
|
||||
|
||||
absHref = (function () {
|
||||
|
||||
var rePrePathname = /.*:\/\/[^\/]*/,
|
||||
rePostPathname = /[^\/]*$/,
|
||||
|
||||
uriToPathname = function (uri) {
|
||||
|
||||
return uri.replace(rePrePathname, '').replace(rePostPathname, '');
|
||||
},
|
||||
|
||||
testpathname = '/a b',
|
||||
a = doc.createElement('a'),
|
||||
isDecoded, location;
|
||||
|
||||
a.href = testpathname;
|
||||
isDecoded = uriToPathname(a.href) === testpathname;
|
||||
|
||||
a.href = doc.location.href;
|
||||
location = uriToPathname(a.href);
|
||||
|
||||
if (isDecoded) {
|
||||
location = encodeURIComponent(location).replace(/%2F/ig, '/');
|
||||
}
|
||||
|
||||
return forceEncoding(location);
|
||||
}());
|
||||
|
||||
return {
|
||||
domain: doc.domain,
|
||||
absHref: absHref,
|
||||
forceEncoding: forceEncoding
|
||||
};
|
||||
});
|
|
@ -1,11 +1,7 @@
|
|||
|
||||
modulejs.define('core/resource', ['core/settings'], function (settings) {
|
||||
|
||||
var api = function () {
|
||||
|
||||
return settings.h5aiAbsHref + 'server/php/api.php';
|
||||
},
|
||||
image = function (id, noPngExt) {
|
||||
var image = function (id, noPngExt) {
|
||||
|
||||
return settings.h5aiAbsHref + 'client/images/' + id + (noPngExt ? '' : '.png');
|
||||
},
|
||||
|
@ -15,7 +11,6 @@ modulejs.define('core/resource', ['core/settings'], function (settings) {
|
|||
};
|
||||
|
||||
return {
|
||||
api: api,
|
||||
image: image,
|
||||
icon: icon
|
||||
};
|
||||
|
|
|
@ -5,41 +5,24 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) {
|
|||
|
||||
request: function (data, callback) {
|
||||
|
||||
if (!server.apiHref) {
|
||||
if (server.apiHref) {
|
||||
$.ajax({
|
||||
url: server.apiHref,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url: server.apiHref,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
requestThumbSmall: function (type, href, callback) {
|
||||
|
||||
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'square', width: 16, height: 16}, function (json) {
|
||||
|
||||
callback(json && json.code === 0 ? json.absHref : null);
|
||||
});
|
||||
},
|
||||
|
||||
requestThumbBig: function (type, href, callback) {
|
||||
|
||||
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'rational', width: 100, height: 48}, function (json) {
|
||||
|
||||
callback(json && json.code === 0 ? json.absHref : null);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/resource', 'core/refresh'], function (_, $, allsettings, entry, resource, refresh) {
|
||||
modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/refresh', 'core/server'], function (_, $, allsettings, entry, refresh, server) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false,
|
||||
|
@ -17,7 +17,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
|
|||
|
||||
init = function () {
|
||||
|
||||
if (!settings.enabled) {
|
||||
if (!settings.enabled || !server.apiHref) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
|
|||
|
||||
maxfiles: settings.maxfiles,
|
||||
maxfilesize: settings.maxfilesize,
|
||||
url: resource.api(),
|
||||
url: server.apiHref,
|
||||
data: {
|
||||
action: 'upload',
|
||||
href: entry.absHref
|
||||
|
|
|
@ -24,7 +24,8 @@ modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/form
|
|||
download: 'download',
|
||||
noMatch: 'no match',
|
||||
dateFormat: 'YYYY-MM-DD HH:mm',
|
||||
filter: 'filter'
|
||||
filter: 'filter',
|
||||
'delete': 'delete'
|
||||
},
|
||||
|
||||
template = '<span id="langSelector">' +
|
||||
|
|
|
@ -67,7 +67,7 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor
|
|||
|
||||
event.sub('entry.mouseenter', function (entry) {
|
||||
|
||||
if (entry.isParentFolder) {
|
||||
if (entry.isCurrentParentFolder()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,22 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
|
|||
delay: 1000
|
||||
}, allsettings.thumbnails),
|
||||
|
||||
requestThumbSmall = function (type, href, callback) {
|
||||
|
||||
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'square', width: 16, height: 16}, function (json) {
|
||||
|
||||
callback(json && json.code === 0 ? json.absHref : null);
|
||||
});
|
||||
},
|
||||
|
||||
requestThumbBig = function (type, href, callback) {
|
||||
|
||||
server.request({action: 'getthumbsrc', type: type, href: href, mode: 'rational', width: 100, height: 48}, function (json) {
|
||||
|
||||
callback(json && json.code === 0 ? json.absHref : null);
|
||||
});
|
||||
},
|
||||
|
||||
checkEntry = function (entry) {
|
||||
|
||||
if (entry.$extended) {
|
||||
|
@ -24,13 +40,13 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
|
|||
}
|
||||
|
||||
if (type) {
|
||||
server.requestThumbSmall(type, entry.absHref, function (src) {
|
||||
requestThumbSmall(type, entry.absHref, function (src) {
|
||||
|
||||
if (src) {
|
||||
entry.$extended.find('.icon.small img').addClass('thumb').attr('src', src);
|
||||
}
|
||||
});
|
||||
server.requestThumbBig(type, entry.absHref, function (src) {
|
||||
requestThumbBig(type, entry.absHref, function (src) {
|
||||
|
||||
if (src) {
|
||||
entry.$extended.find('.icon.big img').addClass('thumb').attr('src', src);
|
||||
|
@ -42,7 +58,7 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
|
|||
|
||||
init = function (entry) {
|
||||
|
||||
if (!settings.enabled) {
|
||||
if (!settings.enabled || !server.apiHref) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,8 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
|||
'</span>',
|
||||
statusHintTemplate = '<span class="hint"/>',
|
||||
|
||||
magicSequence = '=h5ai=',
|
||||
|
||||
// updates the tree for this single entry
|
||||
update = function (entry) {
|
||||
|
||||
|
@ -40,11 +42,11 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
|||
var subfolders = entry.getSubfolders();
|
||||
|
||||
// indicator
|
||||
if (!entry.status || (entry.status === 'h5ai' && !entry.isContentFetched) || subfolders.length) {
|
||||
if (!entry.status || (entry.status === magicSequence && !entry.isContentFetched) || subfolders.length) {
|
||||
|
||||
$indicator.removeClass('none');
|
||||
|
||||
if (!entry.status || (entry.status === 'h5ai' && !entry.isContentFetched)) {
|
||||
if (!entry.status || (entry.status === magicSequence && !entry.isContentFetched)) {
|
||||
$indicator.addClass('unknown');
|
||||
} else if (entry.isContentVisible) {
|
||||
$indicator.addClass('open');
|
||||
|
@ -73,7 +75,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
|||
|
||||
// does it have subfolders?
|
||||
if (subfolders.length) {
|
||||
var $ul = $('<ul class="content" />').appendTo($html);
|
||||
var $ul = $('<ul class="content"/>').appendTo($html);
|
||||
_.each(subfolders, function (e) {
|
||||
$('<li />').append(update(e)).appendTo($ul);
|
||||
});
|
||||
|
@ -206,7 +208,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
|
|||
return;
|
||||
}
|
||||
|
||||
var $tree = $('<div id="tree" />')
|
||||
var $tree = $('<div id="tree"/>')
|
||||
.appendTo('body')
|
||||
.scrollpanel()
|
||||
.on('click', '.indicator', createOnIndicatorClick(parser))
|
||||
|
|
|
@ -1,67 +1,11 @@
|
|||
|
||||
modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings'], function ($, _, types, event, settings) {
|
||||
|
||||
var doc = document,
|
||||
domain = doc.domain,
|
||||
|
||||
forceEncoding = function (href) {
|
||||
|
||||
return href
|
||||
.replace(/\/+/g, '/')
|
||||
.replace(/ /g, '%20')
|
||||
.replace(/'/g, '%27')
|
||||
.replace(/\[/g, '%5B')
|
||||
.replace(/\]/g, '%5D')
|
||||
.replace(/\(/g, '%28')
|
||||
.replace(/\)/g, '%29')
|
||||
.replace(/\+/g, '%2B')
|
||||
.replace(/\=/g, '%3D');
|
||||
},
|
||||
|
||||
|
||||
location = (function () {
|
||||
|
||||
var rePrePathname = /.*:\/\/[^\/]*/,
|
||||
rePostPathname = /[^\/]*$/,
|
||||
|
||||
uriToPathname = function (uri) {
|
||||
|
||||
return uri.replace(rePrePathname, '').replace(rePostPathname, '');
|
||||
},
|
||||
|
||||
testpathname = '/a b',
|
||||
a = doc.createElement('a'),
|
||||
isDecoded, location;
|
||||
|
||||
a.href = testpathname;
|
||||
isDecoded = uriToPathname(a.href) === testpathname;
|
||||
|
||||
a.href = doc.location.href;
|
||||
location = uriToPathname(a.href);
|
||||
|
||||
if (isDecoded) {
|
||||
location = encodeURIComponent(location).replace(/%2F/ig, '/');
|
||||
}
|
||||
|
||||
return forceEncoding(location);
|
||||
}()),
|
||||
|
||||
folderstatus = (function () {
|
||||
|
||||
try { return modulejs.require('ext/folderstatus'); } catch (e) {}
|
||||
return {};
|
||||
}()),
|
||||
|
||||
|
||||
|
||||
// utils
|
||||
|
||||
reEndsWithSlash = /\/$/,
|
||||
modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings', 'core/location'], function ($, _, types, event, settings, location) {
|
||||
|
||||
var reEndsWithSlash = /\/$/,
|
||||
|
||||
startsWith = function (sequence, part) {
|
||||
|
||||
return sequence.length >= part.length && sequence.slice(0, part.length) === part;
|
||||
return sequence.slice && part.length && sequence.slice(0, part.length) === part;
|
||||
},
|
||||
|
||||
|
||||
|
@ -92,7 +36,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
}
|
||||
},
|
||||
|
||||
|
||||
magicSequence = '=h5ai=',
|
||||
reContentType = /^text\/html;h5ai=/,
|
||||
getStatus = function (href, withContent, callback) {
|
||||
|
||||
|
@ -107,7 +51,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
};
|
||||
|
||||
if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
|
||||
res.status = 'h5ai';
|
||||
res.status = magicSequence;
|
||||
}
|
||||
|
||||
callback(res);
|
||||
|
@ -119,7 +63,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
getStatus(self.absHref, parser, function (response) {
|
||||
|
||||
self.status = response.status;
|
||||
if (parser && response.status === 'h5ai') {
|
||||
if (parser && response.status === magicSequence) {
|
||||
parser.parse(self.absHref, response.content);
|
||||
}
|
||||
callback(self);
|
||||
|
@ -134,7 +78,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
|
||||
getEntry = function (absHref, time, size, status, isContentFetched) {
|
||||
|
||||
absHref = forceEncoding(absHref || location);
|
||||
absHref = location.forceEncoding(absHref || location.absHref);
|
||||
|
||||
if (!startsWith(absHref, settings.rootAbsHref)) {
|
||||
return null;
|
||||
|
@ -178,7 +122,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
|
||||
removeEntry = function (absHref) {
|
||||
|
||||
absHref = forceEncoding(absHref || location);
|
||||
absHref = location.forceEncoding(absHref || location.absHref);
|
||||
|
||||
var self = cache[absHref];
|
||||
|
||||
|
@ -202,9 +146,6 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
|
||||
if (self.status || !self.isFolder()) {
|
||||
callback(self);
|
||||
} else if (folderstatus[absHref]) {
|
||||
self.status = folderstatus[absHref];
|
||||
callback(self);
|
||||
} else {
|
||||
ajaxRequest(self, null, callback);
|
||||
}
|
||||
|
@ -220,7 +161,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
fetchStatus(absHref, function (self) {
|
||||
|
||||
self.isContentFetched = true;
|
||||
if (self.status === 'h5ai') {
|
||||
if (self.status === magicSequence) {
|
||||
ajaxRequest(self, parser, callback);
|
||||
} else {
|
||||
callback(self);
|
||||
|
@ -241,7 +182,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
|
||||
this.absHref = absHref;
|
||||
this.type = types.getType(absHref);
|
||||
this.label = createLabel(absHref === '/' ? domain : split.name);
|
||||
this.label = createLabel(absHref === '/' ? location.domain : split.name);
|
||||
this.time = null;
|
||||
this.size = null;
|
||||
this.parent = null;
|
||||
|
@ -266,7 +207,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
|
||||
isCurrentFolder: function () {
|
||||
|
||||
return this.absHref === location;
|
||||
return this.absHref === location.absHref;
|
||||
},
|
||||
|
||||
isInCurrentFolder: function () {
|
||||
|
@ -274,6 +215,11 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
|
|||
return !!this.parent && this.parent.isCurrentFolder();
|
||||
},
|
||||
|
||||
isCurrentParentFolder: function () {
|
||||
|
||||
return this === getEntry().parent;
|
||||
},
|
||||
|
||||
isDomain: function () {
|
||||
|
||||
return this.absHref === '/';
|
||||
|
|
|
@ -66,7 +66,7 @@ modulejs.define('view/extended', ['_', '$', 'core/settings', 'core/resource', 'c
|
|||
}
|
||||
}
|
||||
|
||||
if (entry.isParentFolder) {
|
||||
if (entry.isCurrentParentFolder()) {
|
||||
$imgSmall.attr('src', resource.icon('folder-parent'));
|
||||
$imgBig.attr('src', resource.icon('folder-parent', true));
|
||||
if (!settings.setParentFolderLabels) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue