More changes. Improves styles.

This commit is contained in:
Lars Jung 2012-10-07 21:31:13 +02:00
parent cb9341451b
commit d6c5696f96
16 changed files with 130 additions and 151 deletions

View file

@ -24,18 +24,19 @@
} }
} }
.left { .left {
position: absolute;
left: 0;
display: block; display: block;
padding: 0 8px; padding: 0 8px;
float: left
} }
.center { .center {
display: block; display: block;
margin: 0 100px;
} }
.right { .right {
position: absolute;
right: 0;
display: block; display: block;
padding: 0 8px; padding: 0 8px;
float: right
} }
.noJsMsg { .noJsMsg {
color: #c33; color: #c33;

View file

@ -57,6 +57,8 @@
td:nth-child(1), th:nth-child(1) { td:nth-child(1), th:nth-child(1) {
text-align: center; text-align: center;
width: 16px; width: 16px;
color: #ccc;
font-size: 0.9em;
img { img {
width: 16px; width: 16px;

View file

@ -4,12 +4,7 @@ modulejs.define('core/entry', ['$', 'core/parser', 'model/entry'], function ($,
var entry = Entry.get(); var entry = Entry.get();
parser.parse(entry.absHref, $('body')); parser.parse(entry.absHref, $('body'));
$('#data-apache-autoindex').remove(); entry.status = '=h5ai=';
entry.status = 'h5ai';
if (entry.parent) {
entry.parent.isParentFolder = true;
}
return entry; return entry;
}); });

View file

@ -12,6 +12,8 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
k: 1024.0, k: 1024.0,
u: ['B', 'KiB', 'MiB', 'GiB', 'TiB'] u: ['B', 'KiB', 'MiB', 'GiB', 'TiB']
}, },
defaultMetric = decimalMetric,
defaultDateFormat = 'YYYY-MM-DD HH:mm',
parseSize = function (str) { parseSize = function (str) {
@ -37,8 +39,6 @@ modulejs.define('core/format', ['_', 'moment'], function (_, moment) {
return val; return val;
}, },
defaultMetric = decimalMetric,
setDefaultMetric = function (metric) { setDefaultMetric = function (metric) {
if (!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]; return (i <= 1 ? Math.round(size) : size.toFixed(1)).toString() + ' ' + metric.u[i];
}, },
defaultDateFormat = 'YYYY-MM-DD HH:mm',
setDefaultDateFormat = function (dateFormat) { setDefaultDateFormat = function (dateFormat) {
defaultDateFormat = dateFormat; defaultDateFormat = dateFormat;

View 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
};
});

View file

@ -1,11 +1,7 @@
modulejs.define('core/resource', ['core/settings'], function (settings) { modulejs.define('core/resource', ['core/settings'], function (settings) {
var api = function () { var image = function (id, noPngExt) {
return settings.h5aiAbsHref + 'server/php/api.php';
},
image = function (id, noPngExt) {
return settings.h5aiAbsHref + 'client/images/' + id + (noPngExt ? '' : '.png'); return settings.h5aiAbsHref + 'client/images/' + id + (noPngExt ? '' : '.png');
}, },
@ -15,7 +11,6 @@ modulejs.define('core/resource', ['core/settings'], function (settings) {
}; };
return { return {
api: api,
image: image, image: image,
icon: icon icon: icon
}; };

View file

@ -5,41 +5,24 @@ modulejs.define('core/server', ['$', '_', 'config'], function ($, _, config) {
request: function (data, callback) { 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(); 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);
});
} }
}); });

View file

@ -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({ var settings = _.extend({
enabled: false, enabled: false,
@ -17,7 +17,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
init = function () { init = function () {
if (!settings.enabled) { if (!settings.enabled || !server.apiHref) {
return; return;
} }
@ -47,7 +47,7 @@ modulejs.define('ext/dropbox', ['_', '$', 'core/settings', 'core/entry', 'core/r
maxfiles: settings.maxfiles, maxfiles: settings.maxfiles,
maxfilesize: settings.maxfilesize, maxfilesize: settings.maxfilesize,
url: resource.api(), url: server.apiHref,
data: { data: {
action: 'upload', action: 'upload',
href: entry.absHref href: entry.absHref

View file

@ -24,7 +24,8 @@ modulejs.define('ext/l10n', ['_', '$', 'core/settings', 'core/langs', 'core/form
download: 'download', download: 'download',
noMatch: 'no match', noMatch: 'no match',
dateFormat: 'YYYY-MM-DD HH:mm', dateFormat: 'YYYY-MM-DD HH:mm',
filter: 'filter' filter: 'filter',
'delete': 'delete'
}, },
template = '<span id="langSelector">' + template = '<span id="langSelector">' +

View file

@ -67,7 +67,7 @@ modulejs.define('ext/statusbar', ['_', '$', 'core/settings', 'core/format', 'cor
event.sub('entry.mouseenter', function (entry) { event.sub('entry.mouseenter', function (entry) {
if (entry.isParentFolder) { if (entry.isCurrentParentFolder()) {
return; return;
} }

View file

@ -9,6 +9,22 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
delay: 1000 delay: 1000
}, allsettings.thumbnails), }, 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) { checkEntry = function (entry) {
if (entry.$extended) { if (entry.$extended) {
@ -24,13 +40,13 @@ modulejs.define('ext/thumbnails', ['_', 'core/settings', 'core/entry', 'core/eve
} }
if (type) { if (type) {
server.requestThumbSmall(type, entry.absHref, function (src) { requestThumbSmall(type, entry.absHref, function (src) {
if (src) { if (src) {
entry.$extended.find('.icon.small img').addClass('thumb').attr('src', 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) { if (src) {
entry.$extended.find('.icon.big img').addClass('thumb').attr('src', 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) { init = function (entry) {
if (!settings.enabled) { if (!settings.enabled || !server.apiHref) {
return; return;
} }

View file

@ -17,6 +17,8 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
'</span>', '</span>',
statusHintTemplate = '<span class="hint"/>', statusHintTemplate = '<span class="hint"/>',
magicSequence = '=h5ai=',
// updates the tree for this single entry // updates the tree for this single entry
update = function (entry) { update = function (entry) {
@ -40,11 +42,11 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
var subfolders = entry.getSubfolders(); var subfolders = entry.getSubfolders();
// indicator // indicator
if (!entry.status || (entry.status === 'h5ai' && !entry.isContentFetched) || subfolders.length) { if (!entry.status || (entry.status === magicSequence && !entry.isContentFetched) || subfolders.length) {
$indicator.removeClass('none'); $indicator.removeClass('none');
if (!entry.status || (entry.status === 'h5ai' && !entry.isContentFetched)) { if (!entry.status || (entry.status === magicSequence && !entry.isContentFetched)) {
$indicator.addClass('unknown'); $indicator.addClass('unknown');
} else if (entry.isContentVisible) { } else if (entry.isContentVisible) {
$indicator.addClass('open'); $indicator.addClass('open');
@ -73,7 +75,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
// does it have subfolders? // does it have subfolders?
if (subfolders.length) { if (subfolders.length) {
var $ul = $('<ul class="content" />').appendTo($html); var $ul = $('<ul class="content"/>').appendTo($html);
_.each(subfolders, function (e) { _.each(subfolders, function (e) {
$('<li />').append(update(e)).appendTo($ul); $('<li />').append(update(e)).appendTo($ul);
}); });
@ -206,7 +208,7 @@ modulejs.define('ext/tree', ['_', '$', 'core/settings', 'core/resource', 'core/e
return; return;
} }
var $tree = $('<div id="tree" />') var $tree = $('<div id="tree"/>')
.appendTo('body') .appendTo('body')
.scrollpanel() .scrollpanel()
.on('click', '.indicator', createOnIndicatorClick(parser)) .on('click', '.indicator', createOnIndicatorClick(parser))

View file

@ -1,67 +1,11 @@
modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings'], function ($, _, types, event, settings) { modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/settings', 'core/location'], function ($, _, types, event, settings, location) {
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 = /\/$/,
var reEndsWithSlash = /\/$/,
startsWith = function (sequence, part) { 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=/, reContentType = /^text\/html;h5ai=/,
getStatus = function (href, withContent, callback) { 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'))) { if (xhr.status === 200 && reContentType.test(xhr.getResponseHeader('Content-Type'))) {
res.status = 'h5ai'; res.status = magicSequence;
} }
callback(res); callback(res);
@ -119,7 +63,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
getStatus(self.absHref, parser, function (response) { getStatus(self.absHref, parser, function (response) {
self.status = response.status; self.status = response.status;
if (parser && response.status === 'h5ai') { if (parser && response.status === magicSequence) {
parser.parse(self.absHref, response.content); parser.parse(self.absHref, response.content);
} }
callback(self); callback(self);
@ -134,7 +78,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
getEntry = function (absHref, time, size, status, isContentFetched) { getEntry = function (absHref, time, size, status, isContentFetched) {
absHref = forceEncoding(absHref || location); absHref = location.forceEncoding(absHref || location.absHref);
if (!startsWith(absHref, settings.rootAbsHref)) { if (!startsWith(absHref, settings.rootAbsHref)) {
return null; return null;
@ -178,7 +122,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
removeEntry = function (absHref) { removeEntry = function (absHref) {
absHref = forceEncoding(absHref || location); absHref = location.forceEncoding(absHref || location.absHref);
var self = cache[absHref]; var self = cache[absHref];
@ -202,9 +146,6 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
if (self.status || !self.isFolder()) { if (self.status || !self.isFolder()) {
callback(self); callback(self);
} else if (folderstatus[absHref]) {
self.status = folderstatus[absHref];
callback(self);
} else { } else {
ajaxRequest(self, null, callback); ajaxRequest(self, null, callback);
} }
@ -220,7 +161,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
fetchStatus(absHref, function (self) { fetchStatus(absHref, function (self) {
self.isContentFetched = true; self.isContentFetched = true;
if (self.status === 'h5ai') { if (self.status === magicSequence) {
ajaxRequest(self, parser, callback); ajaxRequest(self, parser, callback);
} else { } else {
callback(self); callback(self);
@ -241,7 +182,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
this.absHref = absHref; this.absHref = absHref;
this.type = types.getType(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.time = null;
this.size = null; this.size = null;
this.parent = null; this.parent = null;
@ -266,7 +207,7 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
isCurrentFolder: function () { isCurrentFolder: function () {
return this.absHref === location; return this.absHref === location.absHref;
}, },
isInCurrentFolder: function () { isInCurrentFolder: function () {
@ -274,6 +215,11 @@ modulejs.define('model/entry', ['$', '_', 'core/types', 'core/event', 'core/sett
return !!this.parent && this.parent.isCurrentFolder(); return !!this.parent && this.parent.isCurrentFolder();
}, },
isCurrentParentFolder: function () {
return this === getEntry().parent;
},
isDomain: function () { isDomain: function () {
return this.absHref === '/'; return this.absHref === '/';

View file

@ -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')); $imgSmall.attr('src', resource.icon('folder-parent'));
$imgBig.attr('src', resource.icon('folder-parent', true)); $imgBig.attr('src', resource.icon('folder-parent', true));
if (!settings.setParentFolderLabels) { if (!settings.setParentFolderLabels) {

View file

@ -26,10 +26,7 @@ class App {
$this->abs_href = normalize_path($abs_href, true); $this->abs_href = normalize_path($abs_href, true);
$this->abs_path = $this->get_abs_path($this->abs_href); $this->abs_path = $this->get_abs_path($this->abs_href);
$config = array("options" => array(), "types" => array(), "langs" => array()); $this->options = load_commented_json($this->app_abs_path . "/conf/options.json");
$config = merge_config($config, load_commented_json($this->app_abs_path . "/conf/config.json"));
$config = merge_config($config, load_commented_json($this->abs_path . "/" . App::$FILE_PREFIX . ".config.json"));
$this->options = $config["options"];
} }
@ -178,14 +175,6 @@ class App {
} }
public function get_custom_config() {
$config = App::$FILE_PREFIX . ".config.json";
$config = $this->fileExists($config ? $this->abs_path . "/" . $config : "ignore") ? $config : "ignore";
return $config;
}
public function get_entries($abs_href, $what) { public function get_entries($abs_href, $what) {
$cache = array(); $cache = array();
@ -227,12 +216,12 @@ class App {
$html = "<table>"; $html = "<table>";
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>"; $html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
if ($folder->get_parent($cache)) { if ($folder->get_parent($cache)) {
$html .= "<tr><td>[^]</td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>"; $html .= "<tr><td>UP</td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
} }
foreach ($entries as $entry) { foreach ($entries as $entry) {
$html .= "<tr>"; $html .= "<tr>";
$html .= "<td>" . ($entry->is_folder ? "[D]" : "[F]") . "</td>"; $html .= "<td>" . ($entry->is_folder ? "DIR" : "FILE") . "</td>";
$html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . ($entry->is_folder ? "/" : "") . "</a></td>"; $html .= "<td><a href=\"" . $entry->abs_href . "\">" . basename($entry->abs_path) . "</a></td>";
$html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>"; $html .= "<td>" . date("Y-m-d H:i", $entry->date) . "</td>";
$html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>"; $html .= "<td>" . ($entry->size !== null ? intval($entry->size / 1000) . " KB" : "" ) . "</td>";
$html .= "</tr>"; $html .= "</tr>";

View file

@ -3,7 +3,6 @@
- var href = "<?php echo $APP->get_app_abs_href(); ?>" - var href = "<?php echo $APP->get_app_abs_href(); ?>"
- var json = "<?php echo $APP->get_generic_json(); ?>" - var json = "<?php echo $APP->get_generic_json(); ?>"
- var fallback = "<?php echo $APP->get_no_js_fallback(); ?>" - var fallback = "<?php echo $APP->get_no_js_fallback(); ?>"
- var config = "<?php echo $APP->get_custom_config(); ?>"
doctype 5 doctype 5
//if lt IE 9 //if lt IE 9