From 542f81e5cb4690994a40f21fc2869c17a44220b7 Mon Sep 17 00:00:00 2001 From: fay Date: Tue, 2 Jun 2020 14:46:53 +0800 Subject: [PATCH] =?UTF-8?q?BI-66116=20&=20BI-66032=20&=20BI-66034=20?= =?UTF-8?q?=E9=80=82=E9=85=8D=E6=96=B0=E5=8A=9F=E8=83=BD=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plugin/web/plugin.screen_adaptive.js | 220 ++++++++++++++---- .../com/finebi/plugin/web/scripts/entry.js | 220 ++++++++++++++---- 2 files changed, 354 insertions(+), 86 deletions(-) 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 384f1e2..94f9a4d 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 @@ -2,14 +2,19 @@ var scale = 1, transformY = 0, selected = true, globalScaleRatio = parseFloat(BI.Cache.getItem('scaleRatio')) || null; var html = document.getElementsByTagName('html')[0]; var wrapper = document.getElementById("wrapper"); + var scrollContainer = document.createElement("div"); var fixedWrapper = document.createElement("div"); - var fixedContainer = document.createElement('div'); + var fixedContainer = document.createElement('div'); // tooltip等fixed元素 + scrollContainer.style.width = "100%"; + scrollContainer.style.height = "100%"; fixedContainer.style.position = "absolute"; fixedContainer.style.top = "0"; fixedContainer.style.left = "0"; fixedContainer.style.width = "100%"; + fixedContainer.style.height = "100%"; - document.body.appendChild(fixedWrapper); + document.body.appendChild(scrollContainer); + scrollContainer.appendChild(fixedWrapper); fixedWrapper.appendChild(wrapper); wrapper.appendChild(fixedContainer); @@ -21,7 +26,10 @@ var injectBubblesShow = null; var adjustHeight = BI.Combo.prototype.adjustHeight; var originalRender = BI.Widget._renderEngine; - var injectSearch = BI.Searcher.prototype._assertPopupView; + var injectSearch = BI.Searcher.prototype._search; + var injectSearchView = BI.Searcher.prototype.setValue; + var injectTooltipsShow = BI.TooltipsController.prototype.show; + var injectSwitcherPopup = BI.Switcher.prototype.adjustView; var injectCreate = BI.createWidget; @@ -62,12 +70,11 @@ wrapper.style.transformOrigin = "top left"; wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform-origin"] = "top left"; - fixedContainer.style.height = (document.body.clientHeight / scale) + "px"; wrapper.style.overflowY = "auto"; html.style.backgroundColor = "#ffffff"; - document.body.style.overflowX = globalScaleRatio ? "auto" : "hidden"; - document.body.style.overflowY = "auto"; + scrollContainer.style.overflowX = "auto"; + scrollContainer.style.overflowY = "auto"; fixedWrapper.style.overflow = "hidden"; fixedWrapper.style.width = bounds.width * scale + "px"; fixedWrapper.style.height = bounds.height * scale + "px"; @@ -85,12 +92,9 @@ wrapper.style["-ms-transform-origin"] = ""; wrapper.style.overflowY = "hidden"; wrapper.style.top = ""; - fixedContainer.style.height = "0px"; html.style.backgroundColor = "#ffffff"; - document.body.style.overflow = "hidden"; - document.body.style.width = "100%"; - document.body.style.height = "100%"; + scrollContainer.style.overflow = "hidden"; fixedWrapper.style.overflow = "hidden"; fixedWrapper.style.width = "100%"; fixedWrapper.style.height = "100%"; @@ -243,44 +247,50 @@ if (BI.isIE()) { BI.Combo.prototype.adjustHeight = function (e) { adjustHeight.call(this, e); + var transformX = 0, transformY = 0; if (this.popupView) { if (!checkInPopupView(this.popupView.element[0])) { - this.popupView.element[0].style.left = (parseInt(this.popupView.element[0].style.left) * scale - document.body.scrollLeft) + "px"; - this.popupView.element[0].style.top = (parseInt(this.popupView.element[0].style.top) * scale + transformY - document.body.scrollTop) + "px"; + transformX = scrollContainer.scrollLeft; + transformY = scrollContainer.scrollTop; + this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale - transformX + "px"; + this.popupView.element[0].style.top = parseInt(this.popupView.element[0].style.top) * scale - transformY + "px"; } else { - var cBounds = this.popupView.element[0].getBoundingClientRect(); - var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect(); - 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"; + var cBounds = BI.extend({}, this.popupView.element[0].getBoundingClientRect()); + var pBounds = BI.extend({}, this.popupView.element[0].parentElement.getBoundingClientRect()); + + var minWidth = parseInt(this.popupView.element[0].style.minWidth); + var minHeight = parseInt(this.popupView.element[0].style.minHeight); + cBounds.width = Math.max(cBounds.width, minWidth * scale); + cBounds.height = Math.max(cBounds.height, minHeight * scale); + + if (cBounds.left + cBounds.width - scrollContainer.scrollLeft> body.clientWidth * scale) { + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale - transformX + "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"; + this.popupView.element[0].style.top = parseInt(pBounds.top) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.right) - transformX + "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.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.left) - transformX + "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.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(Math.min(pBounds.left, body.clientWidth - cBounds.width)) - transformX + "px"; + } else { + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.left) - transformX + "px"; } } this.popupView.element[0].style.transform = "scale(" + scale+ ")"; this.popupView.element[0].style.transformOrigin = "top left"; } }; - BI.Tooltips.show = function (e, name, text, level, context, opt) { - injectToolTipShow.call(this, e, name, text, level, context, opt); - var tooltip = this.get(name); - tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - document.body.scrollLeft + "px"; - tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale + transformY - document.body.scrollTop + "px"; - tooltip.element[0].style.transform = "scale(" + scale+ ")"; - tooltip.element[0].style.transformOrigin = "top left"; - } + BI.Bubbles.show = function (name, text, context, opt) { injectBubblesShow.call(this, name, text, context, opt); var tooltip = this.get(name); - tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - document.body.scrollLeft + "px"; - tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale + transformY - document.body.scrollTop + "px"; + var transformX = scrollContainer.scrollLeft / scale, transformY = scrollContainer.scrollTop / scale; + tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - transformX + "px"; + tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale - transformY + "px"; tooltip.element[0].style.transform = "scale(" + scale+ ")"; tooltip.element[0].style.transformOrigin = "top left"; } @@ -294,16 +304,72 @@ } // Searcher - BI.Searcher.prototype._assertPopupView = function () { - injectSearch.call(this); - var self = this; + BI.Searcher.prototype._search = function (result, searchResult, keyword) { + var self = this, o = this.options, keyword = o.allowSearchBlank ? this.editor.getValue() : this._getLastSearchKeyword(); + if (keyword === "" || this._stop) { + return; + } + if (o.isAutoSearch) { + var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; + var finding = BI.Func.getSearchResult(items, keyword); + var match = finding.match, find = finding.find; + this.popupView.populate(find, match, keyword); + o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); + self.fireEvent(BI.Searcher.EVENT_SEARCHING); + if (self.popupView) { + 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.transformOrigin = "left top"; + }) + } + return; + } + this.popupView.loading && this.popupView.loading(); + o.onSearch({ + times: 1, + keyword: keyword, + selectedValues: o.adapter && o.adapter.getValue() + }, function (searchResult, matchResult) { + if (!self._stop) { + var args = [].slice.call(arguments); + if (args.length > 0) { + args.push(keyword); + } + BI.Maskers.show(self.getName()); + self.popupView.populate.apply(self.popupView, args); + o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); + self.popupView.loaded && self.popupView.loaded(); + self.fireEvent(BI.Searcher.EVENT_SEARCHING); + if (self.popupView) { + 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.transformOrigin = "left top"; + } + } + }); + }; + BI.Searcher.prototype.setValue = function () { + injectSearchView.call(this, arguments); + if (this.popupView && this.popupView.element[0].parentElement) { + this.popupView.element[0].parentElement.style.left = parseInt(this.popupView.element[0].parentElement.style.left) * scale + "px"; + this.popupView.element[0].parentElement.style.top = parseInt(this.popupView.element[0].parentElement.style.top) * scale + "px"; + this.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; + this.popupView.element[0].parentElement.style.transformOrigin = "left top"; + } + + } + + // switcher + BI.Switcher.prototype.adjustView = function () { + injectSwitcherPopup.call(this, arguments); if (this.popupView) { - 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.transformOrigin = "left top"; - }) + this.popupView.element[0].parentElement.style.left = parseInt(this.popupView.element[0].parentElement.style.left) * scale + "px"; + this.popupView.element[0].parentElement.style.top = parseInt(this.popupView.element[0].parentElement.style.top) * scale + "px"; + this.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; + this.popupView.element[0].parentElement.style.transformOrigin = "left top"; } } } @@ -327,6 +393,71 @@ } }); + BI.TooltipsController.prototype.show = function (e, name, text, level, context, opt) { + opt || (opt = {}); + var self = this; + BI.each(this.showingTips, function (i, tip) { + self.hide(i); + }); + this.showingTips = {}; + if (!this.has(name)) { + this.create(name, text, level, opt.container || "body"); + } + if (!opt.belowMouse) { + var offset = context.element.offset(); + var bounds = context.element.bounds(); + if (bounds.height === 0 || bounds.width === 0) { + return; + } + var top = offset.top + bounds.height + 5; + } + var tooltip = this.get(name); + tooltip.setText(text); + tooltip.element.css({ + left: "0px", + top: "0px" + }); + tooltip.visible(); + tooltip.element.height(tooltip.element[0].scrollHeight); + this.showingTips[name] = true; + // scale影响要计算在内 + // var scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left; + // var x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15; + var x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15; + var originY = 0; + if (BI.isIE()) { + x = x * scale; + y = y * scale; + } else { + x = x + scrollContainer.scrollLeft / scale; + } + if (x + tooltip.element.outerWidth() > BI.Widget._renderEngine.createElement("body").outerWidth()) { + x -= tooltip.element.outerWidth() + 15; + } + var bodyHeight = BI.Widget._renderEngine.createElement("body").outerHeight(); + if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) { + y -= tooltip.element.outerHeight() + 15; + originY = y; + !opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5)); + } else { + originY = y; + !opt.belowMouse && (y = Math.max(y, top)); + } + tooltip.element.css({ + left: x < 0 ? 0 : x + "px", + top: y < 0 ? 0 : y + "px" + }); + tooltip.element.hover(function () { + self.remove(name); + context.element.trigger("mouseleave.title" + context.getName()); + }); + if (BI.isIE()) { + tooltip.element[0].style.transform = "scale(" + scale+ ")"; + tooltip.element[0].style.transformOrigin = "top left"; + } + return this; + } + window.addEventListener('resize', updateScale); window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). addListener(selectHandler); @@ -347,7 +478,10 @@ BI.Popovers = new BI.PopoverController(); BI.Widget.registerRenderEngine(originalRender); - BI.Searcher.prototype._assertPopupView = injectSearch; + BI.Searcher.prototype._search = injectSearch; + BI.Searcher.prototype.setValue = injectSearchView; + BI.Switcher.prototype.adjustView = injectSwitcherPopup; + BI.TooltipsController.prototype.show = injectTooltipsShow; document.body.onmousedown = null; window.removeEventListener('resize', updateScale); 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 384f1e2..94f9a4d 100644 --- a/src/main/resources/com/finebi/plugin/web/scripts/entry.js +++ b/src/main/resources/com/finebi/plugin/web/scripts/entry.js @@ -2,14 +2,19 @@ var scale = 1, transformY = 0, selected = true, globalScaleRatio = parseFloat(BI.Cache.getItem('scaleRatio')) || null; var html = document.getElementsByTagName('html')[0]; var wrapper = document.getElementById("wrapper"); + var scrollContainer = document.createElement("div"); var fixedWrapper = document.createElement("div"); - var fixedContainer = document.createElement('div'); + var fixedContainer = document.createElement('div'); // tooltip等fixed元素 + scrollContainer.style.width = "100%"; + scrollContainer.style.height = "100%"; fixedContainer.style.position = "absolute"; fixedContainer.style.top = "0"; fixedContainer.style.left = "0"; fixedContainer.style.width = "100%"; + fixedContainer.style.height = "100%"; - document.body.appendChild(fixedWrapper); + document.body.appendChild(scrollContainer); + scrollContainer.appendChild(fixedWrapper); fixedWrapper.appendChild(wrapper); wrapper.appendChild(fixedContainer); @@ -21,7 +26,10 @@ var injectBubblesShow = null; var adjustHeight = BI.Combo.prototype.adjustHeight; var originalRender = BI.Widget._renderEngine; - var injectSearch = BI.Searcher.prototype._assertPopupView; + var injectSearch = BI.Searcher.prototype._search; + var injectSearchView = BI.Searcher.prototype.setValue; + var injectTooltipsShow = BI.TooltipsController.prototype.show; + var injectSwitcherPopup = BI.Switcher.prototype.adjustView; var injectCreate = BI.createWidget; @@ -62,12 +70,11 @@ wrapper.style.transformOrigin = "top left"; wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")"; wrapper.style["-ms-transform-origin"] = "top left"; - fixedContainer.style.height = (document.body.clientHeight / scale) + "px"; wrapper.style.overflowY = "auto"; html.style.backgroundColor = "#ffffff"; - document.body.style.overflowX = globalScaleRatio ? "auto" : "hidden"; - document.body.style.overflowY = "auto"; + scrollContainer.style.overflowX = "auto"; + scrollContainer.style.overflowY = "auto"; fixedWrapper.style.overflow = "hidden"; fixedWrapper.style.width = bounds.width * scale + "px"; fixedWrapper.style.height = bounds.height * scale + "px"; @@ -85,12 +92,9 @@ wrapper.style["-ms-transform-origin"] = ""; wrapper.style.overflowY = "hidden"; wrapper.style.top = ""; - fixedContainer.style.height = "0px"; html.style.backgroundColor = "#ffffff"; - document.body.style.overflow = "hidden"; - document.body.style.width = "100%"; - document.body.style.height = "100%"; + scrollContainer.style.overflow = "hidden"; fixedWrapper.style.overflow = "hidden"; fixedWrapper.style.width = "100%"; fixedWrapper.style.height = "100%"; @@ -243,44 +247,50 @@ if (BI.isIE()) { BI.Combo.prototype.adjustHeight = function (e) { adjustHeight.call(this, e); + var transformX = 0, transformY = 0; if (this.popupView) { if (!checkInPopupView(this.popupView.element[0])) { - this.popupView.element[0].style.left = (parseInt(this.popupView.element[0].style.left) * scale - document.body.scrollLeft) + "px"; - this.popupView.element[0].style.top = (parseInt(this.popupView.element[0].style.top) * scale + transformY - document.body.scrollTop) + "px"; + transformX = scrollContainer.scrollLeft; + transformY = scrollContainer.scrollTop; + this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale - transformX + "px"; + this.popupView.element[0].style.top = parseInt(this.popupView.element[0].style.top) * scale - transformY + "px"; } else { - var cBounds = this.popupView.element[0].getBoundingClientRect(); - var pBounds = this.popupView.element[0].parentElement.getBoundingClientRect(); - 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"; + var cBounds = BI.extend({}, this.popupView.element[0].getBoundingClientRect()); + var pBounds = BI.extend({}, this.popupView.element[0].parentElement.getBoundingClientRect()); + + var minWidth = parseInt(this.popupView.element[0].style.minWidth); + var minHeight = parseInt(this.popupView.element[0].style.minHeight); + cBounds.width = Math.max(cBounds.width, minWidth * scale); + cBounds.height = Math.max(cBounds.height, minHeight * scale); + + if (cBounds.left + cBounds.width - scrollContainer.scrollLeft> body.clientWidth * scale) { + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale - transformX + "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"; + this.popupView.element[0].style.top = parseInt(pBounds.top) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.right) - transformX + "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.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.left) - transformX + "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.left = (parseInt(pBounds.left) + transformY - document.body.scrollTop) + "px"; + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(Math.min(pBounds.left, body.clientWidth - cBounds.width)) - transformX + "px"; + } else { + this.popupView.element[0].style.top = parseInt(pBounds.bottom) - transformY + "px"; + this.popupView.element[0].style.left = parseInt(pBounds.left) - transformX + "px"; } } this.popupView.element[0].style.transform = "scale(" + scale+ ")"; this.popupView.element[0].style.transformOrigin = "top left"; } }; - BI.Tooltips.show = function (e, name, text, level, context, opt) { - injectToolTipShow.call(this, e, name, text, level, context, opt); - var tooltip = this.get(name); - tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - document.body.scrollLeft + "px"; - tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale + transformY - document.body.scrollTop + "px"; - tooltip.element[0].style.transform = "scale(" + scale+ ")"; - tooltip.element[0].style.transformOrigin = "top left"; - } + BI.Bubbles.show = function (name, text, context, opt) { injectBubblesShow.call(this, name, text, context, opt); var tooltip = this.get(name); - tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - document.body.scrollLeft + "px"; - tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale + transformY - document.body.scrollTop + "px"; + var transformX = scrollContainer.scrollLeft / scale, transformY = scrollContainer.scrollTop / scale; + tooltip.element[0].style.left = parseInt(tooltip.element[0].style.left) * scale - transformX + "px"; + tooltip.element[0].style.top = parseInt(tooltip.element[0].style.top) * scale - transformY + "px"; tooltip.element[0].style.transform = "scale(" + scale+ ")"; tooltip.element[0].style.transformOrigin = "top left"; } @@ -294,16 +304,72 @@ } // Searcher - BI.Searcher.prototype._assertPopupView = function () { - injectSearch.call(this); - var self = this; + BI.Searcher.prototype._search = function (result, searchResult, keyword) { + var self = this, o = this.options, keyword = o.allowSearchBlank ? this.editor.getValue() : this._getLastSearchKeyword(); + if (keyword === "" || this._stop) { + return; + } + if (o.isAutoSearch) { + var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; + var finding = BI.Func.getSearchResult(items, keyword); + var match = finding.match, find = finding.find; + this.popupView.populate(find, match, keyword); + o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); + self.fireEvent(BI.Searcher.EVENT_SEARCHING); + if (self.popupView) { + 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.transformOrigin = "left top"; + }) + } + return; + } + this.popupView.loading && this.popupView.loading(); + o.onSearch({ + times: 1, + keyword: keyword, + selectedValues: o.adapter && o.adapter.getValue() + }, function (searchResult, matchResult) { + if (!self._stop) { + var args = [].slice.call(arguments); + if (args.length > 0) { + args.push(keyword); + } + BI.Maskers.show(self.getName()); + self.popupView.populate.apply(self.popupView, args); + o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); + self.popupView.loaded && self.popupView.loaded(); + self.fireEvent(BI.Searcher.EVENT_SEARCHING); + if (self.popupView) { + 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.transformOrigin = "left top"; + } + } + }); + }; + BI.Searcher.prototype.setValue = function () { + injectSearchView.call(this, arguments); + if (this.popupView && this.popupView.element[0].parentElement) { + this.popupView.element[0].parentElement.style.left = parseInt(this.popupView.element[0].parentElement.style.left) * scale + "px"; + this.popupView.element[0].parentElement.style.top = parseInt(this.popupView.element[0].parentElement.style.top) * scale + "px"; + this.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; + this.popupView.element[0].parentElement.style.transformOrigin = "left top"; + } + + } + + // switcher + BI.Switcher.prototype.adjustView = function () { + injectSwitcherPopup.call(this, arguments); if (this.popupView) { - 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.transformOrigin = "left top"; - }) + this.popupView.element[0].parentElement.style.left = parseInt(this.popupView.element[0].parentElement.style.left) * scale + "px"; + this.popupView.element[0].parentElement.style.top = parseInt(this.popupView.element[0].parentElement.style.top) * scale + "px"; + this.popupView.element[0].parentElement.style.transform = "scale(" + scale + ")"; + this.popupView.element[0].parentElement.style.transformOrigin = "left top"; } } } @@ -327,6 +393,71 @@ } }); + BI.TooltipsController.prototype.show = function (e, name, text, level, context, opt) { + opt || (opt = {}); + var self = this; + BI.each(this.showingTips, function (i, tip) { + self.hide(i); + }); + this.showingTips = {}; + if (!this.has(name)) { + this.create(name, text, level, opt.container || "body"); + } + if (!opt.belowMouse) { + var offset = context.element.offset(); + var bounds = context.element.bounds(); + if (bounds.height === 0 || bounds.width === 0) { + return; + } + var top = offset.top + bounds.height + 5; + } + var tooltip = this.get(name); + tooltip.setText(text); + tooltip.element.css({ + left: "0px", + top: "0px" + }); + tooltip.visible(); + tooltip.element.height(tooltip.element[0].scrollHeight); + this.showingTips[name] = true; + // scale影响要计算在内 + // var scale = context.element.offset().left / context.element.get(0).getBoundingClientRect().left; + // var x = (e.pageX || e.clientX) * scale + 15, y = (e.pageY || e.clientY) * scale + 15; + var x = (e.pageX || e.clientX) + 15, y = (e.pageY || e.clientY) + 15; + var originY = 0; + if (BI.isIE()) { + x = x * scale; + y = y * scale; + } else { + x = x + scrollContainer.scrollLeft / scale; + } + if (x + tooltip.element.outerWidth() > BI.Widget._renderEngine.createElement("body").outerWidth()) { + x -= tooltip.element.outerWidth() + 15; + } + var bodyHeight = BI.Widget._renderEngine.createElement("body").outerHeight(); + if (y + tooltip.element.outerHeight() > bodyHeight || top + tooltip.element.outerHeight() > bodyHeight) { + y -= tooltip.element.outerHeight() + 15; + originY = y; + !opt.belowMouse && (y = Math.min(y, offset.top - tooltip.element.outerHeight() - 5)); + } else { + originY = y; + !opt.belowMouse && (y = Math.max(y, top)); + } + tooltip.element.css({ + left: x < 0 ? 0 : x + "px", + top: y < 0 ? 0 : y + "px" + }); + tooltip.element.hover(function () { + self.remove(name); + context.element.trigger("mouseleave.title" + context.getName()); + }); + if (BI.isIE()) { + tooltip.element[0].style.transform = "scale(" + scale+ ")"; + tooltip.element[0].style.transformOrigin = "top left"; + } + return this; + } + window.addEventListener('resize', updateScale); window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)'). addListener(selectHandler); @@ -347,7 +478,10 @@ BI.Popovers = new BI.PopoverController(); BI.Widget.registerRenderEngine(originalRender); - BI.Searcher.prototype._assertPopupView = injectSearch; + BI.Searcher.prototype._search = injectSearch; + BI.Searcher.prototype.setValue = injectSearchView; + BI.Switcher.prototype.adjustView = injectSwitcherPopup; + BI.TooltipsController.prototype.show = injectTooltipsShow; document.body.onmousedown = null; window.removeEventListener('resize', updateScale);