minimal-mistakes-jekyll 4.25.0 → 4.26.0

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,27 @@ $(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
+ document.addEventListener("gumshoeActivate", 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
+
84
80
  // add lightbox class to all image links
85
81
  $(
86
82
  "a[href$='.jpg'],a[href$='.jpeg'],a[href$='.JPG'],a[href$='.png'],a[href$='.gif'],a[href$='.webp']"
@@ -99,38 +95,120 @@ $(function() {
99
95
  gallery: {
100
96
  enabled: true,
101
97
  navigateByImgClick: true,
102
- preload: [0, 1] // Will preload 0 - before current, and 1 after the current image
98
+ preload: [0, 1], // Will preload 0 - before current, and 1 after the current image
103
99
  },
104
100
  image: {
105
- tError: '<a href="%url%">Image #%curr%</a> could not be loaded.'
101
+ tError: '<a href="%url%">Image #%curr%</a> could not be loaded.',
106
102
  },
107
103
  removalDelay: 500, // Delay in milliseconds before popup is removed
108
104
  // Class that is added to body when popup is open.
109
105
  // make it unique to apply your CSS animations just to this exact popup
110
106
  mainClass: "mfp-zoom-in",
111
107
  callbacks: {
112
- beforeOpen: function() {
108
+ beforeOpen: function () {
113
109
  // just a hack that adds mfp-anim class to markup
114
110
  this.st.image.markup = this.st.image.markup.replace(
115
111
  "mfp-figure",
116
112
  "mfp-figure mfp-with-anim"
117
113
  );
118
- }
114
+ },
119
115
  },
120
116
  closeOnContentClick: true,
121
- midClick: true // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
117
+ midClick: true, // allow opening popup on middle mouse click. Always set it to true if you don't provide alternative source.
122
118
  });
123
119
 
124
120
  // 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);
121
+ document
122
+ .querySelector(".page__content")
123
+ .querySelectorAll("h1, h2, h3, h4, h5, h6")
124
+ .forEach(function (element) {
125
+ var id = element.getAttribute("id");
126
+ if (id) {
127
+ var anchor = document.createElement("a");
128
+ anchor.className = "header-link";
129
+ anchor.href = "#" + id;
130
+ anchor.innerHTML =
131
+ '<span class="sr-only">Permalink</span><i class="fas fa-link"></i>';
132
+ anchor.title = "Permalink";
133
+ element.appendChild(anchor);
134
+ }
135
+ });
136
+
137
+ // Add copy button for <pre> blocks
138
+ var copyText = function (text) {
139
+ if (document.queryCommandEnabled("copy") && navigator.clipboard) {
140
+ navigator.clipboard.writeText(text).then(
141
+ () => true,
142
+ () => console.error("Failed to copy text to clipboard: " + text)
143
+ );
144
+ return true;
145
+ } else {
146
+ var isRTL = document.documentElement.getAttribute("dir") === "rtl";
147
+
148
+ var textarea = document.createElement("textarea");
149
+ textarea.className = "clipboard-helper";
150
+ textarea.style[isRTL ? "right" : "left"] = "-9999px";
151
+ // Move element to the same position vertically
152
+ var yPosition = window.pageYOffset || document.documentElement.scrollTop;
153
+ textarea.style.top = yPosition + "px";
154
+
155
+ textarea.setAttribute("readonly", "");
156
+ textarea.value = text;
157
+ document.body.appendChild(textarea);
158
+
159
+ var success = true;
160
+ try {
161
+ textarea.select();
162
+ success = document.execCommand("copy");
163
+ } catch (e) {
164
+ success = false;
165
+ }
166
+ textarea.parentNode.removeChild(textarea);
167
+ return success;
134
168
  }
135
- });
169
+ };
170
+
171
+ var copyButtonEventListener = function (event) {
172
+ var thisButton = event.target;
173
+
174
+ // Locate the <code> element
175
+ var codeBlock = thisButton.nextElementSibling;
176
+ while (codeBlock && codeBlock.tagName.toLowerCase() !== "code") {
177
+ codeBlock = codeBlock.nextElementSibling;
178
+ }
179
+ if (!codeBlock) {
180
+ // No <code> found - wtf?
181
+ console.warn(thisButton);
182
+ throw new Error("No code block found for this button.");
183
+ }
184
+
185
+ // Skip line numbers if present (i.e. {% highlight lineno %})
186
+ var realCodeBlock = codeBlock.querySelector("td.code, td.rouge-code");
187
+ if (realCodeBlock) {
188
+ codeBlock = realCodeBlock;
189
+ }
190
+ var result = copyText(codeBlock.innerText);
191
+ // Restore the focus to the button
192
+ thisButton.focus();
193
+ return result;
194
+ };
195
+
196
+ if (window.enable_copy_code_button) {
197
+ document
198
+ .querySelectorAll(".page__content pre > code")
199
+ .forEach(function (element, index, parentList) {
200
+ // Locate the <pre> element
201
+ var container = element.parentElement;
202
+ // Sanity check - don't add an extra button if there's already one
203
+ if (container.firstElementChild.tagName.toLowerCase() !== "code") {
204
+ return;
205
+ }
206
+ var copyButton = document.createElement("button");
207
+ copyButton.title = "Copy to clipboard";
208
+ copyButton.className = "clipboard-copy-button";
209
+ copyButton.innerHTML = '<span class="sr-only">Copy code</span><i class="far fa-copy"></i>';
210
+ copyButton.addEventListener("click", copyButtonEventListener);
211
+ container.prepend(copyButton);
212
+ });
213
+ }
136
214
  });
@@ -47,7 +47,7 @@ var store = [
47
47
  }{%- unless forloop.last and l -%},{%- endunless -%}
48
48
  {%- endfor -%}
49
49
  {%- endfor -%}{%- if site.lunr.search_within_pages -%},
50
- {%- assign pages = site.pages | where_exp:'doc','doc.search != false and doc.title != null' -%}
50
+ {%- assign pages = site.pages | where_exp: 'doc', 'doc.search != false' | where_exp: 'doc', 'doc.title != null' -%}
51
51
  {%- for doc in pages -%}
52
52
  {%- if forloop.last -%}
53
53
  {%- assign l = true -%}