minimal-mistakes-jekyll 4.25.1 → 4.26.1

Sign up to get free protection for your applications and to get access to all the features.
data/assets/js/_main.js CHANGED
@@ -2,39 +2,18 @@
2
2
  jQuery plugin settings and other scripts
3
3
  ========================================================================== */
4
4
 
5
- $(function() {
5
+ $(document).ready(function () {
6
6
  // FitVids init
7
7
  $("#main").fitVids();
8
8
 
9
- // Sticky sidebar
10
- var stickySideBar = function() {
11
- var show =
12
- $(".author__urls-wrapper").find("button").length === 0
13
- ? $(window).width() > 1024 // width should match $large Sass variable
14
- : !$(".author__urls-wrapper").find("button").is(":visible");
15
- if (show) {
16
- // fix
17
- $(".sidebar").addClass("sticky");
18
- } else {
19
- // unfix
20
- $(".sidebar").removeClass("sticky");
21
- }
22
- };
23
-
24
- stickySideBar();
25
-
26
- $(window).resize(function() {
27
- stickySideBar();
28
- });
29
-
30
9
  // Follow menu drop down
31
- $(".author__urls-wrapper").find("button").on("click", function() {
10
+ $(".author__urls-wrapper button").on("click", function () {
32
11
  $(".author__urls").toggleClass("is--visible");
33
12
  $(".author__urls-wrapper").find("button").toggleClass("open");
34
13
  });
35
14
 
36
15
  // Close search screen with Esc key
37
- $(document).keyup(function(e) {
16
+ $(document).keyup(function (e) {
38
17
  if (e.keyCode === 27) {
39
18
  if ($(".initial-content").hasClass("is--hidden")) {
40
19
  $(".search-content").toggleClass("is--visible");
@@ -44,12 +23,12 @@ $(function() {
44
23
  });
45
24
 
46
25
  // Search toggle
47
- $(".search__toggle").on("click", function() {
26
+ $(".search__toggle").on("click", function () {
48
27
  $(".search-content").toggleClass("is--visible");
49
28
  $(".initial-content").toggleClass("is--hidden");
50
29
  // set focus on input
51
- setTimeout(function() {
52
- $(".search-content").find("input").focus();
30
+ setTimeout(function () {
31
+ $(".search-content input").focus();
53
32
  }, 400);
54
33
  });
55
34
 
@@ -58,11 +37,11 @@ $(function() {
58
37
  offset: 20,
59
38
  speed: 400,
60
39
  speedAsDuration: true,
61
- durationMax: 500
40
+ durationMax: 500,
62
41
  });
63
42
 
64
43
  // Gumshoe scroll spy init
65
- if($("nav.toc").length > 0) {
44
+ if ($("nav.toc").length > 0) {
66
45
  var spy = new Gumshoe("nav.toc a", {
67
46
  // Active classes
68
47
  navClass: "active", // applied to the nav list item
@@ -77,10 +56,32 @@ $(function() {
77
56
  reflow: true, // if true, listen for reflows
78
57
 
79
58
  // Event support
80
- events: true // if true, emit custom events
59
+ events: true, // if true, emit custom events
81
60
  });
82
61
  }
83
62
 
63
+ // Auto scroll sticky ToC with content
64
+ const scrollTocToContent = function (event) {
65
+ var target = event.target;
66
+ var scrollOptions = { behavior: "auto", block: "nearest", inline: "start" };
67
+
68
+ var tocElement = document.querySelector("aside.sidebar__right.sticky");
69
+ if (!tocElement) return;
70
+ if (window.getComputedStyle(tocElement).position !== "sticky") return;
71
+
72
+ if (target.parentElement.classList.contains("toc__menu") && target == target.parentElement.firstElementChild) {
73
+ // Scroll to top instead
74
+ document.querySelector("nav.toc header").scrollIntoView(scrollOptions);
75
+ } else {
76
+ target.scrollIntoView(scrollOptions);
77
+ }
78
+ };
79
+
80
+ // Has issues on Firefox, whitelist Chrome for now
81
+ if (!!window.chrome) {
82
+ document.addEventListener("gumshoeActivate", scrollTocToContent);
83
+ }
84
+
84
85
  // add lightbox class to all image links
85
86
  $(
86
87
  "a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif'],a[href$='.webp']"
@@ -99,38 +100,131 @@ $(function() {
99
100
  gallery: {
100
101
  enabled: true,
101
102
  navigateByImgClick: true,
102
- preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
103
+ preload: [0, 1], // Will preload 0 - before current, and 1 after the current image
103
104
  },
104
105
  image: {
105
- tError: '<a href="%url%">Image #%curr%</a> could not be loaded.'
106
+ tError: '<a href="%url%">Image #%curr%</a> could not be loaded.',
106
107
  },
107
108
  removalDelay: 500, // Delay in milliseconds before popup is removed
108
109
  // Class that is added to body when popup is open.
109
110
  // make it unique to apply your CSS animations just to this exact popup
110
111
  mainClass: "mfp-zoom-in",
111
112
  callbacks: {
112
- beforeOpen: function() {
113
+ beforeOpen: function () {
113
114
  // just a hack that adds mfp-anim class to markup
114
115
  this.st.image.markup = this.st.image.markup.replace(
115
116
  "mfp-figure",
116
117
  "mfp-figure mfp-with-anim"
117
118
  );
118
- }
119
+ },
119
120
  },
120
121
  closeOnContentClick: true,
121
- midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
122
+ midClick: true, // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
122
123
  });
123
124
 
124
125
  // Add anchors for headings
125
- $('.page__content').find('h1, h2, h3, h4, h5, h6').each(function() {
126
- var id = $(this).attr('id');
127
- if (id) {
128
- var anchor = document.createElement("a");
129
- anchor.className = 'header-link';
130
- anchor.href = '#' + id;
131
- anchor.innerHTML = '<span class=\"sr-only\">Permalink</span><i class=\"fas fa-link\"></i>';
132
- anchor.title = "Permalink";
133
- $(this).append(anchor);
126
+ document
127
+ .querySelector(".page__content")
128
+ .querySelectorAll("h1, h2, h3, h4, h5, h6")
129
+ .forEach(function (element) {
130
+ var id = element.getAttribute("id");
131
+ if (id) {
132
+ var anchor = document.createElement("a");
133
+ anchor.className = "header-link";
134
+ anchor.href = "#" + id;
135
+ anchor.innerHTML =
136
+ '<span class="sr-only">Permalink</span><i class="fas fa-link"></i>';
137
+ anchor.title = "Permalink";
138
+ element.appendChild(anchor);
139
+ }
140
+ });
141
+
142
+ // Add copy button for <pre> blocks
143
+ var copyText = function (text) {
144
+ if (document.queryCommandEnabled("copy") && navigator.clipboard) {
145
+ navigator.clipboard.writeText(text).then(
146
+ () => true,
147
+ () => console.error("Failed to copy text to clipboard: " + text)
148
+ );
149
+ return true;
150
+ } else {
151
+ var isRTL = document.documentElement.getAttribute("dir") === "rtl";
152
+
153
+ var textarea = document.createElement("textarea");
154
+ textarea.className = "clipboard-helper";
155
+ textarea.style[isRTL ? "right" : "left"] = "-9999px";
156
+ // Move element to the same position vertically
157
+ var yPosition = window.pageYOffset || document.documentElement.scrollTop;
158
+ textarea.style.top = yPosition + "px";
159
+
160
+ textarea.setAttribute("readonly", "");
161
+ textarea.value = text;
162
+ document.body.appendChild(textarea);
163
+
164
+ var success = true;
165
+ try {
166
+ textarea.select();
167
+ success = document.execCommand("copy");
168
+ } catch (e) {
169
+ success = false;
170
+ }
171
+ textarea.parentNode.removeChild(textarea);
172
+ return success;
134
173
  }
135
- });
174
+ };
175
+
176
+ var copyButtonEventListener = function (event) {
177
+ var thisButton = event.target;
178
+
179
+ // Locate the <code> element
180
+ var codeBlock = thisButton.nextElementSibling;
181
+ while (codeBlock && codeBlock.tagName.toLowerCase() !== "code") {
182
+ codeBlock = codeBlock.nextElementSibling;
183
+ }
184
+ if (!codeBlock) {
185
+ // No <code> found - wtf?
186
+ console.warn(thisButton);
187
+ throw new Error("No code block found for this button.");
188
+ }
189
+
190
+ // Skip line numbers if present (i.e. {% highlight lineno %})
191
+ var realCodeBlock = codeBlock.querySelector("td.code, td.rouge-code");
192
+ if (realCodeBlock) {
193
+ codeBlock = realCodeBlock;
194
+ }
195
+ var result = copyText(codeBlock.innerText);
196
+ // Restore the focus to the button
197
+ thisButton.focus();
198
+ if (result) {
199
+ if (thisButton.interval !== null) {
200
+ clearInterval(thisButton.interval);
201
+ }
202
+ thisButton.classList.add('copied');
203
+ thisButton.interval = setTimeout(function () {
204
+ thisButton.classList.remove('copied');
205
+ clearInterval(thisButton.interval);
206
+ thisButton.interval = null;
207
+ }, 1500);
208
+ }
209
+ return result;
210
+ };
211
+
212
+ if (window.enable_copy_code_button) {
213
+ document
214
+ .querySelectorAll(".page__content pre.highlight > code")
215
+ .forEach(function (element, index, parentList) {
216
+ // Locate the <pre> element
217
+ var container = element.parentElement;
218
+ // Sanity check - don't add an extra button if there's already one
219
+ if (container.firstElementChild.tagName.toLowerCase() !== "code") {
220
+ return;
221
+ }
222
+ var copyButton = document.createElement("button");
223
+ copyButton.title = "Copy to clipboard";
224
+ copyButton.className = "clipboard-copy-button";
225
+ copyButton.innerHTML = '<span class="sr-only">Copy code</span><i class="far fa-fw fa-copy"></i><i class="fas fa-fw fa-check copied"></i>';
226
+ copyButton.addEventListener("click", copyButtonEventListener);
227
+ container.prepend(copyButton);
228
+ });
229
+ }
136
230
  });