Browse Source

BI-55967 & BI-55751 & BI-55749 计算popup位置时用wrapper代替

release/10.0
Fay 5 years ago
parent
commit
7fbe0760fa
  1. 101
      src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js
  2. 101
      src/main/resources/com/finebi/plugin/web/scripts/entry.js

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

@ -17,9 +17,7 @@
var injectToolTipShow = null; var injectToolTipShow = null;
var injectBubblesShow = null; var injectBubblesShow = null;
var adjustHeight = BI.Combo.prototype.adjustHeight; var adjustHeight = BI.Combo.prototype.adjustHeight;
var injectOuterWidth = jQuery.fn.outerWidth; var originalRender = BI.Widget._renderEngine;
var injectOuterHeight = jQuery.fn.outerHeight;
var injectBounds = jQuery.fn.bounds;
var injectCreate = BI.createWidget; var injectCreate = BI.createWidget;
@ -61,21 +59,12 @@
wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
wrapper.style["-ms-transform-origin"] = "top left"; wrapper.style["-ms-transform-origin"] = "top left";
fixedContainer.style.height = (document.body.clientHeight / scale) + "px"; fixedContainer.style.height = (document.body.clientHeight / scale) + "px";
// html.style.backgroundColor = document.getElementsByClassName('bi-theme-dark').length === 0 ? "#2c3d59" : "#ffffff"; wrapper.style.overflowY = "hidden";
document.body.style.overflowX = "hidden";
document.body.style.overflowY = "auto";
html.style.backgroundColor = "#ffffff"; html.style.backgroundColor = "#ffffff";
// if (bounds.height * bounds.scale < html.clientHeight) {
// transformY = (html.clientHeight - bounds.height * bounds.scale) / 2;
// html.style.overflowY = "hidden";
// } else {
// transformY = 0;
// }
// document.body.style.height = (bounds.height * scale) + "px";
// document.body.style.overflow = "hidden";
// document.body.style.top = transformY + "px";
window.scale = window.devicePixelRatio * scale; window.scale = window.devicePixelRatio * scale;
// scaleFixed();
} }
// 取消缩放 // 取消缩放
@ -89,16 +78,12 @@
wrapper.style.overflowY = "hidden"; wrapper.style.overflowY = "hidden";
wrapper.style.top = ""; wrapper.style.top = "";
fixedContainer.style.height = "0px"; fixedContainer.style.height = "0px";
document.body.style.overflowX = "hidden";
document.body.style.overflowY = "hidden";
html.style.backgroundColor = "#ffffff"; html.style.backgroundColor = "#ffffff";
scale = 1; scale = 1;
// document.body.style.top = "0px";
// document.body.style.width = "";
// document.body.style.height = "";
// document.body.style.overflowY = "";
window.scale = window.devicePixelRatio / scale; window.scale = window.devicePixelRatio / scale;
// revertFixed();
} }
// 获取缩放倍数,原模板宽高 // 获取缩放倍数,原模板宽高
@ -203,9 +188,11 @@
} while( el ); } while( el );
var elm = elem; var elm = elem;
// 不知道该怎么写代码了,就这样了
if (!checkInPopupView(elm)) { if (!checkInPopupView(elm)) {
do{ do{
if (elm === document.body) {
break;
}
offsetLeft -= elm.scrollLeft || 0; offsetLeft -= elm.scrollLeft || 0;
offsetTop -= elm.scrollTop || 0; offsetTop -= elm.scrollTop || 0;
elm = elm.parentNode; elm = elm.parentNode;
@ -222,8 +209,6 @@
return correctEvent(injectEventFix.call(this, e)); return correctEvent(injectEventFix.call(this, e));
}; };
if (BI.isIE()) { if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = function (e) { BI.Combo.prototype.adjustHeight = function (e) {
adjustHeight.call(this, e); adjustHeight.call(this, e);
if (this.popupView) { if (this.popupView) {
@ -253,32 +238,6 @@
tooltip.element[0].style.transform = "scale(" + scale+ ")"; tooltip.element[0].style.transform = "scale(" + scale+ ")";
tooltip.element[0].style.transformOrigin = "top left"; tooltip.element[0].style.transformOrigin = "top left";
} }
// jQuery.fn.outerWidth = function () {
// var wdith = injectOuterWidth.apply(this, arguments);
// if (this[0] === document.body) {
// return wdith / scale;
// }
// return wdith;
// }
// jQuery.fn.outerHeight = function () {
// var height = injectOuterHeight.apply(this, arguments);
// if (this[0] === document.body) {
// return height / scale;
// }
// return height;
// }
// BI.DOM.getBottomPosition = function (combo, popup, extraHeight) {
// var el = combo.element;
// return {
// top: el.offset().top + el.outerHeight() * (1 - checkInPopupView(el[0]) ? scale : 0) + (extraHeight || 0)
// };
// }
// BI.DOM.getRightPosition = function (combo, popup, extraWidth) {
// var el = combo.element;
// return {
// left: el.offset().left + el.outerWidth() * (1-checkInPopupView(el[0]) ? scale : 0) + (extraWidth || 0)
// };
// }
} }
BI.createWidget = function () { BI.createWidget = function () {
@ -291,7 +250,19 @@
// Popovers // Popovers
BI.Popovers = new BI.PopoverController({render: fixedContainer}); BI.Popovers = new BI.PopoverController({render: fixedContainer});
// document.body.onmousedown = scaleFixed; //
BI.Widget.registerRenderEngine({
createElement: function (widget) {
if (widget === "body") {
return BI.$(wrapper);
}
return originalRender.createElement(widget);
},
createFragment: function () {
return originalRender.createFragment();
}
});
window.addEventListener('resize', updateScale); window.addEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
addListener(selectHandler); addListener(selectHandler);
@ -301,18 +272,16 @@
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; jQuery.fn.__isMouseInBounds__ = injectMouseInBounds;
jQuery.fn.offset = injectOffset; jQuery.fn.offset = injectOffset;
jQuery.event.fix = injectEventFix; jQuery.event.fix = injectEventFix;
// jQuery.fn.bounds = injectBounds;
if (BI.isIE()) { if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = adjustHeight; BI.Combo.prototype.adjustHeight = adjustHeight;
BI.Tooltips.show = injectToolTipShow; BI.Tooltips.show = injectToolTipShow;
BI.Bubbles.show = injectBubblesShow; BI.Bubbles.show = injectBubblesShow;
// jQuery.fn.outerWidth = injectOuterWidth;
// jQuery.fn.outerHeight = injectOuterHeight;
} }
BI.createWidget = injectCreate; BI.createWidget = injectCreate;
// Popovers // Popovers
BI.Popovers = new BI.PopoverController(); BI.Popovers = new BI.PopoverController();
BI.Widget.registerRenderEngine(originalRender);
document.body.onmousedown = null; document.body.onmousedown = null;
window.removeEventListener('resize', updateScale); window.removeEventListener('resize', updateScale);
@ -346,30 +315,6 @@
} }
} }
injectMouseMoveTracker(); injectMouseMoveTracker();
// popupview
// function scaleFixed() {
// if (BI.isIE()) {
// var fixedList = document.getElementsByClassName("bi-popup-view");
// BI.each(fixedList, function (i, el) {
// if (window.getComputedStyle(el).position === 'fixed') {
// el.style.transformOrigin = "top left";
// el.style.transform = "scale(" + scale + ")";
// }
// })
// }
// }
//
// function revertFixed() {
// if (BI.isIE()) {
// var fixedList = document.getElementsByClassName("bi-popup-view");
// BI.each(fixedList, function (i, el) {
// if (window.getComputedStyle(el).position === 'fixed') {
// el.style.transformOrigin = "";
// el.style.transform = "";
// }
// })
// }
// }
selectHandler(); selectHandler();
BI.config("bi.constant.dashboard.toolbar.left.items", function (config) { BI.config("bi.constant.dashboard.toolbar.left.items", function (config) {

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

@ -17,9 +17,7 @@
var injectToolTipShow = null; var injectToolTipShow = null;
var injectBubblesShow = null; var injectBubblesShow = null;
var adjustHeight = BI.Combo.prototype.adjustHeight; var adjustHeight = BI.Combo.prototype.adjustHeight;
var injectOuterWidth = jQuery.fn.outerWidth; var originalRender = BI.Widget._renderEngine;
var injectOuterHeight = jQuery.fn.outerHeight;
var injectBounds = jQuery.fn.bounds;
var injectCreate = BI.createWidget; var injectCreate = BI.createWidget;
@ -61,21 +59,12 @@
wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
wrapper.style["-ms-transform-origin"] = "top left"; wrapper.style["-ms-transform-origin"] = "top left";
fixedContainer.style.height = (document.body.clientHeight / scale) + "px"; fixedContainer.style.height = (document.body.clientHeight / scale) + "px";
// html.style.backgroundColor = document.getElementsByClassName('bi-theme-dark').length === 0 ? "#2c3d59" : "#ffffff"; wrapper.style.overflowY = "hidden";
document.body.style.overflowX = "hidden";
document.body.style.overflowY = "auto";
html.style.backgroundColor = "#ffffff"; html.style.backgroundColor = "#ffffff";
// if (bounds.height * bounds.scale < html.clientHeight) {
// transformY = (html.clientHeight - bounds.height * bounds.scale) / 2;
// html.style.overflowY = "hidden";
// } else {
// transformY = 0;
// }
// document.body.style.height = (bounds.height * scale) + "px";
// document.body.style.overflow = "hidden";
// document.body.style.top = transformY + "px";
window.scale = window.devicePixelRatio * scale; window.scale = window.devicePixelRatio * scale;
// scaleFixed();
} }
// 取消缩放 // 取消缩放
@ -89,16 +78,12 @@
wrapper.style.overflowY = "hidden"; wrapper.style.overflowY = "hidden";
wrapper.style.top = ""; wrapper.style.top = "";
fixedContainer.style.height = "0px"; fixedContainer.style.height = "0px";
document.body.style.overflowX = "hidden";
document.body.style.overflowY = "hidden";
html.style.backgroundColor = "#ffffff"; html.style.backgroundColor = "#ffffff";
scale = 1; scale = 1;
// document.body.style.top = "0px";
// document.body.style.width = "";
// document.body.style.height = "";
// document.body.style.overflowY = "";
window.scale = window.devicePixelRatio / scale; window.scale = window.devicePixelRatio / scale;
// revertFixed();
} }
// 获取缩放倍数,原模板宽高 // 获取缩放倍数,原模板宽高
@ -203,9 +188,11 @@
} while( el ); } while( el );
var elm = elem; var elm = elem;
// 不知道该怎么写代码了,就这样了
if (!checkInPopupView(elm)) { if (!checkInPopupView(elm)) {
do{ do{
if (elm === document.body) {
break;
}
offsetLeft -= elm.scrollLeft || 0; offsetLeft -= elm.scrollLeft || 0;
offsetTop -= elm.scrollTop || 0; offsetTop -= elm.scrollTop || 0;
elm = elm.parentNode; elm = elm.parentNode;
@ -222,8 +209,6 @@
return correctEvent(injectEventFix.call(this, e)); return correctEvent(injectEventFix.call(this, e));
}; };
if (BI.isIE()) { if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = function (e) { BI.Combo.prototype.adjustHeight = function (e) {
adjustHeight.call(this, e); adjustHeight.call(this, e);
if (this.popupView) { if (this.popupView) {
@ -253,32 +238,6 @@
tooltip.element[0].style.transform = "scale(" + scale+ ")"; tooltip.element[0].style.transform = "scale(" + scale+ ")";
tooltip.element[0].style.transformOrigin = "top left"; tooltip.element[0].style.transformOrigin = "top left";
} }
// jQuery.fn.outerWidth = function () {
// var wdith = injectOuterWidth.apply(this, arguments);
// if (this[0] === document.body) {
// return wdith / scale;
// }
// return wdith;
// }
// jQuery.fn.outerHeight = function () {
// var height = injectOuterHeight.apply(this, arguments);
// if (this[0] === document.body) {
// return height / scale;
// }
// return height;
// }
// BI.DOM.getBottomPosition = function (combo, popup, extraHeight) {
// var el = combo.element;
// return {
// top: el.offset().top + el.outerHeight() * (1 - checkInPopupView(el[0]) ? scale : 0) + (extraHeight || 0)
// };
// }
// BI.DOM.getRightPosition = function (combo, popup, extraWidth) {
// var el = combo.element;
// return {
// left: el.offset().left + el.outerWidth() * (1-checkInPopupView(el[0]) ? scale : 0) + (extraWidth || 0)
// };
// }
} }
BI.createWidget = function () { BI.createWidget = function () {
@ -291,7 +250,19 @@
// Popovers // Popovers
BI.Popovers = new BI.PopoverController({render: fixedContainer}); BI.Popovers = new BI.PopoverController({render: fixedContainer});
// document.body.onmousedown = scaleFixed; //
BI.Widget.registerRenderEngine({
createElement: function (widget) {
if (widget === "body") {
return BI.$(wrapper);
}
return originalRender.createElement(widget);
},
createFragment: function () {
return originalRender.createFragment();
}
});
window.addEventListener('resize', updateScale); window.addEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
addListener(selectHandler); addListener(selectHandler);
@ -301,18 +272,16 @@
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; jQuery.fn.__isMouseInBounds__ = injectMouseInBounds;
jQuery.fn.offset = injectOffset; jQuery.fn.offset = injectOffset;
jQuery.event.fix = injectEventFix; jQuery.event.fix = injectEventFix;
// jQuery.fn.bounds = injectBounds;
if (BI.isIE()) { if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = adjustHeight; BI.Combo.prototype.adjustHeight = adjustHeight;
BI.Tooltips.show = injectToolTipShow; BI.Tooltips.show = injectToolTipShow;
BI.Bubbles.show = injectBubblesShow; BI.Bubbles.show = injectBubblesShow;
// jQuery.fn.outerWidth = injectOuterWidth;
// jQuery.fn.outerHeight = injectOuterHeight;
} }
BI.createWidget = injectCreate; BI.createWidget = injectCreate;
// Popovers // Popovers
BI.Popovers = new BI.PopoverController(); BI.Popovers = new BI.PopoverController();
BI.Widget.registerRenderEngine(originalRender);
document.body.onmousedown = null; document.body.onmousedown = null;
window.removeEventListener('resize', updateScale); window.removeEventListener('resize', updateScale);
@ -346,30 +315,6 @@
} }
} }
injectMouseMoveTracker(); injectMouseMoveTracker();
// popupview
// function scaleFixed() {
// if (BI.isIE()) {
// var fixedList = document.getElementsByClassName("bi-popup-view");
// BI.each(fixedList, function (i, el) {
// if (window.getComputedStyle(el).position === 'fixed') {
// el.style.transformOrigin = "top left";
// el.style.transform = "scale(" + scale + ")";
// }
// })
// }
// }
//
// function revertFixed() {
// if (BI.isIE()) {
// var fixedList = document.getElementsByClassName("bi-popup-view");
// BI.each(fixedList, function (i, el) {
// if (window.getComputedStyle(el).position === 'fixed') {
// el.style.transformOrigin = "";
// el.style.transform = "";
// }
// })
// }
// }
selectHandler(); selectHandler();
BI.config("bi.constant.dashboard.toolbar.left.items", function (config) { BI.config("bi.constant.dashboard.toolbar.left.items", function (config) {

Loading…
Cancel
Save