@pushword/js-helper 0.0.75 → 0.0.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +10 -10
- package/package.json~ +49 -0
- package/src/app.js +2 -0
- package/src/encore.js +1 -1
- package/src/helpers.js +103 -83
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pushword/js-helper",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.78",
|
|
4
4
|
"description": "Pushword front end helpers. ",
|
|
5
5
|
"author": "Robin@PiedWeb <contact@piedweb.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,29 +8,29 @@
|
|
|
8
8
|
"prettier": "prettier ./src/*.{js,scss} --write"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"
|
|
12
|
-
"@
|
|
13
|
-
"@tailwindcss/
|
|
11
|
+
"140.css": "^1.0.1",
|
|
12
|
+
"@symfony/webpack-encore": "^1.7",
|
|
13
|
+
"@tailwindcss/aspect-ratio": "^0.2",
|
|
14
|
+
"@tailwindcss/forms": "^0.4",
|
|
14
15
|
"@tailwindcss/line-clamp": "^0.4",
|
|
15
16
|
"@tailwindcss/typography": "^0.5",
|
|
16
17
|
"ace-builds": "^1.4.12",
|
|
17
18
|
"autoprefixer": "^10.1.0",
|
|
19
|
+
"babel-preset-stage-2": "^6.24.1",
|
|
18
20
|
"codemirror": "^5.59.0",
|
|
19
21
|
"core-js": "^3.8.1",
|
|
20
22
|
"easymde": "^2.13.0",
|
|
21
|
-
"file-loader": "^6.
|
|
23
|
+
"file-loader": "^6.0",
|
|
22
24
|
"fslightbox": "^3.2.2",
|
|
25
|
+
"node-sass": "^5.0.0",
|
|
23
26
|
"postcss": "^8.2.1",
|
|
24
27
|
"postcss-import": "^14.0.0",
|
|
25
|
-
"postcss-loader": "^
|
|
26
|
-
"sass-
|
|
27
|
-
"sass-loader": "^13.0.0",
|
|
28
|
+
"postcss-loader": "^4.1",
|
|
29
|
+
"sass-loader": "^10.1.0",
|
|
28
30
|
"simple-jekyll-search": "^1.9.1",
|
|
29
31
|
"tailwindcss": "^3",
|
|
30
32
|
"tailwindcss-hero-patterns": "^0.0.1",
|
|
31
33
|
"tailwindcss-multi-column": "^1.0.2",
|
|
32
|
-
"webpack": "^5.65",
|
|
33
|
-
"webpack-cli": "^4.9",
|
|
34
34
|
"webpack-watch-files-plugin": "^1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"repository": {
|
package/package.json~
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
## UPGRADE WEBPACK ##
|
|
2
|
+
{
|
|
3
|
+
"name": "@pushword/js-helper",
|
|
4
|
+
"version": "0.0.76",
|
|
5
|
+
"description": "Pushword front end helpers. ",
|
|
6
|
+
"author": "Robin@PiedWeb <contact@piedweb.com>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"prettier": "prettier ./src/*.{js,scss} --write"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@symfony/webpack-encore": "^3",
|
|
13
|
+
"@tailwindcss/aspect-ratio": "^0.4",
|
|
14
|
+
"@tailwindcss/forms": "^0.5",
|
|
15
|
+
"@tailwindcss/line-clamp": "^0.4",
|
|
16
|
+
"@tailwindcss/typography": "^0.5",
|
|
17
|
+
"ace-builds": "^1.4.12",
|
|
18
|
+
"autoprefixer": "^10.1.0",
|
|
19
|
+
"codemirror": "^5.59.0",
|
|
20
|
+
"core-js": "^3.8.1",
|
|
21
|
+
"easymde": "^2.13.0",
|
|
22
|
+
"file-loader": "^6.2.0",
|
|
23
|
+
"fslightbox": "^3.2.2",
|
|
24
|
+
"postcss": "^8.2.1",
|
|
25
|
+
"postcss-import": "^14.0.0",
|
|
26
|
+
"postcss-loader": "^7",
|
|
27
|
+
"sass-embedded": "^1.54.4",
|
|
28
|
+
"sass-loader": "^13.0.0",
|
|
29
|
+
"simple-jekyll-search": "^1.9.1",
|
|
30
|
+
"tailwindcss": "^3",
|
|
31
|
+
"tailwindcss-hero-patterns": "^0.0.1",
|
|
32
|
+
"tailwindcss-multi-column": "^1.0.2",
|
|
33
|
+
"webpack": "^5.65",
|
|
34
|
+
"webpack-cli": "^4.9",
|
|
35
|
+
"webpack-watch-files-plugin": "^1.1.0"
|
|
36
|
+
},
|
|
37
|
+
"repository": {
|
|
38
|
+
"type": "git",
|
|
39
|
+
"url": "git+https://github.com/Pushword/js-helper.git"
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"native"
|
|
43
|
+
],
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/Pushword/Pushword/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://pushword.piedweb.com",
|
|
48
|
+
"gitHead": "242ec54483dca1be93d7a62d8d554c9c08008c28"
|
|
49
|
+
}
|
package/src/app.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require('fslightbox');
|
|
2
2
|
import {
|
|
3
3
|
uncloakLinks,
|
|
4
|
+
addClassForNormalUser,
|
|
4
5
|
readableEmail,
|
|
5
6
|
convertImageLinkToWebPLink,
|
|
6
7
|
replaceOn,
|
|
@@ -16,6 +17,7 @@ function onDomChanged() {
|
|
|
16
17
|
replaceOn();
|
|
17
18
|
refreshFsLightbox();
|
|
18
19
|
allClickable('.clickable');
|
|
20
|
+
addClassForNormalUser();
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
function onPageLoaded() {
|
package/src/encore.js
CHANGED
|
@@ -66,7 +66,7 @@ module.exports = {
|
|
|
66
66
|
outputPath = outputPath ? outputPath : './../public/assets/';
|
|
67
67
|
publicPath = publicPath ? publicPath : '/assets';
|
|
68
68
|
|
|
69
|
-
Encore.configureRuntimeEnvironment('dev');
|
|
69
|
+
//Encore.configureRuntimeEnvironment('dev');
|
|
70
70
|
|
|
71
71
|
Encore.setOutputPath(outputPath)
|
|
72
72
|
.setPublicPath(publicPath)
|
package/src/helpers.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import 'core-js/stable';
|
|
2
|
+
import 'regenerator-runtime/runtime';
|
|
3
3
|
/**
|
|
4
4
|
* List of all functions
|
|
5
5
|
*
|
|
@@ -21,19 +21,19 @@ import "regenerator-runtime/runtime";
|
|
|
21
21
|
*
|
|
22
22
|
* @param {string} attribute
|
|
23
23
|
*/
|
|
24
|
-
export function liveBlock(liveBlockAttribute =
|
|
24
|
+
export function liveBlock(liveBlockAttribute = 'data-live', liveFormSelector = '.live-form') {
|
|
25
25
|
var btnToBlock = function (event, btn) {
|
|
26
|
-
btn.setAttribute(liveBlockAttribute, btn.getAttribute(
|
|
26
|
+
btn.setAttribute(liveBlockAttribute, btn.getAttribute('src-' + liveBlockAttribute));
|
|
27
27
|
getLiveBlock(btn);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
var getLiveBlock = function (item) {
|
|
31
31
|
var url = item.getAttribute(liveBlockAttribute);
|
|
32
|
-
url = url.startsWith(
|
|
32
|
+
url = url.startsWith('e:') ? convertShortchutForLink(rot13ToText(url.substring(2))) : url;
|
|
33
33
|
fetch(url, {
|
|
34
34
|
//headers: { "Content-Type": "application/json", Accept: "text/plain" },
|
|
35
|
-
method:
|
|
36
|
-
credentials:
|
|
35
|
+
method: 'POST',
|
|
36
|
+
credentials: 'include',
|
|
37
37
|
})
|
|
38
38
|
.then(function (response) {
|
|
39
39
|
return response.text();
|
|
@@ -43,19 +43,19 @@ export function liveBlock(liveBlockAttribute = "data-live", liveFormSelector = "
|
|
|
43
43
|
item.outerHTML = body;
|
|
44
44
|
})
|
|
45
45
|
.then(function () {
|
|
46
|
-
document.dispatchEvent(new Event(
|
|
46
|
+
document.dispatchEvent(new Event('DOMChanged'));
|
|
47
47
|
});
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
const spinner =
|
|
51
51
|
'<span style="border-top-color: transparent" class="inline-block w-5 h-5 border-4 border-gray-50 border-solid rounded-full animate-spin"></span>';
|
|
52
|
-
const htmlLoader =
|
|
52
|
+
const htmlLoader = '<div>' + spinner.replace('border-gray-50', 'border-gray-800') + '</div>';
|
|
53
53
|
|
|
54
54
|
var setLoader = function (form) {
|
|
55
55
|
var $submitButton = getSubmitButton(form);
|
|
56
56
|
if ($submitButton !== undefined) {
|
|
57
57
|
//var initialButton = $submitButton.outerHTML;
|
|
58
|
-
$submitButton.innerHTML =
|
|
58
|
+
$submitButton.innerHTML = '';
|
|
59
59
|
$submitButton.outerHTML = htmlLoader;
|
|
60
60
|
}
|
|
61
61
|
};
|
|
@@ -65,9 +65,9 @@ export function liveBlock(liveBlockAttribute = "data-live", liveFormSelector = "
|
|
|
65
65
|
|
|
66
66
|
var formData = new FormData(form.srcElement);
|
|
67
67
|
fetch(form.srcElement.action, {
|
|
68
|
-
method:
|
|
68
|
+
method: 'POST',
|
|
69
69
|
body: formData,
|
|
70
|
-
credentials:
|
|
70
|
+
credentials: 'include',
|
|
71
71
|
})
|
|
72
72
|
.then(function (response) {
|
|
73
73
|
return response.text();
|
|
@@ -76,31 +76,31 @@ export function liveBlock(liveBlockAttribute = "data-live", liveFormSelector = "
|
|
|
76
76
|
liveFormBlock.outerHTML = body;
|
|
77
77
|
})
|
|
78
78
|
.then(function () {
|
|
79
|
-
document.dispatchEvent(new Event(
|
|
79
|
+
document.dispatchEvent(new Event('DOMChanged'));
|
|
80
80
|
});
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
var getSubmitButton = function (form) {
|
|
84
|
-
if (form.srcElement.querySelector(
|
|
85
|
-
return form.srcElement.querySelector(
|
|
84
|
+
if (form.srcElement.querySelector('[type=submit]') !== null) {
|
|
85
|
+
return form.srcElement.querySelector('[type=submit]');
|
|
86
86
|
}
|
|
87
|
-
if (form.srcElement.getElementsByTagName(
|
|
88
|
-
return form.srcElement.getElementsByTagName(
|
|
87
|
+
if (form.srcElement.getElementsByTagName('button') !== null) {
|
|
88
|
+
return form.srcElement.getElementsByTagName('button')[0];
|
|
89
89
|
}
|
|
90
90
|
return null;
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
// Listen data-live
|
|
94
|
-
document.querySelectorAll(
|
|
94
|
+
document.querySelectorAll('[' + liveBlockAttribute + ']').forEach((item) => {
|
|
95
95
|
getLiveBlock(item);
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
// Listen button src-data-live
|
|
99
|
-
document.querySelectorAll(
|
|
100
|
-
item.addEventListener(
|
|
101
|
-
if (item.tagName ==
|
|
99
|
+
document.querySelectorAll('[src-' + liveBlockAttribute + ']').forEach((item) => {
|
|
100
|
+
item.addEventListener('click', (event) => {
|
|
101
|
+
if (item.tagName == 'BUTTON') {
|
|
102
102
|
item.innerHTML = spinner;
|
|
103
|
-
item.setAttribute(
|
|
103
|
+
item.setAttribute('disabled', true);
|
|
104
104
|
}
|
|
105
105
|
btnToBlock(event, item);
|
|
106
106
|
});
|
|
@@ -108,8 +108,8 @@ export function liveBlock(liveBlockAttribute = "data-live", liveFormSelector = "
|
|
|
108
108
|
|
|
109
109
|
// Listen live-form
|
|
110
110
|
document.querySelectorAll(liveFormSelector).forEach((item) => {
|
|
111
|
-
if (item.querySelector(
|
|
112
|
-
item.querySelector(
|
|
111
|
+
if (item.querySelector('form') !== null) {
|
|
112
|
+
item.querySelector('form').addEventListener('submit', (e) => {
|
|
113
113
|
e.preventDefault();
|
|
114
114
|
sendForm(e, item);
|
|
115
115
|
});
|
|
@@ -121,33 +121,33 @@ export function liveBlock(liveBlockAttribute = "data-live", liveFormSelector = "
|
|
|
121
121
|
* Block to replace Watcher
|
|
122
122
|
* On $event on element find via $attribute, set attribute's content in element.innerHTML
|
|
123
123
|
*/
|
|
124
|
-
export function replaceOn(attribute =
|
|
124
|
+
export function replaceOn(attribute = 'replaceBy', eventName = 'click') {
|
|
125
125
|
var loadVideo = function (element) {
|
|
126
126
|
var content = element.getAttribute(attribute);
|
|
127
127
|
if (
|
|
128
|
-
element.classList.contains(
|
|
129
|
-
element.querySelector(
|
|
128
|
+
element.classList.contains('hero-banner-overlay-lg') &&
|
|
129
|
+
element.querySelector('picture') &&
|
|
130
130
|
window.innerWidth < 992
|
|
131
131
|
) {
|
|
132
|
-
element.querySelector(
|
|
133
|
-
element.querySelector(
|
|
132
|
+
element.querySelector('picture').outerHTML = content;
|
|
133
|
+
element.querySelector('.btn-play').outerHTML = ' ';
|
|
134
134
|
} else {
|
|
135
135
|
element.innerHTML = content;
|
|
136
136
|
}
|
|
137
|
-
if (element.classList.contains(
|
|
138
|
-
element.style.zIndex =
|
|
137
|
+
if (element.classList.contains('hero-banner-overlay-lg')) {
|
|
138
|
+
element.style.zIndex = '2000';
|
|
139
139
|
}
|
|
140
140
|
element.removeAttribute(attribute);
|
|
141
|
-
document.dispatchEvent(new Event(
|
|
141
|
+
document.dispatchEvent(new Event('DOMChanged'));
|
|
142
142
|
};
|
|
143
143
|
|
|
144
|
-
document.querySelectorAll(
|
|
145
|
-
element.setAttribute(
|
|
144
|
+
document.querySelectorAll('[' + attribute + ']:not([listen])').forEach(function (element) {
|
|
145
|
+
element.setAttribute('listen', '');
|
|
146
146
|
element.addEventListener(
|
|
147
147
|
eventName,
|
|
148
148
|
function (event) {
|
|
149
149
|
loadVideo(event.currentTarget); //event.currentTarget;
|
|
150
|
-
element.removeAttribute(
|
|
150
|
+
element.removeAttribute('listen');
|
|
151
151
|
},
|
|
152
152
|
{ once: true }
|
|
153
153
|
);
|
|
@@ -159,13 +159,13 @@ export function replaceOn(attribute = "replaceBy", eventName = "click") {
|
|
|
159
159
|
*
|
|
160
160
|
*/
|
|
161
161
|
export function seasonedBackground() {
|
|
162
|
-
document.querySelectorAll(
|
|
162
|
+
document.querySelectorAll('[x-hash]').forEach(function (element) {
|
|
163
163
|
if (window.location.hash) {
|
|
164
|
-
if (element.getAttribute(
|
|
165
|
-
element.parentNode.parentNode.querySelectorAll(
|
|
166
|
-
img.style =
|
|
164
|
+
if (element.getAttribute('x-hash') == window.location.hash.substring(1)) {
|
|
165
|
+
element.parentNode.parentNode.querySelectorAll('img').forEach(function (img) {
|
|
166
|
+
img.style = 'display:none';
|
|
167
167
|
});
|
|
168
|
-
element.style =
|
|
168
|
+
element.style = 'display:block';
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
});
|
|
@@ -179,54 +179,69 @@ export function seasonedBackground() {
|
|
|
179
179
|
export function responsiveImage(src) {
|
|
180
180
|
var screenWidth = window.innerWidth;
|
|
181
181
|
if (screenWidth <= 576) {
|
|
182
|
-
src = src.replace(
|
|
182
|
+
src = src.replace('/default/', '/xs/');
|
|
183
183
|
} else if (screenWidth <= 768) {
|
|
184
|
-
src = src.replace(
|
|
184
|
+
src = src.replace('/default/', '/sm/');
|
|
185
185
|
} else if (screenWidth <= 992) {
|
|
186
|
-
src = src.replace(
|
|
186
|
+
src = src.replace('/default/', '/md/');
|
|
187
187
|
} else if (screenWidth <= 1200) {
|
|
188
|
-
src = src.replace(
|
|
188
|
+
src = src.replace('/default/', '/lg/');
|
|
189
189
|
} else {
|
|
190
190
|
// 1200+
|
|
191
|
-
src = src.replace(
|
|
191
|
+
src = src.replace('/default/', '/xl/');
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
return src;
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
+
export function addClassForNormalUser(attribute = 'data-acinb') {
|
|
198
|
+
var startScrolling = 0;
|
|
199
|
+
document.addEventListener('scroll', function () {
|
|
200
|
+
if (startScrolling < 5) {
|
|
201
|
+
startScrolling++;
|
|
202
|
+
}
|
|
203
|
+
if (startScrolling === 4) {
|
|
204
|
+
[].forEach.call(document.querySelectorAll('[' + attribute + ']'), function (element) {
|
|
205
|
+
var classToAdd = element.getAttribute(attribute);
|
|
206
|
+
element.removeAttribute(attribute);
|
|
207
|
+
element.classList.add(' ' + classToAdd);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
}
|
|
197
212
|
/**
|
|
198
213
|
* Convert elements wich contain attribute (data-href) in normal link (a href)
|
|
199
214
|
* You can use a callback function to decrypt the link (eg: rot13ToText ;-))
|
|
200
215
|
*
|
|
201
216
|
* @param {string} attribute
|
|
202
217
|
*/
|
|
203
|
-
export async function uncloakLinks(attribute =
|
|
218
|
+
export async function uncloakLinks(attribute = 'data-rot', when = 'onEvent') {
|
|
204
219
|
var convertLink = function (element) {
|
|
205
220
|
// fix "bug" with img
|
|
206
221
|
if (element.getAttribute(attribute) === null) {
|
|
207
|
-
var element = element.closest(
|
|
222
|
+
var element = element.closest('[' + attribute + ']');
|
|
208
223
|
}
|
|
209
224
|
if (element === null || element.getAttribute(attribute) === null) return;
|
|
210
|
-
var link = document.createElement(
|
|
225
|
+
var link = document.createElement('a');
|
|
211
226
|
var href = element.getAttribute(attribute);
|
|
212
227
|
element.removeAttribute(attribute);
|
|
213
228
|
for (var i = 0, n = element.attributes.length; i < n; i++) {
|
|
214
229
|
link.setAttribute(element.attributes[i].nodeName, element.attributes[i].nodeValue);
|
|
215
230
|
}
|
|
216
231
|
link.innerHTML = element.innerHTML;
|
|
217
|
-
link.setAttribute(
|
|
232
|
+
link.setAttribute('href', responsiveImage(convertShortchutForLink(rot13ToText(href))));
|
|
218
233
|
element.parentNode.replaceChild(link, element);
|
|
219
234
|
return link;
|
|
220
235
|
};
|
|
221
236
|
|
|
222
237
|
var convertThemAll = function (attribute) {
|
|
223
|
-
[].forEach.call(document.querySelectorAll(
|
|
238
|
+
[].forEach.call(document.querySelectorAll('[' + attribute + ']'), function (element) {
|
|
224
239
|
convertLink(element);
|
|
225
240
|
});
|
|
226
241
|
};
|
|
227
242
|
|
|
228
243
|
var fireEventLinksBuilt = async function (element, event) {
|
|
229
|
-
await document.dispatchEvent(new Event(
|
|
244
|
+
await document.dispatchEvent(new Event('DOMChanged'));
|
|
230
245
|
|
|
231
246
|
var clickEvent = new Event(event.type);
|
|
232
247
|
element.dispatchEvent(clickEvent);
|
|
@@ -234,7 +249,7 @@ export async function uncloakLinks(attribute = "data-rot", when = "onEvent") {
|
|
|
234
249
|
|
|
235
250
|
var convertLinkOnEvent = async function (event) {
|
|
236
251
|
// convert them all if it's an image (thanks this bug), permit to use gallery (baguetteBox)
|
|
237
|
-
if (event.target.tagName ==
|
|
252
|
+
if (event.target.tagName == 'IMG') {
|
|
238
253
|
await convertThemAll(attribute);
|
|
239
254
|
var element = event.target;
|
|
240
255
|
} else {
|
|
@@ -243,24 +258,24 @@ export async function uncloakLinks(attribute = "data-rot", when = "onEvent") {
|
|
|
243
258
|
if (element) fireEventLinksBuilt(element, event);
|
|
244
259
|
};
|
|
245
260
|
|
|
246
|
-
if (when ==
|
|
247
|
-
[].forEach.call(document.querySelectorAll(
|
|
261
|
+
if (when == 'onEvent') {
|
|
262
|
+
[].forEach.call(document.querySelectorAll('[' + attribute + ']'), function (element) {
|
|
248
263
|
element.addEventListener(
|
|
249
|
-
|
|
264
|
+
'touchstart',
|
|
250
265
|
function (e) {
|
|
251
266
|
convertLinkOnEvent(e);
|
|
252
267
|
},
|
|
253
268
|
{ once: true, passive: true }
|
|
254
269
|
);
|
|
255
270
|
element.addEventListener(
|
|
256
|
-
|
|
271
|
+
'click',
|
|
257
272
|
function (e) {
|
|
258
273
|
convertLinkOnEvent(e);
|
|
259
274
|
},
|
|
260
275
|
{ once: true }
|
|
261
276
|
);
|
|
262
277
|
element.addEventListener(
|
|
263
|
-
|
|
278
|
+
'mouseover',
|
|
264
279
|
function (e) {
|
|
265
280
|
convertLinkOnEvent(e);
|
|
266
281
|
},
|
|
@@ -275,23 +290,23 @@ export async function uncloakLinks(attribute = "data-rot", when = "onEvent") {
|
|
|
275
290
|
*
|
|
276
291
|
* @param {string} attribute
|
|
277
292
|
*/
|
|
278
|
-
export function convertFormFromRot13(attribute =
|
|
279
|
-
[].forEach.call(document.querySelectorAll(
|
|
293
|
+
export function convertFormFromRot13(attribute = 'data-frot') {
|
|
294
|
+
[].forEach.call(document.querySelectorAll('[' + attribute + ']'), function (element) {
|
|
280
295
|
var action = element.getAttribute(attribute);
|
|
281
296
|
element.removeAttribute(attribute);
|
|
282
|
-
element.setAttribute(
|
|
297
|
+
element.setAttribute('action', convertShortchutForLink(rot13ToText(action)));
|
|
283
298
|
});
|
|
284
299
|
}
|
|
285
300
|
|
|
286
301
|
export function convertShortchutForLink(str) {
|
|
287
|
-
if (str.charAt(0) ==
|
|
288
|
-
return
|
|
302
|
+
if (str.charAt(0) == '-') {
|
|
303
|
+
return 'http://' + str.substring(1);
|
|
289
304
|
}
|
|
290
|
-
if (str.charAt(0) ==
|
|
291
|
-
return
|
|
305
|
+
if (str.charAt(0) == '_') {
|
|
306
|
+
return 'https://' + str.substring(1);
|
|
292
307
|
}
|
|
293
|
-
if (str.charAt(0) ==
|
|
294
|
-
return
|
|
308
|
+
if (str.charAt(0) == '@') {
|
|
309
|
+
return 'mailto:' + str.substring(1);
|
|
295
310
|
}
|
|
296
311
|
return str;
|
|
297
312
|
}
|
|
@@ -304,9 +319,9 @@ export function convertShortchutForLink(str) {
|
|
|
304
319
|
export function readableEmail(selector) {
|
|
305
320
|
document.querySelectorAll(selector).forEach(function (item) {
|
|
306
321
|
var mail = rot13ToText(item.textContent);
|
|
307
|
-
item.classList.remove(
|
|
308
|
-
item.innerHTML = '<a href="mailto:' + mail + '">' + mail +
|
|
309
|
-
if (selector.charAt(0) ==
|
|
322
|
+
item.classList.remove('hidden');
|
|
323
|
+
item.innerHTML = '<a href="mailto:' + mail + '">' + mail + '</a>';
|
|
324
|
+
if (selector.charAt(0) == '.') {
|
|
310
325
|
item.classList.remove(selector.substring(1));
|
|
311
326
|
}
|
|
312
327
|
});
|
|
@@ -319,15 +334,17 @@ export function readableEmail(selector) {
|
|
|
319
334
|
*/
|
|
320
335
|
export function rot13ToText(str) {
|
|
321
336
|
return str.replace(/[a-zA-Z]/g, function (c) {
|
|
322
|
-
return String.fromCharCode(
|
|
337
|
+
return String.fromCharCode(
|
|
338
|
+
(c <= 'Z' ? 90 : 122) >= (c = c.charCodeAt(0) + 13) ? c : c - 26
|
|
339
|
+
);
|
|
323
340
|
});
|
|
324
341
|
}
|
|
325
342
|
|
|
326
343
|
export function testWebPSupport() {
|
|
327
|
-
var elem = document.createElement(
|
|
344
|
+
var elem = document.createElement('canvas');
|
|
328
345
|
|
|
329
|
-
if (elem.getContext && elem.getContext(
|
|
330
|
-
return elem.toDataURL(
|
|
346
|
+
if (elem.getContext && elem.getContext('2d')) {
|
|
347
|
+
return elem.toDataURL('image/webp').indexOf('data:image/webp') == 0;
|
|
331
348
|
}
|
|
332
349
|
|
|
333
350
|
return false;
|
|
@@ -338,10 +355,10 @@ export function testWebPSupport() {
|
|
|
338
355
|
*/
|
|
339
356
|
export function convertImageLinkToWebPLink() {
|
|
340
357
|
var switchToWebP = function () {
|
|
341
|
-
[].forEach.call(document.querySelectorAll(
|
|
342
|
-
var href = responsiveImage(element.getAttribute(
|
|
343
|
-
element.setAttribute(
|
|
344
|
-
element.removeAttribute(
|
|
358
|
+
[].forEach.call(document.querySelectorAll('a[dwl]'), function (element) {
|
|
359
|
+
var href = responsiveImage(element.getAttribute('dwl'));
|
|
360
|
+
element.setAttribute('href', href);
|
|
361
|
+
element.removeAttribute('dwl');
|
|
345
362
|
});
|
|
346
363
|
};
|
|
347
364
|
|
|
@@ -364,18 +381,21 @@ export function convertImageLinkToWebPLink() {
|
|
|
364
381
|
*
|
|
365
382
|
* still used in piedvert. To remove ?!
|
|
366
383
|
*/
|
|
367
|
-
export function imgLazyLoad(attribute =
|
|
368
|
-
[].forEach.call(document.querySelectorAll(
|
|
369
|
-
var newDomImg = document.createElement(
|
|
384
|
+
export function imgLazyLoad(attribute = 'data-img') {
|
|
385
|
+
[].forEach.call(document.querySelectorAll('[' + attribute + ']'), function (img) {
|
|
386
|
+
var newDomImg = document.createElement('img');
|
|
370
387
|
var src = img.getAttribute(attribute);
|
|
371
388
|
img.removeAttribute(attribute);
|
|
372
389
|
for (var i = 0, n = img.attributes.length; i < n; i++) {
|
|
373
390
|
newDomImg.setAttribute(img.attributes[i].nodeName, img.attributes[i].nodeValue);
|
|
374
391
|
}
|
|
375
|
-
if (newDomImg.getAttribute(
|
|
376
|
-
newDomImg.setAttribute(
|
|
392
|
+
if (newDomImg.getAttribute('alt') === null && img.textContent != '') {
|
|
393
|
+
newDomImg.setAttribute('alt', img.textContent);
|
|
377
394
|
}
|
|
378
|
-
newDomImg.setAttribute(
|
|
395
|
+
newDomImg.setAttribute(
|
|
396
|
+
'src',
|
|
397
|
+
typeof responsiveImage === 'function' ? responsiveImage(src) : src
|
|
398
|
+
);
|
|
379
399
|
img.outerHTML = newDomImg.outerHTML;
|
|
380
400
|
});
|
|
381
401
|
}
|