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
7 changes: 4 additions & 3 deletions docs/designer/what-is-patternslib.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# What is Patternslib?

Patternslib is a library of reusable patterns which let you create rich,
dynamic and interactive prototypes or websites, without having to know or care about Javascript.
Patternslib is a library of reusable patterns which let you create rich, dynamic and interactive prototypes or websites, without having to know or care about Javascript.

Instead of writing or integrating Javascript, you simply add special CSS classes and HTML5 data attributes to your HTML.
These classes and `data-` attributes describe the so-called "interaction patterns" of Patternslib.
These classes and `data-` attributes describe and invoke the so-called "interaction patterns" of Patternslib which add rich functionality to your page.

Patternslib is both a library of reusable interaction patterns as well as a small framework for creating such patterns.
11 changes: 0 additions & 11 deletions docs/general/what-is-patternslib.md

This file was deleted.

1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<title>Patterns demo pages</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/style/common.css" />
<script src="/modernizr.min.js"></script>
<script src="/bundle.min.js"></script>
</head>
<body class="component-index">
Expand Down
32 changes: 32 additions & 0 deletions src/core/feature-detection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
(function () {
// Add JavaScript feature as class to the <html> element, just like
// Modernizr does. This is needed for accessibility reasons, to support
// browsers and situations where JavaScript is not available or disabled.
// The HTML root tag needs to have the `no-js` class set which is then
// replaced by `js`.
const html = document.getElementsByTagName("html")[0];
if (html.classList.contains("no-js")) {
html.classList.remove("no-js");
html.classList.add("js");
}

// Do not load modernizr if disabled. It's enabled by default.
// You might want to disable it for your project by setting:
// window.__patternslib_disable_modernizr = true;
if (window.__patternslib_disable_modernizr) {
return;
}

// Get the current script tag's URL.
// See: https://stackoverflow.com/a/984656/1337474
const scripts = document.getElementsByTagName("script");
const script = scripts[scripts.length - 1];
let script_url = script.src;
// Get the base URL of the current script tag's URL.
script_url = script_url.substring(0, script_url.lastIndexOf("/")) + "/";

// Inject a new one with the modernizr bundle.
const script_tag = document.createElement("script");
script_tag.src = script_url + "modernizr.min.js";
document.getElementsByTagName("head")[0].appendChild(script_tag);
})();
71 changes: 71 additions & 0 deletions src/core/feature-detection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Feature detection

This module adds the `js` class to the HTML root node and loads Modernizr for more feature detection.

---
** Note **

If you create own bundles based on Patternslib, you would need to import the `src/core/feature-detection` module for these features to be available.

---


## Adding the "js" class for accessibility styles

There are situations where web browsers do not have JavaScript available or when it is disabled.
In situations where no JavaScript is available you might want to show certain elements where in JavaScript situations you might want to hide them until a JavaScript functionality is showing them.

In the Media Query Level 5 specification there is a CSS media feature to detect JavaScript via a [`scripting` at-rule](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/scripting).
But at time of this writing this is [not available in any of the major browsers](https://caniuse.com/mdn-css_at-rules_media_scripting).

Therefore Patternslib adds a `js` class to the HTML root node, if the HTML root node already has a `no-js` class.
The `js` class is set very early before any browser layout is done if you include the Patternslib script in the HEAD of your site.

Markup:

```
<html class="no-js">
<head>
<script src="https://cdn.jsdelivr.net/npm/@patternslib/[email protected]/dist/bundle.min.js"></script>
</head>
<body>
</body>
</html>
```

When the JavaScript is loaded, the `no-js` class is removed and the `js` class is set:

```
<html class="js">
<head>
<script src="https://cdn.jsdelivr.net/npm/@patternslib/[email protected]/dist/bundle.min.js"></script>
</head>
<body>
</body>
</html>
```


## Loading Modernizr

Modernizr is loaded for more feature detection.

To disable Modernizr you can set `window.__patternslib_disable_modernizr = true;` just before you load the Patternslib bundle:

```
<html class="no-js">
<head>
<script>window.__patternslib_disable_modernizr = true;</script>
<script src="https://cdn.jsdelivr.net/npm/@patternslib/[email protected]/dist/bundle.min.js"></script>
</head>
<body>
</body>
</html>
```

---
** Note **

The Modernizr feature detection is being phased out and might be removed in a future version of Patternslib.

---
4 changes: 0 additions & 4 deletions src/globals.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Load modernizr and the `html.js` feature class.
import "./core/feature-detection";

// Webpack entry point for module federation.
import "@patternslib/dev/webpack/module_federation";

// The next import needs to be kept with parentheses, otherwise we get this error:
// "Shared module is not available for eager consumption."
import("./patterns");
Expand Down
1 change: 1 addition & 0 deletions src/pat/clone-code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>pat-clone demo page</title>
<meta charset="utf-8">
<link rel="stylesheet" href="/style/common.css" />
<script>window.__patternslib_disable_modernizr = true;</script>
<script src="/bundle.min.js"></script>
</head>
<body>
Expand Down
4 changes: 0 additions & 4 deletions src/patterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
*/

// Import base
import "./globals";
import registry from "./core/registry";

// Import all used patterns for the bundle to be generated
Expand Down Expand Up @@ -59,9 +58,6 @@ import "./pat/tooltip/tooltip";
import "./pat/validation/validation";
import "./pat/zoom/zoom";

// example pattern
import "./pat/minimalpattern/minimalpattern";

// External patterns
import "@patternslib/pat-content-mirror";
import "@patternslib/pat-doclock";
Expand Down