Refactoring
Browse files- .eslintrc.json +1 -0
- assets/scripts/src/element.js +9 -6
- assets/scripts/src/sholo.js +10 -14
- index.html +3 -3
.eslintrc.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
| 9 |
"no-plusplus": "off",
|
| 10 |
"no-cond-assign": "off",
|
| 11 |
"func-names": "off",
|
|
|
|
| 12 |
"no-param-reassign": [
|
| 13 |
"off"
|
| 14 |
],
|
|
|
|
| 9 |
"no-plusplus": "off",
|
| 10 |
"no-cond-assign": "off",
|
| 11 |
"func-names": "off",
|
| 12 |
+
"no-bitwise": "off",
|
| 13 |
"no-param-reassign": [
|
| 14 |
"off"
|
| 15 |
],
|
assets/scripts/src/element.js
CHANGED
|
@@ -4,10 +4,13 @@ export default class Element {
|
|
| 4 |
/**
|
| 5 |
* DOM element object
|
| 6 |
* @param node
|
|
|
|
| 7 |
*/
|
| 8 |
-
constructor(node) {
|
| 9 |
-
this.
|
| 10 |
this.document = document;
|
|
|
|
|
|
|
| 11 |
}
|
| 12 |
|
| 13 |
/**
|
|
@@ -15,7 +18,7 @@ export default class Element {
|
|
| 15 |
* @returns {{x: number, y: number}}
|
| 16 |
*/
|
| 17 |
getScreenCoordinates() {
|
| 18 |
-
let tempNode = this.
|
| 19 |
|
| 20 |
let x = this.document.documentElement.offsetLeft;
|
| 21 |
let y = this.document.documentElement.offsetTop;
|
|
@@ -45,11 +48,11 @@ export default class Element {
|
|
| 45 |
|
| 46 |
// If we have the position for this element
|
| 47 |
// and the element is visible on screen (has some height)
|
| 48 |
-
if (typeof coordinates.x === 'number' && typeof coordinates.y === 'number' && (this.
|
| 49 |
position.left = Math.min(position.left, coordinates.x);
|
| 50 |
position.top = Math.min(position.top, coordinates.y);
|
| 51 |
-
position.right = Math.max(position.right, coordinates.x + this.
|
| 52 |
-
position.bottom = Math.max(position.bottom, coordinates.y + this.
|
| 53 |
}
|
| 54 |
|
| 55 |
return position;
|
|
|
|
| 4 |
/**
|
| 5 |
* DOM element object
|
| 6 |
* @param node
|
| 7 |
+
* @param options
|
| 8 |
*/
|
| 9 |
+
constructor(node, options) {
|
| 10 |
+
this.node = node;
|
| 11 |
this.document = document;
|
| 12 |
+
this.window = window;
|
| 13 |
+
this.options = options;
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
|
|
|
| 18 |
* @returns {{x: number, y: number}}
|
| 19 |
*/
|
| 20 |
getScreenCoordinates() {
|
| 21 |
+
let tempNode = this.node;
|
| 22 |
|
| 23 |
let x = this.document.documentElement.offsetLeft;
|
| 24 |
let y = this.document.documentElement.offsetTop;
|
|
|
|
| 48 |
|
| 49 |
// If we have the position for this element
|
| 50 |
// and the element is visible on screen (has some height)
|
| 51 |
+
if (typeof coordinates.x === 'number' && typeof coordinates.y === 'number' && (this.node.offsetWidth > 0 || this.node.offsetHeight > 0)) {
|
| 52 |
position.left = Math.min(position.left, coordinates.x);
|
| 53 |
position.top = Math.min(position.top, coordinates.y);
|
| 54 |
+
position.right = Math.max(position.right, coordinates.x + this.node.offsetWidth);
|
| 55 |
+
position.bottom = Math.max(position.bottom, coordinates.y + this.node.offsetHeight);
|
| 56 |
}
|
| 57 |
|
| 58 |
return position;
|
assets/scripts/src/sholo.js
CHANGED
|
@@ -7,20 +7,16 @@ import './polyfill';
|
|
| 7 |
*/
|
| 8 |
export default class Sholo {
|
| 9 |
/**
|
| 10 |
-
* @param
|
| 11 |
-
* @param padding number
|
| 12 |
-
* @param animate boolean
|
| 13 |
*/
|
| 14 |
-
constructor({
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
animate,
|
| 23 |
-
});
|
| 24 |
|
| 25 |
this.document = document;
|
| 26 |
this.window = window;
|
|
@@ -89,7 +85,7 @@ export default class Sholo {
|
|
| 89 |
}
|
| 90 |
|
| 91 |
if (domElement) {
|
| 92 |
-
const element = new Element(domElement);
|
| 93 |
this.overlay.highlight(element);
|
| 94 |
} else {
|
| 95 |
this.overlay.clear();
|
|
|
|
| 7 |
*/
|
| 8 |
export default class Sholo {
|
| 9 |
/**
|
| 10 |
+
* @param options
|
|
|
|
|
|
|
| 11 |
*/
|
| 12 |
+
constructor(options = {}) {
|
| 13 |
+
this.options = Object.assign({
|
| 14 |
+
padding: 10,
|
| 15 |
+
animate: true,
|
| 16 |
+
opacity: 0.75,
|
| 17 |
+
}, options);
|
| 18 |
+
|
| 19 |
+
this.overlay = new Overlay(options);
|
|
|
|
|
|
|
| 20 |
|
| 21 |
this.document = document;
|
| 22 |
this.window = window;
|
|
|
|
| 85 |
}
|
| 86 |
|
| 87 |
if (domElement) {
|
| 88 |
+
const element = new Element(domElement, this.options);
|
| 89 |
this.overlay.highlight(element);
|
| 90 |
} else {
|
| 91 |
this.overlay.clear();
|
index.html
CHANGED
|
@@ -9,7 +9,7 @@
|
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div class="page-wrap">
|
| 12 |
-
<section class="section__header">
|
| 13 |
<h1>Sholo</h1>
|
| 14 |
<p class="text-muted">A light-weight, no-dependency, vanilla JavaScript library to bring certain parts of page in spotlight</p>
|
| 15 |
<a href="#" class="btn btn__dark">Show an Example</a>
|
|
@@ -35,7 +35,7 @@
|
|
| 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>
|
|
@@ -45,7 +45,7 @@
|
|
| 45 |
<script src="./assets/scripts/dist/sholo.js"></script>
|
| 46 |
<script>
|
| 47 |
const sholo = new Sholo({
|
| 48 |
-
animate:
|
| 49 |
opacity: 0.8
|
| 50 |
});
|
| 51 |
sholo.highlight('.section__header');
|
|
|
|
| 9 |
</head>
|
| 10 |
<body>
|
| 11 |
<div class="page-wrap">
|
| 12 |
+
<section class="section__header" data-sholo="Hey welcome to presenter!">
|
| 13 |
<h1>Sholo</h1>
|
| 14 |
<p class="text-muted">A light-weight, no-dependency, vanilla JavaScript library to bring certain parts of page in spotlight</p>
|
| 15 |
<a href="#" class="btn btn__dark">Show an Example</a>
|
|
|
|
| 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 class="section__contributing">
|
| 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>
|
|
|
|
| 45 |
<script src="./assets/scripts/dist/sholo.js"></script>
|
| 46 |
<script>
|
| 47 |
const sholo = new Sholo({
|
| 48 |
+
animate: true,
|
| 49 |
opacity: 0.8
|
| 50 |
});
|
| 51 |
sholo.highlight('.section__header');
|