mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Cosmetics.
This commit is contained in:
parent
7494491637
commit
c71f891af2
311 changed files with 55 additions and 46 deletions
98
src/_h5ai/client/js/inc/ext/crumb.js
Normal file
98
src/_h5ai/client/js/inc/ext/crumb.js
Normal file
|
@ -0,0 +1,98 @@
|
|||
|
||||
modulejs.define('ext/crumb', ['_', '$', 'core/settings', 'core/resource', 'core/event', 'core/entry'], function (_, $, allsettings, resource, event, entry) {
|
||||
|
||||
var settings = _.extend({
|
||||
enabled: false
|
||||
}, allsettings.crumb),
|
||||
|
||||
template = '<li class="crumb">' +
|
||||
'<a>' +
|
||||
'<img src="' + resource.image('crumb') + '" alt=">"/>' +
|
||||
'<span/>' +
|
||||
'</a>' +
|
||||
'</li>',
|
||||
pageHintTemplate = '<img class="hint" src="' + resource.image('page') + '" alt="has index page"/>',
|
||||
statusHintTemplate = '<span class="hint"/>',
|
||||
|
||||
// updates the crumb for this single entry
|
||||
update = function (entry, force) {
|
||||
|
||||
if (!force && entry.$crumb && entry.$crumb.data('status') === entry.status) {
|
||||
return entry.$crumb;
|
||||
}
|
||||
|
||||
var $html = $(template),
|
||||
$a = $html.find('a');
|
||||
|
||||
$html
|
||||
.addClass(entry.isFolder() ? 'folder' : 'file')
|
||||
.data('status', entry.status);
|
||||
|
||||
$a
|
||||
.attr('href', entry.absHref)
|
||||
.find('span').text(entry.label).end();
|
||||
|
||||
if (entry.isDomain()) {
|
||||
$html.addClass('domain');
|
||||
$a.find('img').attr('src', resource.image('home'));
|
||||
}
|
||||
|
||||
if (entry.isRoot()) {
|
||||
$html.addClass('root');
|
||||
$a.find('img').attr('src', resource.image('home'));
|
||||
}
|
||||
|
||||
if (entry.isCurrentFolder()) {
|
||||
$html.addClass('current');
|
||||
}
|
||||
|
||||
if (_.isNumber(entry.status)) {
|
||||
if (entry.status === 200) {
|
||||
$a.append($(pageHintTemplate));
|
||||
} else {
|
||||
$a.append($(statusHintTemplate).text('(' + entry.status + ')'));
|
||||
}
|
||||
}
|
||||
|
||||
if (entry.$crumb) {
|
||||
entry.$crumb.replaceWith($html);
|
||||
}
|
||||
entry.$crumb = $html;
|
||||
|
||||
return $html;
|
||||
},
|
||||
|
||||
onContentChanged = function (entry) {
|
||||
|
||||
if (entry.$crumb) {
|
||||
update(entry, true);
|
||||
}
|
||||
},
|
||||
|
||||
// creates the complete crumb from entry down to the root
|
||||
init = function (entry) {
|
||||
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
var crumb = entry.getCrumb(),
|
||||
$ul = $('#navbar');
|
||||
|
||||
_.each(crumb, function (e) {
|
||||
|
||||
$ul.append(update(e));
|
||||
|
||||
e.fetchStatus(function (e) {
|
||||
|
||||
update(e);
|
||||
});
|
||||
});
|
||||
|
||||
event.sub('entry.created', onContentChanged);
|
||||
event.sub('entry.removed', onContentChanged);
|
||||
event.sub('entry.changed', onContentChanged);
|
||||
};
|
||||
|
||||
init(entry);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue