Skip to content

Commit 41f8bb3

Browse files
committed
maint(pat-stacks): Add updated dom to pat-update event data.
1 parent 18711eb commit 41f8bb3

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

src/pat/stacks/stacks.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Pattern extends BasePattern {
2828
_setupStack() {
2929
let selected = this._currentFragment();
3030
const $sheets = this.$el.find(this.options.selector);
31-
let $visible = [];
31+
this.$active = [];
3232

3333
if ($sheets.length < 2) {
3434
log.warn("Stacks pattern: must have more than one sheet.", this.$el[0]);
@@ -37,18 +37,18 @@ class Pattern extends BasePattern {
3737

3838
if (selected) {
3939
try {
40-
$visible = $sheets.filter("#" + selected);
40+
this.$active = $sheets.filter("#" + selected);
4141
} catch (e) {
4242
selected = undefined;
4343
}
4444
}
4545

46-
if (!$visible.length) {
47-
$visible = $sheets.first();
48-
selected = $visible[0].id;
46+
if (!this.$active.length) {
47+
this.$active = $sheets.first();
48+
selected = this.$active[0].id;
4949
}
50-
const $invisible = $sheets.not($visible);
51-
utils.hideOrShow($visible, true, { transition: "none" }, this.name);
50+
const $invisible = $sheets.not(this.$active);
51+
utils.hideOrShow(this.$active, true, { transition: "none" }, this.name);
5252
utils.hideOrShow($invisible, false, { transition: "none" }, this.name);
5353
this._updateAnchors(selected);
5454
}
@@ -80,6 +80,8 @@ class Pattern extends BasePattern {
8080
this._switch(href_parts[1]);
8181
$(e.target).trigger("pat-update", {
8282
pattern: "stacks",
83+
action: "attribute-changed",
84+
dom: this.$active[0],
8385
originalEvent: e,
8486
});
8587
}
@@ -104,13 +106,13 @@ class Pattern extends BasePattern {
104106
}
105107

106108
_switch(sheet_id) {
107-
const $sheet = this.$el.find("#" + sheet_id);
108-
if (!$sheet.length || $sheet.hasClass("visible")) {
109+
this.$active = this.$el.find("#" + sheet_id);
110+
if (!this.$active.length || this.$active.hasClass("visible")) {
109111
return;
110112
}
111-
const $invisible = this.$el.find(this.options.selector).not($sheet);
113+
const $invisible = this.$el.find(this.options.selector).not(this.$active);
112114
utils.hideOrShow($invisible, false, this.options, this.name);
113-
utils.hideOrShow($sheet, true, this.options, this.name);
115+
utils.hideOrShow(this.$active, true, this.options, this.name);
114116
}
115117
}
116118

src/pat/stacks/stacks.test.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,23 @@ describe("pat-stacks", function () {
117117
await events.await_pattern_init(pattern);
118118
pattern.document = { URL: document.URL };
119119
pattern.document.URL = "http://www.example.com";
120-
const spy_trigger = jest.spyOn($.fn, "trigger");
120+
121+
let data = null;
122+
$el.on("pat-update", (e, d) => {
123+
data = d;
124+
});
125+
121126
const e = {
122127
target: $el,
123128
type: "click",
124129
preventDefault: function () {},
125130
currentTarget: { href: "http://www.example.com#s1" },
126131
};
127132
pattern._onClick(e);
128-
expect(spy_trigger).toHaveBeenCalledWith(
129-
"pat-update",
130-
expect.objectContaining({ pattern: "stacks" })
131-
);
133+
134+
expect(data.pattern).toBe("stacks");
135+
expect(data.action).toBe("attribute-changed");
136+
expect(data.dom).toBe($el[0].querySelector("#s1"));
132137
});
133138
});
134139

0 commit comments

Comments
 (0)