PluginProbe
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder / 51.1.44
King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder v51.1.44
51.1.86 51.1.84 51.1.85 51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 All 40 releases
king-addons / includes / widgets / Styled_Text_Builder / script.js

script.js in King Addons for Elementor – 100+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce Builder, Mega Menu, Popup Builder 51.1.44, at includes/widgets/Styled_Text_Builder/script.js

126 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 (function ($) {
4 const isMobile = () => window.matchMedia("(max-width: 1023px)").matches;
5
6 const revealSpoiler = ($inner) => {
7 $inner.addClass("is-revealed");
8 };
9
10 const hideSpoiler = ($inner) => {
11 $inner.removeClass("is-revealed");
12 };
13
14 const bindSpoiler = ($item) => {
15 const $inner = $item.find(".king-addons-styled-text-inner");
16 if (!$inner.length) return;
17
18 const triggerDesktop = $item.data("spoiler-desktop") || "hover";
19 const triggerMobile = $item.data("spoiler-mobile") || "tap";
20
21 const attachHover = () => {
22 $item.on("mouseenter", () => revealSpoiler($inner));
23 $item.on("mouseleave", () => hideSpoiler($inner));
24 };
25
26 const attachClick = () => {
27 $item.on("click", (e) => {
28 e.preventDefault();
29 const isOpen = $inner.hasClass("is-revealed");
30 if (isOpen) {
31 hideSpoiler($inner);
32 } else {
33 revealSpoiler($inner);
34 }
35 });
36 };
37
38 if (isMobile()) {
39 if (triggerMobile === "hover") {
40 attachHover();
41 } else {
42 attachClick();
43 }
44 } else {
45 if (triggerDesktop === "click") {
46 attachClick();
47 } else {
48 attachHover();
49 }
50 }
51 };
52
53 const startTyping = ($item) => {
54 const $inner = $item.find(".king-addons-styled-text-inner span").first();
55 if (!$inner.length) return;
56
57 const fullText = $inner.text();
58 const speed = parseInt($item.data("typing-speed"), 10) || 80;
59 const delay = parseInt($item.data("typing-delay"), 10) || 1200;
60 const loop = $item.data("typing-loop") === "yes";
61 const cursorChar = ($item.data("typing-cursor") || "|").toString();
62
63 const $cursor = $('<span class="king-addons-styled-text__cursor"></span>').text(cursorChar);
64 $inner.after($cursor);
65
66 let pos = 0;
67 let isTyping = false;
68
69 const typeOnce = () => {
70 if (isTyping) return;
71 isTyping = true;
72 $inner.text("");
73 pos = 0;
74
75 const step = () => {
76 if (pos <= fullText.length) {
77 $inner.text(fullText.substring(0, pos));
78 pos += 1;
79 setTimeout(step, speed);
80 } else {
81 isTyping = false;
82 if (loop) {
83 setTimeout(typeOnce, delay);
84 }
85 }
86 };
87
88 step();
89 };
90
91 typeOnce();
92 };
93
94 const initStyledText = ($scope) => {
95 const $items = $scope.find('.king-addons-styled-text[data-effect="spoiler"]');
96 if ($items.length) {
97 $items.each(function () {
98 bindSpoiler($(this));
99 });
100 }
101
102 const $typingItems = $scope.find('.king-addons-styled-text[data-effect="typing"]');
103 if ($typingItems.length) {
104 $typingItems.each(function () {
105 startTyping($(this));
106 });
107 }
108 };
109
110 $(window).on("elementor/frontend/init", function () {
111 elementorFrontend.hooks.addAction(
112 "frontend/element_ready/king-addons-styled-text-builder.default",
113 function ($scope) {
114 initStyledText($scope);
115 }
116 );
117 });
118 })(jQuery);
119
120
121
122
123
124
125
126