1
0
mirror of https://github.com/lrsjng/h5ai.git synced 2025-08-09 23:36:43 +02:00

Clean code.

This commit is contained in:
Lars Jung
2016-06-24 23:06:00 +02:00
parent 3e14d7bed4
commit 95c473a7c7
5 changed files with 26 additions and 27 deletions

View File

@@ -3,7 +3,6 @@ const event = require('../core/event');
const location = require('../core/location'); const location = require('../core/location');
const allsettings = require('../core/settings'); const allsettings = require('../core/settings');
const settings = Object.assign({ const settings = Object.assign({
enabled: false, enabled: false,
interval: 5000 interval: 5000
@@ -11,20 +10,20 @@ const settings = Object.assign({
let timeoutId = null; let timeoutId = null;
function heartbeat() { const heartbeat = () => {
location.refresh(); location.refresh();
} };
function before() { const before = () => {
win.clearTimeout(timeoutId); win.clearTimeout(timeoutId);
} };
function after() { const after = () => {
win.clearTimeout(timeoutId); win.clearTimeout(timeoutId);
timeoutId = win.setTimeout(heartbeat, settings.interval); timeoutId = win.setTimeout(heartbeat, settings.interval);
} };
function init() { const init = () => {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
} }
@@ -35,7 +34,7 @@ function init() {
event.sub('location.beforeRefresh', before); event.sub('location.beforeRefresh', before);
event.sub('location.changed', after); event.sub('location.changed', after);
event.sub('location.refreshed', after); event.sub('location.refreshed', after);
} };
init(); init();

View File

@@ -20,7 +20,7 @@ const pageHintTemplate =
let $crumbbar; let $crumbbar;
function createHtml(item) { const createHtml = item => {
const $html = jq(crumbTemplate); const $html = jq(crumbTemplate);
$html[0]._item = item; $html[0]._item = item;
item.elCrumb = $html[0]; item.elCrumb = $html[0];
@@ -37,9 +37,9 @@ function createHtml(item) {
} }
return $html; return $html;
} };
function onLocationChanged(item) { const onLocationChanged = item => {
const $crumb = jq(item.elCrumb); const $crumb = jq(item.elCrumb);
if ($crumb && $crumb.parent()[0] === $crumbbar[0]) { if ($crumb && $crumb.parent()[0] === $crumbbar[0]) {
@@ -51,9 +51,9 @@ function onLocationChanged(item) {
$crumbbar.append(createHtml(crumbItem)); $crumbbar.append(createHtml(crumbItem));
}); });
} }
} };
function init() { const init = () => {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
} }
@@ -61,7 +61,7 @@ function init() {
$crumbbar = jq('<div id="crumbbar"/>').appendTo(base.$flowbar); $crumbbar = jq('<div id="crumbbar"/>').appendTo(base.$flowbar);
event.sub('location.changed', onLocationChanged); event.sub('location.changed', onLocationChanged);
} };
init(); init();

View File

@@ -12,7 +12,7 @@ let $footer;
const duration = 200; const duration = 200;
function 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 custom = response && response.custom;
let hasHeader; let hasHeader;
@@ -49,9 +49,9 @@ function onLocationChanged(item) {
$footer.stop().slideUp(duration); $footer.stop().slideUp(duration);
} }
}); });
} };
function init() { const init = () => {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
} }
@@ -60,7 +60,7 @@ function init() {
$footer = jq('<div id="content-footer"/>').hide().appendTo('#content'); $footer = jq('<div id="content-footer"/>').hide().appendTo('#content');
event.sub('location.changed', onLocationChanged); event.sub('location.changed', onLocationChanged);
} };
init(); init();

View File

@@ -9,16 +9,16 @@ const settings = Object.assign({
id: 'UA-000000-0' id: 'UA-000000-0'
}, allsettings['google-analytics-ua']); }, allsettings['google-analytics-ua']);
function snippet() { const snippet = () => {
/* eslint-disable */ /* eslint-disable */
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (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), (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) 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'); })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
/* eslint-enable */ /* eslint-enable */
} };
function init() { const init = () => {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
} }
@@ -34,6 +34,6 @@ function init() {
title: map(item.getCrumb(), i => i.label).join(' > ') title: map(item.getCrumb(), i => i.label).join(' > ')
}); });
}); });
} };
init(); init();

View File

@@ -9,7 +9,7 @@ const settings = Object.assign({
enabled: false enabled: false
}, allsettings.title); }, allsettings.title);
function onLocationChanged(item) { const onLocationChanged = item => {
const labels = map(item.getCrumb(), i => i.label); const labels = map(item.getCrumb(), i => i.label);
let title = labels.join(' > '); let title = labels.join(' > ');
@@ -18,14 +18,14 @@ function onLocationChanged(item) {
} }
doc.title = title; doc.title = title;
} };
function init() { const init = () => {
if (!settings.enabled) { if (!settings.enabled) {
return; return;
} }
event.sub('location.changed', onLocationChanged); event.sub('location.changed', onLocationChanged);
} };
init(); init();