mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-08-09 15:26:46 +02:00
Clean code.
This commit is contained in:
@@ -3,7 +3,6 @@ const event = require('../core/event');
|
||||
const location = require('../core/location');
|
||||
const allsettings = require('../core/settings');
|
||||
|
||||
|
||||
const settings = Object.assign({
|
||||
enabled: false,
|
||||
interval: 5000
|
||||
@@ -11,20 +10,20 @@ const settings = Object.assign({
|
||||
let timeoutId = null;
|
||||
|
||||
|
||||
function heartbeat() {
|
||||
const heartbeat = () => {
|
||||
location.refresh();
|
||||
}
|
||||
};
|
||||
|
||||
function before() {
|
||||
const before = () => {
|
||||
win.clearTimeout(timeoutId);
|
||||
}
|
||||
};
|
||||
|
||||
function after() {
|
||||
const after = () => {
|
||||
win.clearTimeout(timeoutId);
|
||||
timeoutId = win.setTimeout(heartbeat, settings.interval);
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
const init = () => {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -35,7 +34,7 @@ function init() {
|
||||
event.sub('location.beforeRefresh', before);
|
||||
event.sub('location.changed', after);
|
||||
event.sub('location.refreshed', after);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
init();
|
||||
|
@@ -20,7 +20,7 @@ const pageHintTemplate =
|
||||
let $crumbbar;
|
||||
|
||||
|
||||
function createHtml(item) {
|
||||
const createHtml = item => {
|
||||
const $html = jq(crumbTemplate);
|
||||
$html[0]._item = item;
|
||||
item.elCrumb = $html[0];
|
||||
@@ -37,9 +37,9 @@ function createHtml(item) {
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
};
|
||||
|
||||
function onLocationChanged(item) {
|
||||
const onLocationChanged = item => {
|
||||
const $crumb = jq(item.elCrumb);
|
||||
|
||||
if ($crumb && $crumb.parent()[0] === $crumbbar[0]) {
|
||||
@@ -51,9 +51,9 @@ function onLocationChanged(item) {
|
||||
$crumbbar.append(createHtml(crumbItem));
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
const init = () => {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ function init() {
|
||||
$crumbbar = jq('<div id="crumbbar"/>').appendTo(base.$flowbar);
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
init();
|
||||
|
@@ -12,7 +12,7 @@ let $footer;
|
||||
const duration = 200;
|
||||
|
||||
|
||||
function onLocationChanged(item) {
|
||||
const onLocationChanged = item => {
|
||||
server.request({action: 'get', custom: item.absHref}).then(response => {
|
||||
const custom = response && response.custom;
|
||||
let hasHeader;
|
||||
@@ -49,9 +49,9 @@ function onLocationChanged(item) {
|
||||
$footer.stop().slideUp(duration);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
const init = () => {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ function init() {
|
||||
$footer = jq('<div id="content-footer"/>').hide().appendTo('#content');
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
init();
|
||||
|
@@ -9,16 +9,16 @@ const settings = Object.assign({
|
||||
id: 'UA-000000-0'
|
||||
}, allsettings['google-analytics-ua']);
|
||||
|
||||
function snippet() {
|
||||
const snippet = () => {
|
||||
/* eslint-disable */
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
||||
/* eslint-enable */
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
const init = () => {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
@@ -34,6 +34,6 @@ function init() {
|
||||
title: map(item.getCrumb(), i => i.label).join(' > ')
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
|
@@ -9,7 +9,7 @@ const settings = Object.assign({
|
||||
enabled: false
|
||||
}, allsettings.title);
|
||||
|
||||
function onLocationChanged(item) {
|
||||
const onLocationChanged = item => {
|
||||
const labels = map(item.getCrumb(), i => i.label);
|
||||
let title = labels.join(' > ');
|
||||
|
||||
@@ -18,14 +18,14 @@ function onLocationChanged(item) {
|
||||
}
|
||||
|
||||
doc.title = title;
|
||||
}
|
||||
};
|
||||
|
||||
function init() {
|
||||
const init = () => {
|
||||
if (!settings.enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.sub('location.changed', onLocationChanged);
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
|
Reference in New Issue
Block a user