mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-12 08:54:05 +02:00
Clean custom code.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
const {jq, marked} = require('../globals');
|
const {each, dom} = require('../util');
|
||||||
|
const {marked} = require('../globals');
|
||||||
const server = require('../server');
|
const server = require('../server');
|
||||||
const event = require('../core/event');
|
const event = require('../core/event');
|
||||||
const allsettings = require('../core/settings');
|
const allsettings = require('../core/settings');
|
||||||
@@ -7,47 +8,25 @@ const allsettings = require('../core/settings');
|
|||||||
const settings = Object.assign({
|
const settings = Object.assign({
|
||||||
enabled: false
|
enabled: false
|
||||||
}, allsettings.custom);
|
}, allsettings.custom);
|
||||||
let $header;
|
|
||||||
let $footer;
|
|
||||||
const duration = 200;
|
|
||||||
|
|
||||||
|
const update = (data, key) => {
|
||||||
|
const $el = dom(`#content-${key}`);
|
||||||
|
|
||||||
|
if (data && data[key].content) {
|
||||||
|
let content = data[key].content;
|
||||||
|
if (data[key].type === 'md') {
|
||||||
|
content = marked(content);
|
||||||
|
}
|
||||||
|
$el.html(content).show();
|
||||||
|
} else {
|
||||||
|
$el.hide();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const onLocationChanged = item => {
|
const onLocationChanged = item => {
|
||||||
server.request({action: 'get', custom: item.absHref}).then(response => {
|
server.request({action: 'get', custom: item.absHref}).then(response => {
|
||||||
const custom = response && response.custom;
|
const data = response && response.custom;
|
||||||
let hasHeader;
|
each(['header', 'footer'], key => update(data, key));
|
||||||
let hasFooter;
|
|
||||||
|
|
||||||
if (custom) {
|
|
||||||
const header = custom.header;
|
|
||||||
const footer = custom.footer;
|
|
||||||
let content;
|
|
||||||
|
|
||||||
if (header.content) {
|
|
||||||
content = header.content;
|
|
||||||
if (header.type === 'md') {
|
|
||||||
content = marked(content);
|
|
||||||
}
|
|
||||||
$header.html(content).stop().slideDown(duration);
|
|
||||||
hasHeader = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (footer.content) {
|
|
||||||
content = footer.content;
|
|
||||||
if (footer.type === 'md') {
|
|
||||||
content = marked(content);
|
|
||||||
}
|
|
||||||
$footer.html(content).stop().slideDown(duration);
|
|
||||||
hasFooter = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hasHeader) {
|
|
||||||
$header.stop().slideUp(duration);
|
|
||||||
}
|
|
||||||
if (!hasFooter) {
|
|
||||||
$footer.stop().slideUp(duration);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,8 +35,8 @@ const init = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$header = jq('<div id="content-header"/>').hide().prependTo('#content');
|
dom('<div id="content-header"></div>').hide().preTo('#content');
|
||||||
$footer = jq('<div id="content-footer"/>').hide().appendTo('#content');
|
dom('<div id="content-footer"></div>').hide().appTo('#content');
|
||||||
|
|
||||||
event.sub('location.changed', onLocationChanged);
|
event.sub('location.changed', onLocationChanged);
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user