Add basic element selection on reload
Browse files- .eslintrc.json +7 -1
- assets/scripts/src/sholo.js +78 -1
- assets/styles/scss/base.scss +1 -0
- assets/styles/scss/demo.scss +1 -0
- index.html +18 -2
- types/index.d.ts +0 -0
.eslintrc.json
CHANGED
@@ -4,6 +4,12 @@
|
|
4 |
"browser": true
|
5 |
},
|
6 |
"rules": {
|
7 |
-
"no-console": "off"
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
}
|
9 |
}
|
|
|
4 |
"browser": true
|
5 |
},
|
6 |
"rules": {
|
7 |
+
"no-console": "off",
|
8 |
+
"no-underscore-dangle": "off",
|
9 |
+
"no-plusplus": "off",
|
10 |
+
"no-cond-assign": "off",
|
11 |
+
"func-names": "off",
|
12 |
+
"no-param-reassign": ["off"],
|
13 |
+
"max-len": "off"
|
14 |
}
|
15 |
}
|
assets/scripts/src/sholo.js
CHANGED
@@ -1 +1,78 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
let overlay;
|
2 |
+
let overlayContext;
|
3 |
+
|
4 |
+
// overlay is going to cover the whole page and then we will
|
5 |
+
// cut out a chunk for the element to be visible out of it
|
6 |
+
function createOverlay() {
|
7 |
+
overlay = document.createElement('canvas');
|
8 |
+
overlayContext = overlay.getContext('2d');
|
9 |
+
|
10 |
+
overlay.style.background = 'transparent';
|
11 |
+
overlay.style.position = 'fixed';
|
12 |
+
overlay.style.top = '0';
|
13 |
+
overlay.style.left = '0';
|
14 |
+
overlay.style.zIndex = '999999999';
|
15 |
+
overlay.width = window.innerWidth;
|
16 |
+
overlay.height = window.innerHeight;
|
17 |
+
|
18 |
+
overlayContext.clearRect(0, 0, overlay.width, overlay.height);
|
19 |
+
overlayContext.fillStyle = 'rgba( 0, 0, 0, 0.7)';
|
20 |
+
overlayContext.fillRect(0, 0, overlay.width, overlay.height);
|
21 |
+
}
|
22 |
+
|
23 |
+
// Finds the correct position of node on screen
|
24 |
+
function getNodePosition(node) {
|
25 |
+
let x = document.documentElement.offsetLeft;
|
26 |
+
let y = document.documentElement.offsetTop;
|
27 |
+
|
28 |
+
if (node.offsetParent) {
|
29 |
+
do {
|
30 |
+
x += node.offsetLeft;
|
31 |
+
y += node.offsetTop;
|
32 |
+
} while (node = node.offsetParent);
|
33 |
+
}
|
34 |
+
|
35 |
+
return { x, y };
|
36 |
+
}
|
37 |
+
|
38 |
+
// selects the node on the screen
|
39 |
+
function selectNode(node) {
|
40 |
+
if (!node) {
|
41 |
+
return;
|
42 |
+
}
|
43 |
+
|
44 |
+
// Default to non-existing space
|
45 |
+
const currentRegion = {
|
46 |
+
left: Number.MAX_VALUE, top: Number.MAX_VALUE, right: 0, bottom: 0,
|
47 |
+
};
|
48 |
+
const nodePosition = getNodePosition(node);
|
49 |
+
|
50 |
+
// If we have the position and has some height
|
51 |
+
if (typeof nodePosition.x === 'number' && typeof nodePosition.y === 'number' && (node.offsetWidth > 0 || node.offsetHeight > 0)) {
|
52 |
+
currentRegion.left = Math.min(currentRegion.left, nodePosition.x);
|
53 |
+
currentRegion.top = Math.min(currentRegion.top, nodePosition.y);
|
54 |
+
currentRegion.right = Math.max(currentRegion.right, nodePosition.x + node.offsetWidth);
|
55 |
+
currentRegion.bottom = Math.max(currentRegion.bottom, nodePosition.y + node.offsetHeight);
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
const isValidRegion = currentRegion.left < currentRegion.right && currentRegion.top < currentRegion.bottom;
|
60 |
+
if (!isValidRegion) {
|
61 |
+
return;
|
62 |
+
}
|
63 |
+
|
64 |
+
// Cut out the cleared region
|
65 |
+
overlayContext.clearRect(
|
66 |
+
currentRegion.left - window.scrollX,
|
67 |
+
currentRegion.top - window.scrollY,
|
68 |
+
(currentRegion.right - currentRegion.left),
|
69 |
+
(currentRegion.bottom - currentRegion.top),
|
70 |
+
);
|
71 |
+
|
72 |
+
document.body.appendChild(overlay);
|
73 |
+
}
|
74 |
+
|
75 |
+
const nodeToSelect = document.querySelector('.section__header');
|
76 |
+
|
77 |
+
createOverlay();
|
78 |
+
selectNode(nodeToSelect);
|
assets/styles/scss/base.scss
CHANGED
@@ -28,6 +28,7 @@ html, body {
|
|
28 |
}
|
29 |
|
30 |
body {
|
|
|
31 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
32 |
font-size: 16px;
|
33 |
line-height: 1.4;
|
|
|
28 |
}
|
29 |
|
30 |
body {
|
31 |
+
padding-top: 1px;
|
32 |
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
33 |
font-size: 16px;
|
34 |
line-height: 1.4;
|
assets/styles/scss/demo.scss
CHANGED
@@ -8,6 +8,7 @@ $light-button-bg: #f5f5f5 !default;
|
|
8 |
$light-button-text: #2d2d2d !default;
|
9 |
|
10 |
.page-wrap {
|
|
|
11 |
width: $container-width;
|
12 |
margin: auto;
|
13 |
}
|
|
|
8 |
$light-button-text: #2d2d2d !default;
|
9 |
|
10 |
.page-wrap {
|
11 |
+
padding-top: 1px;
|
12 |
width: $container-width;
|
13 |
margin: auto;
|
14 |
}
|
index.html
CHANGED
@@ -15,14 +15,30 @@
|
|
15 |
<a href="#" class="btn btn__dark">Show an Example</a>
|
16 |
<a href="#" class="btn btn__light">Learn More</a>
|
17 |
</section>
|
18 |
-
<section>
|
19 |
<h1>Whats does it do?</h1>
|
20 |
<p>Let's you bring any component on the page into the spotlight.</p>
|
21 |
<p>It lets you focus any element of the page while putting an overlay on top of the other elements in page. You can use it to make powerful introduction for different features of your application or for example if you want to highlight some component that needs user attention.</p>
|
22 |
</section>
|
23 |
-
<section>
|
24 |
<h1>How does it do that?</h1>
|
25 |
<p>Ever heard of magic? ...it is not that, it just uses some canvas manipulation to put the focus on some element</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
</section>
|
27 |
</div>
|
28 |
|
|
|
15 |
<a href="#" class="btn btn__dark">Show an Example</a>
|
16 |
<a href="#" class="btn btn__light">Learn More</a>
|
17 |
</section>
|
18 |
+
<section class="section__purpose">
|
19 |
<h1>Whats does it do?</h1>
|
20 |
<p>Let's you bring any component on the page into the spotlight.</p>
|
21 |
<p>It lets you focus any element of the page while putting an overlay on top of the other elements in page. You can use it to make powerful introduction for different features of your application or for example if you want to highlight some component that needs user attention.</p>
|
22 |
</section>
|
23 |
+
<section class="section__how">
|
24 |
<h1>How does it do that?</h1>
|
25 |
<p>Ever heard of magic? ...it is not that, it just uses some canvas manipulation to put the focus on some element</p>
|
26 |
+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi assumenda, at consectetur cupiditate inventore ipsa molestias, natus nulla odit optio pariatur perspiciatis, quae quam quasi quibusdam recusandae repellendus reprehenderit tempora!</p>
|
27 |
+
</section>
|
28 |
+
<section class="section__examples">
|
29 |
+
<h1>Can you show some Examples?</h1>
|
30 |
+
<p>Here are some of the examples</p>
|
31 |
+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi assumenda, at consectetur cupiditate inventore ipsa molestias, natus nulla odit optio pariatur perspiciatis, quae quam quasi quibusdam recusandae repellendus reprehenderit tempora!</p>
|
32 |
+
</section>
|
33 |
+
<section class="section__learn">
|
34 |
+
<h1>I want to learn more</h1>
|
35 |
+
<p>Here are some of the examples</p>
|
36 |
+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi assumenda, at consectetur cupiditate inventore ipsa molestias, natus nulla odit optio pariatur perspiciatis, quae quam quasi quibusdam recusandae repellendus reprehenderit tempora!</p>
|
37 |
+
</section>
|
38 |
+
<section>
|
39 |
+
<h1>Contributing</h1>
|
40 |
+
<p>Here are some of the examples</p>
|
41 |
+
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Animi assumenda, at consectetur cupiditate inventore ipsa molestias, natus nulla odit optio pariatur perspiciatis, quae quam quasi quibusdam recusandae repellendus reprehenderit tempora!</p>
|
42 |
</section>
|
43 |
</div>
|
44 |
|
types/index.d.ts
ADDED
File without changes
|