Browse Source

Pull request #32: BI-65305 fix: popup方向判断在scale影响下错误

Merge in PG2/plugin-bi-screen-adaptive from ~FAY/plugin-bi-screen-adaptive:release/10.0 to release/10.0

* commit '9bf65c63211f8c1efe84d4693c71b528f79c7e61':
  BI-65305 fix: popup方向判断在scale影响下错误
release/10.0
fay 5 years ago
parent
commit
ee5a25aa3a
  1. 20
      src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js
  2. 20
      src/main/resources/com/finebi/plugin/web/scripts/entry.js

20
src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js

@ -191,8 +191,8 @@
offsetTop = 0; offsetTop = 0;
do{ do{
offsetLeft += el.offsetLeft; offsetLeft += ( BI.isIE() ? window.getComputedStyle(el).position === "fixed" ? el.offsetLeft / scale : el.offsetLeft : el.offsetLeft );
offsetTop += el.offsetTop; offsetTop += ( BI.isIE() ? window.getComputedStyle(el).position === "fixed" ? el.offsetTop / scale : el.offsetTop : el.offsetTop );
el = el.offsetParent; el = el.offsetParent;
} while( el ); } while( el );
@ -231,12 +231,16 @@
} else { } else {
var cBounds = this.popupView.element[0].getBoundingClientRect(); var cBounds = this.popupView.element[0].getBoundingClientRect();
var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect(); var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect();
if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) >= parseInt(pBounds.left)) { if (cBounds.left + cBounds.width > body.clientWidth * scale) {
this.popupView.element[0].style.top = (parseInt(pBounds.top) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(this.popupView.element[0].style.left) * scale) + "px";
} else if (this.options.direction === "right") {
this.popupView.element[0].style.top = (parseInt(pBounds.top) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.right) + transformY - document.body.scrollTop) + "px";
} else if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) >= parseInt(pBounds.left)) {
this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px";
} }else if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) < parseInt(pBounds.left)) {
if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) < parseInt(pBounds.left)) {
this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px";
} }
@ -275,7 +279,9 @@
injectSearch.call(this); injectSearch.call(this);
var self = this; var self = this;
if (this.popupView) { if (this.popupView) {
BI.nextTick(function () { BI.defer(function () {
self.popupView.element[0].parentElement.style.left = parseInt(self.popupView.element[0].parentElement.style.left) * scale + "px";
self.popupView.element[0].parentElement.style.top = parseInt(self.popupView.element[0].parentElement.style.top) * scale + "px";
self.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; self.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")";
self.popupView.element[0].parentElement.style.transformOrigin = "left top"; self.popupView.element[0].parentElement.style.transformOrigin = "left top";
}) })

20
src/main/resources/com/finebi/plugin/web/scripts/entry.js

@ -191,8 +191,8 @@
offsetTop = 0; offsetTop = 0;
do{ do{
offsetLeft += el.offsetLeft; offsetLeft += ( BI.isIE() ? window.getComputedStyle(el).position === "fixed" ? el.offsetLeft / scale : el.offsetLeft : el.offsetLeft );
offsetTop += el.offsetTop; offsetTop += ( BI.isIE() ? window.getComputedStyle(el).position === "fixed" ? el.offsetTop / scale : el.offsetTop : el.offsetTop );
el = el.offsetParent; el = el.offsetParent;
} while( el ); } while( el );
@ -231,12 +231,16 @@
} else { } else {
var cBounds = this.popupView.element[0].getBoundingClientRect(); var cBounds = this.popupView.element[0].getBoundingClientRect();
var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect(); var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect();
if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) >= parseInt(pBounds.left)) { if (cBounds.left + cBounds.width > body.clientWidth * scale) {
this.popupView.element[0].style.top = (parseInt(pBounds.top) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(this.popupView.element[0].style.left) * scale) + "px";
} else if (this.options.direction === "right") {
this.popupView.element[0].style.top = (parseInt(pBounds.top) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.right) + transformY - document.body.scrollTop) + "px";
} else if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) >= parseInt(pBounds.left)) {
this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px";
} }else if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) < parseInt(pBounds.left)) {
if (parseInt(cBounds.top) >= parseInt(pBounds.top) && parseInt(cBounds.left) < parseInt(pBounds.left)) {
this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.top = (parseInt(pBounds.bottom) + transformY - document.body.scrollTop) + "px";
this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; this.popupView.element[0].style.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px";
} }
@ -275,7 +279,9 @@
injectSearch.call(this); injectSearch.call(this);
var self = this; var self = this;
if (this.popupView) { if (this.popupView) {
BI.nextTick(function () { BI.defer(function () {
self.popupView.element[0].parentElement.style.left = parseInt(self.popupView.element[0].parentElement.style.left) * scale + "px";
self.popupView.element[0].parentElement.style.top = parseInt(self.popupView.element[0].parentElement.style.top) * scale + "px";
self.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; self.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")";
self.popupView.element[0].parentElement.style.transformOrigin = "left top"; self.popupView.element[0].parentElement.style.transformOrigin = "left top";
}) })

Loading…
Cancel
Save