Skip to content

Commit 0259be5

Browse files
committed
[Update] Adding initial scripts.
Initial scripts and folders got added to the project, this include several functionalities: - Copy to Clipboard - Hide Container - Limit Text - Read Time - Social Links - Tabs Slider All this functionalities have been tested multiple times and may only require a cleanup before the first official release
1 parent 4625b30 commit 0259be5

6 files changed

Lines changed: 281 additions & 0 deletions

File tree

Dist/Functional/CopyToClipboard.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Trigger element = wt-copycb-element="trigger"
3+
* Target element = wt-copycb-element="target"
4+
* textTarget = wt-copycb-element="textTarget"
5+
* copiedMsg = wt-copycb-copiedMsg
6+
* activeClass = wt-copycb-activeClass
7+
*/
8+
9+
'use strict'
10+
11+
const UpdateTriggerDisplay = (_txt, _target, _trigger, _class ) => {
12+
if (_txt){
13+
if(_target) _target.innerText = _txt;
14+
else _trigger.innerHTML = _txt;
15+
}
16+
17+
if (_class) _trigger.classList.toggle(_class);
18+
}
19+
20+
const SetCopyToClipboard = () => {
21+
const copyTriggers = document.querySelectorAll('[wt-copycb-element^="trigger-"], [wt-copycb-element="trigger"]');
22+
23+
if(!copyTriggers || copyTriggers.length === 0) return;
24+
25+
for(let _trigger of copyTriggers) {
26+
let _triggerAttr = _trigger.getAttribute(`wt-copycb-element`);
27+
let index = _triggerAttr.replace('trigger','');
28+
let _target = document.querySelector(`[wt-copycb-element="target${index}"]`);
29+
30+
if(_target) {
31+
_trigger.addEventListener('click', () => {
32+
let textToCopy = _target.innerText;
33+
let copiedTxt = _trigger.getAttribute("wt-copycb-copiedMsg");
34+
let activeClass = _trigger.getAttribute('wt-copycb-activeClass');
35+
let timeOut = _trigger.getAttribute('wt-copycb-timeout') || 2000;
36+
let _defaultTxt = _trigger.innerText;
37+
let textTarget = document.querySelector(`[wt-copycb-element="textTarget${index}"]`);
38+
39+
UpdateTriggerDisplay(copiedTxt, textTarget, _trigger, activeClass);
40+
41+
setTimeout(() => {
42+
UpdateTriggerDisplay(_defaultTxt, textTarget, _trigger, activeClass);
43+
}, timeOut);
44+
45+
navigator.clipboard.writeText(textToCopy);
46+
});
47+
}
48+
}
49+
}
50+
51+
window.addEventListener('DOMContentLoaded', SetCopyToClipboard());

Dist/Functional/HideContainer.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const SetHideContainers = () => {
4+
let containers = document.querySelectorAll('[wt-hidecontainer-element^="container-"], [wt-hidecontainer-element="container"]');
5+
let err = [];
6+
let valid = true;
7+
8+
if(!containers || containers.length === 0) {
9+
err.push(`%cThere are no containers in this page.`);
10+
valid = false;
11+
}
12+
13+
if (!valid) {
14+
console.log("%cThanks for using Webflow Trickery","color: blue; font-size: 18px; padding: 8px; font-weight:500");
15+
console.log("%cIt seems like you're missing an element that is required for the integration.","color: red; font-size: 12px; padding: 8px; font-weight:500");
16+
for(let e of err){
17+
console.log(e,"color: red; font-size: 12px; padding: 8px; font-weight:500")
18+
}
19+
return;
20+
}
21+
22+
for(let _container of containers) {
23+
let _cmsList = _container.querySelector('[wt-hidecontainer-element="list"]');
24+
let _r = _container.getAttribute('wt-hidecontainer-remove');
25+
if(!_cmsList) return;
26+
if(_cmsList.classList.contains("w-dyn-empty")) {
27+
if(_r) {
28+
_container.remove();
29+
}
30+
else{
31+
_container.style.display = 'none';
32+
}
33+
}
34+
}
35+
}
36+
37+
window.addEventListener('DOMContentLoaded', SetHideContainers());

Dist/Functional/LimitText.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
3+
const LimitText = () => {
4+
let _fullText = document.querySelectorAll('[wt-limittext-element="text"]');
5+
6+
if(!_fullText || _fullText.length === 0) return;
7+
8+
for (text of _fullText) {
9+
let suffix = text.getAttribute("wt-limittext-suffix") || null;
10+
let textLength = text.getAttribute("wt-limittext-length") || 300 ;
11+
let description = text.innerText;
12+
if (description.length > textLength) {
13+
var _substr = `${description.substring(0, textLength)} ${ suffix ? suffix : "..."}`;
14+
text.innerText = _substr;
15+
}
16+
}
17+
}
18+
19+
window.addEventListener('DOMContentLoaded', LimitText());

Dist/Functional/ReadTime.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict'
2+
3+
const SetReadTime = () => {
4+
const timeDisplays = document.querySelectorAll('[wt-readtime-element="display"]');
5+
const container = document.querySelector('[wt-readtime-element="article"]');
6+
7+
let valid = true;
8+
let err = []
9+
10+
if(!timeDisplays || timeDisplays.length === 0) {
11+
err.push(`%c display element is missing`);
12+
valid = false;
13+
}
14+
if(!container){
15+
err.push(`%c article element is missing`);
16+
valid = false;
17+
}
18+
19+
if (!valid) {
20+
console.log("%cThanks for using Webflow Trickery","color: blue; font-size: 18px; padding: 8px; font-weight:500");
21+
console.log("%cIt seems like you're missing an element that is required for the integration.","color: red; font-size: 12px; padding: 8px; font-weight:500");
22+
for(let e of err){
23+
console.log(e,"color: red; font-size: 12px; padding: 8px; font-weight:500")
24+
}
25+
return;
26+
}
27+
28+
const text = container.innerText;
29+
const words = text.trim().split(/\s+/).length;
30+
const wpm = container.getAttribute("wt-readtime-words") || 225;
31+
const suffix = container.getAttribute('wt-readtime-suffix');
32+
const smallsuffix = container.getAttribute('wt-readtime-smallsuffix');
33+
const rawTime = words / wpm;
34+
35+
for(let display of timeDisplays) {
36+
if(rawTime < 1 ) {
37+
display.innerText = smallsuffix ? smallsuffix : "less than a minute.";
38+
}
39+
else if(rawTime == 1 ) {
40+
display.innerText = "a minute.";
41+
}
42+
else {
43+
display.innerText = suffix ? `${Math.ceil(rawTime)} ${suffix}` : `${Math.ceil(rawTime)} minutes.`;
44+
}
45+
}
46+
}
47+
48+
window.addEventListener('DOMContentLoaded', SetReadTime());

Dist/Functional/ShareLink.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict'
2+
3+
const CheckNodelist = (arr) => {
4+
return (arr && arr.length !== 0);
5+
}
6+
7+
const SetLinks = (_arr, link) => {
8+
for(let elem of _arr) {
9+
elem.setAttribute("href", link );
10+
elem.setAttribute("target", '_blank');
11+
}
12+
}
13+
14+
const SetShareLinks = () => {
15+
let title = document.title;
16+
let url = window.location.href;
17+
let unencodedURI = `${url}&title='${title}'&description='${title}'`;
18+
let encoded = encodeURI(unencodedURI);
19+
20+
let social_fb = document.querySelectorAll('[wt-share-element="facebook"]');
21+
let social_tw = document.querySelectorAll('[wt-share-element="twitter"]');
22+
let social_ln = document.querySelectorAll('[wt-share-element="linkedin"]');
23+
let social_wp = document.querySelectorAll('[wt-share-element="whatsapp"]');
24+
let social_pi = document.querySelectorAll('[wt-share-element="pinterest"]');
25+
let social_red = document.querySelectorAll('[wt-share-element="reddit"]');
26+
let social_cp = document.querySelectorAll('[wt-share-element="copy"]');
27+
28+
if (CheckNodelist(social_fb)) {
29+
SetLinks(social_fb,`https://www.facebook.com/sharer/sharer.php?u=${encoded}`);
30+
}
31+
if (CheckNodelist(social_tw)) {
32+
SetLinks(social_tw,`https://twitter.com/share?url=${encoded}`);
33+
}
34+
if (CheckNodelist(social_ln)) {
35+
SetLinks(social_ln,`https://www.linkedin.com/shareArticle?mini=true&url='${encoded}`);
36+
}
37+
if (CheckNodelist(social_wp)) {
38+
SetLinks(social_wp,`https://wa.me/?text=${encoded}`);
39+
}
40+
if (CheckNodelist(social_pi)) {
41+
SetLinks(social_pi,`http://pinterest.com/pin/create/button/?url=${encoded}`);
42+
}
43+
if (CheckNodelist(social_red)) {
44+
SetLinks(social_red,`http://www.reddit.com/submit?url=${encoded}`);
45+
}
46+
if (CheckNodelist(social_cp)) {
47+
for(let btn of social_cp) {
48+
btn.addEventListener('click', () => navigator.clipboard.writeText(`${url}`));
49+
}
50+
}
51+
}
52+
53+
window.addEventListener('DOMContentLoaded', SetShareLinks());

Dist/Functional/TabsSlider.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*!
2+
* Webflow Utilities v1.2.0
3+
* Have you ever tried fixing the same small thing over and over again on your webflow projects?
4+
* Well I have so I made a small compillation of the different fixes, utilities and tricks that will
5+
* not only make my life easier in the future but hopefuly yours as well.
6+
* (c) 2023 Jorge Cortez
7+
* MIT License
8+
* https://github.com/JorchCortez/Weblfow-Trickery
9+
*
10+
* This code is a sligtly modified version of the Auto Rotate Webflow Tabs by Flowbase.co (v1.4 Updated 10/04/2023)
11+
* fixed for reusability in any project using attributes instead of classes, feel free to check it out and if needs any update
12+
* you can open an issue in github.
13+
*
14+
* Webflow only function
15+
*
16+
*/
17+
18+
var Webflow = Webflow || [];
19+
Webflow.push(function () {
20+
//Allow site to load in case there's any extra integrations that require it
21+
setTimeout(function () {
22+
23+
let tabsComponent = document.querySelectorAll("[wt-tabSlider-element='tabs']");
24+
25+
if (tabsComponent) {
26+
tabsComponent.forEach(tabs => {
27+
28+
let timeout = tabs.getAttribute("wt-tabSlider-speed") || 5000;
29+
let tabBtns = tabs.querySelector("[wt-tabSlider-element='menu']");
30+
var tb = Array.from(tabBtns.children);
31+
32+
const tabLoop = (tm, timeout) => {
33+
tabTimeout = setTimeout(setTabTimeout, timeout, tm); // 5 Second Rotation
34+
}
35+
36+
const setTabTimeout = (tm) => {
37+
var $next = tm.querySelector(".w--current").nextElementSibling;
38+
if ($next) {
39+
$next.click(); // user click resets timeout
40+
} else {
41+
tm.firstChild.click();
42+
}
43+
}
44+
45+
// Fix for Safari
46+
if (navigator.userAgent.includes("Safari")) {
47+
tb.forEach((t) => (t.focus = function () {
48+
const x = window.scrollX, y = window.scrollY;const f = () => {
49+
setTimeout(() => window.scrollTo(x, y), 1);
50+
t.removeEventListener("focus", f)};
51+
t.addEventListener("focus", f);
52+
HTMLElement.prototype.focus.apply(this, arguments)
53+
})
54+
);
55+
}
56+
57+
// Reset Loops
58+
tb.forEach(tBtn => {
59+
tBtn.addEventListener('click', function (e) {
60+
e.preventDefault();
61+
clearTimeout(tabTimeout);
62+
tabLoop(tabBtns, timeout);
63+
}, false);
64+
})
65+
66+
// Start Tabs
67+
var tabTimeout;
68+
clearTimeout(tabTimeout);
69+
tabLoop(tabBtns, timeout);
70+
})
71+
}
72+
}, 500)
73+
});

0 commit comments

Comments
 (0)