1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/frontend/app/ui/gallery/overlay.service.ts

58 lines
1.4 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {Injectable} from '@angular/core';
import {Event} from '../../../../common/event/Event';
import {PageHelper} from '../../model/page.helper';
@Injectable()
export class OverlayService {
OnOverlayChange = new Event<boolean>();
private scrollWidth: number = null;
public showOverlay() {
2018-05-10 01:37:21 +08:00
// disable scrolling
2018-05-10 01:56:02 +08:00
PageHelper.hideScrollY();
this.OnOverlayChange.trigger(true);
}
public hideOverlay() {
2018-05-10 01:56:02 +08:00
PageHelper.showScrollY();
this.OnOverlayChange.trigger(false);
}
getScrollbarWidth() {
if (this.scrollWidth == null) {
2018-05-10 01:37:21 +08:00
const outer = document.createElement('div');
2018-03-31 03:30:30 +08:00
outer.style.visibility = 'hidden';
outer.style.width = '100px';
outer.style.msOverflowStyle = 'scrollbar'; // needed for WinJS apps
document.body.appendChild(outer);
2018-05-10 01:37:21 +08:00
const widthNoScroll = outer.offsetWidth;
// force scrollbars
2018-03-31 03:30:30 +08:00
outer.style.overflowY = 'scroll';
// add innerdiv
2018-05-10 01:37:21 +08:00
const inner = document.createElement('div');
2018-03-31 03:30:30 +08:00
inner.style.width = '100%';
outer.appendChild(inner);
2018-05-10 01:37:21 +08:00
const widthWithScroll = inner.offsetWidth;
// remove divs
outer.parentNode.removeChild(outer);
this.scrollWidth = widthNoScroll - widthWithScroll;
}
return this.scrollWidth;
}
getPhantomScrollbarWidth() {
2018-05-10 01:56:02 +08:00
if (!PageHelper.isScrollYVisible()) {
return this.getScrollbarWidth();
}
return 0;
}
}