Browse Source

Add "check if there's header and comments" function

Track3 7 years ago
parent
commit
9d66217c8a

+ 7 - 0
layouts/404.html

@@ -12,4 +12,11 @@
 			</p>
 		</div>
 	</div>
+{{ end }}
+
+{{ define "footer" }}
+	<script>
+		let haveHeader = false;
+		let haveComments = false;
+	</script>
 {{ end }}

+ 3 - 3
layouts/_default/baseof.html

@@ -20,9 +20,9 @@
 </head>
 
 <body id="page">
-	{{ block "header" . }}{{ end }}
-	{{ block "main" . }}{{ end }}
-	{{ block "footer" . }}{{ end }}
+	{{- block "header" . }}{{- end }}
+	{{- block "main" . }}{{- end }}
+	{{- block "footer" . }}{{- end }}
 	<script src="{{ "js/main.min.js" | absURL }}"></script>
 	<script>
 		var _hmt = _hmt || [];

+ 10 - 2
layouts/_default/list.html

@@ -1,4 +1,6 @@
-{{ define "header" }}{{ partial "header.html" . }}{{ end }}
+{{ define "header" }}
+{{ partial "header.html" . }}
+{{ end }}
 
 {{ define "main" }}
 	<main class="site-main section-inner thin">
@@ -19,4 +21,10 @@
 	</main>
 {{ end }}
 
-{{ define "footer" }}{{ partial "footer.html" . }}{{ end }}
+{{ define "footer" }}
+{{ partial "footer.html" . }}
+	<script>
+		let haveHeader = true;
+		let haveComments = false;
+	</script>
+{{ end }}

+ 10 - 2
layouts/_default/single.html

@@ -1,4 +1,6 @@
-{{ define "header" }}{{ partial "header.html" . }}{{ end }}
+{{ define "header" }}
+{{ partial "header.html" . }}
+{{ end }}
 
 {{ define "main" }}
 	<main class="site-main section-inner thin">
@@ -12,4 +14,10 @@
 	</main>
 {{ end }}
 
-{{ define "footer" }}{{ partial "footer.html" . }}{{ end }}
+{{ define "footer" }}
+{{ partial "footer.html" . }}
+	<script>
+		let haveHeader = true;
+		let haveComments ={{.Params.comments}};
+	</script>
+{{ end }}

+ 7 - 0
layouts/index.html

@@ -12,4 +12,11 @@
 			{{- end }}
 		</nav>
 	</div>
+{{ end }}
+
+{{ define "footer" }}
+	<script>
+		let haveHeader = false;
+		let haveComments = false;
+	</script>
 {{ end }}

+ 1 - 1
layouts/partials/footer.html

@@ -1,4 +1,4 @@
-<footer id="site-footer">
+	<footer id="site-footer">
 		<div id="copyright">
 			<p>&copy; 2018 {{ .Site.Params.author }}</p>
 			<p>Powered by Hugo</p>

+ 1 - 1
layouts/partials/header.html

@@ -1,4 +1,4 @@
-<header id="site-header" class="animated slideInUp">
+	<header id="site-header" class="animated slideInUp">
 		<div class="hdr-wrapper section-inner">
 			<div class="hdr-left">
 				<div class="site-branding">

+ 10 - 2
layouts/posts/single.html

@@ -1,4 +1,6 @@
-{{ define "header" }}{{ partial "header.html" . }}{{ end }}
+{{ define "header" }}
+{{ partial "header.html" . }}
+{{ end }}
 
 {{ define "main" }}
 	<main class="site-main section-inner">
@@ -28,4 +30,10 @@
 	</main>
 {{ end }}
 
-{{ define "footer" }}{{ partial "footer.html" . }}{{ end }}
+{{ define "footer" }}
+{{ partial "footer.html" . }}
+	<script>
+		let haveHeader = true;
+		let haveComments = true;
+	</script>
+{{ end }}

+ 23 - 19
static/js/main.js

@@ -20,24 +20,26 @@ const autoHideHeader = () => {
 //
 let mobileMenu = document.getElementById('mobile-menu');
 
-document.getElementById('menu-btn').addEventListener('click', () => {
-  if (mobileMenu.style.display == 'none') {
-    mobileMenu.style.display = 'block';
-  } else {
-    mobileMenu.classList.remove('bounceInRight');
-    mobileMenu.classList.add('bounceOutRight');
-    setTimeout(() => {
-      mobileMenu.style.display = 'none';
-      mobileMenu.classList.remove('bounceOutRight');
-      mobileMenu.classList.add('bounceInRight');
-    }, 750);
-  }
-});
+if (haveHeader == true) {
+  document.getElementById('menu-btn').addEventListener('click', () => {
+    if (mobileMenu.style.display == 'none') {
+      mobileMenu.style.display = 'block';
+    } else {
+      mobileMenu.classList.remove('bounceInRight');
+      mobileMenu.classList.add('bounceOutRight');
+      setTimeout(() => {
+        mobileMenu.style.display = 'none';
+        mobileMenu.classList.remove('bounceOutRight');
+        mobileMenu.classList.add('bounceInRight');
+      }, 750);
+    }
+  });
+}
 
 //Load Comments
 //
 let commentsLoaded = false;
-let commentsOffsetTop = document.getElementById('comments').offsetTop;
+let comments = document.getElementById('comments');
 let commentsLoader = document.getElementById('comments-loader');
 
 const avJsUrl = '//cdn1.lncld.net/static/js/3.0.4/av-min.js';
@@ -89,7 +91,7 @@ const loadComments = () => {
 }
 
 // Load comments if the window is not scrollable
-if (commentsOffsetTop < window.innerHeight) {
+if ((haveComments == true) && (comments.offsetTop < window.innerHeight)) {
   console.log('Ready to Load Comments');
   commentsLoader.style.display = 'block';
   loadComments();
@@ -97,11 +99,13 @@ if (commentsOffsetTop < window.innerHeight) {
 }
 
 window.addEventListener('scroll', () => {
-  autoHideHeader();
-  mobileMenu.style.display = 'none'; //Hide Mobile Menu When Scroll
+  if (haveHeader == true) {
+    autoHideHeader();
+    mobileMenu.style.display = 'none'; //Hide Mobile Menu When Scroll
+  }
 
-  if (commentsLoaded == false) {
-    if (window.pageYOffset + window.innerHeight > commentsOffsetTop) {
+  if ((haveComments == true) && (commentsLoaded == false)) {
+    if (window.pageYOffset + window.innerHeight > comments.offsetTop) {
       console.log('Ready to Load Comments');
       commentsLoader.style.display = 'block';
       loadComments();

File diff suppressed because it is too large
+ 0 - 0
static/js/main.min.js


Some files were not shown because too many files changed in this diff