Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few ideas for fluentRevealNavbar.uc.js #77

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Changes from 13 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d7bc621
Fix issue of script non-working for me on Firefox 115
emvaized Jul 22, 2023
0cc13b7
Add option to cache nav bar buttons
emvaized Jul 22, 2023
0f5df53
Add option to filter out mouse events too far from navbar
emvaized Jul 22, 2023
e45dba3
Added variable to store cached buttons
emvaized Jul 22, 2023
130957e
Changed default color to browser navbar button hover
emvaized Jul 22, 2023
293cc72
Add option to apply the effect to url bar as well
emvaized Jul 22, 2023
75f9e8d
Remove unused scroll listener
emvaized Jul 22, 2023
ab69194
Added comment about the change
emvaized Jul 22, 2023
a0dec4f
Don't apply effect to focused url bar
emvaized Jul 22, 2023
aeceba5
Add comment and some padding to make sure effect clears out
emvaized Jul 22, 2023
73c0482
Clear all effects once when cursor leaves the interactive zone
emvaized Jul 22, 2023
77bf366
Changed cacheButtons default value to prevent unexpected behavior for…
emvaized Jul 22, 2023
8126494
Bring back "scroll" event listener (as I figured out why it was there)
emvaized Jul 23, 2023
7af0251
Move cached buttons from static to script scope
emvaized Jul 23, 2023
97905a7
Remove console log and commented lines
emvaized Jul 23, 2023
d1091d5
Added alternative default color
emvaized Jul 23, 2023
94dc10c
Better selector for url background
emvaized Jul 23, 2023
2179e71
Change area selector for url bar
emvaized Jul 23, 2023
4586237
Fixed comment
emvaized Jul 23, 2023
a2cfeb5
Fix for bookmarks
emvaized Jul 23, 2023
0c82178
Changed pointer events check to use getComputedStyle(el)
emvaized Jul 23, 2023
af6d576
Use this._toolbarButtons for storing cached buttons
emvaized Jul 23, 2023
96f3ba2
Change static padding to dynamic + cache browser element
emvaized Jul 23, 2023
4cf3620
Fixed typo
emvaized Jul 23, 2023
aeb10b2
Removed old comment
emvaized Jul 25, 2023
cd09975
Changed default "filterDy" value to false
emvaized Jul 25, 2023
0c96706
Code cleanup
emvaized Jul 25, 2023
819fd64
Removed "!area" check
emvaized Jul 25, 2023
91c0217
Removed "window." part
emvaized Jul 25, 2023
e2aa84f
Removed absolete comment
emvaized Jul 25, 2023
3fafeff
Moved "this_someEffectsApplied" assignments to the bottom
emvaized Jul 25, 2023
36a2814
Removed unused "placesToolbarItems getter"
emvaized Jul 25, 2023
80ac4bb
Removed extra line on bottom
emvaized Jul 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 57 additions & 9 deletions JS/fluentRevealNavbar.uc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,32 @@
// if true, show the effect on bookmarks on the toolbar
includeBookmarks: true,

// if ture, show the effect on the urlbar as well
emvaized marked this conversation as resolved.
Show resolved Hide resolved
includeUrlBar: true,

// the color of the gradient. default is sort of a faint baby blue. you may prefer just white, e.g. hsla(0, 0%, 100%, 0.05)
lightColor: "hsla(224, 100%, 80%, 0.15)",
// lightColor: "hsla(224, 100%, 80%, 0.15)",
emvaized marked this conversation as resolved.
Show resolved Hide resolved
emvaized marked this conversation as resolved.
Show resolved Hide resolved

// the color of the gradient. default is the browser's color of navbar button's hover
lightColor: "var(--button-hover-bgcolor)",
emvaized marked this conversation as resolved.
Show resolved Hide resolved

// how wide the radial gradient is.
gradientSize: 50,

// whether to show an additional light burst when clicking an element. (not recommended)
clickEffect: false,

// don't process mouse movements greater than {gradientSize}px from top of the screen, in order to reduce system load.
// disable if you modified the ui to have toolbar buttons on different side of the screen (left, right or bottom)
filterDy: true,
aminomancer marked this conversation as resolved.
Show resolved Hide resolved
emvaized marked this conversation as resolved.
Show resolved Hide resolved

// looks for all toolbar buttons only once on script startup — reduces system load, but requires browser restart if toolbar buttons were changed
cacheButtons: false,
};

// store cached navbar buttons
static buttons;
emvaized marked this conversation as resolved.
Show resolved Hide resolved

// instantiate the handler for a given window
constructor() {
this._options = FluentRevealEffect.options;
Expand All @@ -38,15 +54,20 @@

// get all the toolbar buttons in the navbar, in iterable form
get toolbarButtons() {
let buttons = Array.from(
gNavToolbox.querySelectorAll(".toolbarbutton-1")
);
if (this._options.includeBookmarks) {
buttons = buttons.concat(
Array.from(this.placesToolbarItems.querySelectorAll(".bookmark-item"))
if (!this.buttons || this._options.cacheButtons == false) {
this.buttons = Array.from(
gNavToolbox.querySelectorAll(".toolbarbutton-1")
);
if (this._options.includeUrlBar) {
this.buttons.push(gNavToolbox.querySelector("#urlbar-background"));
}
if (this._options.includeBookmarks) {
this.buttons = this.buttons.concat(
Array.from(this.placesToolbarItems.querySelectorAll(".bookmark-item"))
);
}
emvaized marked this conversation as resolved.
Show resolved Hide resolved
}
return buttons;
return this.buttons;
}

get placesToolbarItems() {
emvaized marked this conversation as resolved.
Show resolved Hide resolved
emvaized marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -63,6 +84,13 @@
* @param {object} e (event)
*/
handleEvent(e) {
/// filter out mouse events which are too far from toolbar to cause any actual redraw
/// value is {gradientSize} + some additional padding to make sure effect fully clears out
if (this._options.filterDy && e.clientY > this._options.gradientSize + 25) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (this._options.filterDy && e.clientY > this._options.gradientSize + 25) {
if (
this._options.filterDy &&
e.clientY >
document.getElementById("browser").getBoundingClientRect().y +
this._options.gradientSize
) {

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to change the comments too since this changes the meaning of filterDy.
It's filtering out mouse events that are more than {gradientSize} pixels below the toolbar.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning for this is that the toolbar height is variable, not fixed. For example, Ctrl+Shift+B makes the bookmarks toolbar appear, which significantly increases its height. There are also infobars that can rarely appear below the main toolbar, above the browser content viewer.

if (this.someEffectsApplied) this.clearEffectsForAll();
return;
}

requestAnimationFrame(time => {
switch (e.type) {
case "scroll":
Expand Down Expand Up @@ -139,6 +167,13 @@
? el
: el.querySelector(".toolbarbutton-badge-stack") ||
el.querySelector(".toolbarbutton-icon");
if (!area) area = el;
emvaized marked this conversation as resolved.
Show resolved Hide resolved

// don't apply effect to focused url bar
if (this._options.includeUrlBar && el.id == 'urlbar-background' && window.gURLBar.focused) {
emvaized marked this conversation as resolved.
Show resolved Hide resolved
return this.clearEffect(area);
}

let areaStyle = getComputedStyle(area);
if (
areaStyle.display == "none" ||
Expand All @@ -149,7 +184,9 @@
area = el.querySelector(".toolbarbutton-text");
}

if (el.disabled || areaStyle.pointerEvents == "none") {
// previous pointerEvents check may break the effect in FF 115
emvaized marked this conversation as resolved.
Show resolved Hide resolved
//if (el.disabled || areaStyle.pointerEvents == "none") {
if (el.disabled) {
emvaized marked this conversation as resolved.
Show resolved Hide resolved
return this.clearEffect(area);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code below needs to be fixed, or there is a bug when you move the mouse around the top of the page on about:config or about:preferences, etc. It's because they are in the parent process so their true event targets pass all the way up to the chrome window listener (normally the event target we see would be <browser>).

It's better if we just use MousePosTracker.

      let x = MousePosTracker._x - this.getOffset(area).left - window.scrollX;
      let y = MousePosTracker._y - this.getOffset(area).top - window.scrollY;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't know about this bug, so my first thought was this check was added just for UX convenience. So now this should be handled by new getComputedStyle(el).pointerEvents == "none" check, right?

Expand Down Expand Up @@ -232,6 +269,17 @@
this._options.is_pressed = false;
el.style.removeProperty("background-image");
}

/**
* invoked once when {filterDy} option enabled, and cursor leaves the interactive area
*/
clearEffectsForAll() {
console.log('clear all effects');
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There shouldn't be logs

this.someEffectsApplied = false;
this.toolbarButtons.forEach(button =>
this.clearEffect(button)
);
}
}

function init() {
Expand Down