Fay
6 years ago
15 changed files with 668 additions and 0 deletions
@ -0,0 +1,4 @@
|
||||
/.idea |
||||
install/ |
||||
bi-plugin-*/ |
||||
bi-plugin-*.jar |
@ -0,0 +1,142 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<project basedir="." default="jar" name="plugin"> |
||||
<!-- JDK路径,根据自己机器上实际位置修改--> |
||||
<property name="jdk.home" value="/Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home"/> |
||||
|
||||
<property name="libs" value="${basedir}/lib"/> |
||||
<property name="publicLibs" value=""/> |
||||
<property name="reportLibs" value="/Users/lifenghao/Downloads/BI5.1_spider_jar_jdk1.8"/> |
||||
<property name="destLoc" value="."/> |
||||
<property name="classes" value="classes"/> |
||||
<xmlproperty file="${basedir}/plugin.xml"/> |
||||
<property name="current-version" value="${plugin.version}"/> |
||||
<property name="js-path" value="${basedir}/src/main/resources/com/finebi/plugin/web/scripts"/> |
||||
|
||||
<!-- 插件版本--> |
||||
<property name="plugin-version" value="${current-version}"/> |
||||
<!-- 插件名字--> |
||||
<property name="plugin-name" value="screen_adaptive"/> |
||||
<property name="plugin-jar" value="bi-plugin-${plugin-name}-${plugin-version}.jar"/> |
||||
|
||||
<target name="prepare"> |
||||
<delete dir="${classes}"/> |
||||
<delete dir="bi-plugin-${plugin-name}-${plugin-version}"/> |
||||
<xmlproperty file="${basedir}/plugin.xml"/> |
||||
<delete dir="${destLoc}/${plugin.name}"/> |
||||
</target> |
||||
<path id="compile.classpath"> |
||||
<fileset dir="${libs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
<fileset dir="${publicLibs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
<fileset dir="${reportLibs}"> |
||||
<include name="**/*.jar"/> |
||||
</fileset> |
||||
</path> |
||||
<patternset id="resources4Jar"> |
||||
<exclude name="**/.settings/**"/> |
||||
<exclude name=".classpath"/> |
||||
<exclude name=".project"/> |
||||
|
||||
<exclude name="**/*.java"/> |
||||
<exclude name="**/*.db"/> |
||||
<exclude name="**/*.g"/> |
||||
<exclude name="**/package.html"/> |
||||
</patternset> |
||||
<target name="copy_resources"> |
||||
<echo message="从${resources_from}拷贝图片,JS,CSS等资源文件"/> |
||||
<delete dir="tmp"/> |
||||
<copy todir="tmp"> |
||||
<fileset dir="${resources_from}/src/main/resources"> |
||||
<patternset refid="resources4Jar"/> |
||||
</fileset> |
||||
</copy> |
||||
<copy todir="${classes}"> |
||||
<fileset dir="tmp"/> |
||||
</copy> |
||||
<delete dir="tmp"/> |
||||
</target> |
||||
<target name="compile_javas"> |
||||
<echo message="编译${compile_files}下的Java文件"/> |
||||
<javac destdir="${classes}" debug="false" optimize="on" source="${source_jdk_version}" |
||||
target="${target_jdk_version}" |
||||
fork="true" memoryMaximumSize="512m" listfiles="false" srcdir="${basedir}" |
||||
executable="${compile_jdk_version}/bin/javac"> |
||||
<src path="${basedir}/src/main/java"/> |
||||
<exclude name="**/.svn/**"/> |
||||
<compilerarg line="-encoding UTF8 "/> |
||||
<classpath refid="compile.classpath"/> |
||||
</javac> |
||||
<taskdef name="pretreatment" classname="com.fr.plugin.pack.PluginPretreatmentTask"> |
||||
<classpath refid="compile.classpath"/> |
||||
</taskdef> |
||||
<pretreatment baseDir="${basedir}"/> |
||||
</target> |
||||
|
||||
<target name="jar_classes"> |
||||
<echo message="打Jar包:${jar_name}"/> |
||||
<delete file="${basedir}/${jar_name}"/> |
||||
<jar jarfile="${basedir}/${jar_name}"> |
||||
<fileset dir="${classes}"> |
||||
</fileset> |
||||
</jar> |
||||
</target> |
||||
|
||||
<target name="super_jar" depends="prepare"> |
||||
<antcall target="concat_js"> |
||||
</antcall> |
||||
<antcall target="copy_resources"> |
||||
<param name="resources_from" value="${basedir}"/> |
||||
</antcall> |
||||
<antcall target="compile_javas"> |
||||
<param name="source_jdk_version" value="1.6"/> |
||||
<param name="target_jdk_version" value="1.6"/> |
||||
<param name="compile_jdk_version" value="${jdk.home}"/> |
||||
<param name="compile_files" value="${basedir}/src"/> |
||||
</antcall> |
||||
<echo message="compile plugin success!"/> |
||||
|
||||
<antcall target="jar_classes"> |
||||
<param name="jar_name" value="${plugin-jar}"/> |
||||
</antcall> |
||||
<delete dir="${classes}"/> |
||||
|
||||
</target> |
||||
|
||||
<target name="jar" depends="super_jar"> |
||||
<antcall target="zip"/> |
||||
</target> |
||||
|
||||
<target name="zip"> |
||||
<property name="plugin-folder" value="bi-plugin-${plugin-name}-${plugin-version}"/> |
||||
<echo message="----------zip files----------"/> |
||||
<mkdir dir="${plugin-folder}"/> |
||||
<copy todir="${plugin-folder}"> |
||||
<fileset dir="."> |
||||
<include name="${plugin-jar}"/> |
||||
<include name="plugin.xml"/> |
||||
</fileset> |
||||
<fileset dir="${libs}"> |
||||
<include name="*.jar"/> |
||||
<include name="*.dll"/> |
||||
</fileset> |
||||
</copy> |
||||
<zip destfile="${basedir}/${plugin-folder}.zip" basedir="."> |
||||
<include name="${plugin-folder}/*.jar"/> |
||||
<include name="${plugin-folder}/*.dll"/> |
||||
<include name="${plugin-folder}/plugin.xml"/> |
||||
</zip> |
||||
<move file="${plugin-folder}.zip" todir="${destLoc}/install"/> |
||||
</target> |
||||
|
||||
<!-- 合并静态文件 --> |
||||
<target name="concat_js"> |
||||
<concat destfile="${js-path}/../plugin.screen_adaptive.js" encoding="utf-8" append="false"> |
||||
<fileset dir="${js-path}"> |
||||
<include name="**/*.js"/> |
||||
</fileset> |
||||
</concat> |
||||
</target> |
||||
</project> |
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
||||
<plugin> |
||||
<id>com.finebi.plugin.screen_adaptive</id> |
||||
<name><![CDATA[BI模板屏幕自适应]]></name> |
||||
<active>yes</active> |
||||
<version>1.1.19</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2019-03-01</jartime> |
||||
<vendor>fay</vendor> |
||||
<description><![CDATA[预览BI模板时,根据屏幕的宽度自适应显示模板]]></description> |
||||
<extra-decision> |
||||
<AbstractWebResourceProvider class="com.finebi.plugin.ScreenAdaptive"/> |
||||
</extra-decision> |
||||
<extra-core> |
||||
<LocaleFinder class="com.finebi.plugin.ScreenAdaptiveLocaleFinder"/> |
||||
</extra-core> |
||||
<function-recorder class="com.finebi.plugin.ScreenAdaptive"/> |
||||
<main-package>com.finebi</main-package> |
||||
</plugin> |
@ -0,0 +1,23 @@
|
||||
package com.finebi.plugin; |
||||
|
||||
import com.finebi.conf.internalimp.component.ShowComponent; |
||||
import com.fr.decision.fun.impl.AbstractWebResourceProvider; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.web.struct.Atom; |
||||
|
||||
@EnableMetrics |
||||
public class ScreenAdaptive extends AbstractWebResourceProvider { |
||||
|
||||
@Override |
||||
public Atom attach() { |
||||
return ShowComponent.KEY; |
||||
} |
||||
|
||||
@Override |
||||
@Focus(id = "com.finebi.plugin.ScreenAdaptive", text = "BI插件测试", source = Original.PLUGIN) |
||||
public Atom client() { |
||||
return ScreenAdaptiveComponent.KEY; |
||||
} |
||||
} |
@ -0,0 +1,19 @@
|
||||
package com.finebi.plugin; |
||||
|
||||
import com.fr.web.struct.Component; |
||||
import com.fr.web.struct.category.ScriptPath; |
||||
import com.fr.web.struct.category.StylePath; |
||||
|
||||
public class ScreenAdaptiveComponent extends Component { |
||||
|
||||
public static final ScreenAdaptiveComponent KEY = new ScreenAdaptiveComponent(); |
||||
|
||||
private ScreenAdaptiveComponent() { |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public ScriptPath script() { |
||||
return ScriptPath.build("com/finebi/plugin/web/plugin.screen_adaptive.js"); |
||||
} |
||||
} |
@ -0,0 +1,13 @@
|
||||
package com.finebi.plugin; |
||||
|
||||
import com.fr.plugin.transform.ExecuteFunctionRecord; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.stable.fun.impl.AbstractLocaleFinder; |
||||
@FunctionRecorder |
||||
public class ScreenAdaptiveLocaleFinder extends AbstractLocaleFinder { |
||||
@Override |
||||
@ExecuteFunctionRecord |
||||
public String find() { |
||||
return "com/finebi/plugin/web/i18n/plugin"; |
||||
} |
||||
} |
@ -0,0 +1 @@
|
||||
BI-Plugin-Scale_Adaptive= |
@ -0,0 +1 @@
|
||||
BI-Plugin-Scale_Adaptive=\u7B49\u6BD4\u81EA\u9002\u5E94 |
@ -0,0 +1,223 @@
|
||||
!(function () { |
||||
var scale = 1, transformY = 0, selected = false; |
||||
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__; |
||||
|
||||
// 修正事件偏移
|
||||
function correctEvent(e) { |
||||
if (e && !e.corrected) { |
||||
e.pageX = e.pageX / scale; |
||||
e.pageY = (e.pageY - transformY) / scale; |
||||
e.clientX = e.clientX / scale; |
||||
e.clientY = (e.clientY - transformY) / scale; |
||||
e.corrected = true; |
||||
} |
||||
return e; |
||||
} |
||||
|
||||
// 进行缩放
|
||||
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; |
||||
} |
||||
|
||||
|
||||
window.scale = window.devicePixelRatio * scale; |
||||
} |
||||
|
||||
// 取消缩放
|
||||
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"; |
||||
html.style.backgroundColor = "#ffffff"; |
||||
|
||||
window.scale = window.devicePixelRatio / scale; |
||||
scale = 1; |
||||
} |
||||
|
||||
// 获取缩放倍数,原模板宽高
|
||||
function getScaleBounds() { |
||||
var widgts = BI.designConfigure.widgets, |
||||
layoutRatio = BI.designConfigure.layoutRatio, |
||||
freeLayoutRatio = BI.designConfigure.freeLayoutRatio, |
||||
freeWidgets = BI.designConfigure.freeWidgetIds; |
||||
var left = null, right = null, top = null, bottom = null, |
||||
freeLeft = null, freeRight = null, freeTop = null, freeBottom = null; |
||||
BI.each(widgts, function (wId, widget) { |
||||
var bounds = widget.bounds || {}; |
||||
if (BI.contains(freeWidgets, wId)) { |
||||
freeLeft = BI.isNull(freeLeft) ? bounds.left : Math.min(freeLeft, bounds.left); |
||||
freeRight = Math.max(freeRight, bounds.left + bounds.width); |
||||
freeTop = BI.isNull(freeTop) ? bounds.top : Math.min(freeTop, bounds.top); |
||||
freeBottom = Math.max(freeBottom, bounds.top + bounds.height); |
||||
} else { |
||||
left = BI.isNull(left) ? bounds.left : Math.min(left, bounds.left); |
||||
right = Math.max(right, bounds.left + bounds.width); |
||||
top = BI.isNull(top) ? bounds.top : Math.min(top, bounds.top); |
||||
bottom = Math.max(bottom, bounds.top + bounds.height); |
||||
} |
||||
}); |
||||
|
||||
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 scaleRatio = parseFloat((html.clientWidth / templateWidth).toFixed(1)); |
||||
return { |
||||
scale: scaleRatio, |
||||
width: html.clientWidth / scaleRatio, |
||||
height: 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; |
||||
} |
||||
|
||||
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; |
||||
} |
||||
|
||||
docElem = doc.documentElement; |
||||
|
||||
// Make sure it's not a disconnected DOM node
|
||||
if ( !jQuery.contains( docElem, elem ) ) { |
||||
return box; |
||||
} |
||||
|
||||
var el = elem, |
||||
offsetLeft = 0, |
||||
offsetTop = 0; |
||||
|
||||
do{ |
||||
offsetLeft += el.offsetLeft; |
||||
offsetTop += el.offsetTop; |
||||
el = el.offsetParent; |
||||
} while( el ); |
||||
|
||||
var elm = elem; |
||||
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 ) |
||||
}; |
||||
}; |
||||
jQuery.event.fix = function ( e ) { |
||||
return correctEvent(injectEventFix.call(this, e)); |
||||
}; |
||||
} |
||||
|
||||
window.addEventListener('resize', updateScale); |
||||
} |
||||
|
||||
function restoreEnv() { |
||||
if (!BI.isIE()) { |
||||
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; |
||||
jQuery.fn.offset = injectOffset; |
||||
jQuery.event.fix = injectEventFix; |
||||
} |
||||
|
||||
window.removeEventListener('resize', updateScale); |
||||
} |
||||
|
||||
function selectHandler () { |
||||
selected && prepareEnv(); |
||||
selected ? transformScale() : removeScale(); |
||||
!selected && restoreEnv(); |
||||
} |
||||
|
||||
function updateScale () { |
||||
if (html.getBoundingClientRect().width !== document.body.getBoundingClientRect().width) { |
||||
selectHandler(); |
||||
} |
||||
} |
||||
|
||||
var injectCaptureMouseMoves = BI.MouseMoveTracker.prototype.captureMouseMoves; |
||||
var injectOnMouseMove = BI.MouseMoveTracker.prototype._onMouseMove; |
||||
// 用jQEvent代替MouseEvent
|
||||
function injectMouseMoveTracker() { |
||||
BI.MouseMoveTracker.prototype.captureMouseMoves = function (e) { |
||||
var jQEvent = e.originalEvent ? e : jQuery.event.fix(e); |
||||
injectCaptureMouseMoves.call(this, correctEvent(jQEvent)); |
||||
}; |
||||
BI.MouseMoveTracker.prototype._onMouseMove = function (e) { |
||||
var jQEvent = e.originalEvent ? e : jQuery.event.fix(e); |
||||
injectOnMouseMove.call(this, correctEvent(jQEvent)); |
||||
} |
||||
} |
||||
injectMouseMoveTracker(); |
||||
|
||||
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, |
||||
listeners: [{ |
||||
eventName: BI.MultiSelectItem.EVENT_CHANGE, |
||||
action: function () { |
||||
selected = this.isSelected(); |
||||
selectHandler(); |
||||
} |
||||
}] |
||||
}]) |
||||
}); |
||||
}()); |
@ -0,0 +1,223 @@
|
||||
!(function () { |
||||
var scale = 1, transformY = 0, selected = false; |
||||
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__; |
||||
|
||||
// 修正事件偏移
|
||||
function correctEvent(e) { |
||||
if (e && !e.corrected) { |
||||
e.pageX = e.pageX / scale; |
||||
e.pageY = (e.pageY - transformY) / scale; |
||||
e.clientX = e.clientX / scale; |
||||
e.clientY = (e.clientY - transformY) / scale; |
||||
e.corrected = true; |
||||
} |
||||
return e; |
||||
} |
||||
|
||||
// 进行缩放
|
||||
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; |
||||
} |
||||
|
||||
|
||||
window.scale = window.devicePixelRatio * scale; |
||||
} |
||||
|
||||
// 取消缩放
|
||||
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"; |
||||
html.style.backgroundColor = "#ffffff"; |
||||
|
||||
window.scale = window.devicePixelRatio / scale; |
||||
scale = 1; |
||||
} |
||||
|
||||
// 获取缩放倍数,原模板宽高
|
||||
function getScaleBounds() { |
||||
var widgts = BI.designConfigure.widgets, |
||||
layoutRatio = BI.designConfigure.layoutRatio, |
||||
freeLayoutRatio = BI.designConfigure.freeLayoutRatio, |
||||
freeWidgets = BI.designConfigure.freeWidgetIds; |
||||
var left = null, right = null, top = null, bottom = null, |
||||
freeLeft = null, freeRight = null, freeTop = null, freeBottom = null; |
||||
BI.each(widgts, function (wId, widget) { |
||||
var bounds = widget.bounds || {}; |
||||
if (BI.contains(freeWidgets, wId)) { |
||||
freeLeft = BI.isNull(freeLeft) ? bounds.left : Math.min(freeLeft, bounds.left); |
||||
freeRight = Math.max(freeRight, bounds.left + bounds.width); |
||||
freeTop = BI.isNull(freeTop) ? bounds.top : Math.min(freeTop, bounds.top); |
||||
freeBottom = Math.max(freeBottom, bounds.top + bounds.height); |
||||
} else { |
||||
left = BI.isNull(left) ? bounds.left : Math.min(left, bounds.left); |
||||
right = Math.max(right, bounds.left + bounds.width); |
||||
top = BI.isNull(top) ? bounds.top : Math.min(top, bounds.top); |
||||
bottom = Math.max(bottom, bounds.top + bounds.height); |
||||
} |
||||
}); |
||||
|
||||
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 scaleRatio = parseFloat((html.clientWidth / templateWidth).toFixed(1)); |
||||
return { |
||||
scale: scaleRatio, |
||||
width: html.clientWidth / scaleRatio, |
||||
height: 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; |
||||
} |
||||
|
||||
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; |
||||
} |
||||
|
||||
docElem = doc.documentElement; |
||||
|
||||
// Make sure it's not a disconnected DOM node
|
||||
if ( !jQuery.contains( docElem, elem ) ) { |
||||
return box; |
||||
} |
||||
|
||||
var el = elem, |
||||
offsetLeft = 0, |
||||
offsetTop = 0; |
||||
|
||||
do{ |
||||
offsetLeft += el.offsetLeft; |
||||
offsetTop += el.offsetTop; |
||||
el = el.offsetParent; |
||||
} while( el ); |
||||
|
||||
var elm = elem; |
||||
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 ) |
||||
}; |
||||
}; |
||||
jQuery.event.fix = function ( e ) { |
||||
return correctEvent(injectEventFix.call(this, e)); |
||||
}; |
||||
} |
||||
|
||||
window.addEventListener('resize', updateScale); |
||||
} |
||||
|
||||
function restoreEnv() { |
||||
if (!BI.isIE()) { |
||||
jQuery.fn.__isMouseInBounds__ = injectMouseInBounds; |
||||
jQuery.fn.offset = injectOffset; |
||||
jQuery.event.fix = injectEventFix; |
||||
} |
||||
|
||||
window.removeEventListener('resize', updateScale); |
||||
} |
||||
|
||||
function selectHandler () { |
||||
selected && prepareEnv(); |
||||
selected ? transformScale() : removeScale(); |
||||
!selected && restoreEnv(); |
||||
} |
||||
|
||||
function updateScale () { |
||||
if (html.getBoundingClientRect().width !== document.body.getBoundingClientRect().width) { |
||||
selectHandler(); |
||||
} |
||||
} |
||||
|
||||
var injectCaptureMouseMoves = BI.MouseMoveTracker.prototype.captureMouseMoves; |
||||
var injectOnMouseMove = BI.MouseMoveTracker.prototype._onMouseMove; |
||||
// 用jQEvent代替MouseEvent
|
||||
function injectMouseMoveTracker() { |
||||
BI.MouseMoveTracker.prototype.captureMouseMoves = function (e) { |
||||
var jQEvent = e.originalEvent ? e : jQuery.event.fix(e); |
||||
injectCaptureMouseMoves.call(this, correctEvent(jQEvent)); |
||||
}; |
||||
BI.MouseMoveTracker.prototype._onMouseMove = function (e) { |
||||
var jQEvent = e.originalEvent ? e : jQuery.event.fix(e); |
||||
injectOnMouseMove.call(this, correctEvent(jQEvent)); |
||||
} |
||||
} |
||||
injectMouseMoveTracker(); |
||||
|
||||
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, |
||||
listeners: [{ |
||||
eventName: BI.MultiSelectItem.EVENT_CHANGE, |
||||
action: function () { |
||||
selected = this.isSelected(); |
||||
selectHandler(); |
||||
} |
||||
}] |
||||
}]) |
||||
}); |
||||
}()); |
Loading…
Reference in new issue