Skip to content

Instantly share code, notes, and snippets.

@kvnol
Created December 4, 2018 18:05
Show Gist options
  • Save kvnol/05b0fa0ea2c2311821112e5475a47573 to your computer and use it in GitHub Desktop.
Save kvnol/05b0fa0ea2c2311821112e5475a47573 to your computer and use it in GitHub Desktop.
// BEM.min.js v1.0.2
function BEM(element,patchBEM){if(element==undefined){element=$('[bem]')};if(patchBEM==undefined){patchBEM=getPatchBEM(element)};element.each(function(){if(typeof $(this).attr('bem')!='undefined'){patchBEM=getPatchBEM($(this));$(this).removeAttr('bem')};let thisChildrens=$(this).children();thisChildrens.each(function(){let thisClass=$(this).attr('class');if(typeof thisClass!='undefined'){if(!!thisClass.match(/^__/)){let thisBEMName='';for(i=0;i<thisClass.length;i++){thisLetter=thisClass[i];if(!thisLetter.match(/\s/)){thisBEMName+=thisLetter}else{break}};$(this).attr('class',thisClass.replace(thisBEMName,patchBEM+thisBEMName));let newPatchBEM=patchBEM+thisBEMName;BEM($(this),newPatchBEM);return!0}};BEM($(this),patchBEM)})})};function getPatchBEM(element){let thisClass=element.attr('class');let thisBEMName='';for(i=0;i<thisClass.length;i++){thisLetter=thisClass[i];if(!!!thisLetter.match(/\s/)){thisBEMName+=thisLetter}else{break}};patchBEM=thisBEMName;return patchBEM}
@luizbills
Copy link

Ajuda nós ae kkkk

// BEM.min.js v1.0.2
function BEM(element, patchBEM) {
    if (element == undefined) {
        element = $('[bem]')
    };
    if (patchBEM == undefined) {
        patchBEM = getPatchBEM(element)
    };
    element.each(function() {
        if (typeof $(this).attr('bem') != 'undefined') {
            patchBEM = getPatchBEM($(this));
            $(this).removeAttr('bem')
        };
        let thisChildrens = $(this).children();
        thisChildrens.each(function() {
            let thisClass = $(this).attr('class');
            if (typeof thisClass != 'undefined') {
                if (!!thisClass.match(/^__/)) {
                    let thisBEMName = '';
                    for (i = 0; i < thisClass.length; i++) {
                        thisLetter = thisClass[i];
                        if (!thisLetter.match(/\s/)) {
                            thisBEMName += thisLetter
                        } else {
                            break
                        }
                    };
                    $(this).attr('class', thisClass.replace(thisBEMName, patchBEM + thisBEMName));
                    let newPatchBEM = patchBEM + thisBEMName;
                    BEM($(this), newPatchBEM);
                    return !0
                }
            };
            BEM($(this), patchBEM)
        })
    })
};

function getPatchBEM(element) {
    let thisClass = element.attr('class');
    let thisBEMName = '';
    for (i = 0; i < thisClass.length; i++) {
        thisLetter = thisClass[i];
        if (!!!thisLetter.match(/\s/)) {
            thisBEMName += thisLetter
        } else {
            break
        }
    };
    patchBEM = thisBEMName;
    return patchBEM
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment