Add JSDoc
Browse files- assets/scripts/src/element.js +22 -6
- assets/scripts/src/overlay.js +21 -17
- assets/scripts/src/popover.js +18 -6
- assets/scripts/src/position.js +4 -4
- assets/scripts/src/sholo.js +1 -1
assets/scripts/src/element.js
CHANGED
|
@@ -7,12 +7,12 @@ import Position from './position';
|
|
| 7 |
export default class Element {
|
| 8 |
/**
|
| 9 |
* DOM element object
|
| 10 |
-
* @param node
|
| 11 |
-
* @param options
|
| 12 |
-
* @param popover
|
| 13 |
-
* @param overlay
|
| 14 |
-
* @param window
|
| 15 |
-
* @param document
|
| 16 |
*/
|
| 17 |
constructor(node, options, popover, overlay, window, document) {
|
| 18 |
this.node = node;
|
|
@@ -43,6 +43,10 @@ export default class Element {
|
|
| 43 |
return { x, y };
|
| 44 |
}
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
isInView() {
|
| 47 |
let top = this.node.offsetTop;
|
| 48 |
let left = this.node.offsetLeft;
|
|
@@ -65,6 +69,9 @@ export default class Element {
|
|
| 65 |
);
|
| 66 |
}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
bringInView() {
|
| 69 |
if (this.isInView()) {
|
| 70 |
return;
|
|
@@ -127,6 +134,9 @@ export default class Element {
|
|
| 127 |
this.showPopover();
|
| 128 |
}
|
| 129 |
|
|
|
|
|
|
|
|
|
|
| 130 |
onHighlighted() {
|
| 131 |
if (this.popover) {
|
| 132 |
this.showPopover();
|
|
@@ -152,12 +162,18 @@ export default class Element {
|
|
| 152 |
}
|
| 153 |
}
|
| 154 |
|
|
|
|
|
|
|
|
|
|
| 155 |
showPopover() {
|
| 156 |
const position = this.getCalculatedPosition();
|
| 157 |
|
| 158 |
this.popover.show(position);
|
| 159 |
}
|
| 160 |
|
|
|
|
|
|
|
|
|
|
| 161 |
getFullPageSize() {
|
| 162 |
// eslint-disable-next-line prefer-destructuring
|
| 163 |
const body = this.document.body;
|
|
|
|
| 7 |
export default class Element {
|
| 8 |
/**
|
| 9 |
* DOM element object
|
| 10 |
+
* @param {Node} node
|
| 11 |
+
* @param {Object} options
|
| 12 |
+
* @param {Popover} popover
|
| 13 |
+
* @param {Overlay} overlay
|
| 14 |
+
* @param {Window} window
|
| 15 |
+
* @param {Document} document
|
| 16 |
*/
|
| 17 |
constructor(node, options, popover, overlay, window, document) {
|
| 18 |
this.node = node;
|
|
|
|
| 43 |
return { x, y };
|
| 44 |
}
|
| 45 |
|
| 46 |
+
/**
|
| 47 |
+
* Checks if the current element is visible in viewport
|
| 48 |
+
* @returns {boolean}
|
| 49 |
+
*/
|
| 50 |
isInView() {
|
| 51 |
let top = this.node.offsetTop;
|
| 52 |
let left = this.node.offsetLeft;
|
|
|
|
| 69 |
);
|
| 70 |
}
|
| 71 |
|
| 72 |
+
/**
|
| 73 |
+
* Brings the element to middle of the view port if not in view
|
| 74 |
+
*/
|
| 75 |
bringInView() {
|
| 76 |
if (this.isInView()) {
|
| 77 |
return;
|
|
|
|
| 134 |
this.showPopover();
|
| 135 |
}
|
| 136 |
|
| 137 |
+
/**
|
| 138 |
+
* Is called when the element has been successfully highlighted
|
| 139 |
+
*/
|
| 140 |
onHighlighted() {
|
| 141 |
if (this.popover) {
|
| 142 |
this.showPopover();
|
|
|
|
| 162 |
}
|
| 163 |
}
|
| 164 |
|
| 165 |
+
/**
|
| 166 |
+
* Shows the popover on the current element
|
| 167 |
+
*/
|
| 168 |
showPopover() {
|
| 169 |
const position = this.getCalculatedPosition();
|
| 170 |
|
| 171 |
this.popover.show(position);
|
| 172 |
}
|
| 173 |
|
| 174 |
+
/**
|
| 175 |
+
* @returns {{height: number, width: number}}
|
| 176 |
+
*/
|
| 177 |
getFullPageSize() {
|
| 178 |
// eslint-disable-next-line prefer-destructuring
|
| 179 |
const body = this.document.body;
|
assets/scripts/src/overlay.js
CHANGED
|
@@ -7,9 +7,9 @@ import { ID_OVERLAY, OVERLAY_ZINDEX } from './constants';
|
|
| 7 |
*/
|
| 8 |
export default class Overlay {
|
| 9 |
/**
|
| 10 |
-
* @param options
|
| 11 |
-
* @param window
|
| 12 |
-
* @param document
|
| 13 |
*/
|
| 14 |
constructor(options, window, document) {
|
| 15 |
this.options = options;
|
|
@@ -56,8 +56,8 @@ export default class Overlay {
|
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Highlights the dom element on the screen
|
| 59 |
-
* @param element
|
| 60 |
-
* @param animate
|
| 61 |
*/
|
| 62 |
highlight(element, animate = true) {
|
| 63 |
if (!element || !element.node) {
|
|
@@ -124,7 +124,7 @@ export default class Overlay {
|
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
-
* `draw` is called for
|
| 128 |
* filled overlay on body (i.e. while removing existing highlight if any) and
|
| 129 |
* Slowly eases towards the item to be selected.
|
| 130 |
*/
|
|
@@ -200,6 +200,10 @@ export default class Overlay {
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
hasPositionHighlighted() {
|
| 204 |
return this.positionToHighlight.equals(this.highlightedPosition) &&
|
| 205 |
this.overlayAlpha > (this.options.opacity - 0.05);
|
|
@@ -210,10 +214,10 @@ export default class Overlay {
|
|
| 210 |
* i.e. cuts the chunk of layout which is over the element
|
| 211 |
* to be highlighted
|
| 212 |
*
|
| 213 |
-
* @param posX
|
| 214 |
-
* @param posY
|
| 215 |
-
* @param width
|
| 216 |
-
* @param height
|
| 217 |
*/
|
| 218 |
removeCloak({
|
| 219 |
posX = 0,
|
|
@@ -228,10 +232,10 @@ export default class Overlay {
|
|
| 228 |
* Adds the overlay i.e. to cover the given
|
| 229 |
* position with dark overlay
|
| 230 |
*
|
| 231 |
-
* @param posX
|
| 232 |
-
* @param posY
|
| 233 |
-
* @param width
|
| 234 |
-
* @param height
|
| 235 |
*/
|
| 236 |
addCloak({
|
| 237 |
posX = 0,
|
|
@@ -246,8 +250,8 @@ export default class Overlay {
|
|
| 246 |
/**
|
| 247 |
* Sets the size for the overlay
|
| 248 |
*
|
| 249 |
-
* @param width
|
| 250 |
-
* @param height
|
| 251 |
*/
|
| 252 |
setSize(width = null, height = null) {
|
| 253 |
// By default it is going to cover the whole page and then we will
|
|
@@ -260,7 +264,7 @@ export default class Overlay {
|
|
| 260 |
* Refreshes the overlay i.e. sets the size according to current window size
|
| 261 |
* And moves the highlight around if necessary
|
| 262 |
*
|
| 263 |
-
* @param animate
|
| 264 |
*/
|
| 265 |
refresh(animate = true) {
|
| 266 |
this.setSize();
|
|
|
|
| 7 |
*/
|
| 8 |
export default class Overlay {
|
| 9 |
/**
|
| 10 |
+
* @param {Object} options
|
| 11 |
+
* @param {Window} window
|
| 12 |
+
* @param {Document} document
|
| 13 |
*/
|
| 14 |
constructor(options, window, document) {
|
| 15 |
this.options = options;
|
|
|
|
| 56 |
|
| 57 |
/**
|
| 58 |
* Highlights the dom element on the screen
|
| 59 |
+
* @param {Element} element
|
| 60 |
+
* @param {boolean} animate
|
| 61 |
*/
|
| 62 |
highlight(element, animate = true) {
|
| 63 |
if (!element || !element.node) {
|
|
|
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
+
* `draw` is called for every frame . Puts back the
|
| 128 |
* filled overlay on body (i.e. while removing existing highlight if any) and
|
| 129 |
* Slowly eases towards the item to be selected.
|
| 130 |
*/
|
|
|
|
| 200 |
}
|
| 201 |
}
|
| 202 |
|
| 203 |
+
/**
|
| 204 |
+
* Checks if there as any position highlighted
|
| 205 |
+
* @returns {boolean}
|
| 206 |
+
*/
|
| 207 |
hasPositionHighlighted() {
|
| 208 |
return this.positionToHighlight.equals(this.highlightedPosition) &&
|
| 209 |
this.overlayAlpha > (this.options.opacity - 0.05);
|
|
|
|
| 214 |
* i.e. cuts the chunk of layout which is over the element
|
| 215 |
* to be highlighted
|
| 216 |
*
|
| 217 |
+
* @param {number} posX
|
| 218 |
+
* @param {number} posY
|
| 219 |
+
* @param {number} width
|
| 220 |
+
* @param {number} height
|
| 221 |
*/
|
| 222 |
removeCloak({
|
| 223 |
posX = 0,
|
|
|
|
| 232 |
* Adds the overlay i.e. to cover the given
|
| 233 |
* position with dark overlay
|
| 234 |
*
|
| 235 |
+
* @param {number} posX
|
| 236 |
+
* @param {number} posY
|
| 237 |
+
* @param {number} width
|
| 238 |
+
* @param {number} height
|
| 239 |
*/
|
| 240 |
addCloak({
|
| 241 |
posX = 0,
|
|
|
|
| 250 |
/**
|
| 251 |
* Sets the size for the overlay
|
| 252 |
*
|
| 253 |
+
* @param {number|null} width
|
| 254 |
+
* @param {number|null} height
|
| 255 |
*/
|
| 256 |
setSize(width = null, height = null) {
|
| 257 |
// By default it is going to cover the whole page and then we will
|
|
|
|
| 264 |
* Refreshes the overlay i.e. sets the size according to current window size
|
| 265 |
* And moves the highlight around if necessary
|
| 266 |
*
|
| 267 |
+
* @param {boolean} animate
|
| 268 |
*/
|
| 269 |
refresh(animate = true) {
|
| 270 |
this.setSize();
|
assets/scripts/src/popover.js
CHANGED
|
@@ -14,6 +14,11 @@ import {
|
|
| 14 |
* Popover that is displayed on top of the highlighted element
|
| 15 |
*/
|
| 16 |
export default class Popover extends Element {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
constructor(options, window, document) {
|
| 18 |
super();
|
| 19 |
|
|
@@ -35,6 +40,9 @@ export default class Popover extends Element {
|
|
| 35 |
this.hide();
|
| 36 |
}
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
makeNode() {
|
| 39 |
let popover = this.document.getElementById(ID_POPOVER);
|
| 40 |
if (!popover) {
|
|
@@ -65,6 +73,10 @@ export default class Popover extends Element {
|
|
| 65 |
return div.firstChild;
|
| 66 |
}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
getSize() {
|
| 69 |
return {
|
| 70 |
height: Math.max(this.node.scrollHeight, this.node.offsetHeight),
|
|
@@ -91,7 +103,7 @@ export default class Popover extends Element {
|
|
| 91 |
|
| 92 |
/**
|
| 93 |
* Shows the popover at the given position
|
| 94 |
-
* @param position
|
| 95 |
*/
|
| 96 |
show(position) {
|
| 97 |
this.reset();
|
|
@@ -154,7 +166,7 @@ export default class Popover extends Element {
|
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Shows the popover on the left of the given position
|
| 157 |
-
* @param elementPosition
|
| 158 |
*/
|
| 159 |
positionOnLeft(elementPosition) {
|
| 160 |
const popoverWidth = this.getSize().width;
|
|
@@ -170,7 +182,7 @@ export default class Popover extends Element {
|
|
| 170 |
|
| 171 |
/**
|
| 172 |
* Shows the popover on the right of the given position
|
| 173 |
-
* @param elementPosition
|
| 174 |
*/
|
| 175 |
positionOnRight(elementPosition) {
|
| 176 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
@@ -185,7 +197,7 @@ export default class Popover extends Element {
|
|
| 185 |
|
| 186 |
/**
|
| 187 |
* Shows the popover on the top of the given position
|
| 188 |
-
* @param elementPosition
|
| 189 |
*/
|
| 190 |
positionOnTop(elementPosition) {
|
| 191 |
const popoverHeight = this.getSize().height;
|
|
@@ -201,7 +213,7 @@ export default class Popover extends Element {
|
|
| 201 |
|
| 202 |
/**
|
| 203 |
* Shows the popover on the bottom of the given position
|
| 204 |
-
* @param elementPosition
|
| 205 |
*/
|
| 206 |
positionOnBottom(elementPosition) {
|
| 207 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
@@ -218,7 +230,7 @@ export default class Popover extends Element {
|
|
| 218 |
* Automatically positions the popover around the given position
|
| 219 |
* such that the element and popover remain in view
|
| 220 |
* @todo add the left and right positioning decisions
|
| 221 |
-
* @param elementPosition
|
| 222 |
*/
|
| 223 |
autoPosition(elementPosition) {
|
| 224 |
const pageSize = this.getFullPageSize();
|
|
|
|
| 14 |
* Popover that is displayed on top of the highlighted element
|
| 15 |
*/
|
| 16 |
export default class Popover extends Element {
|
| 17 |
+
/**
|
| 18 |
+
* @param {Object} options
|
| 19 |
+
* @param {Window} window
|
| 20 |
+
* @param {Document} document
|
| 21 |
+
*/
|
| 22 |
constructor(options, window, document) {
|
| 23 |
super();
|
| 24 |
|
|
|
|
| 40 |
this.hide();
|
| 41 |
}
|
| 42 |
|
| 43 |
+
/**
|
| 44 |
+
* Prepares the dom element for popover
|
| 45 |
+
*/
|
| 46 |
makeNode() {
|
| 47 |
let popover = this.document.getElementById(ID_POPOVER);
|
| 48 |
if (!popover) {
|
|
|
|
| 73 |
return div.firstChild;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
/**
|
| 77 |
+
* Gets the size for popover
|
| 78 |
+
* @returns {{height: number, width: number}}
|
| 79 |
+
*/
|
| 80 |
getSize() {
|
| 81 |
return {
|
| 82 |
height: Math.max(this.node.scrollHeight, this.node.offsetHeight),
|
|
|
|
| 103 |
|
| 104 |
/**
|
| 105 |
* Shows the popover at the given position
|
| 106 |
+
* @param {Position} position
|
| 107 |
*/
|
| 108 |
show(position) {
|
| 109 |
this.reset();
|
|
|
|
| 166 |
|
| 167 |
/**
|
| 168 |
* Shows the popover on the left of the given position
|
| 169 |
+
* @param {Position} elementPosition
|
| 170 |
*/
|
| 171 |
positionOnLeft(elementPosition) {
|
| 172 |
const popoverWidth = this.getSize().width;
|
|
|
|
| 182 |
|
| 183 |
/**
|
| 184 |
* Shows the popover on the right of the given position
|
| 185 |
+
* @param {Position} elementPosition
|
| 186 |
*/
|
| 187 |
positionOnRight(elementPosition) {
|
| 188 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
|
|
| 197 |
|
| 198 |
/**
|
| 199 |
* Shows the popover on the top of the given position
|
| 200 |
+
* @param {Position} elementPosition
|
| 201 |
*/
|
| 202 |
positionOnTop(elementPosition) {
|
| 203 |
const popoverHeight = this.getSize().height;
|
|
|
|
| 213 |
|
| 214 |
/**
|
| 215 |
* Shows the popover on the bottom of the given position
|
| 216 |
+
* @param {Position} elementPosition
|
| 217 |
*/
|
| 218 |
positionOnBottom(elementPosition) {
|
| 219 |
const popoverMargin = this.options.padding + 10; // adding 10 to give it a little distance from the element
|
|
|
|
| 230 |
* Automatically positions the popover around the given position
|
| 231 |
* such that the element and popover remain in view
|
| 232 |
* @todo add the left and right positioning decisions
|
| 233 |
+
* @param {Position} elementPosition
|
| 234 |
*/
|
| 235 |
autoPosition(elementPosition) {
|
| 236 |
const pageSize = this.getFullPageSize();
|
assets/scripts/src/position.js
CHANGED
|
@@ -4,10 +4,10 @@
|
|
| 4 |
*/
|
| 5 |
export default class Position {
|
| 6 |
/**
|
| 7 |
-
* @param left
|
| 8 |
-
* @param top
|
| 9 |
-
* @param right
|
| 10 |
-
* @param bottom
|
| 11 |
*/
|
| 12 |
constructor({
|
| 13 |
left = 0,
|
|
|
|
| 4 |
*/
|
| 5 |
export default class Position {
|
| 6 |
/**
|
| 7 |
+
* @param {number} left
|
| 8 |
+
* @param {number} top
|
| 9 |
+
* @param {number} right
|
| 10 |
+
* @param {number} bottom
|
| 11 |
*/
|
| 12 |
constructor({
|
| 13 |
left = 0,
|
assets/scripts/src/sholo.js
CHANGED
|
@@ -18,7 +18,7 @@ import {
|
|
| 18 |
*/
|
| 19 |
export default class Sholo {
|
| 20 |
/**
|
| 21 |
-
* @param options
|
| 22 |
*/
|
| 23 |
constructor(options = {}) {
|
| 24 |
this.options = Object.assign({
|
|
|
|
| 18 |
*/
|
| 19 |
export default class Sholo {
|
| 20 |
/**
|
| 21 |
+
* @param {Object} options
|
| 22 |
*/
|
| 23 |
constructor(options = {}) {
|
| 24 |
this.options = Object.assign({
|