Created
September 22, 2016 15:20
-
-
Save vangheem/ed0b3c0f62532bde0efd493adf568a47 to your computer and use it in GitHub Desktop.
This file contains 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
/* globals define */ | |
define(function(){ | |
'use strict'; | |
var REGISTERED = {}; | |
var register = function(name, config){ | |
REGISTERED[name] = config; | |
}; | |
var scan = function(baseDoc){ | |
if(!baseDoc){ | |
baseDoc = document; | |
} | |
for(var patternName in REGISTERED){ | |
var pattern = REGISTERED[patternName]; | |
baseDoc.querySelectorAll(pattern.selector).forEach(function(el){ // jshint ignore:line | |
if(el.patternInstance){ | |
return; | |
} | |
el.patternInstance = pattern.init(el); | |
}); | |
} | |
}; | |
var get = function(name){ | |
return REGISTERED[name]; | |
}; | |
return { | |
register: register, | |
scan: scan, | |
get: get | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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: https://github.com/Patternslib/Patterns/blob/master/src/core/registry.js