diff --git a/src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js b/src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js index c63e581..1eb30a4 100644 --- a/src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js +++ b/src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js @@ -17,9 +17,7 @@ var injectToolTipShow = null; var injectBubblesShow = null; var adjustHeight = BI.Combo.prototype.adjustHeight; - var injectOuterWidth = jQuery.fn.outerWidth; - var injectOuterHeight = jQuery.fn.outerHeight; - var injectBounds = jQuery.fn.bounds; + var originalRender = BI.Widget._renderEngine; var injectCreate = BI.createWidget; @@ -61,21 +59,12 @@ wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform-origin"] = "top left"; 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"; - // 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; - // scaleFixed(); } // 取消缩放 @@ -89,16 +78,12 @@ wrapper.style.overflowY = "hidden"; wrapper.style.top = ""; fixedContainer.style.height = "0px"; + document.body.style.overflowX = "hidden"; + document.body.style.overflowY = "hidden"; html.style.backgroundColor = "#ffffff"; scale = 1; - // document.body.style.top = "0px"; - // document.body.style.width = ""; - // document.body.style.height = ""; - // document.body.style.overflowY = ""; window.scale = window.devicePixelRatio / scale; - - // revertFixed(); } // 获取缩放倍数,原模板宽高 @@ -203,9 +188,11 @@ } while( el ); var elm = elem; - // 不知道该怎么写代码了,就这样了 if (!checkInPopupView(elm)) { do{ + if (elm === document.body) { + break; + } offsetLeft -= elm.scrollLeft || 0; offsetTop -= elm.scrollTop || 0; elm = elm.parentNode; @@ -222,8 +209,6 @@ return correctEvent(injectEventFix.call(this, e)); }; if (BI.isIE()) { - - BI.Combo.prototype.adjustHeight = function (e) { adjustHeight.call(this, e); if (this.popupView) { @@ -253,32 +238,6 @@ tooltip.element[0].style.transform = "scale(" + scale+ ")"; 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 () { @@ -291,7 +250,19 @@ // Popovers 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.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). addListener(selectHandler); @@ -301,18 +272,16 @@ jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; jQuery.fn.offset = injectOffset; jQuery.event.fix = injectEventFix; - // jQuery.fn.bounds = injectBounds; if (BI.isIE()) { BI.Combo.prototype.adjustHeight = adjustHeight; BI.Tooltips.show = injectToolTipShow; BI.Bubbles.show = injectBubblesShow; - // jQuery.fn.outerWidth = injectOuterWidth; - // jQuery.fn.outerHeight = injectOuterHeight; } BI.createWidget = injectCreate; // Popovers BI.Popovers = new BI.PopoverController(); + BI.Widget.registerRenderEngine(originalRender); document.body.onmousedown = null; window.removeEventListener('resize', updateScale); @@ -346,30 +315,6 @@ } } 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(); BI.config("bi.constant.dashboard.toolbar.left.items", function (config) { diff --git a/src/main/resources/com/finebi/plugin/web/scripts/entry.js b/src/main/resources/com/finebi/plugin/web/scripts/entry.js index c63e581..1eb30a4 100644 --- a/src/main/resources/com/finebi/plugin/web/scripts/entry.js +++ b/src/main/resources/com/finebi/plugin/web/scripts/entry.js @@ -17,9 +17,7 @@ var injectToolTipShow = null; var injectBubblesShow = null; var adjustHeight = BI.Combo.prototype.adjustHeight; - var injectOuterWidth = jQuery.fn.outerWidth; - var injectOuterHeight = jQuery.fn.outerHeight; - var injectBounds = jQuery.fn.bounds; + var originalRender = BI.Widget._renderEngine; var injectCreate = BI.createWidget; @@ -61,21 +59,12 @@ wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform-origin"] = "top left"; 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"; - // 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; - // scaleFixed(); } // 取消缩放 @@ -89,16 +78,12 @@ wrapper.style.overflowY = "hidden"; wrapper.style.top = ""; fixedContainer.style.height = "0px"; + document.body.style.overflowX = "hidden"; + document.body.style.overflowY = "hidden"; html.style.backgroundColor = "#ffffff"; scale = 1; - // document.body.style.top = "0px"; - // document.body.style.width = ""; - // document.body.style.height = ""; - // document.body.style.overflowY = ""; window.scale = window.devicePixelRatio / scale; - - // revertFixed(); } // 获取缩放倍数,原模板宽高 @@ -203,9 +188,11 @@ } while( el ); var elm = elem; - // 不知道该怎么写代码了,就这样了 if (!checkInPopupView(elm)) { do{ + if (elm === document.body) { + break; + } offsetLeft -= elm.scrollLeft || 0; offsetTop -= elm.scrollTop || 0; elm = elm.parentNode; @@ -222,8 +209,6 @@ return correctEvent(injectEventFix.call(this, e)); }; if (BI.isIE()) { - - BI.Combo.prototype.adjustHeight = function (e) { adjustHeight.call(this, e); if (this.popupView) { @@ -253,32 +238,6 @@ tooltip.element[0].style.transform = "scale(" + scale+ ")"; 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 () { @@ -291,7 +250,19 @@ // Popovers 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.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). addListener(selectHandler); @@ -301,18 +272,16 @@ jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; jQuery.fn.offset = injectOffset; jQuery.event.fix = injectEventFix; - // jQuery.fn.bounds = injectBounds; if (BI.isIE()) { BI.Combo.prototype.adjustHeight = adjustHeight; BI.Tooltips.show = injectToolTipShow; BI.Bubbles.show = injectBubblesShow; - // jQuery.fn.outerWidth = injectOuterWidth; - // jQuery.fn.outerHeight = injectOuterHeight; } BI.createWidget = injectCreate; // Popovers BI.Popovers = new BI.PopoverController(); + BI.Widget.registerRenderEngine(originalRender); document.body.onmousedown = null; window.removeEventListener('resize', updateScale); @@ -346,30 +315,6 @@ } } 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(); BI.config("bi.constant.dashboard.toolbar.left.items", function (config) {