Skip to content

Instantly share code, notes, and snippets.

Created September 22, 2016 15:20
What would you like to do?
/* globals define */
'use strict';
var REGISTERED = {};
var register = function(name, config){
REGISTERED[name] = config;
var scan = function(baseDoc){
baseDoc = document;
for(var patternName in REGISTERED){
var pattern = REGISTERED[patternName];
baseDoc.querySelectorAll(pattern.selector).forEach(function(el){ // jshint ignore:line
el.patternInstance = pattern.init(el);
var get = function(name){
return REGISTERED[name];
return {
register: register,
scan: scan,
get: get
Copy link

thet commented Sep 22, 2016

Awesome implementation of the Patternslib scanner! If you don't need inside-out pattern initialization and options parsing, this is it.

This is the original implementation, by the way:

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