Last active
April 18, 2016 14:56
-
-
Save DragorWW/a338040fac03b1cb4984bda7e50e031e to your computer and use it in GitHub Desktop.
vegetarianFilter - вегетарианский фильтр для меню на сайтах доставки
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
| /** | |
| * Фильтрация карточек суши на предмет не вегетарианской ингредиентов. | |
| * Фильтр скрывает все itemSelector где есть стоп слова. | |
| * | |
| * @param {string} itemSelector селектор карточек. | |
| * @param {string} paramSelector селектор описания внутри карточки. | |
| * | |
| * @return void | |
| */ | |
| function vegetarianFilter(itemSelector, paramSelector) { | |
| var stopList = [ | |
| 'кожа', | |
| 'лосос', | |
| 'краб', | |
| 'лава', | |
| 'мясо', | |
| 'икра', | |
| 'филе', | |
| 'креветк', | |
| 'рыбы', | |
| 'рыба', | |
| 'курица', | |
| 'угорь', | |
| ]; | |
| var itemList = document.querySelectorAll(itemSelector); | |
| [].forEach.call(itemList, function (el) { | |
| var text = el.querySelector(paramSelector).innerText.toLowerCase(); | |
| var isVeget = true; | |
| stopList.forEach(function(test) { | |
| if (!isVeget) return false; | |
| if (text.search(test) >= 0) { | |
| console.log('[vegetaFilter]', el, test, text); | |
| isVeget = false; | |
| } | |
| }); | |
| if (!isVeget) el.style.display = 'none'; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment