Skip to content

Commit a6ffe12

Browse files
authored
Merge pull request #1096 from Patternslib/pat-bumper-regressions-pre
Pat bumper regressions pre
2 parents f9548b0 + 2b04cbc commit a6ffe12

File tree

4 files changed

+30
-36
lines changed

4 files changed

+30
-36
lines changed

src/core/utils.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,6 @@ const date_diff = (date_1, date_2) => {
680680
};
681681

682682
var utils = {
683-
// pattern pimping - own module?
684683
jqueryPlugin: jqueryPlugin,
685684
escapeRegExp: escapeRegExp,
686685
isObject: isObject,

src/pat/bumper/bumper.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,24 @@
1-
/**
2-
* Patterns bumper - Add bumping classes for sticky elements.
3-
*/
4-
5-
import Base from "../../core/base";
1+
import { BasePattern } from "@patternslib/patternslib/src/core/basepattern";
62
import dom from "../../core/dom";
7-
import logging from "../../core/logging";
83
import Parser from "../../core/parser";
4+
import registry from "@patternslib/patternslib/src/core/registry";
95
import utils from "../../core/utils";
106

11-
const logger = logging.getLogger("tabs");
12-
137
export const parser = new Parser("bumper");
148
parser.addArgument("selector");
159
parser.addArgument("bump-add", "bumped");
1610
parser.addArgument("bump-remove");
1711
parser.addArgument("unbump-add");
1812
parser.addArgument("unbump-remove", "bumped");
1913

20-
export default Base.extend({
21-
name: "bumper",
22-
trigger: ".pat-bumper",
14+
class Pattern extends BasePattern {
15+
static name = "bumper";
16+
static trigger = ".pat-bumper";
17+
static parser = parser;
2318

2419
async init() {
2520
// Based on: https://davidwalsh.name/detect-sticky
2621

27-
if (!utils.checkCSSFeature("position", "sticky")) {
28-
// IE11
29-
logger.warn("No position sticky support.");
30-
return;
31-
}
32-
33-
this.options = parser.parse(this.el, this.options);
34-
3522
this.target_element = this.options.selector
3623
? document.querySelector(this.options.selector)
3724
: this.el;
@@ -40,7 +27,7 @@ export default Base.extend({
4027
// e.g. CSS applied for injected content.
4128
await utils.timeout(1);
4229
this._init();
43-
},
30+
}
4431

4532
_init() {
4633
const scroll_container_y = dom.find_scroll_container(
@@ -85,7 +72,7 @@ export default Base.extend({
8572
);
8673
observer_x.observe(this.el);
8774
}
88-
},
75+
}
8976

9077
_intersection_observer_callback(entries) {
9178
const el = this.target_element;
@@ -143,5 +130,10 @@ export default Base.extend({
143130
el.classList.remove("bumped-bottom");
144131
}
145132
}
146-
},
147-
});
133+
}
134+
}
135+
136+
registry.register(Pattern);
137+
138+
export default Pattern;
139+
export { Pattern };

src/pat/bumper/documentation.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## Description
22

3+
Pumber Pattern - Add bumping classes for sticky elements.
4+
35
A bumper is an element that, when the user starts scrolling, stays within view when a viewport border touches it.
46

57
## Documentation
@@ -10,9 +12,14 @@ Below is a simple example of a bumper.
1012
Bumper content
1113
</div>
1214

13-
When the user starts scrolling the page and the top edge of the above div reaches the top
14-
edge of the viewport, a `bumped` class will be added. For this to work the pattern
15-
will automatically set the `position` of the div to `relative`.
15+
When the user starts scrolling the page and the top edge of the above div
16+
reaches the top edge of the viewport, a `bumped` class and - depending on the
17+
bumping edges - `bumped-top`, `bumped-right`, `bumped-botton` or `bumped-left`
18+
classes will be added.
19+
20+
It's up to you to style the element with the help of these classes. You might
21+
also want to set the element to `position: sticky`, so that it keeps it's
22+
position relative to the viewport while scrolling.
1623

1724
### Bumpers in scrolling containers
1825

@@ -23,13 +30,10 @@ You can also put a bumper in a scrolling container. Here is an example:
2330
<p>...</p>
2431
</div>
2532

26-
If the container has its overflow style set to `auto` or `scroll` and its
27-
contents do not fit in the available space the browser will automatically
28-
add scrollbars. The bumper pattern will detect this and _stick_ the bumped
29-
element so it is always visible in its container.
30-
31-
To implement this the bumper pattern will set the `position` of both the
32-
bumper and its scrolling container to `relative`.
33+
If the container has its `overflow` style set to `auto` or `scroll` and its
34+
contents do not fit in the available space the browser will automatically add
35+
scrollbars. When the `pat-bumper` element touches any edge of the scrolling
36+
container the bumper classes will be added.
3337

3438
### Class specification
3539

@@ -61,4 +65,3 @@ The available options are:
6165
| `bump-remove` | _unset_ | CSS class(es) to removed when an element is bumped. | String |
6266
| `unbump-add` | _unset_ | CSS class(es) to add when an element is no longer bumped. | String |
6367
| `unbump-remove` | `bumped` | CSS class(es) to removed when an element is no longer bumped. | String |
64-
| `side` | `top` | The side which should bump. A combination of `all top right bottom left`. `all` is equivalent to `top right bottom left`. | String |

src/pat/clone-code/clone-code.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ parser.addArgument("features", null, ["format"]);
1212
class Pattern extends BasePattern {
1313
static name = "clone-code";
1414
static trigger = ".pat-clone-code";
15-
parser = parser;
15+
static parser = parser;
1616

1717
async init() {
1818
// Source

0 commit comments

Comments
 (0)