Browse Source

Merge remote-tracking branch 'origin/release/10.0'

master
richie 5 years ago
parent
commit
29455314b7
  1. 6
      .gitignore
  2. 5
      README.md
  3. 12
      plugin.xml
  4. 52
      pom.xml
  5. 335
      src/main/resources/com/finebi/plugin/web/plugin.screen_adaptive.js
  6. 335
      src/main/resources/com/finebi/plugin/web/scripts/entry.js

6
.gitignore vendored

@ -1,4 +1,6 @@
/.idea
install/
bi-plugin-*/
bi-plugin-*.jar
bi-plugin-*.jar
.idea/
*.iml
lib/report/*.jar

5
README.md

@ -1,6 +1,3 @@
# BI模板自适应插件
用户查看模板时可以选择自适应屏幕宽度的查看方式。
待解决问题:
1. IE下图表的弹出框错位
用户查看模板时可以选择自适应屏幕宽度的查看方式。

12
plugin.xml

@ -1,15 +1,19 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<plugin>
<id>com.finebi.plugin.screen_adaptive</id>
<id>com.finebi.plugin.screenadaptive</id>
<name><![CDATA[BI模板屏幕自适应]]></name>
<active>yes</active>
<version>1.1.19</version>
<version>1.1.33</version>
<env-version>10.0</env-version>
<jartime>2019-03-01</jartime>
<jartime>2019-08-16</jartime>
<vendor>fay</vendor>
<description><![CDATA[预览BI模板时,根据屏幕的宽度自适应显示模板]]></description>
<change-notes><![CDATA[
[2019-10-24]修复IE中有空白部分的情况<br/>
[2019-08-28]为BI模板添加模板自适应功能。<br/>
]]></change-notes>
<extra-decision>
<AbstractWebResourceProvider class="com.finebi.plugin.ScreenAdaptive"/>
<WebResourceProvider class="com.finebi.plugin.ScreenAdaptive"/>
</extra-decision>
<extra-core>
<LocaleFinder class="com.finebi.plugin.ScreenAdaptiveLocaleFinder"/>

52
pom.xml

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>plugin-bi-screen-adaptive</artifactId>
<build>
<!---如果要更改调试插件,改这里的配置就可以了-->
<outputDirectory>${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.finebi.plugin.screenadaptive-1.0/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>6</source>
<target>6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>fanruan</id>
<name>fanruan</name>
<url>http://mvn.finedevelop.com/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>fanruan</id>
<name>fanruan</name>
<url>http://mvn.finedevelop.com/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>

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

@ -1,11 +1,20 @@
!(function () {
var scale = 1, transformY = 0, selected = false;
var scale = 1, transformY = 0, selected = true;
var wrapper = document.getElementById("wrapper");
var html = document.getElementsByTagName('html')[0];
var jQuery = $ || window.jQuery;
var injectOffset = jQuery.fn.offset;
var injectEventFix = jQuery.event.fix;
var injectMouseInBounds = jQuery.fn.__isMouseInBounds__;
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 injectCreate = BI.createWidget;
// 修正事件偏移
function correctEvent(e) {
@ -19,56 +28,87 @@
return e;
}
function checkInPopupView(el) {
var t = el.parentElement;
var flag = false;
do {
if (t.className && t.className.indexOf("bi-popup-view") !== -1) {
flag = true;
break;
}
t = t.parentElement
} while (t);
return flag;
}
// 进行缩放
function transformScale() {
var bounds = getScaleBounds();
scale = bounds.scale;
document.body.style.width = bounds.width + "px";
document.body.style.height = bounds.height + "px";
document.body.style.transform = "scale(" + bounds.scale+ ")";
document.body.style.transformOrigin = "top left";
document.body.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
document.body.style["-ms-transform-origin"] = "top left";
html.style.overflowY = "auto";
html.style.backgroundColor = "#2c3d59";
if (bounds.height * bounds.scale < html.clientHeight) {
transformY = (html.clientHeight - bounds.height * bounds.scale) / 2;
document.body.style.top = transformY + "px";
html.style.overflowY = "hidden";
} else {
transformY = 0;
}
wrapper.style.width = bounds.width + "px";
wrapper.style.height = bounds.height + "px";
wrapper.style.transform = "scale(" + bounds.scale+ ")";
wrapper.style.transformOrigin = "top left";
wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
wrapper.style["-ms-transform-origin"] = "top left";
// html.style.backgroundColor = document.getElementsByClassName('bi-theme-dark').length === 0 ? "#2c3d59" : "#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;
// scaleFixed();
}
// 取消缩放
function removeScale() {
document.body.style.width = "100%";
document.body.style.height = "100%";
document.body.style.transform = "";
document.body.style.transformOrigin = "";
document.body.style["-ms-transform"] = "";
document.body.style["-ms-transform-origin"] = "";
document.body.style.overflowY = "hidden";
document.body.style.top = "0px";
wrapper.style.width = "100%";
wrapper.style.height = "100%";
wrapper.style.transform = "";
wrapper.style.transformOrigin = "";
wrapper.style["-ms-transform"] = "";
wrapper.style["-ms-transform-origin"] = "";
wrapper.style.overflowY = "hidden";
wrapper.style.top = "";
html.style.backgroundColor = "#ffffff";
window.scale = window.devicePixelRatio / scale;
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();
}
// 获取缩放倍数,原模板宽高
function getScaleBounds() {
var widgts = BI.designConfigure.widgets,
var widgets = BI.designConfigure.widgets,
layoutRatio = BI.designConfigure.layoutRatio,
freeLayoutRatio = BI.designConfigure.freeLayoutRatio,
freeWidgets = BI.designConfigure.freeWidgetIds;
if (Object.keys(widgets).length === 0) {
return {
scale: 1,
width: html.clientWidth,
height: html.clientHeight
}
}
var left = null, right = null, top = null, bottom = null,
freeLeft = null, freeRight = null, freeTop = null, freeBottom = null;
BI.each(widgts, function (wId, widget) {
BI.each(widgets, function (wId, widget) {
var bounds = widget.bounds || {};
if (BI.contains(freeWidgets, wId)) {
freeLeft = BI.isNull(freeLeft) ? bounds.left : Math.min(freeLeft, bounds.left);
@ -83,110 +123,196 @@
}
});
var templateWidth = Math.round((right / (layoutRatio.x || 1)) || (freeRight / (freeLayoutRatio.x || 1)));
var templateHeight = Math.round((bottom / (layoutRatio.y || 1)) || (freeBottom / (freeLayoutRatio.y || 1)));
var templateWidth = (Math.round((right / (layoutRatio.x || 1)) || (freeRight / (freeLayoutRatio.x || 1)))) + 60;
var templateHeight = (Math.round((bottom / (layoutRatio.y || 1)) || (freeBottom / (freeLayoutRatio.y || 1)))) + 30;
var scaleRatio = parseFloat((html.clientWidth / templateWidth).toFixed(1));
var bHeight = html.clientHeight / scaleRatio;
return {
scale: scaleRatio,
width: html.clientWidth / scaleRatio,
height: templateHeight
height: Math.max(bHeight, scaleRatio === 1 ? html.clientHeight : templateHeight)
};
}
// 准备环境,主要是纠正事件偏移
function prepareEnv() {
// IE的fixed元素不受transform:scale影响
if (!BI.isIE()) {
jQuery.fn.__isMouseInBounds__ = function (e) {
var offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset();
var width = offset2Body.width || this.outerWidth();
var height = offset2Body.height || this.outerHeight();
var pageX = e.pageX * scale,
pageY = e.pageY * scale + transformY;
return !(pageX < Math.floor(offset2Body.left) || pageX > offset2Body.left + width
|| pageY < Math.floor(offset2Body.top) || pageY > offset2Body.top + height);
};
jQuery.fn.offset = function( options ) {
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :
false;
}
injectToolTipShow = injectToolTipShow || BI.Tooltips.show;
injectBubblesShow = injectBubblesShow || BI.Bubbles.show;
jQuery.fn.__isMouseInBounds__ = function (e) {
var offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset();
var width = offset2Body.width || this.outerWidth();
var height = offset2Body.height || this.outerHeight();
var pageX = e.clientX * scale,
pageY = e.clientY * scale + transformY;
return !(pageX < Math.floor(offset2Body.left) || pageX > offset2Body.left + width
|| pageY < Math.floor(offset2Body.top) || pageY > offset2Body.top + height);
};
jQuery.fn.offset = function( options ) {
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :
false;
}
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
docElem = doc.documentElement;
if ( !doc ) {
return;
}
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
docElem = doc.documentElement;
var el = elem,
offsetLeft = 0,
offsetTop = 0;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
do{
offsetLeft += el.offsetLeft;
offsetTop += el.offsetTop;
el = el.offsetParent;
} while( el );
var el = elem,
offsetLeft = 0,
offsetTop = 0;
var elm = elem;
do{
offsetLeft += el.offsetLeft;
offsetTop += el.offsetTop;
el = el.offsetParent;
} while( el );
var elm = elem;
// 不知道该怎么写代码了,就这样了
if (!checkInPopupView(elm)) {
do{
offsetLeft -= elm.scrollLeft || 0;
offsetTop -= elm.scrollTop || 0;
elm = elm.parentNode;
} while( elm );
win = getWindow( doc );
return {
top: offsetTop + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
left: offsetLeft + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
};
}
win = getWindow( doc );
return {
top: offsetTop + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
left: offsetLeft + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
};
jQuery.event.fix = function ( e ) {
return correctEvent(injectEventFix.call(this, e));
};
jQuery.event.fix = function ( e ) {
return correctEvent(injectEventFix.call(this, e));
};
if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = function (e) {
adjustHeight.call(this, e);
if (this.popupView) {
if (!checkInPopupView(this.popupView.element[0])) {
this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale + "px";
this.popupView.element[0].style.top = parseInt(this.popupView.element[0].style.top) * scale + transformY + "px";
} else {
}
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 + "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";
}
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 + "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";
}
// 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 () {
if (arguments[0] && arguments[0].element === "body") {
arguments[0].element = wrapper;
}
return injectCreate.apply(this, arguments);
};
// document.body.onmousedown = scaleFixed;
window.addEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
addListener(selectHandler);
}
function restoreEnv() {
if (!BI.isIE()) {
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds;
jQuery.fn.offset = injectOffset;
jQuery.event.fix = injectEventFix;
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;
document.body.onmousedown = null;
window.removeEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
removeListener(selectHandler);
}
function selectHandler () {
var selectHandler = BI.debounce(function () {
selected && prepareEnv();
selected ? transformScale() : removeScale();
!selected && restoreEnv();
}
}, 30);
function updateScale () {
if (html.getBoundingClientRect().width !== document.body.getBoundingClientRect().width) {
if (html.getBoundingClientRect().width !== wrapper.getBoundingClientRect().width) {
selectHandler();
}
}
@ -205,12 +331,37 @@
}
}
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) {
return BI.concat(config, [{
type: "bi.multi_select_item",
text: BI.i18nText("BI-Plugin-Scale_Adaptive"),
selected: false,
selected: true,
listeners: [{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: function () {

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

@ -1,11 +1,20 @@
!(function () {
var scale = 1, transformY = 0, selected = false;
var scale = 1, transformY = 0, selected = true;
var wrapper = document.getElementById("wrapper");
var html = document.getElementsByTagName('html')[0];
var jQuery = $ || window.jQuery;
var injectOffset = jQuery.fn.offset;
var injectEventFix = jQuery.event.fix;
var injectMouseInBounds = jQuery.fn.__isMouseInBounds__;
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 injectCreate = BI.createWidget;
// 修正事件偏移
function correctEvent(e) {
@ -19,56 +28,87 @@
return e;
}
function checkInPopupView(el) {
var t = el.parentElement;
var flag = false;
do {
if (t.className && t.className.indexOf("bi-popup-view") !== -1) {
flag = true;
break;
}
t = t.parentElement
} while (t);
return flag;
}
// 进行缩放
function transformScale() {
var bounds = getScaleBounds();
scale = bounds.scale;
document.body.style.width = bounds.width + "px";
document.body.style.height = bounds.height + "px";
document.body.style.transform = "scale(" + bounds.scale+ ")";
document.body.style.transformOrigin = "top left";
document.body.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
document.body.style["-ms-transform-origin"] = "top left";
html.style.overflowY = "auto";
html.style.backgroundColor = "#2c3d59";
if (bounds.height * bounds.scale < html.clientHeight) {
transformY = (html.clientHeight - bounds.height * bounds.scale) / 2;
document.body.style.top = transformY + "px";
html.style.overflowY = "hidden";
} else {
transformY = 0;
}
wrapper.style.width = bounds.width + "px";
wrapper.style.height = bounds.height + "px";
wrapper.style.transform = "scale(" + bounds.scale+ ")";
wrapper.style.transformOrigin = "top left";
wrapper.style["-ms-transform"] = "scale(" + bounds.scale+ ")";
wrapper.style["-ms-transform-origin"] = "top left";
// html.style.backgroundColor = document.getElementsByClassName('bi-theme-dark').length === 0 ? "#2c3d59" : "#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;
// scaleFixed();
}
// 取消缩放
function removeScale() {
document.body.style.width = "100%";
document.body.style.height = "100%";
document.body.style.transform = "";
document.body.style.transformOrigin = "";
document.body.style["-ms-transform"] = "";
document.body.style["-ms-transform-origin"] = "";
document.body.style.overflowY = "hidden";
document.body.style.top = "0px";
wrapper.style.width = "100%";
wrapper.style.height = "100%";
wrapper.style.transform = "";
wrapper.style.transformOrigin = "";
wrapper.style["-ms-transform"] = "";
wrapper.style["-ms-transform-origin"] = "";
wrapper.style.overflowY = "hidden";
wrapper.style.top = "";
html.style.backgroundColor = "#ffffff";
window.scale = window.devicePixelRatio / scale;
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();
}
// 获取缩放倍数,原模板宽高
function getScaleBounds() {
var widgts = BI.designConfigure.widgets,
var widgets = BI.designConfigure.widgets,
layoutRatio = BI.designConfigure.layoutRatio,
freeLayoutRatio = BI.designConfigure.freeLayoutRatio,
freeWidgets = BI.designConfigure.freeWidgetIds;
if (Object.keys(widgets).length === 0) {
return {
scale: 1,
width: html.clientWidth,
height: html.clientHeight
}
}
var left = null, right = null, top = null, bottom = null,
freeLeft = null, freeRight = null, freeTop = null, freeBottom = null;
BI.each(widgts, function (wId, widget) {
BI.each(widgets, function (wId, widget) {
var bounds = widget.bounds || {};
if (BI.contains(freeWidgets, wId)) {
freeLeft = BI.isNull(freeLeft) ? bounds.left : Math.min(freeLeft, bounds.left);
@ -83,110 +123,196 @@
}
});
var templateWidth = Math.round((right / (layoutRatio.x || 1)) || (freeRight / (freeLayoutRatio.x || 1)));
var templateHeight = Math.round((bottom / (layoutRatio.y || 1)) || (freeBottom / (freeLayoutRatio.y || 1)));
var templateWidth = (Math.round((right / (layoutRatio.x || 1)) || (freeRight / (freeLayoutRatio.x || 1)))) + 60;
var templateHeight = (Math.round((bottom / (layoutRatio.y || 1)) || (freeBottom / (freeLayoutRatio.y || 1)))) + 30;
var scaleRatio = parseFloat((html.clientWidth / templateWidth).toFixed(1));
var bHeight = html.clientHeight / scaleRatio;
return {
scale: scaleRatio,
width: html.clientWidth / scaleRatio,
height: templateHeight
height: Math.max(bHeight, scaleRatio === 1 ? html.clientHeight : templateHeight)
};
}
// 准备环境,主要是纠正事件偏移
function prepareEnv() {
// IE的fixed元素不受transform:scale影响
if (!BI.isIE()) {
jQuery.fn.__isMouseInBounds__ = function (e) {
var offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset();
var width = offset2Body.width || this.outerWidth();
var height = offset2Body.height || this.outerHeight();
var pageX = e.pageX * scale,
pageY = e.pageY * scale + transformY;
return !(pageX < Math.floor(offset2Body.left) || pageX > offset2Body.left + width
|| pageY < Math.floor(offset2Body.top) || pageY > offset2Body.top + height);
};
jQuery.fn.offset = function( options ) {
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :
false;
}
injectToolTipShow = injectToolTipShow || BI.Tooltips.show;
injectBubblesShow = injectBubblesShow || BI.Bubbles.show;
jQuery.fn.__isMouseInBounds__ = function (e) {
var offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset();
var width = offset2Body.width || this.outerWidth();
var height = offset2Body.height || this.outerHeight();
var pageX = e.clientX * scale,
pageY = e.clientY * scale + transformY;
return !(pageX < Math.floor(offset2Body.left) || pageX > offset2Body.left + width
|| pageY < Math.floor(offset2Body.top) || pageY > offset2Body.top + height);
};
jQuery.fn.offset = function( options ) {
function getWindow( elem ) {
return jQuery.isWindow( elem ) ?
elem :
elem.nodeType === 9 ?
elem.defaultView || elem.parentWindow :
false;
}
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
if ( arguments.length ) {
return options === undefined ?
this :
this.each(function( i ) {
jQuery.offset.setOffset( this, options, i );
});
}
var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
if ( !doc ) {
return;
}
var docElem, win,
box = { top: 0, left: 0 },
elem = this[ 0 ],
doc = elem && elem.ownerDocument;
docElem = doc.documentElement;
if ( !doc ) {
return;
}
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
docElem = doc.documentElement;
var el = elem,
offsetLeft = 0,
offsetTop = 0;
// Make sure it's not a disconnected DOM node
if ( !jQuery.contains( docElem, elem ) ) {
return box;
}
do{
offsetLeft += el.offsetLeft;
offsetTop += el.offsetTop;
el = el.offsetParent;
} while( el );
var el = elem,
offsetLeft = 0,
offsetTop = 0;
var elm = elem;
do{
offsetLeft += el.offsetLeft;
offsetTop += el.offsetTop;
el = el.offsetParent;
} while( el );
var elm = elem;
// 不知道该怎么写代码了,就这样了
if (!checkInPopupView(elm)) {
do{
offsetLeft -= elm.scrollLeft || 0;
offsetTop -= elm.scrollTop || 0;
elm = elm.parentNode;
} while( elm );
win = getWindow( doc );
return {
top: offsetTop + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
left: offsetLeft + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
};
}
win = getWindow( doc );
return {
top: offsetTop + ( win.pageYOffset || docElem.scrollTop ) - ( docElem.clientTop || 0 ),
left: offsetLeft + ( win.pageXOffset || docElem.scrollLeft ) - ( docElem.clientLeft || 0 )
};
jQuery.event.fix = function ( e ) {
return correctEvent(injectEventFix.call(this, e));
};
jQuery.event.fix = function ( e ) {
return correctEvent(injectEventFix.call(this, e));
};
if (BI.isIE()) {
BI.Combo.prototype.adjustHeight = function (e) {
adjustHeight.call(this, e);
if (this.popupView) {
if (!checkInPopupView(this.popupView.element[0])) {
this.popupView.element[0].style.left = parseInt(this.popupView.element[0].style.left) * scale + "px";
this.popupView.element[0].style.top = parseInt(this.popupView.element[0].style.top) * scale + transformY + "px";
} else {
}
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 + "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";
}
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 + "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";
}
// 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 () {
if (arguments[0] && arguments[0].element === "body") {
arguments[0].element = wrapper;
}
return injectCreate.apply(this, arguments);
};
// document.body.onmousedown = scaleFixed;
window.addEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
addListener(selectHandler);
}
function restoreEnv() {
if (!BI.isIE()) {
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds;
jQuery.fn.offset = injectOffset;
jQuery.event.fix = injectEventFix;
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;
document.body.onmousedown = null;
window.removeEventListener('resize', updateScale);
window.matchMedia && window.matchMedia('screen and (min-resolution: 2dppx)').
removeListener(selectHandler);
}
function selectHandler () {
var selectHandler = BI.debounce(function () {
selected && prepareEnv();
selected ? transformScale() : removeScale();
!selected && restoreEnv();
}
}, 30);
function updateScale () {
if (html.getBoundingClientRect().width !== document.body.getBoundingClientRect().width) {
if (html.getBoundingClientRect().width !== wrapper.getBoundingClientRect().width) {
selectHandler();
}
}
@ -205,12 +331,37 @@
}
}
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) {
return BI.concat(config, [{
type: "bi.multi_select_item",
text: BI.i18nText("BI-Plugin-Scale_Adaptive"),
selected: false,
selected: true,
listeners: [{
eventName: BI.MultiSelectItem.EVENT_CHANGE,
action: function () {

Loading…
Cancel
Save