kamrify commited on
Commit
0aebd1a
·
1 Parent(s): fe79342

Add docs and allow modifying padding

Browse files
.eslintrc.json CHANGED
@@ -9,7 +9,10 @@
9
  "no-plusplus": "off",
10
  "no-cond-assign": "off",
11
  "func-names": "off",
12
- "no-param-reassign": ["off"],
13
- "max-len": "off"
 
 
 
14
  }
15
  }
 
9
  "no-plusplus": "off",
10
  "no-cond-assign": "off",
11
  "func-names": "off",
12
+ "no-param-reassign": [
13
+ "off"
14
+ ],
15
+ "max-len": "off",
16
+ "no-multi-spaces": "off"
17
  }
18
  }
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## spotlight-js
2
+ > Allows highlighting any element, adding feature introduction, adding hints
3
+
4
+ ## Highlighting Single Elements
5
+
6
+ ```javascript
7
+ const spotlight = new Spotlight({
8
+ opacity: 0.7, // opacity for the background
9
+ padding: 5, // padding around the element
10
+ });
11
+
12
+ spotlight.highlight('#some-element');
13
+ spotlight.clear();
14
+ ```
assets/scripts/src/overlay.js CHANGED
@@ -5,15 +5,17 @@ import Position from './position';
5
  * cutting out the visible part, animating between the sections etc
6
  */
7
  export default class Overlay {
8
- constructor({ opacity = 0.75 }) {
9
- this.opacity = opacity;
10
- this.overlayAlpha = 0;
11
- this.positionToHighlight = new Position({});
12
- this.highlightedPosition = new Position({});
13
- this.redrawAnimation = null;
14
- this.highlightedElement = null;
 
 
15
 
16
- this.draw = this.draw.bind(this);
17
 
18
  this.window = window;
19
  this.document = document;
@@ -101,10 +103,10 @@ export default class Overlay {
101
 
102
  // Remove the cloak from the position to highlight
103
  this.removeCloak({
104
- posX: this.highlightedPosition.left - window.scrollX - 5,
105
- posY: this.highlightedPosition.top - window.scrollY - 5,
106
- width: (this.highlightedPosition.right - this.highlightedPosition.left) + (5 * 2),
107
- height: (this.highlightedPosition.bottom - this.highlightedPosition.top) + (5 * 2),
108
  });
109
 
110
  if (canHighlight) {
 
5
  * cutting out the visible part, animating between the sections etc
6
  */
7
  export default class Overlay {
8
+ constructor({ opacity = 0.75, padding = 5 }) {
9
+ this.opacity = opacity; // Fixed opacity for the layover
10
+ this.padding = padding; // Padding around the highlighted item
11
+
12
+ this.overlayAlpha = 0; // Is used to animate the layover
13
+ this.positionToHighlight = new Position({}); // position at which layover is to be patched at
14
+ this.highlightedPosition = new Position({}); // position at which layover is patched currently
15
+ this.redrawAnimation = null; // used to cancel the redraw animation
16
+ this.highlightedElement = null; // currently highlighted dom element (instance of Element)
17
 
18
+ this.draw = this.draw.bind(this); // To pass the context of class, as it is to be used in redraw animation callback
19
 
20
  this.window = window;
21
  this.document = document;
 
103
 
104
  // Remove the cloak from the position to highlight
105
  this.removeCloak({
106
+ posX: this.highlightedPosition.left - window.scrollX - this.padding,
107
+ posY: this.highlightedPosition.top - window.scrollY - this.padding,
108
+ width: (this.highlightedPosition.right - this.highlightedPosition.left) + (this.padding * 2),
109
+ height: (this.highlightedPosition.bottom - this.highlightedPosition.top) + (this.padding * 2),
110
  });
111
 
112
  if (canHighlight) {
assets/scripts/src/sholo.js CHANGED
@@ -6,8 +6,11 @@ import './polyfill';
6
  * Plugin class that drives the plugin
7
  */
8
  export default class Sholo {
9
- constructor({ opacity = 0.75 } = {}) {
10
- this.overlay = new Overlay({ opacity });
 
 
 
11
  }
12
 
13
  highlight(selector) {
 
6
  * Plugin class that drives the plugin
7
  */
8
  export default class Sholo {
9
+ constructor({ opacity = 0.75, padding = 5 } = {}) {
10
+ this.overlay = new Overlay({
11
+ opacity,
12
+ padding,
13
+ });
14
  }
15
 
16
  highlight(selector) {