Skip to content

Commit 8cfc98b

Browse files
authored
Merge pull request #993 from Patternslib/disable-patterns
feat: Introduce ``disable-patterns`` class to prevent from initializing.
2 parents 96f7bac + 5f137f0 commit 8cfc98b

File tree

6 files changed

+15
-13
lines changed

6 files changed

+15
-13
lines changed

src/core/registry.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,17 @@ const registry = {
146146
);
147147
matches = matches.filter((el) => {
148148
// Filter out patterns:
149-
// - with class ``.cant-touch-this``
150-
// - wrapped in ``.cant-touch-this`` elements
149+
// - with class ``.disable-patterns``
150+
// - wrapped in ``.disable-patterns`` elements
151151
// - wrapped in ``<pre>`` elements
152152
// - wrapped in ``<template>`` elements
153153
return (
154-
!el.matches(".cant-touch-this") &&
155-
!el?.parentNode?.closest?.(".cant-touch-this") &&
154+
!el.matches(".disable-patterns") &&
155+
!el?.parentNode?.closest?.(".disable-patterns") &&
156156
!el?.parentNode?.closest?.("pre") &&
157-
!el?.parentNode?.closest?.("template") // NOTE: not strictly necessary. Template is a DocumentFragment and not reachable except for IE.
157+
!el?.parentNode?.closest?.("template") && // NOTE: not strictly necessary. Template is a DocumentFragment and not reachable except for IE.
158+
!el.matches(".cant-touch-this") && // BBB. TODO: Remove with next major version.
159+
!el?.parentNode?.closest?.(".cant-touch-this") // BBB. TODO: Remove with next major version.
158160
);
159161
});
160162

src/core/registry.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ describe("pat-registry: The registry for patterns", function () {
7171
const tree = document.createElement("div");
7272
tree.innerHTML = `
7373
<div class="e1 pat-example"></div>
74-
<div class="e2 cant-touch-this pat-example"></div>
75-
<div class="cant-touch-this">
74+
<div class="e2 disable-patterns pat-example"></div>
75+
<div class="disable-patterns">
7676
<div class="e3 pat-example"></div>
7777
</div>
7878
<pre>

src/pat/clone/clone.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default Base.extend({
5757
: $(this.template).safeClone();
5858

5959
const ids = ($clone.attr("id") || "").split(" ").filter((it) => it);
60-
$clone.removeAttr("id").removeClass("cant-touch-this");
60+
$clone.removeAttr("id").removeClass("disable-patterns");
6161
$.each(
6262
ids,
6363
function (idx, id) {

src/pat/clone/clone.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ describe("pat-clone", function () {
294294
).toBe("initializedinitialized");
295295
});
296296

297-
it("will not initialize patterns in the template wrapped in cant-touch-this.", function () {
297+
it("will not initialize patterns in the template wrapped in disable-patterns.", function () {
298298
Base.extend({
299299
name: "example",
300300
trigger: ".pat-example",
@@ -304,7 +304,7 @@ describe("pat-clone", function () {
304304
});
305305

306306
document.body.innerHTML = `
307-
<div id="template" class="cant-touch-this">
307+
<div id="template" class="disable-patterns">
308308
<div class="pat-example"></div>
309309
</div>
310310
<div class="pat-clone" data-pat-clone="template: #template">

src/pat/clone/documentation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ The markup below would have exactly the same effect as the first example, but us
8686
### Example with a hidden template which includes a pattern
8787

8888
Patterns in templates are initialized after cloning.
89-
However, the patterns in the template itself are not initialized if the template has the attribute ``hidden`` or the class ``cant-touch-this``.
89+
However, the patterns in the template itself are not initialized if the template has the attribute ``hidden`` or the class ``disable-patterns``.
9090
This is to prevent double-initialization within the template and after being cloned.
9191

92-
<div id="template" class="cant-touch-this" hidden>
92+
<div id="template" class="disable-patterns" hidden>
9393
<input name="date-1" type="date" class="pat-date-picker" />
9494
</fieldset>
9595

src/pat/legend/legend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var legend = {
2424

2525
transform: function ($root) {
2626
const root = utils.jqToNode($root);
27-
const all = dom.querySelectorAllAndMe(root, "legend:not(.cant-touch-this)");
27+
const all = dom.querySelectorAllAndMe(root, "legend:not(.disable-patterns)");
2828
for (const el of all) {
2929
$(el).replaceWith("<p class='legend'>" + $(el).html() + "</p>");
3030
}

0 commit comments

Comments
 (0)