Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ To facilitate debugging you can change the default log level through the URL que
- `http://www.example.com/?loglevel-inject=DEBUG` changes the log level for just the inject pattern to `DEBUG`.
- `http://www.example.com/?loglevel=ERROR&loglevel-inject=INFO` changes the standard log level error, but enables messages at the `INFO` level for the inject pattern.

### Patternslib global variables

There are some global variables that are available and can be used to make
global settings or access otherwise hidden objects.

| Global variable | Purpose | Default |
| --------------- | ------- | ------ |
| window.__patternslib_import_styles | Whether to import pattern-specific styles | false |
| window.__patternslib_patterns_blacklist | A list of patterns that should not be loaded. | [] |
| window.__patternslib_registry | Global access to the Patternslib registry object. | - |
| window.__patternslib_registry_initialized | True, if the registry has been initialized. | false |
| window.__patternslib_disable_modernizr (Deprecated) | Disable modernizr, but still write the js/no-js classes to the body. | undefined |

### Bundle build analyzation

Expand Down
11 changes: 11 additions & 0 deletions src/core/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ const registry = {
log.error("Pattern lacks a name.", pattern);
return false;
}

// Do not register blacklisted patterns.
let BLACKLIST = window.__patternslib_patterns_blacklist;
if (!Array.isArray(BLACKLIST)) {
BLACKLIST = [];
}
if (BLACKLIST.includes(name)) {
log.warn(`Pattern name ${name} is blacklisted.`);
return false;
}

if (registry.patterns[name]) {
log.debug(`Already have a pattern called ${name}.`);
return false;
Expand Down
34 changes: 34 additions & 0 deletions src/core/registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,38 @@ describe("pat-registry: The registry for patterns", function () {
expect(() => { registry.scan(el) }).not.toThrow(DOMException);
});

it("Does not initialize the pattern if blacklisted", function () {
window.__patternslib_patterns_blacklist = ["example"];

Base.extend({
name: "example",
trigger: ".pat-example",
init: function () {
this.el.innerHTML = "initialized";
},
});

const tree = document.createElement("div");
tree.setAttribute("class", "pat-example");
registry.scan(tree);
expect(tree.textContent).toBe("");
});

it("but also doesn't break with invalid blacklists", function () {
window.__patternslib_patterns_blacklist = "example"; // not an array

Base.extend({
name: "example",
trigger: ".pat-example",
init: function () {
this.el.innerHTML = "initialized";
},
});

const tree = document.createElement("div");
tree.setAttribute("class", "pat-example");
registry.scan(tree);
expect(tree.textContent).toBe("initialized");
});

});
2 changes: 0 additions & 2 deletions src/polyfills-loader.js

This file was deleted.

15 changes: 0 additions & 15 deletions src/public_path.js

This file was deleted.