Last active
March 4, 2016 02:51
-
-
Save asvny/c4be342fbb56b9c47972 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const code = `clicking on ".container" add class "active" on it`; | |
// | |
const compose = (...funcs) => value => funcs.reduceRight((a, b) => b(a), value); | |
const flatten = (arr) => { return Array.isArray(arr) ? [].concat.apply([], arr) : [arr] }; | |
const findBlocks = () => { | |
let codeBlocks = [...document.querySelectorAll('code')]; | |
// return codeBlocks.map(codeBlock => codeBlock.textContent.trim()) | |
return codeBlocks.map(codeBlock => code.trim()).join() | |
} | |
const textParser = (codeContents) => { | |
let delimiter = 'clicking on '; | |
return codeContents.split(delimiter).map(content => | |
content.split(' ') | |
).slice(1); | |
}; | |
const domEvents = (tokens) => { | |
let callback = (target,classie,behavior) => (event) => { | |
let classToggle = (el) => el.classList[behavior](classie); | |
['target','itself','self','it','this'].includes(target) ? | |
classToggle(event.currentTarget) : | |
0// [...document.querySelectorAll(target)].forEach(classToggle) | |
} | |
for(let [el,behavior,,classie,,target] of (tokens)) { | |
console.log(el,behavior,classie,target); | |
document.querySelectorAll(el.replace(/"/g,'')).forEach(elem=>{ | |
console.log(elem) | |
elem.tagName && elem.addEventListener('click',callback(target,classie,behavior)) | |
}) | |
} | |
} | |
let uilang = compose( | |
domEvents, | |
textParser, | |
findBlocks | |
); | |
uilang(''); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment