Fix dash
This commit is contained in:
parent
91338f9185
commit
4b01ca94bb
@ -34,7 +34,7 @@ Simple utility to **avoid writing Javascript** when working with **classes**. It
|
||||
Add to your `<head>` the following tag.
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.2.1/dist/ffnm.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.2.2/dist/ffnm.min.js"></script>
|
||||
```
|
||||
|
||||
### Examples
|
||||
@ -145,7 +145,7 @@ Add to your `<head>` the following tag.
|
||||
Añade a tu `<head>` la siguiente etiqueta.
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.2.1/dist/ffnm.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/tanrax/FFNM@v1.2.2/dist/ffnm.min.js"></script>
|
||||
```
|
||||
|
||||
### Ejemplos de uso
|
||||
|
2
dist/ffnm.min.js
vendored
2
dist/ffnm.min.js
vendored
@ -1,2 +1,2 @@
|
||||
document.addEventListener("DOMContentLoaded",()=>{const e={class:["add","remove","toggle"]};let t=[],c=void 0;function s(e,t){let c=e.getAttribute(t),s=RegExp("^(\\w+):").exec(c)[1],l=RegExp(":(\\w+)\\(").exec(c)[1],a=RegExp("\\('(\\w+)',?").exec(c)[1],o=RegExp(", *'([#,.,a-zA-Z]\\w*)'\\)");return{functionParent:s,functionChild:l,value:a,target:null!==o.exec(c)?o.exec(c)[1]:void 0}}t=[],["i-click","i-scroll-up","i-scroll-down","i-hover"].map(c=>[...document.querySelectorAll(`[${c}]`)].map(s=>{let l=Object.keys(e).map(t=>e[t].map(e=>RegExp(`^${t}:${e}\\('.+'(, *'[.#i\\w][_-\\w0-9]+')?\\)$`).test(s.getAttribute(c))).some(e=>e)).every(e=>e);return l?t.push(s):(console.error("FFNM: Bad syntax"),console.error(s)),l}).every(e=>e)).every(e=>e),[...document.querySelectorAll("[i-click]")].forEach(e=>{let t=s(e,"i-click");switch(t.functionParent){case"class":[...document.querySelectorAll(t.target)].concat(e).forEach(c=>{e.addEventListener("click",()=>{switch(t.functionChild){case"add":c.classList.add(t.value);break;case"remove":c.classList.remove(t.value);break;case"toggle":c.classList.toggle(t.value)}})})}}),window.addEventListener("scroll",()=>{let e=window.pageYOffset||document.documentElement.scrollTop;[...document.querySelectorAll("[i-scroll-down]")].forEach(t=>{if(e>c){let e=s(t,"i-scroll-down");switch(e.functionParent){case"class":switch(e.functionChild){case"add":t.classList.add(e.value);break;case"remove":t.classList.remove(e.value)}}}}),[...document.querySelectorAll("[i-scroll-up]")].forEach(t=>{if(e<=c){let e=s(t,"i-scroll-up");switch(e.functionParent){case"class":switch(e.functionChild){case"add":t.classList.add(e.value);break;case"remove":t.classList.remove(e.value)}}}}),c=e<=0?0:e},!1),[...document.querySelectorAll("[i-hover]")].forEach(e=>{let t=s(e,"i-hover");switch(t.functionParent){case"class":[...document.querySelectorAll(t.target)].concat(e).forEach(c=>{switch(t.functionChild){case"add":e.addEventListener("mouseenter",()=>{c.classList.add(t.value)}),e.addEventListener("mouseout",()=>{c.classList.remove(t.value)});break;case"remove":e.addEventListener("mouseenter",()=>{c.classList.remove(t.value)}),e.addEventListener("mouseout",()=>{c.classList.add(t.value)});break;case"toggle":e.addEventListener("mouseenter",()=>{c.classList.toggle(t.value)}),e.addEventListener("mouseout",()=>{c.classList.toggle(t.value)})}})}})});
|
||||
document.addEventListener("DOMContentLoaded",()=>{const e={class:["add","remove","toggle"]};let t=[],c=void 0;function s(e,t){let c=e.getAttribute(t),s=RegExp("^(\\w+):").exec(c)[1],a=RegExp(":(\\w+)\\(").exec(c)[1],l=RegExp("\\('(\\w[_-\\w0-9]+)',?").exec(c)[1],o=RegExp(", ?'([.#i\\w][_-\\w0-9]+)'\\)");return{functionParent:s,functionChild:a,value:l,target:null!==o.exec(c)?o.exec(c)[1]:void 0}}t=[],["i-click","i-scroll-up","i-scroll-down","i-hover"].map(c=>[...document.querySelectorAll(`[${c}]`)].map(s=>{let a=Object.keys(e).map(t=>e[t].map(e=>RegExp(`^${t}:${e}\\('.+'(, ?'[.#i\\w][_-\\w0-9]+')?\\)$`).test(s.getAttribute(c))).some(e=>e)).every(e=>e);return a?t.push(s):(console.error("FFNM: Bad syntax"),console.error(s)),a}).every(e=>e)).every(e=>e),[...document.querySelectorAll("[i-click]")].forEach(e=>{let t=s(e,"i-click");switch(t.functionParent){case"class":[...document.querySelectorAll(t.target)].concat(void 0===t.target?e:void 0).forEach(c=>{void 0!==c&&e.addEventListener("click",()=>{switch(t.functionChild){case"add":c.classList.add(t.value);break;case"remove":c.classList.remove(t.value);break;case"toggle":c.classList.toggle(t.value)}})})}}),window.addEventListener("scroll",()=>{let e=window.pageYOffset||document.documentElement.scrollTop;[...document.querySelectorAll("[i-scroll-down]")].forEach(t=>{if(e>c){let e=s(t,"i-scroll-down");switch(e.functionParent){case"class":switch(e.functionChild){case"add":t.classList.add(e.value);break;case"remove":t.classList.remove(e.value)}}}}),[...document.querySelectorAll("[i-scroll-up]")].forEach(t=>{if(e<=c){let e=s(t,"i-scroll-up");switch(e.functionParent){case"class":switch(e.functionChild){case"add":t.classList.add(e.value);break;case"remove":t.classList.remove(e.value)}}}}),c=e<=0?0:e},!1),[...document.querySelectorAll("[i-hover]")].forEach(e=>{let t=s(e,"i-hover");switch(t.functionParent){case"class":[...document.querySelectorAll(t.target)].concat(void 0===t.target?e:void 0).forEach(c=>{if(void 0!==c)switch(t.functionChild){case"add":e.addEventListener("mouseenter",()=>{c.classList.add(t.value)}),e.addEventListener("mouseout",()=>{c.classList.remove(t.value)});break;case"remove":e.addEventListener("mouseenter",()=>{c.classList.remove(t.value)}),e.addEventListener("mouseout",()=>{c.classList.add(t.value)});break;case"toggle":e.addEventListener("mouseenter",()=>{c.classList.toggle(t.value)}),e.addEventListener("mouseout",()=>{c.classList.toggle(t.value)})}})}})});
|
||||
//# sourceMappingURL=ffnm.min.js.map
|
||||
|
18
src/core.js
18
src/core.js
@ -28,7 +28,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let checked = Object.keys(FUNCTION_TREE).map((key) => {
|
||||
// Check METHODS FUNCTION_TREE
|
||||
return FUNCTION_TREE[key].map((method) => {
|
||||
return RegExp(`^${key}:${method}\\('.+'(, *'[.#i\\w][_-\\w0-9]+')?\\)$`).test(element.getAttribute(event));
|
||||
return RegExp(`^${key}:${method}\\('.+'(, ?'[.#i\\w][_-\\w0-9]+')?\\)$`).test(element.getAttribute(event));
|
||||
}).some(method => method);
|
||||
}).every(key => key);
|
||||
if(checked) {
|
||||
@ -52,10 +52,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
*/
|
||||
function splitParams(element, attribute) {
|
||||
let params = element.getAttribute(attribute);
|
||||
let functionParent = RegExp(`^(\\w+):`).exec(params)[1];
|
||||
let functionChild = RegExp(`:(\\w+)\\(`).exec(params)[1];
|
||||
let value = RegExp(`\\(\'(\\w+)\',?`).exec(params)[1];
|
||||
let resultTarget = RegExp(`, *\'([#,.,a-zA-Z]\\w*)\'\\)`);
|
||||
let functionParent = RegExp("^(\\w+):").exec(params)[1];
|
||||
let functionChild = RegExp(":(\\w+)\\(").exec(params)[1];
|
||||
let value = RegExp("\\(\'(\\w[_-\\w0-9]+)\',?").exec(params)[1];
|
||||
let resultTarget = RegExp(", ?\'([.#i\\w][_-\\w0-9]+)\'\\)");
|
||||
let target = resultTarget.exec(params) !== null ? resultTarget.exec(params)[1] : undefined;
|
||||
return {'functionParent': functionParent, 'functionChild': functionChild, 'value': value, 'target': target};
|
||||
}
|
||||
@ -70,7 +70,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let params = splitParams(element, eventClick);
|
||||
switch(params.functionParent) {
|
||||
case 'class':
|
||||
[...document.querySelectorAll(params.target)].concat(element).forEach((item) => {
|
||||
[...document.querySelectorAll(params.target)].concat(params.target === undefined ? element : undefined).forEach((item) => {
|
||||
if (item !== undefined) {
|
||||
element.addEventListener('click', () => {
|
||||
switch(params.functionChild) {
|
||||
case 'add':
|
||||
@ -84,6 +85,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
@ -150,7 +152,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
let params = splitParams(element, eventHover);
|
||||
switch(params.functionParent) {
|
||||
case 'class':
|
||||
[...document.querySelectorAll(params.target)].concat(element).forEach((item) => {
|
||||
[...document.querySelectorAll(params.target)].concat(params.target === undefined ? element : undefined).forEach((item) => {
|
||||
if (item !== undefined) {
|
||||
// Enter
|
||||
switch(params.functionChild) {
|
||||
case 'add':
|
||||
@ -184,6 +187,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p i-hover="class:add('uppercase', '.text__-hover')">Place the cursor over this text</p>
|
||||
<p i-hover="class:add('uppercase', '.text__1--hover')">Place the cursor over this text</p>
|
||||
<p class="text__1--hover">
|
||||
Quisque id diam vel quam elementum pulvinar etiam non quam?
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue
Block a user