Feat: add more params for typeit shortcodes

resolves #483
This commit is contained in:
Cell
2024-08-04 12:30:06 +08:00
parent c0942a92b9
commit 976db36bc8
3 changed files with 21 additions and 7 deletions
+8 -7
View File
@@ -738,7 +738,7 @@ class FixIt {
Object.values(groupMap).forEach((group) => {
const typeone = (i) => {
const typeitElement = group[i];
const singleLoop = typeitElement.dataset.loop;
const singleData = typeitElement.dataset;
stagingDOM.stage(typeitElement.querySelector('template').content.cloneNode(true));
// for shortcodes usage
let targetEle = typeitElement.firstElementChild
@@ -750,18 +750,19 @@ class FixIt {
// create a new instance of TypeIt for each element
const instance = new TypeIt(targetEle, {
strings: stagingDOM.$el.querySelector('pre')?.innerHTML || stagingDOM.contentAsHtml(),
speed: speed,
speed: Number(singleData.speed) >= 0 ? Number(singleData.speed) : speed,
lifeLike: true,
cursorSpeed: cursorSpeed,
cursorChar: cursorChar,
cursorSpeed: Number(singleData.cursorSpeed) >= 0 ? Number(singleData.cursorSpeed) : cursorSpeed,
cursorChar: singleData.cursorChar || cursorChar,
waitUntilVisible: true,
loop: singleLoop ? JSON.parse(singleLoop) : loop,
loop: singleData.loop ? singleData.loop === 'true' : loop,
afterComplete: () => {
const duration = Number(singleData.duration ?? vtypeitConfig.duration);
if (i === group.length - 1) {
if (typeitConfig.duration >= 0) {
if (duration >= 0) {
window.setTimeout(() => {
instance.destroy();
}, typeitConfig.duration);
}, duration);
}
return;
}
+1
View File
@@ -11,6 +11,7 @@
{{- end -}}
{{- $related := $posts.Related . | first ($params.related.count | default 5) -}}
{{- with $related -}}
<hr class="awesome-hr" />
<h2 id="see-also">{{ T "single.relatedContent" }}</h2>
<ul>
{{- range $i, $p := . -}}
+12
View File
@@ -25,6 +25,18 @@
{{- with (.Get "group" | string) -}}
{{- $wrapperAttrs = printf `%v data-group="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "speed" -}}
{{- $wrapperAttrs = printf `%v data-speed="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "cursorSpeed" -}}
{{- $wrapperAttrs = printf `%v data-cursor-speed="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "cursorChar" -}}
{{- $wrapperAttrs = printf `%v data-cursor-char="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with .Get "duration" -}}
{{- $wrapperAttrs = printf `%v data-duration="%v"` $wrapperAttrs . -}}
{{- end -}}
{{- with $loop -}}
{{- $wrapperAttrs = printf `%v data-loop="true"` $wrapperAttrs -}}
{{- end -}}