2018-03-31 03:30:30 +08:00
|
|
|
import {Injectable} from '@angular/core';
|
2019-03-03 17:30:12 +08:00
|
|
|
import {Event} from '../../../../common/event/Event';
|
|
|
|
import {PageHelper} from '../../model/page.helper';
|
2017-03-26 04:59:30 +08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class OverlayService {
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
OnOverlayChange = new Event<boolean>();
|
|
|
|
private scrollWidth: number = null;
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public showOverlay() {
|
2018-05-10 01:37:21 +08:00
|
|
|
// disable scrolling
|
2018-05-10 01:56:02 +08:00
|
|
|
PageHelper.hideScrollY();
|
2017-06-11 04:32:56 +08:00
|
|
|
this.OnOverlayChange.trigger(true);
|
|
|
|
}
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
public hideOverlay() {
|
2018-05-10 01:56:02 +08:00
|
|
|
PageHelper.showScrollY();
|
2017-06-11 04:32:56 +08:00
|
|
|
this.OnOverlayChange.trigger(false);
|
|
|
|
}
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
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
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
document.body.appendChild(outer);
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2018-05-10 01:37:21 +08:00
|
|
|
const widthNoScroll = outer.offsetWidth;
|
2017-06-11 04:32:56 +08:00
|
|
|
// force scrollbars
|
2018-03-31 03:30:30 +08:00
|
|
|
outer.style.overflowY = 'scroll';
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
// 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%';
|
2017-06-11 04:32:56 +08:00
|
|
|
outer.appendChild(inner);
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2018-05-10 01:37:21 +08:00
|
|
|
const widthWithScroll = inner.offsetWidth;
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
// remove divs
|
|
|
|
outer.parentNode.removeChild(outer);
|
|
|
|
this.scrollWidth = widthNoScroll - widthWithScroll;
|
2017-03-26 04:59:30 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
return this.scrollWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
getPhantomScrollbarWidth() {
|
2018-05-10 01:56:02 +08:00
|
|
|
if (!PageHelper.isScrollYVisible()) {
|
2017-06-11 04:32:56 +08:00
|
|
|
return this.getScrollbarWidth();
|
2017-03-26 04:59:30 +08:00
|
|
|
}
|
2017-06-11 04:32:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2017-03-26 04:59:30 +08:00
|
|
|
|
|
|
|
}
|