Skip to content

Commit

Permalink
Merge branch 'feature/lrc-script' into enhancement/23-add-tests-to-in…
Browse files Browse the repository at this point in the history
…crease-coverage-of-3.17

# Conflicts:
#	src/BeaconLrc.js
  • Loading branch information
wordpressfan committed Sep 9, 2024
2 parents 82e19b5 + 6463cee commit 9004d72
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/BeaconLrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

import BeaconUtils from "./Utils.js";
import BeaconManager from "./BeaconManager.js";

class BeaconLrc {
constructor(config, logger) {
Expand Down Expand Up @@ -53,7 +52,7 @@ class BeaconLrc {
const rect = element.getBoundingClientRect();
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
console.log( rect, scrollTop );
return Math.max(0, rect.top + scrollTop);
return Math.max(0, rect.top + scrollTop - BeaconUtils.getScreenHeight());
}

_skipElement(element) {
Expand Down Expand Up @@ -84,10 +83,10 @@ class BeaconLrc {
return;
}

const can_push_hash = element.parentElement && this._getElementDistance(element.parentElement) < this.config.lrc_threshold && distance > this.config.lrc_threshold;
const can_push_hash = element.parentElement && this._getElementDistance(element.parentElement) < this.config.lrc_threshold && distance >= this.config.lrc_threshold;

const color = can_push_hash ? "green" : distance === 0 ? "red" : "";
this.logger.logColoredMessage( `${'\t'.repeat(depth)}${element.tagName} (Depth: ${depth}, Distance from viewport top: ${distance}px)`, color );
this.logger.logColoredMessage( `${'\t'.repeat(depth)}${element.tagName} (Depth: ${depth}, Distance from viewport bottom: ${distance}px)`, color );

//const xpath = this._getXPath(element);
//console.log(`%c${'\t'.repeat(depth)}Xpath: ${xpath}`, style);
Expand Down
12 changes: 10 additions & 2 deletions src/Utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
'use strict';

class BeaconUtils {
static getScreenWidth() {
return window.innerWidth || document.documentElement.clientWidth;
}

static getScreenHeight() {
return window.innerHeight || document.documentElement.clientHeight;
}

static isNotValidScreensize( is_mobile, threshold ) {
const screenWidth = window.innerWidth || document.documentElement.clientWidth;
const screenHeight = window.innerHeight || document.documentElement.clientHeight;
const screenWidth = this.getScreenWidth();
const screenHeight = this.getScreenHeight();

const isNotValidForMobile = is_mobile &&
(screenWidth > threshold.width || screenHeight > threshold.height);
Expand Down

0 comments on commit 9004d72

Please sign in to comment.