redeyed-jekyll-theme 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +21 -21
  3. data/README.md +54 -52
  4. data/_config.yml +25 -18
  5. data/_data/assets/cross-origin.yml +1 -7
  6. data/_data/assets/self-host.yml +0 -6
  7. data/_data/locale/en.yml +63 -58
  8. data/_data/locale/es-ES.yml +79 -0
  9. data/_data/locale/fr-FR.yml +79 -0
  10. data/_data/locale/id-ID.yml +79 -0
  11. data/_data/locale/ko-KR.yml +79 -0
  12. data/_data/locale/my-MM.yml +79 -0
  13. data/_data/locale/pt-BR.yml +79 -0
  14. data/_data/locale/ru-RU.yml +79 -0
  15. data/_data/locale/uk-UA.yml +79 -0
  16. data/_data/locale/vi-VN.yml +77 -0
  17. data/_data/locale/zh-CN.yml +78 -0
  18. data/_includes/{breadcrumbs.html → elements/breadcrumbs.html} +0 -0
  19. data/_includes/{datetime.html → elements/datetime.html} +0 -0
  20. data/_includes/{favicons.html → elements/favicons.html} +14 -14
  21. data/_includes/{javascript.html → elements/javascript.html} +2 -2
  22. data/_includes/{jsdelivr-combine.html → elements/jsdelivr-combine.html} +18 -18
  23. data/_includes/elements/lang.html +11 -0
  24. data/_includes/{navbar.html → elements/navbar.html} +5 -5
  25. data/_includes/{no-linenos.html → elements/no-linenos.html} +0 -0
  26. data/_includes/{options.html → elements/options.html} +13 -13
  27. data/_includes/{pagination.html → elements/pagination.html} +0 -0
  28. data/_includes/{readtime.html → elements/readtime.html} +0 -0
  29. data/_includes/{related-posts.html → elements/related-posts.html} +0 -0
  30. data/_includes/{search-loader.html → elements/search-loader.html} +46 -46
  31. data/_includes/{search-results.html → elements/search-results.html} +0 -0
  32. data/_includes/{toc.html → elements/toc.html} +0 -0
  33. data/_includes/{back-to-top.html → extensions/back-to-top.html} +2 -2
  34. data/_includes/extensions/code-highlight.html +89 -0
  35. data/_includes/extensions/comments/disqus.html +17 -0
  36. data/_includes/extensions/comments/giscus.html +56 -0
  37. data/_includes/extensions/comments/gitment.html +15 -0
  38. data/_includes/extensions/comments/utterances.html +46 -0
  39. data/_includes/extensions/geopattern.html +19 -0
  40. data/_includes/extensions/google-analytics.html +7 -0
  41. data/_includes/{google-tags-body.html → extensions/google-tags-body.html} +3 -3
  42. data/_includes/{google-tags-head.html → extensions/google-tags-head.html} +5 -5
  43. data/_includes/extensions/google-translate.html +108 -0
  44. data/_includes/extensions/hashlocate.html +44 -0
  45. data/_includes/extensions/mathjax.html +9 -0
  46. data/_includes/{mode-toggle.html → extensions/theme-mode.html} +0 -10
  47. data/_includes/extensions/theme-toggle.html +108 -0
  48. data/_includes/extensions/trianglify.html +26 -0
  49. data/_includes/functions/get-article-excerpt.html +33 -0
  50. data/_includes/functions/get-article-words.html +18 -0
  51. data/_includes/functions/get-banner.html +67 -0
  52. data/_includes/functions/get-categories.html +9 -0
  53. data/_includes/functions/get-datetimes.html +13 -0
  54. data/_includes/functions/get-reading-time.html +39 -0
  55. data/_includes/functions/get-tags.html +9 -0
  56. data/_includes/functions/get-value.html +41 -0
  57. data/_includes/functions/log.html +17 -0
  58. data/_includes/head.html +4 -4
  59. data/_includes/{copyright.html → views/copyright.html} +0 -0
  60. data/_includes/{footer.html → views/footer.html} +0 -0
  61. data/_includes/{header-banner.html → views/header-banner.html} +0 -0
  62. data/_includes/{header-wide.html → views/header-wide.html} +0 -0
  63. data/_includes/{header.html → views/header.html} +0 -0
  64. data/_includes/{panel-bottom.html → views/panel-bottom.html} +0 -0
  65. data/_includes/{panel-foot-2.html → views/panel-foot-2.html} +0 -0
  66. data/_includes/{panel-foot-3.html → views/panel-foot-3.html} +0 -0
  67. data/_includes/{panel-foot-4.html → views/panel-foot-4.html} +0 -0
  68. data/_includes/{panel-foot-full.html → views/panel-foot-full.html} +0 -0
  69. data/_includes/{panel-top-2.html → views/panel-top-2.html} +0 -0
  70. data/_includes/{panel-top-3.html → views/panel-top-3.html} +0 -0
  71. data/_includes/{panel-top-4.html → views/panel-top-4.html} +0 -0
  72. data/_includes/{panel-top-full.html → views/panel-top-full.html} +0 -0
  73. data/_includes/{post-nav.html → views/post-nav.html} +0 -0
  74. data/_includes/{post-share.html → views/post-share.html} +0 -0
  75. data/_includes/{sidebar.html → views/sidebar.html} +0 -0
  76. data/_javascript/common/back-to-top.js +20 -20
  77. data/_javascript/common/mode-toggle.js +13 -13
  78. data/_javascript/common/scroll-helper.js +36 -36
  79. data/_javascript/common/search-display.js +129 -129
  80. data/_javascript/common/sidebar.js +30 -30
  81. data/_javascript/common/tooltip-loader.js +6 -6
  82. data/_javascript/common/topbar-switcher.js +90 -90
  83. data/_javascript/common/topbar-title.js +67 -67
  84. data/_javascript/utils/category-collapse.js +30 -30
  85. data/_javascript/utils/checkbox.js +12 -12
  86. data/_javascript/utils/clipboard.js +133 -133
  87. data/_javascript/utils/img-extra.js +47 -47
  88. data/_javascript/utils/locale-datetime.js +45 -45
  89. data/_javascript/utils/pageviews.js +250 -250
  90. data/_javascript/utils/smooth-scroll.js +96 -96
  91. data/_layouts/archive.html +5 -0
  92. data/_layouts/categories.html +5 -0
  93. data/_layouts/category.html +5 -0
  94. data/_layouts/compress.html +10 -10
  95. data/_layouts/error.html +44 -0
  96. data/_layouts/errors/404.html +9 -0
  97. data/_layouts/home.html +5 -0
  98. data/_layouts/page.html +5 -5
  99. data/_layouts/panel-both.html +13 -13
  100. data/_layouts/panel-left.html +13 -13
  101. data/_layouts/panel-none.html +24 -26
  102. data/_layouts/panel-right.html +13 -13
  103. data/_layouts/post.html +5 -5
  104. data/_layouts/tag.html +5 -0
  105. data/_layouts/tags.html +5 -0
  106. data/{_includes/comments.html → _sass/addon/alerts.scss} +0 -0
  107. data/_sass/addon/common.scss +56 -1494
  108. data/_sass/addon/mixins.scss +31 -38
  109. data/_sass/addon/syntax.scss +246 -0
  110. data/_sass/{layout/page.scss → addon/typography.scss} +0 -0
  111. data/_sass/layout/_base.scss +16 -0
  112. data/_sass/redeyed-jekyll-theme.scss +30 -15
  113. data/_sass/{layout/panel-both.scss → theme/scheme-brew.scss} +0 -0
  114. data/_sass/theme/scheme-dark.scss +220 -0
  115. data/_sass/theme/scheme-light.scss +220 -0
  116. data/_sass/theme/syntax-dark.scss +150 -0
  117. data/_sass/{colors/light-syntax.scss → theme/syntax-light.scss} +4 -4
  118. data/_sass/theme/variables.scss +60 -0
  119. metadata +147 -105
  120. data/_includes/ga-site-tag.html +0 -8
  121. data/_includes/lang.html +0 -6
  122. data/_includes/mermaid.html +0 -1
  123. data/_sass/addon/variables.scss +0 -31
  124. data/_sass/colors/brew-scheme.scss +0 -7
  125. data/_sass/colors/dark-scheme.scss +0 -21
  126. data/_sass/colors/dark-syntax.scss +0 -88
  127. data/_sass/colors/light-scheme.scss +0 -7
  128. data/_sass/layout/panel-left.scss +0 -0
  129. data/_sass/layout/panel-none.scss +0 -146
  130. data/_sass/layout/panel-right.scss +0 -0
  131. data/_sass/layout/post.scss +0 -0
@@ -1,129 +1,129 @@
1
- /*
2
- * This script make #search-result-wrapper switch to unloaded or shown automatically.
3
- */
4
-
5
- $(function() {
6
- const btnSbTrigger = $("#sidebar-trigger");
7
- const btnSearchTrigger = $("#search-trigger");
8
- const btnCancel = $("#search-cancel");
9
- const main = $("#main");
10
- const topbarTitle = $("#topbar-title");
11
- const searchWrapper = $("#search-wrapper");
12
- const resultWrapper = $("#search-result-wrapper");
13
- const results = $("#search-results");
14
- const input = $("#search-input");
15
- const hints = $("#search-hints");
16
-
17
- const scrollBlocker = (function () {
18
- let offset = 0;
19
- return {
20
- block() {
21
- offset = window.scrollY;
22
- $("html,body").scrollTop(0);
23
- },
24
- release() {
25
- $("html,body").scrollTop(offset);
26
- },
27
- getOffset() {
28
- return offset;
29
- }
30
- };
31
- }());
32
-
33
- /*--- Actions in mobile screens (Sidebar hidden) ---*/
34
-
35
- const mobileSearchBar = (function () {
36
- return {
37
- on() {
38
- btnSbTrigger.addClass("unloaded");
39
- topbarTitle.addClass("unloaded");
40
- btnSearchTrigger.addClass("unloaded");
41
- searchWrapper.addClass("d-flex");
42
- btnCancel.addClass("loaded");
43
- },
44
- off() {
45
- btnCancel.removeClass("loaded");
46
- searchWrapper.removeClass("d-flex");
47
- btnSbTrigger.removeClass("unloaded");
48
- topbarTitle.removeClass("unloaded");
49
- btnSearchTrigger.removeClass("unloaded");
50
- }
51
- };
52
- }());
53
-
54
- const resultSwitch = (function () {
55
- let visible = false;
56
-
57
- return {
58
- on() {
59
- if (!visible) {
60
- // the block method must be called before $(#main) unloaded.
61
- scrollBlocker.block();
62
- resultWrapper.removeClass("unloaded");
63
- main.addClass("unloaded");
64
- visible = true;
65
- }
66
- },
67
- off() {
68
- if (visible) {
69
- results.empty();
70
- if (hints.hasClass("unloaded")) {
71
- hints.removeClass("unloaded");
72
- }
73
- resultWrapper.addClass("unloaded");
74
- main.removeClass("unloaded");
75
-
76
- // now the release method must be called after $(#main) display
77
- scrollBlocker.release();
78
-
79
- input.val("");
80
- visible = false;
81
- }
82
- },
83
- isVisible() {
84
- return visible;
85
- }
86
- };
87
-
88
- }());
89
-
90
- function isMobileView() {
91
- return btnCancel.hasClass("loaded");
92
- }
93
-
94
- btnSearchTrigger.click(function() {
95
- mobileSearchBar.on();
96
- resultSwitch.on();
97
- input.focus();
98
- });
99
-
100
- btnCancel.click(function() {
101
- mobileSearchBar.off();
102
- resultSwitch.off();
103
- });
104
-
105
- input.focus(function() {
106
- searchWrapper.addClass("input-focus");
107
- });
108
-
109
- input.focusout(function() {
110
- searchWrapper.removeClass("input-focus");
111
- });
112
-
113
- input.on("input", () => {
114
- if (input.val() === "") {
115
- if (isMobileView()) {
116
- hints.removeClass("unloaded");
117
- } else {
118
- resultSwitch.off();
119
- }
120
-
121
- } else {
122
- resultSwitch.on();
123
- if (isMobileView()) {
124
- hints.addClass("unloaded");
125
- }
126
- }
127
- });
128
-
129
- });
1
+ /*
2
+ * This script make #search-result-wrapper switch to unloaded or shown automatically.
3
+ */
4
+
5
+ $(function() {
6
+ const btnSbTrigger = $("#sidebar-trigger");
7
+ const btnSearchTrigger = $("#search-trigger");
8
+ const btnCancel = $("#search-cancel");
9
+ const main = $("#main");
10
+ const topbarTitle = $("#topbar-title");
11
+ const searchWrapper = $("#search-wrapper");
12
+ const resultWrapper = $("#search-result-wrapper");
13
+ const results = $("#search-results");
14
+ const input = $("#search-input");
15
+ const hints = $("#search-hints");
16
+
17
+ const scrollBlocker = (function () {
18
+ let offset = 0;
19
+ return {
20
+ block() {
21
+ offset = window.scrollY;
22
+ $("html,body").scrollTop(0);
23
+ },
24
+ release() {
25
+ $("html,body").scrollTop(offset);
26
+ },
27
+ getOffset() {
28
+ return offset;
29
+ }
30
+ };
31
+ }());
32
+
33
+ /*--- Actions in mobile screens (Sidebar hidden) ---*/
34
+
35
+ const mobileSearchBar = (function () {
36
+ return {
37
+ on() {
38
+ btnSbTrigger.addClass("unloaded");
39
+ topbarTitle.addClass("unloaded");
40
+ btnSearchTrigger.addClass("unloaded");
41
+ searchWrapper.addClass("d-flex");
42
+ btnCancel.addClass("loaded");
43
+ },
44
+ off() {
45
+ btnCancel.removeClass("loaded");
46
+ searchWrapper.removeClass("d-flex");
47
+ btnSbTrigger.removeClass("unloaded");
48
+ topbarTitle.removeClass("unloaded");
49
+ btnSearchTrigger.removeClass("unloaded");
50
+ }
51
+ };
52
+ }());
53
+
54
+ const resultSwitch = (function () {
55
+ let visible = false;
56
+
57
+ return {
58
+ on() {
59
+ if (!visible) {
60
+ // the block method must be called before $(#main) unloaded.
61
+ scrollBlocker.block();
62
+ resultWrapper.removeClass("unloaded");
63
+ main.addClass("unloaded");
64
+ visible = true;
65
+ }
66
+ },
67
+ off() {
68
+ if (visible) {
69
+ results.empty();
70
+ if (hints.hasClass("unloaded")) {
71
+ hints.removeClass("unloaded");
72
+ }
73
+ resultWrapper.addClass("unloaded");
74
+ main.removeClass("unloaded");
75
+
76
+ // now the release method must be called after $(#main) display
77
+ scrollBlocker.release();
78
+
79
+ input.val("");
80
+ visible = false;
81
+ }
82
+ },
83
+ isVisible() {
84
+ return visible;
85
+ }
86
+ };
87
+
88
+ }());
89
+
90
+ function isMobileView() {
91
+ return btnCancel.hasClass("loaded");
92
+ }
93
+
94
+ btnSearchTrigger.click(function() {
95
+ mobileSearchBar.on();
96
+ resultSwitch.on();
97
+ input.focus();
98
+ });
99
+
100
+ btnCancel.click(function() {
101
+ mobileSearchBar.off();
102
+ resultSwitch.off();
103
+ });
104
+
105
+ input.focus(function() {
106
+ searchWrapper.addClass("input-focus");
107
+ });
108
+
109
+ input.focusout(function() {
110
+ searchWrapper.removeClass("input-focus");
111
+ });
112
+
113
+ input.on("input", () => {
114
+ if (input.val() === "") {
115
+ if (isMobileView()) {
116
+ hints.removeClass("unloaded");
117
+ } else {
118
+ resultSwitch.off();
119
+ }
120
+
121
+ } else {
122
+ resultSwitch.on();
123
+ if (isMobileView()) {
124
+ hints.addClass("unloaded");
125
+ }
126
+ }
127
+ });
128
+
129
+ });
@@ -1,30 +1,30 @@
1
- /**
2
- * Expand or close the sidebar in mobile screens.
3
- */
4
-
5
- $(function() {
6
-
7
- const sidebarUtil = (function () {
8
- const ATTR_DISPLAY = "sidebar-display";
9
- let isExpanded = false;
10
- const body = $("body");
11
-
12
- return {
13
- toggle() {
14
- if (isExpanded === false) {
15
- body.attr(ATTR_DISPLAY, "");
16
- } else {
17
- body.removeAttr(ATTR_DISPLAY);
18
- }
19
-
20
- isExpanded = !isExpanded;
21
- }
22
- };
23
-
24
- }());
25
-
26
- $("#sidebar-trigger").click(sidebarUtil.toggle);
27
-
28
- $("#mask").click(sidebarUtil.toggle);
29
-
30
- });
1
+ /**
2
+ * Expand or close the sidebar in mobile screens.
3
+ */
4
+
5
+ $(function() {
6
+
7
+ const sidebarUtil = (function () {
8
+ const ATTR_DISPLAY = "sidebar-display";
9
+ let isExpanded = false;
10
+ const body = $("body");
11
+
12
+ return {
13
+ toggle() {
14
+ if (isExpanded === false) {
15
+ body.attr(ATTR_DISPLAY, "");
16
+ } else {
17
+ body.removeAttr(ATTR_DISPLAY);
18
+ }
19
+
20
+ isExpanded = !isExpanded;
21
+ }
22
+ };
23
+
24
+ }());
25
+
26
+ $("#sidebar-trigger").click(sidebarUtil.toggle);
27
+
28
+ $("#mask").click(sidebarUtil.toggle);
29
+
30
+ });
@@ -1,6 +1,6 @@
1
- /**
2
- * Initial Bootstrap Tooltip.
3
- */
4
- $(function () {
5
- $("[data-toggle=\"tooltip\"]").tooltip();
6
- });
1
+ /**
2
+ * Initial Bootstrap Tooltip.
3
+ */
4
+ $(function () {
5
+ $("[data-toggle=\"tooltip\"]").tooltip();
6
+ });
@@ -1,90 +1,90 @@
1
- /*
2
- * Hide Header on scroll down
3
- */
4
-
5
- $(function() {
6
- const $searchInput = $("#search-input");
7
- const delta = ScrollHelper.getTopbarHeight();
8
-
9
- let didScroll;
10
- let lastScrollTop = 0;
11
-
12
- function hasScrolled() {
13
- let st = $(this).scrollTop();
14
-
15
- /* Make sure they scroll more than delta */
16
- if (Math.abs(lastScrollTop - st) <= delta) {
17
- return;
18
- }
19
-
20
- if (st > lastScrollTop ) { // Scroll Down
21
- ScrollHelper.hideTopbar();
22
-
23
- if ($searchInput.is(":focus")) {
24
- $searchInput.blur(); /* remove focus */
25
- }
26
-
27
- } else { // Scroll up
28
- // has not yet scrolled to the bottom of the screen, that is, there is still space for scrolling
29
- if (st + $(window).height() < $(document).height()) {
30
-
31
- if (ScrollHelper.hasScrollUpTask()) {
32
- return;
33
- }
34
-
35
- if (ScrollHelper.topbarLocked()) { // avoid redundant scroll up event from smooth scrolling
36
- ScrollHelper.unlockTopbar();
37
- } else {
38
- if (ScrollHelper.orientationLocked()) { // avoid device auto scroll up on orientation change
39
- ScrollHelper.unLockOrientation();
40
- } else {
41
- ScrollHelper.showTopbar();
42
- }
43
- }
44
- }
45
- }
46
-
47
- lastScrollTop = st;
48
-
49
- } // hasScrolled()
50
-
51
- function handleLandscape() {
52
- if ($(window).scrollTop() === 0) {
53
- return;
54
- }
55
- ScrollHelper.lockOrientation();
56
- ScrollHelper.hideTopbar();
57
- }
58
-
59
- if (screen.orientation) {
60
- screen.orientation.onchange = () => {
61
- const type = screen.orientation.type;
62
- if (type === "landscape-primary" || type === "landscape-secondary") {
63
- handleLandscape();
64
- }
65
- };
66
-
67
- } else {
68
- // for the browsers that not support `window.screen.orientation` API
69
- $(window).on("orientationchange",() => {
70
- if ($(window).width() < $(window).height()) { // before rotating, it is still in portrait mode.
71
- handleLandscape();
72
- }
73
- });
74
- }
75
-
76
- $(window).scroll(() => {
77
- if (didScroll) {
78
- return;
79
- }
80
- didScroll = true;
81
- });
82
-
83
- setInterval(() => {
84
- if (didScroll) {
85
- hasScrolled();
86
- didScroll = false;
87
- }
88
- }, 250);
89
-
90
- });
1
+ /*
2
+ * Hide Header on scroll down
3
+ */
4
+
5
+ $(function() {
6
+ const $searchInput = $("#search-input");
7
+ const delta = ScrollHelper.getTopbarHeight();
8
+
9
+ let didScroll;
10
+ let lastScrollTop = 0;
11
+
12
+ function hasScrolled() {
13
+ let st = $(this).scrollTop();
14
+
15
+ /* Make sure they scroll more than delta */
16
+ if (Math.abs(lastScrollTop - st) <= delta) {
17
+ return;
18
+ }
19
+
20
+ if (st > lastScrollTop ) { // Scroll Down
21
+ ScrollHelper.hideTopbar();
22
+
23
+ if ($searchInput.is(":focus")) {
24
+ $searchInput.blur(); /* remove focus */
25
+ }
26
+
27
+ } else { // Scroll up
28
+ // has not yet scrolled to the bottom of the screen, that is, there is still space for scrolling
29
+ if (st + $(window).height() < $(document).height()) {
30
+
31
+ if (ScrollHelper.hasScrollUpTask()) {
32
+ return;
33
+ }
34
+
35
+ if (ScrollHelper.topbarLocked()) { // avoid redundant scroll up event from smooth scrolling
36
+ ScrollHelper.unlockTopbar();
37
+ } else {
38
+ if (ScrollHelper.orientationLocked()) { // avoid device auto scroll up on orientation change
39
+ ScrollHelper.unLockOrientation();
40
+ } else {
41
+ ScrollHelper.showTopbar();
42
+ }
43
+ }
44
+ }
45
+ }
46
+
47
+ lastScrollTop = st;
48
+
49
+ } // hasScrolled()
50
+
51
+ function handleLandscape() {
52
+ if ($(window).scrollTop() === 0) {
53
+ return;
54
+ }
55
+ ScrollHelper.lockOrientation();
56
+ ScrollHelper.hideTopbar();
57
+ }
58
+
59
+ if (screen.orientation) {
60
+ screen.orientation.onchange = () => {
61
+ const type = screen.orientation.type;
62
+ if (type === "landscape-primary" || type === "landscape-secondary") {
63
+ handleLandscape();
64
+ }
65
+ };
66
+
67
+ } else {
68
+ // for the browsers that not support `window.screen.orientation` API
69
+ $(window).on("orientationchange",() => {
70
+ if ($(window).width() < $(window).height()) { // before rotating, it is still in portrait mode.
71
+ handleLandscape();
72
+ }
73
+ });
74
+ }
75
+
76
+ $(window).scroll(() => {
77
+ if (didScroll) {
78
+ return;
79
+ }
80
+ didScroll = true;
81
+ });
82
+
83
+ setInterval(() => {
84
+ if (didScroll) {
85
+ hasScrolled();
86
+ didScroll = false;
87
+ }
88
+ }, 250);
89
+
90
+ });
@@ -1,67 +1,67 @@
1
- /*
2
- * Top bar title auto change while scrolling up/down in mobile screens.
3
- */
4
-
5
- $(function() {
6
- const titleSelector = "div.post>h1:first-of-type";
7
- const $pageTitle = $(titleSelector);
8
- const $topbarTitle = $("#topbar-title");
9
-
10
- if ($pageTitle.length === 0 /* on Home page */
11
- || $pageTitle.hasClass("dynamic-title")
12
- || $topbarTitle.is(":hidden")) {/* not in mobile views */
13
- return;
14
- }
15
-
16
- const defaultTitleText = $topbarTitle.text().trim();
17
- let pageTitleText = $pageTitle.text().trim();
18
- let hasScrolled = false;
19
- let lastScrollTop = 0;
20
-
21
- if ($("#page-category").length || $("#page-tag").length) {
22
- /* The title in Category or Tag page will be "<title> <count_of_posts>" */
23
- if (/\s/.test(pageTitleText)) {
24
- pageTitleText = pageTitleText.replace(/[0-9]/g, "").trim();
25
- }
26
- }
27
-
28
- // When the page is scrolled down and then refreshed, the topbar title needs to be initialized
29
- if ($pageTitle.offset().top < $(window).scrollTop()) {
30
- $topbarTitle.text(pageTitleText);
31
- }
32
-
33
- let options = {
34
- rootMargin: '-48px 0px 0px 0px', // 48px equals to the topbar height (3rem)
35
- threshold: [0, 1]
36
- };
37
-
38
- let observer = new IntersectionObserver((entries) => {
39
- if (!hasScrolled) {
40
- hasScrolled = true;
41
- return;
42
- }
43
-
44
- let curScrollTop = $(window).scrollTop();
45
- let isScrollDown = lastScrollTop < curScrollTop;
46
- lastScrollTop = curScrollTop;
47
- let heading = entries[0];
48
-
49
- if (isScrollDown) {
50
- if (heading.intersectionRatio === 0) {
51
- $topbarTitle.text(pageTitleText);
52
- }
53
- } else {
54
- if (heading.intersectionRatio === 1) {
55
- $topbarTitle.text(defaultTitleText);
56
- }
57
- }
58
- }, options);
59
-
60
- observer.observe(document.querySelector(titleSelector));
61
-
62
- /* Click title will scroll to top */
63
- $topbarTitle.click(function() {
64
- $("body,html").animate({scrollTop: 0}, 800);
65
- });
66
-
67
- });
1
+ /*
2
+ * Top bar title auto change while scrolling up/down in mobile screens.
3
+ */
4
+
5
+ $(function() {
6
+ const titleSelector = "div.post>h1:first-of-type";
7
+ const $pageTitle = $(titleSelector);
8
+ const $topbarTitle = $("#topbar-title");
9
+
10
+ if ($pageTitle.length === 0 /* on Home page */
11
+ || $pageTitle.hasClass("dynamic-title")
12
+ || $topbarTitle.is(":hidden")) {/* not in mobile views */
13
+ return;
14
+ }
15
+
16
+ const defaultTitleText = $topbarTitle.text().trim();
17
+ let pageTitleText = $pageTitle.text().trim();
18
+ let hasScrolled = false;
19
+ let lastScrollTop = 0;
20
+
21
+ if ($("#page-category").length || $("#page-tag").length) {
22
+ /* The title in Category or Tag page will be "<title> <count_of_posts>" */
23
+ if (/\s/.test(pageTitleText)) {
24
+ pageTitleText = pageTitleText.replace(/[0-9]/g, "").trim();
25
+ }
26
+ }
27
+
28
+ // When the page is scrolled down and then refreshed, the topbar title needs to be initialized
29
+ if ($pageTitle.offset().top < $(window).scrollTop()) {
30
+ $topbarTitle.text(pageTitleText);
31
+ }
32
+
33
+ let options = {
34
+ rootMargin: '-48px 0px 0px 0px', // 48px equals to the topbar height (3rem)
35
+ threshold: [0, 1]
36
+ };
37
+
38
+ let observer = new IntersectionObserver((entries) => {
39
+ if (!hasScrolled) {
40
+ hasScrolled = true;
41
+ return;
42
+ }
43
+
44
+ let curScrollTop = $(window).scrollTop();
45
+ let isScrollDown = lastScrollTop < curScrollTop;
46
+ lastScrollTop = curScrollTop;
47
+ let heading = entries[0];
48
+
49
+ if (isScrollDown) {
50
+ if (heading.intersectionRatio === 0) {
51
+ $topbarTitle.text(pageTitleText);
52
+ }
53
+ } else {
54
+ if (heading.intersectionRatio === 1) {
55
+ $topbarTitle.text(defaultTitleText);
56
+ }
57
+ }
58
+ }, options);
59
+
60
+ observer.observe(document.querySelector(titleSelector));
61
+
62
+ /* Click title will scroll to top */
63
+ $topbarTitle.click(function() {
64
+ $("body,html").animate({scrollTop: 0}, 800);
65
+ });
66
+
67
+ });