2017-03-26 04:59:30 +08:00
|
|
|
import {Injectable} from "@angular/core";
|
|
|
|
import {Event} from "../../../common/event/Event";
|
|
|
|
|
|
|
|
@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() {
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
//disable scrolling
|
2017-07-21 05:00:49 +08:00
|
|
|
document.getElementsByTagName('body')[0].style.overflowY = 'hidden';
|
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() {
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
document.getElementsByTagName('body')[0].style.overflowY = 'scroll';
|
|
|
|
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) {
|
2017-03-26 04:59:30 +08:00
|
|
|
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
let outer = document.createElement("div");
|
|
|
|
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
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
let widthNoScroll = outer.offsetWidth;
|
|
|
|
// force scrollbars
|
2017-07-21 05:00:49 +08:00
|
|
|
outer.style.overflowY = "scroll";
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
// add innerdiv
|
|
|
|
let inner = document.createElement("div");
|
|
|
|
inner.style.width = "100%";
|
|
|
|
outer.appendChild(inner);
|
2017-03-26 04:59:30 +08:00
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
let 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() {
|
2017-07-21 05:00:49 +08:00
|
|
|
if (document.getElementsByTagName('body')[0].style.overflowY == 'hidden') {
|
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
|
|
|
|
|
|
|
}
|