-
-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New feature: mediaBrowse by wheel (#3606)
- Loading branch information
1 parent
586b4d2
commit 6814b73
Showing
4 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.res-wheel-media-browse { | ||
position: relative; | ||
width: 30px; | ||
height: 16px; | ||
margin-left: 4px; | ||
border-radius: 5px; | ||
cursor: crosshair; | ||
background-color: rgba(0, 0, 0, 0.24); | ||
overflow: hidden; | ||
|
||
&-gallery { | ||
position: absolute; | ||
width: 50%; | ||
height: 100%; | ||
right: 0; | ||
background-color: rgba(255, 0, 0, 0.24); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* @flow */ | ||
|
||
import { $ } from '../vendor'; | ||
import { Module } from '../core/module'; | ||
import * as Floater from './floater'; | ||
import * as KeyboardNav from './keyboardNav'; | ||
import * as SelectedEntry from './selectedEntry'; | ||
import * as SettingsNavigation from './settingsNavigation'; | ||
|
||
export const module: Module<*> = new Module('wheelBrowse'); | ||
|
||
module.moduleName = 'wheelBrowseName'; | ||
module.category = 'browsingCategory'; | ||
module.description = 'wheelBrowseDesc'; | ||
module.include = [ | ||
'linklist', | ||
]; | ||
|
||
module.go = () => { | ||
const wheelBrowseWidget = $('<div class="res-wheel-media-browse"></div>') | ||
.click(() => SettingsNavigation.loadSettingsPage(module.moduleID)) | ||
.get(0); | ||
const galleryPart = $('<div hidden class="res-wheel-media-browse-gallery"></div>') | ||
.appendTo(wheelBrowseWidget) | ||
.get(0); | ||
|
||
function updateGalleryPart(selected = SelectedEntry.selectedThing(), scrollDirection) { | ||
const expando = selected && selected.getEntryExpando(); | ||
|
||
galleryPart.hidden = !( | ||
expando && | ||
expando.media && | ||
expando.media.classList.contains('res-gallery-slideshow') && | ||
( | ||
!scrollDirection || | ||
( // Do not show the gallery scroll widget when at the end of the gallery | ||
!(scrollDirection === 'down' && expando.media.querySelector('[last-piece=true]')) && | ||
!(scrollDirection === 'up' && expando.media.querySelector('[first-piece=true]')) | ||
) | ||
) | ||
); | ||
} | ||
|
||
let isSelectionCause = false; | ||
|
||
function scrollWidget(target, scrollDirection) { | ||
if (target === wheelBrowseWidget) { | ||
isSelectionCause = true; | ||
if (scrollDirection === 'down') KeyboardNav.module.options.moveDown.callback(); | ||
else KeyboardNav.module.options.moveUp.callback(); | ||
isSelectionCause = false; | ||
} else if (target === galleryPart) { | ||
if (scrollDirection === 'down') KeyboardNav.module.options.nextGalleryImage.callback(); | ||
else KeyboardNav.module.options.previousGalleryImage.callback(); | ||
updateGalleryPart(undefined, scrollDirection); | ||
} | ||
} | ||
|
||
SelectedEntry.addListener((selected, unselected, options) => { | ||
// Avoid the floater disappearing when approaching the header, which may happen when using other scrollStyles | ||
if (isSelectionCause) options.scrollStyle = 'top'; | ||
|
||
updateGalleryPart(selected); | ||
}, 'beforeScroll'); | ||
|
||
wheelBrowseWidget.addEventListener('wheel', (e: WheelEvent) => { | ||
e.stopImmediatePropagation(); | ||
e.preventDefault(); | ||
scrollWidget(e.target, e.deltaY > 0 ? 'down' : 'up'); | ||
}); | ||
|
||
Floater.addElement(wheelBrowseWidget); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters