Browse Source

Fixed merge conflict

es6
Zhenfei.Li-李振飞 2 years ago
parent
commit
0743286aea
  1. 3
      demo/app.js
  2. 4
      package.json
  3. 2
      src/case/calendar/calendar.js
  4. 4
      src/core/func/function.js
  5. 3
      src/core/index.js
  6. 559
      src/core/platform/web/config.js
  7. 590
      src/core/platform/web/detectElementResize.js
  8. 1472
      src/core/platform/web/dom.js
  9. 285
      src/core/platform/web/function.js
  10. 7
      src/core/platform/web/index.js
  11. 11053
      src/core/platform/web/jquery/_jquery.js
  12. 4
      src/core/platform/web/jquery/event.js
  13. 465
      src/core/platform/web/jquery/fn.js
  14. 4
      src/core/platform/web/jquery/index.js
  15. 107
      src/core/platform/web/load.js
  16. 5
      src/less/case/calendar/calendar.less

3
demo/app.js

@ -1,6 +1,9 @@
Demo = { Demo = {
version: 1.0 version: 1.0
}; };
BI.EVENT_BLUR = false
BI.$(function () { BI.$(function () {
var ref; var ref;

4
package.json

@ -1,6 +1,6 @@
{ {
"name": "fineui", "name": "fineui",
"version": "2.0.20230107203454", "version": "2.0.20230109200447",
"description": "fineui", "description": "fineui",
"main": "dist/fineui_without_conflict.min.js", "main": "dist/fineui_without_conflict.min.js",
"types": "dist/lib/index.d.ts", "types": "dist/lib/index.d.ts",
@ -12,6 +12,7 @@
"@babel/polyfill": "7.6.0", "@babel/polyfill": "7.6.0",
"@fui/babel-preset-fineui": "^2.0.0", "@fui/babel-preset-fineui": "^2.0.0",
"@fui/eslint-plugin": "^1.0.19", "@fui/eslint-plugin": "^1.0.19",
"@juggle/resize-observer": "^3.4.0",
"@types/node": "15.6.1", "@types/node": "15.6.1",
"@typescript-eslint/eslint-plugin": "2.33.0", "@typescript-eslint/eslint-plugin": "2.33.0",
"@typescript-eslint/parser": "2.33.0", "@typescript-eslint/parser": "2.33.0",
@ -89,6 +90,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/yargs": "17.0.13", "@types/yargs": "17.0.13",
"jquery": "3.6.3",
"yargs": "17.6.2" "yargs": "17.6.2"
} }
} }

2
src/case/calendar/calendar.js

@ -170,7 +170,7 @@ BI.Calendar = BI.inherit(BI.Widget, {
forceSelected: true, forceSelected: true,
value: year + "-" + month + "-" + td.text, value: year + "-" + month + "-" + td.text,
disabled: td.disabled, disabled: td.disabled,
cls: td.lastMonth || td.nextMonth ? "not-current-month-day" : "", cls: td.lastMonth || td.nextMonth ? "bi-tips" : "",
lgap: 2, lgap: 2,
rgap: 2, rgap: 2,
tgap: 4, tgap: 4,

4
src/core/func/function.js

@ -2,8 +2,8 @@
* 基本的函数 * 基本的函数
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
*/ */
import {every, isKey, isArray, toUpperCase, each, stripEL, isNotNull, isNull, isObject} from "../2.base"; import { every, isKey, isArray, toUpperCase, each, stripEL, isNotNull, isNull, isObject } from "../2.base";
import {makeFirstPY} from "../utils/chinesePY"; import { makeFirstPY } from "../utils/chinesePY";
/** /**
* 创建唯一的名字 * 创建唯一的名字

3
src/core/index.js

@ -17,6 +17,7 @@ import * as logic from "./logic";
import { Element } from "./element"; import { Element } from "./element";
import * as utils from "./utils"; import * as utils from "./utils";
import * as wrapper from "./wrapper"; import * as wrapper from "./wrapper";
import * as platform from "./platform/web";
export * from "./decorator"; export * from "./decorator";
export * from "./2.base"; export * from "./2.base";
@ -33,6 +34,7 @@ export * from "./constant";
export * from "./logic"; export * from "./logic";
export * from "./utils"; export * from "./utils";
export * from "./wrapper"; export * from "./wrapper";
export * from "./platform/web";
export { export {
StyleLoaderManager, StyleLoaderManager,
@ -63,4 +65,5 @@ Object.assign(BI, {
...h, ...h,
...utils, ...utils,
...wrapper, ...wrapper,
...platform,
}); });

559
src/core/platform/web/config.js

@ -1,286 +1,315 @@
import { Plugin } from "../../6.plugin";
// 工程配置 // 工程配置
!(function () { // 注册布局
// 注册布局 // adapt类布局优先级规则
// adapt类布局优先级规则 // 1、支持flex的浏览器下使用flex布局
// 1、支持flex的浏览器下使用flex布局 // 2、不支持flex的浏览器下使用inline布局
// 2、不支持flex的浏览器下使用inline布局 // 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局
// 3、当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了。当横向出滚动条时使用table布局,不出滚动条时使用float布局 let _isSupportFlex, _isSupportGrid;
var _isSupportFlex, _isSupportGrid;
var isSupportFlex = function () {
if (_isSupportFlex == null) {
_isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex"));
}
return _isSupportFlex;
};
var isSupportGrid = function () {
if (_isSupportGrid == null) {
_isSupportGrid = !!(BI.isSupportCss3 && BI.isSupportCss3("grid"));
}
return _isSupportGrid;
};
// 判断浏览器是否支持sticky 属性
var isSupportSticky = (function () {
var vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"],
vendorListLength = vendorList.length,
stickyElement = document.createElement("div");
for (var i = 0; i < vendorListLength; i++) {
stickyElement.style.position = vendorList[i] + "sticky";
if (stickyElement.style.position !== "") {
return true;
}
}
return false;
})();
BI.Plugin.configWidget("bi.horizontal", function (ob) {
var supportFlex = isSupportFlex();
// // 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// // 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
// if (ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// return BI.extend({}, ob, {type: "bi.table_adapt"});
// }
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
scrollx: true
}, ob, { type: "bi.inline" });
});
BI.Plugin.configWidget("bi.vertical", function (ob) {
if (ob.horizontalAlign === BI.HorizontalAlign.Left || ob.horizontalAlign === BI.HorizontalAlign.Right) {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_vertical" });
}
return BI.extend({}, ob, {
horizontalAlign: BI.HorizontalAlign.Stretch,
type: "bi.vertical",
items: BI.map(ob.items, function (i, item) {
return {
type: "bi.inline",
horizontalAlign: ob.horizontalAlign,
items: [item]
};
})
});
}
if (ob.verticalAlign === BI.VerticalAlign.Stretch) {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
}, ob, { type: "bi.flex_vertical" });
}
}
return ob;
});
BI.Plugin.configWidget("bi.inline", function (ob) {
// 当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了,降级table处理吧
var hasAutoAndFillColumnSize = false;
if (ob.columnSize && ob.columnSize.length > 0) {
if ((ob.columnSize.indexOf("") >= 0 || ob.columnSize.indexOf("auto") >= 0) && ob.columnSize.indexOf("fill") >= 0) {
hasAutoAndFillColumnSize = true;
}
} else {
var hasAuto = false, hasFill = false;
BI.each(ob.items, function (i, item) {
if (item.width === "fill") {
hasFill = true;
} else if (BI.isNull(item.width) || item.width === "" || item.width === "auto") {
hasAuto = true;
}
});
hasAutoAndFillColumnSize = hasAuto && hasFill;
}
if (hasAutoAndFillColumnSize) { function isSupportFlex() {
// 宽度是不是受限 if (!_isSupportFlex) {
if ((ob.scrollable !== true && ob.scrollx !== true) || ob.horizontalAlign === BI.HorizontalAlign.Stretch) { _isSupportFlex = !!(BI.isSupportCss3 && BI.isSupportCss3("flex"));
return BI.extend({ }
verticalAlign: BI.VerticalAlign.Top
}, ob, { type: "bi.horizontal_float_fill" }); return _isSupportFlex;
} }
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch function isSupportGrid() {
}, ob, { type: "bi.table_adapt" }); if (!_isSupportGrid) {
} _isSupportGrid = !!(BI.isSupportCss3 && BI.isSupportCss3("grid"));
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { }
return BI.extend({}, ob, { type: "bi.responsive_inline" });
} return _isSupportGrid;
return ob; }
});
BI.Plugin.configWidget("bi.center_adapt", function (ob) {
var supportFlex = isSupportFlex();
// var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_center_adapt" });
// }
// return ob;
});
BI.Plugin.configWidget("bi.vertical_adapt", function (ob) {
var supportFlex = isSupportFlex();
// var isAdapt = ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_vertical_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_vertical_adapt" });
// }
// return ob;
});
BI.Plugin.configWidget("bi.horizontal_adapt", function (ob) {
var justOneItem = (ob.items && ob.items.length <= 1);
var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
var verticalAlignTop = !ob.verticalAlign || ob.verticalAlign === BI.VerticalAlign.TOP;
if (verticalAlignTop && justOneItem) {
return BI.extend({}, ob, { type: "bi.horizontal_auto" });
}
var supportFlex = isSupportFlex();
// 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
if (isAdapt) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center
}, ob, { type: "bi.table_adapt" });
}
if (supportFlex) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
scrollx: false
}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center
}, ob, { type: "bi.table_adapt" });
});
BI.Plugin.configWidget("bi.horizontal_float", function (ob) {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_horizontal_adapt" });
}
if (ob.items && ob.items.length <= 1) {
return BI.extend({}, ob, { type: "bi.inline_horizontal_adapt" });
}
return ob;
});
BI.Plugin.configWidget("bi.horizontal_fill", function (ob) { // 判断浏览器是否支持sticky 属性
const isSupportSticky = (function () {
const vendorList = ["", "-webkit-", "-ms-", "-moz-", "-o-"],
vendorListLength = vendorList.length,
stickyElement = document.createElement("div");
for (let i = 0; i < vendorListLength; i++) {
stickyElement.style.position = `${vendorList[i]}sticky`;
if (stickyElement.style.position !== "") {
return true;
}
}
return false;
}());
const configWidget = Plugin.configWidget;
configWidget("bi.horizontal", ob => {
const supportFlex = isSupportFlex();
// // 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// // 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
// if (ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// return BI.extend({}, ob, {type: "bi.table_adapt"});
// }
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
scrollx: true,
}, ob, { type: "bi.inline" });
});
configWidget("bi.vertical", ob => {
if (ob.horizontalAlign === BI.HorizontalAlign.Left || ob.horizontalAlign === BI.HorizontalAlign.Right) {
if (isSupportFlex()) { if (isSupportFlex()) {
return BI.extend({ return BI.extend({}, ob, { type: "bi.flex_vertical" });
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrollx: false
}, ob, { type: "bi.flex_horizontal" });
}
if ((ob.horizontalAlign && ob.horizontalAlign !== BI.HorizontalAlign.Stretch) || (ob.scrollable === true || ob.scrollx === true)) {
// 宽度不受限,要用table布局
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch
}, ob, { type: "bi.table_adapt" });
} }
return BI.extend({}, ob, { type: "bi.horizontal_float_fill" });
}); return BI.extend({}, ob, {
BI.Plugin.configWidget("bi.vertical_fill", function (ob) { horizontalAlign: BI.HorizontalAlign.Stretch,
type: "bi.vertical",
items: BI.map(ob.items, (i, item) => {
return {
type: "bi.inline",
horizontalAlign: ob.horizontalAlign,
items: [item],
};
}),
});
}
if (ob.verticalAlign === BI.VerticalAlign.Stretch) {
if (isSupportFlex()) { if (isSupportFlex()) {
return BI.extend({ return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrolly: false
}, ob, { type: "bi.flex_vertical" }); }, ob, { type: "bi.flex_vertical" });
} }
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { }
// 有滚动条,降级到table布局处理
return BI.extend({}, ob, { return ob;
type: "bi.td", });
items: BI.map(ob.items, function (i, item) { configWidget("bi.inline", ob => {
return [item]; // 当列宽既需要自动列宽又需要自适应列宽时,inline布局也处理不了了,降级table处理吧
}) let hasAutoAndFillColumnSize = false;
}); if (ob.columnSize && ob.columnSize.length > 0) {
} if ((ob.columnSize.indexOf("") >= 0 || ob.columnSize.indexOf("auto") >= 0) && ob.columnSize.indexOf("fill") >= 0) {
var hasAuto = false; hasAutoAndFillColumnSize = true;
if (ob.rowSize && ob.rowSize.length > 0) { }
if (ob.rowSize.indexOf("") >= 0 || ob.rowSize.indexOf("auto") >= 0) { } else {
let hasAuto = false, hasFill = false;
BI.each(ob.items, (i, item) => {
if (item.width === "fill") {
hasFill = true;
} else if (BI.isNull(item.width) || item.width === "" || item.width === "auto") {
hasAuto = true; hasAuto = true;
} }
} else { });
BI.each(ob.items, function (i, item) { hasAutoAndFillColumnSize = hasAuto && hasFill;
if (BI.isNull(item.height) || item.height === "") { }
hasAuto = true;
}
});
}
if (hasAuto) {
// 有自动高的时候
return BI.extend({}, ob, { type: "bi.vtape_auto" });
}
return BI.extend({}, ob, { type: "bi.vtape" });
});
BI.Plugin.configWidget("bi.horizontal_sticky", function (ob) {
if (!isSupportSticky) {
return BI.extend({ scrollx: true }, ob, { type: "bi.horizontal_fill" });
}
});
BI.Plugin.configWidget("bi.vertical_sticky", function (ob) {
if (!isSupportSticky) {
return BI.extend({ scrolly: true }, ob, { type: "bi.vertical_fill" });
}
});
BI.Plugin.configWidget("bi.left_right_vertical_adapt", function (ob) { if (hasAutoAndFillColumnSize) {
if (isSupportFlex()) { // 宽度是不是受限
// IE下其实也是可以使用flex布局的,只要排除掉出现滚动条的情况 if ((ob.scrollable !== true && ob.scrollx !== true) || ob.horizontalAlign === BI.HorizontalAlign.Stretch) {
// if (!BI.isIE() || (ob.scrollable !== true && ob.scrolly !== true)) { return BI.extend({
return BI.extend({}, ob, { type: "bi.flex_left_right_vertical_adapt" }); verticalAlign: BI.VerticalAlign.Top,
// } }, ob, { type: "bi.horizontal_float_fill" });
} }
return ob;
}); return BI.extend({
BI.Plugin.configWidget("bi.flex_horizontal", function (ob) { horizontalAlign: BI.HorizontalAlign.Stretch,
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { }, ob, { type: "bi.table_adapt" });
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) { }
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return BI.extend({}, ob, { type: "bi.responsive_flex_scrollable_horizontal" }); return BI.extend({}, ob, { type: "bi.responsive_inline" });
} }
return BI.extend({}, ob, { type: "bi.flex_scrollable_horizontal" });
return ob;
});
configWidget("bi.center_adapt", ob => {
const supportFlex = isSupportFlex();
// var isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_center_adapt" });
// }
// return ob;
});
configWidget("bi.vertical_adapt", ob => {
const supportFlex = isSupportFlex();
// var isAdapt = ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
// if (!isAdapt || justOneItem) {
if (supportFlex) {
return BI.extend({}, ob, { type: "bi.flex_vertical_center_adapt" });
}
return BI.extend({}, ob, { type: "bi.inline_vertical_adapt" });
// }
// return ob;
});
configWidget("bi.horizontal_adapt", ob => {
const justOneItem = (ob.items && ob.items.length <= 1);
const isAdapt = !ob.horizontalAlign || ob.horizontalAlign === BI.HorizontalAlign.Center || ob.horizontalAlign === BI.HorizontalAlign.Stretch;
const verticalAlignTop = !ob.verticalAlign || ob.verticalAlign === BI.VerticalAlign.TOP;
if (verticalAlignTop && justOneItem) {
return BI.extend({}, ob, { type: "bi.horizontal_auto" });
}
const supportFlex = isSupportFlex();
// 在横向自适应场景下我们需要使用table的自适应撑出滚动条的特性(flex处理不了这种情况)
// 主要出现在center_adapt或者horizontal_adapt的场景,或者主动设置horizontalAlign的场景
if (isAdapt) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
}, ob, { type: "bi.table_adapt" });
}
if (supportFlex) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
scrollx: false,
}, ob, { type: "bi.flex_horizontal" });
}
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Center,
}, ob, { type: "bi.table_adapt" });
});
configWidget("bi.horizontal_float", ob => {
if (isSupportFlex()) {
return BI.extend({}, ob, { type: "bi.flex_horizontal_adapt" });
}
if (ob.items && ob.items.length <= 1) {
return BI.extend({}, ob, { type: "bi.inline_horizontal_adapt" });
}
return ob;
});
configWidget("bi.horizontal_fill", ob => {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrollx: false,
}, ob, { type: "bi.flex_horizontal" });
}
if ((ob.horizontalAlign && ob.horizontalAlign !== BI.HorizontalAlign.Stretch) || (ob.scrollable === true || ob.scrollx === true)) {
// 宽度不受限,要用table布局
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
}, ob, { type: "bi.table_adapt" });
}
return BI.extend({}, ob, { type: "bi.horizontal_float_fill" });
});
configWidget("bi.vertical_fill", ob => {
if (isSupportFlex()) {
return BI.extend({
horizontalAlign: BI.HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch,
scrolly: false,
}, ob, { type: "bi.flex_vertical" });
}
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
// 有滚动条,降级到table布局处理
return BI.extend({}, ob, {
type: "bi.td",
items: BI.map(ob.items, (i, item) => [item]),
});
}
let hasAuto = false;
if (ob.rowSize && ob.rowSize.length > 0) {
if (ob.rowSize.indexOf("") >= 0 || ob.rowSize.indexOf("auto") >= 0) {
hasAuto = true;
}
} else {
BI.each(ob.items, (i, item) => {
if (BI.isNull(item.height) || item.height === "") {
hasAuto = true;
} }
} });
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) { }
return BI.extend({}, ob, { type: "bi.responsive_flex_horizontal" }); if (hasAuto) {
} // 有自动高的时候
}); return BI.extend({}, ob, { type: "bi.vtape_auto" });
BI.Plugin.configWidget("bi.flex_vertical", function (ob) { }
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) { return BI.extend({}, ob, { type: "bi.vtape" });
return BI.extend({}, ob, { type: "bi.flex_scrollable_vertical" }); });
configWidget("bi.horizontal_sticky", ob => {
if (!isSupportSticky) {
return BI.extend({ scrollx: true }, ob, { type: "bi.horizontal_fill" });
}
});
configWidget("bi.vertical_sticky", ob => {
if (!isSupportSticky) {
return BI.extend({ scrolly: true }, ob, { type: "bi.vertical_fill" });
}
});
configWidget("bi.left_right_vertical_adapt", ob => {
if (isSupportFlex()) {
// IE下其实也是可以使用flex布局的,只要排除掉出现滚动条的情况
// if (!BI.isIE() || (ob.scrollable !== true && ob.scrolly !== true)) {
return BI.extend({}, ob, { type: "bi.flex_left_right_vertical_adapt" });
// }
}
return ob;
});
configWidget("bi.flex_horizontal", ob => {
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) {
if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return BI.extend({}, ob, { type: "bi.responsive_flex_scrollable_horizontal" });
} }
}
});
BI.Plugin.configWidget("bi.table", function (ob) { return BI.extend({}, ob, { type: "bi.flex_scrollable_horizontal" });
if (!isSupportGrid()) { }
return BI.extend({}, ob, { type: "bi.td" }); }
} if (BI.Providers.getProvider("bi.provider.system").getResponsiveMode()) {
return ob; return BI.extend({}, ob, { type: "bi.responsive_flex_horizontal" });
}); }
});
configWidget("bi.flex_vertical", ob => {
if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) {
if (ob.hgap > 0 || ob.lgap > 0 || ob.rgap > 0) {
return BI.extend({}, ob, { type: "bi.flex_scrollable_vertical" });
}
}
});
BI.Plugin.configWidget("bi.radio", function (ob) { configWidget("bi.table", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) { if (!isSupportGrid()) {
return BI.extend({}, ob, { type: "bi.image_radio" }); return BI.extend({}, ob, { type: "bi.td" });
} }
return ob;
});
BI.Plugin.configWidget("bi.checkbox", function (ob) { return ob;
if (BI.isIE() && BI.getIEVersion() <= 9) { });
return BI.extend({}, ob, { type: "bi.image_checkbox" });
} configWidget("bi.radio", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) {
return BI.extend({}, ob, { type: "bi.image_radio" });
}
return ob;
});
configWidget("bi.checkbox", ob => {
if (BI.isIE() && BI.getIEVersion() <= 9) {
return BI.extend({}, ob, { type: "bi.image_checkbox" });
}
return ob;
});
configWidget("bi.half_icon_button", ob => {
if (BI.isIE() && BI.getIEVersion() < 9) {
return ob; return ob;
}); }
return BI.extend({}, ob, { type: "bi.half_button" });
});
BI.Plugin.configWidget("bi.half_icon_button", function (ob) {
if (BI.isIE() && BI.getIEVersion() < 9) {
return ob;
}
return BI.extend({}, ob, { type: "bi.half_button" });
});
}());

590
src/core/platform/web/detectElementResize.js

@ -1,571 +1,15 @@
/** import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
* Detect Element Resize.
* A minimal library which polyfills the ResizeObserver API and is entirely based on the latest Draft Specification.
* https://github.com/juggle/resize-observer
* version: 3.4.0
**/
var ResizeObserverPolyfill = (function (exports) {
'use strict';
var resizeObservers = []; const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
var hasActiveObservations = function () { function addResizeListener(element, fn) {
return resizeObservers.some(function (ro) {
return ro.activeTargets.length > 0;
});
};
var hasSkippedObservations = function () {
return resizeObservers.some(function (ro) {
return ro.skippedTargets.length > 0;
});
};
var msg = 'ResizeObserver loop completed with undelivered notifications.';
var deliverResizeLoopError = function () {
var event;
if (typeof ErrorEvent === 'function') {
event = new ErrorEvent('error', {
message: msg
});
} else {
event = document.createEvent('Event');
event.initEvent('error', false, false);
event.message = msg;
}
window.dispatchEvent(event);
};
var ResizeObserverBoxOptions;
(function (ResizeObserverBoxOptions) {
ResizeObserverBoxOptions["BORDER_BOX"] = "border-box";
ResizeObserverBoxOptions["CONTENT_BOX"] = "content-box";
ResizeObserverBoxOptions["DEVICE_PIXEL_CONTENT_BOX"] = "device-pixel-content-box";
})(ResizeObserverBoxOptions || (ResizeObserverBoxOptions = {}));
var freeze = function (obj) {
return Object.freeze(obj);
};
var ResizeObserverSize = (function () {
function ResizeObserverSize(inlineSize, blockSize) {
this.inlineSize = inlineSize;
this.blockSize = blockSize;
freeze(this);
}
return ResizeObserverSize;
}());
var DOMRectReadOnly = (function () {
function DOMRectReadOnly(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.top = this.y;
this.left = this.x;
this.bottom = this.top + this.height;
this.right = this.left + this.width;
return freeze(this);
}
DOMRectReadOnly.prototype.toJSON = function () {
var _a = this, x = _a.x, y = _a.y, top = _a.top, right = _a.right, bottom = _a.bottom, left = _a.left,
width = _a.width, height = _a.height;
return { x: x, y: y, top: top, right: right, bottom: bottom, left: left, width: width, height: height };
};
DOMRectReadOnly.fromRect = function (rectangle) {
return new DOMRectReadOnly(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
};
return DOMRectReadOnly;
}());
var isSVG = function (target) {
return target instanceof SVGElement && 'getBBox' in target;
};
var isHidden = function (target) {
if (isSVG(target)) {
var _a = target.getBBox(), width = _a.width, height = _a.height;
return !width && !height;
}
var _b = target, offsetWidth = _b.offsetWidth, offsetHeight = _b.offsetHeight;
return !(offsetWidth || offsetHeight || target.getClientRects().length);
};
var isElement = function (obj) {
var _a;
if (obj instanceof Element) {
return true;
}
var scope = (_a = obj === null || obj === void 0 ? void 0 : obj.ownerDocument) === null || _a === void 0 ? void 0 : _a.defaultView;
return !!(scope && obj instanceof scope.Element);
};
var isReplacedElement = function (target) {
switch (target.tagName) {
case 'INPUT':
if (target.type !== 'image') {
break;
}
case 'VIDEO':
case 'AUDIO':
case 'EMBED':
case 'OBJECT':
case 'CANVAS':
case 'IFRAME':
case 'IMG':
return true;
}
return false;
};
var global = typeof window !== 'undefined' ? window : {};
var cache = new WeakMap();
var scrollRegexp = /auto|scroll/;
var verticalRegexp = /^tb|vertical/;
var IE = (/msie|trident/i).test(global.navigator && global.navigator.userAgent);
var parseDimension = function (pixel) {
return parseFloat(pixel || '0');
};
var size = function (inlineSize, blockSize, switchSizes) {
if (inlineSize === void 0) {
inlineSize = 0;
}
if (blockSize === void 0) {
blockSize = 0;
}
if (switchSizes === void 0) {
switchSizes = false;
}
return new ResizeObserverSize((switchSizes ? blockSize : inlineSize) || 0, (switchSizes ? inlineSize : blockSize) || 0);
};
var zeroBoxes = freeze({
devicePixelContentBoxSize: size(),
borderBoxSize: size(),
contentBoxSize: size(),
contentRect: new DOMRectReadOnly(0, 0, 0, 0)
});
var calculateBoxSizes = function (target, forceRecalculation) {
if (forceRecalculation === void 0) {
forceRecalculation = false;
}
if (cache.has(target) && !forceRecalculation) {
return cache.get(target);
}
if (isHidden(target)) {
cache.set(target, zeroBoxes);
return zeroBoxes;
}
var cs = getComputedStyle(target);
var svg = isSVG(target) && target.ownerSVGElement && target.getBBox();
var removePadding = !IE && cs.boxSizing === 'border-box';
var switchSizes = verticalRegexp.test(cs.writingMode || '');
var canScrollVertically = !svg && scrollRegexp.test(cs.overflowY || '');
var canScrollHorizontally = !svg && scrollRegexp.test(cs.overflowX || '');
var paddingTop = svg ? 0 : parseDimension(cs.paddingTop);
var paddingRight = svg ? 0 : parseDimension(cs.paddingRight);
var paddingBottom = svg ? 0 : parseDimension(cs.paddingBottom);
var paddingLeft = svg ? 0 : parseDimension(cs.paddingLeft);
var borderTop = svg ? 0 : parseDimension(cs.borderTopWidth);
var borderRight = svg ? 0 : parseDimension(cs.borderRightWidth);
var borderBottom = svg ? 0 : parseDimension(cs.borderBottomWidth);
var borderLeft = svg ? 0 : parseDimension(cs.borderLeftWidth);
var horizontalPadding = paddingLeft + paddingRight;
var verticalPadding = paddingTop + paddingBottom;
var horizontalBorderArea = borderLeft + borderRight;
var verticalBorderArea = borderTop + borderBottom;
var horizontalScrollbarThickness = !canScrollHorizontally ? 0 : target.offsetHeight - verticalBorderArea - target.clientHeight;
var verticalScrollbarThickness = !canScrollVertically ? 0 : target.offsetWidth - horizontalBorderArea - target.clientWidth;
var widthReduction = removePadding ? horizontalPadding + horizontalBorderArea : 0;
var heightReduction = removePadding ? verticalPadding + verticalBorderArea : 0;
var contentWidth = svg ? svg.width : parseDimension(cs.width) - widthReduction - verticalScrollbarThickness;
var contentHeight = svg ? svg.height : parseDimension(cs.height) - heightReduction - horizontalScrollbarThickness;
var borderBoxWidth = contentWidth + horizontalPadding + verticalScrollbarThickness + horizontalBorderArea;
var borderBoxHeight = contentHeight + verticalPadding + horizontalScrollbarThickness + verticalBorderArea;
var boxes = freeze({
devicePixelContentBoxSize: size(Math.round(contentWidth * devicePixelRatio), Math.round(contentHeight * devicePixelRatio), switchSizes),
borderBoxSize: size(borderBoxWidth, borderBoxHeight, switchSizes),
contentBoxSize: size(contentWidth, contentHeight, switchSizes),
contentRect: new DOMRectReadOnly(paddingLeft, paddingTop, contentWidth, contentHeight)
});
cache.set(target, boxes);
return boxes;
};
var calculateBoxSize = function (target, observedBox, forceRecalculation) {
var _a = calculateBoxSizes(target, forceRecalculation), borderBoxSize = _a.borderBoxSize,
contentBoxSize = _a.contentBoxSize, devicePixelContentBoxSize = _a.devicePixelContentBoxSize;
switch (observedBox) {
case ResizeObserverBoxOptions.DEVICE_PIXEL_CONTENT_BOX:
return devicePixelContentBoxSize;
case ResizeObserverBoxOptions.BORDER_BOX:
return borderBoxSize;
default:
return contentBoxSize;
}
};
var ResizeObserverEntry = (function () {
function ResizeObserverEntry(target) {
var boxes = calculateBoxSizes(target);
this.target = target;
this.contentRect = boxes.contentRect;
this.borderBoxSize = freeze([boxes.borderBoxSize]);
this.contentBoxSize = freeze([boxes.contentBoxSize]);
this.devicePixelContentBoxSize = freeze([boxes.devicePixelContentBoxSize]);
}
return ResizeObserverEntry;
}());
var calculateDepthForNode = function (node) {
if (isHidden(node)) {
return Infinity;
}
var depth = 0;
var parent = node.parentNode;
while (parent) {
depth += 1;
parent = parent.parentNode;
}
return depth;
};
var broadcastActiveObservations = function () {
var shallowestDepth = Infinity;
var callbacks = [];
resizeObservers.forEach(function processObserver(ro) {
if (ro.activeTargets.length === 0) {
return;
}
var entries = [];
ro.activeTargets.forEach(function processTarget(ot) {
var entry = new ResizeObserverEntry(ot.target);
var targetDepth = calculateDepthForNode(ot.target);
entries.push(entry);
ot.lastReportedSize = calculateBoxSize(ot.target, ot.observedBox);
if (targetDepth < shallowestDepth) {
shallowestDepth = targetDepth;
}
});
callbacks.push(function resizeObserverCallback() {
ro.callback.call(ro.observer, entries, ro.observer);
});
ro.activeTargets.splice(0, ro.activeTargets.length);
});
for (var _i = 0, callbacks_1 = callbacks; _i < callbacks_1.length; _i++) {
var callback = callbacks_1[_i];
callback();
}
return shallowestDepth;
};
var gatherActiveObservationsAtDepth = function (depth) {
resizeObservers.forEach(function processObserver(ro) {
ro.activeTargets.splice(0, ro.activeTargets.length);
ro.skippedTargets.splice(0, ro.skippedTargets.length);
ro.observationTargets.forEach(function processTarget(ot) {
if (ot.isActive()) {
if (calculateDepthForNode(ot.target) > depth) {
ro.activeTargets.push(ot);
} else {
ro.skippedTargets.push(ot);
}
}
});
});
};
var process = function () {
var depth = 0;
gatherActiveObservationsAtDepth(depth);
while (hasActiveObservations()) {
depth = broadcastActiveObservations();
gatherActiveObservationsAtDepth(depth);
}
if (hasSkippedObservations()) {
deliverResizeLoopError();
}
return depth > 0;
};
var trigger;
var callbacks = [];
var notify = function () {
return callbacks.splice(0).forEach(function (cb) {
return cb();
});
};
var queueMicroTask = function (callback) {
if (!trigger) {
var toggle_1 = 0;
var el_1 = document.createTextNode('');
var config = { characterData: true };
new MutationObserver(function () {
return notify();
}).observe(el_1, config);
trigger = function () {
el_1.textContent = "".concat(toggle_1 ? toggle_1-- : toggle_1++);
};
}
callbacks.push(callback);
trigger();
};
var queueResizeObserver = function (cb) {
queueMicroTask(function ResizeObserver() {
requestAnimationFrame(cb);
});
};
var watching = 0;
var isWatching = function () {
return !!watching;
};
var CATCH_PERIOD = 250;
var observerConfig = { attributes: true, characterData: true, childList: true, subtree: true };
var events = [
'resize',
'load',
'transitionend',
'animationend',
'animationstart',
'animationiteration',
'keyup',
'keydown',
'mouseup',
'mousedown',
'mouseover',
'mouseout',
'blur',
'focus'
];
var time = function (timeout) {
if (timeout === void 0) {
timeout = 0;
}
return Date.now() + timeout;
};
var scheduled = false;
var Scheduler = (function () {
function Scheduler() {
var _this = this;
this.stopped = true;
this.listener = function () {
return _this.schedule();
};
}
Scheduler.prototype.run = function (timeout) {
var _this = this;
if (timeout === void 0) {
timeout = CATCH_PERIOD;
}
if (scheduled) {
return;
}
scheduled = true;
var until = time(timeout);
queueResizeObserver(function () {
var elementsHaveResized = false;
try {
elementsHaveResized = process();
} finally {
scheduled = false;
timeout = until - time();
if (!isWatching()) {
return;
}
if (elementsHaveResized) {
_this.run(1000);
} else if (timeout > 0) {
_this.run(timeout);
} else {
_this.start();
}
}
});
};
Scheduler.prototype.schedule = function () {
this.stop();
this.run();
};
Scheduler.prototype.observe = function () {
var _this = this;
var cb = function () {
return _this.observer && _this.observer.observe(document.body, observerConfig);
};
document.body ? cb() : global.addEventListener('DOMContentLoaded', cb);
};
Scheduler.prototype.start = function () {
var _this = this;
if (this.stopped) {
this.stopped = false;
this.observer = new MutationObserver(this.listener);
this.observe();
events.forEach(function (name) {
return global.addEventListener(name, _this.listener, true);
});
}
};
Scheduler.prototype.stop = function () {
var _this = this;
if (!this.stopped) {
this.observer && this.observer.disconnect();
events.forEach(function (name) {
return global.removeEventListener(name, _this.listener, true);
});
this.stopped = true;
}
};
return Scheduler;
}());
var scheduler = new Scheduler();
var updateCount = function (n) {
!watching && n > 0 && scheduler.start();
watching += n;
!watching && scheduler.stop();
};
var skipNotifyOnElement = function (target) {
return !isSVG(target)
&& !isReplacedElement(target)
&& getComputedStyle(target).display === 'inline';
};
var ResizeObservation = (function () {
function ResizeObservation(target, observedBox) {
this.target = target;
this.observedBox = observedBox || ResizeObserverBoxOptions.CONTENT_BOX;
this.lastReportedSize = {
inlineSize: -1,
blockSize: -1
};
}
ResizeObservation.prototype.isActive = function () {
var size = calculateBoxSize(this.target, this.observedBox, true);
if (skipNotifyOnElement(this.target)) {
this.lastReportedSize = size;
}
if (this.lastReportedSize.inlineSize !== size.inlineSize
|| this.lastReportedSize.blockSize !== size.blockSize) {
return true;
}
return false;
};
return ResizeObservation;
}());
var ResizeObserverDetail = (function () {
function ResizeObserverDetail(resizeObserver, callback) {
this.activeTargets = [];
this.skippedTargets = [];
this.observationTargets = [];
this.observer = resizeObserver;
this.callback = callback;
}
return ResizeObserverDetail;
}());
var observerMap = new WeakMap();
var getObservationIndex = function (observationTargets, target) {
for (var i = 0; i < observationTargets.length; i += 1) {
if (observationTargets[i].target === target) {
return i;
}
}
return -1;
};
var ResizeObserverController = (function () {
function ResizeObserverController() {
}
ResizeObserverController.connect = function (resizeObserver, callback) {
var detail = new ResizeObserverDetail(resizeObserver, callback);
observerMap.set(resizeObserver, detail);
};
ResizeObserverController.observe = function (resizeObserver, target, options) {
var detail = observerMap.get(resizeObserver);
var firstObservation = detail.observationTargets.length === 0;
if (getObservationIndex(detail.observationTargets, target) < 0) {
firstObservation && resizeObservers.push(detail);
detail.observationTargets.push(new ResizeObservation(target, options && options.box));
updateCount(1);
scheduler.schedule();
}
};
ResizeObserverController.unobserve = function (resizeObserver, target) {
var detail = observerMap.get(resizeObserver);
var index = getObservationIndex(detail.observationTargets, target);
var lastObservation = detail.observationTargets.length === 1;
if (index >= 0) {
lastObservation && resizeObservers.splice(resizeObservers.indexOf(detail), 1);
detail.observationTargets.splice(index, 1);
updateCount(-1);
}
};
ResizeObserverController.disconnect = function (resizeObserver) {
var _this = this;
var detail = observerMap.get(resizeObserver);
detail.observationTargets.slice().forEach(function (ot) {
return _this.unobserve(resizeObserver, ot.target);
});
detail.activeTargets.splice(0, detail.activeTargets.length);
};
return ResizeObserverController;
}());
var ResizeObserver = (function () {
function ResizeObserver(callback) {
if (arguments.length === 0) {
throw new TypeError("Failed to construct 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (typeof callback !== 'function') {
throw new TypeError("Failed to construct 'ResizeObserver': The callback provided as parameter 1 is not a function.");
}
ResizeObserverController.connect(this, callback);
}
ResizeObserver.prototype.observe = function (target, options) {
if (arguments.length === 0) {
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (!isElement(target)) {
throw new TypeError("Failed to execute 'observe' on 'ResizeObserver': parameter 1 is not of type 'Element");
}
ResizeObserverController.observe(this, target, options);
};
ResizeObserver.prototype.unobserve = function (target) {
if (arguments.length === 0) {
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': 1 argument required, but only 0 present.");
}
if (!isElement(target)) {
throw new TypeError("Failed to execute 'unobserve' on 'ResizeObserver': parameter 1 is not of type 'Element");
}
ResizeObserverController.unobserve(this, target);
};
ResizeObserver.prototype.disconnect = function () {
ResizeObserverController.disconnect(this);
};
ResizeObserver.toString = function () {
return 'function ResizeObserver () { [polyfill code] }';
};
return ResizeObserver;
}());
return ResizeObserver;
})();
var ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
var addResizeListener = function (element, fn) {
if (ResizeObserver) { if (ResizeObserver) {
if (!element.__resizeObserver__) { if (!element.__resizeObserver__) {
var resizeObserver = new ResizeObserver(function () { const resizeObserver = new ResizeObserver((() => {
element.__resizeListeners__.forEach(function (listener) { element.__resizeListeners__.forEach(listener => {
BI.$(element).is(":visible") && listener(); BI.$(element).is(":visible") && listener();
}); });
}); }));
resizeObserver.observe(element); resizeObserver.observe(element);
element.__resizeObserver__ = resizeObserver; element.__resizeObserver__ = resizeObserver;
} }
@ -574,16 +18,18 @@ var addResizeListener = function (element, fn) {
} }
element.__resizeListeners__.push(fn); element.__resizeListeners__.push(fn);
} }
}; }
var removeResizeListener = function (element, fn) {
function removeResizeListener(element, fn) {
if (ResizeObserver) { if (ResizeObserver) {
if (BI.isNull(fn)) { if (BI.isNull(fn)) {
element.__resizeListeners__ = []; element.__resizeListeners__ = [];
element.__resizeObserver__ && element.__resizeObserver__.unobserve(element); element.__resizeObserver__ && element.__resizeObserver__.unobserve(element);
element.__resizeObserver__ = null; element.__resizeObserver__ = null;
return; return;
} }
var index = element.__resizeListeners__.indexOf(fn); const index = element.__resizeListeners__.indexOf(fn);
if (index >= 0) { if (index >= 0) {
element.__resizeListeners__.splice(index, 1); element.__resizeListeners__.splice(index, 1);
if (!element.__resizeListeners__.length) { if (!element.__resizeListeners__.length) {
@ -592,19 +38,17 @@ var removeResizeListener = function (element, fn) {
} }
} }
} }
}; }
export const ResizeDetector = { export const ResizeDetector = {
addResizeListener: function (widget, fn) { addResizeListener(widget, fn) {
addResizeListener(widget.element[0], fn); addResizeListener(widget.element[0], fn);
return function () { return function () {
removeResizeListener(widget.element[0], fn); removeResizeListener(widget.element[0], fn);
}; };
}, removeResizeListener: function (widget, fn) { },
removeResizeListener(widget, fn) {
removeResizeListener(widget.element[0], fn); removeResizeListener(widget.element[0], fn);
} },
}; };
Object.assign(BI, {
ResizeDetector
});

1472
src/core/platform/web/dom.js

File diff suppressed because it is too large Load Diff

285
src/core/platform/web/function.js

@ -1,151 +1,170 @@
// 浏览器相关方法 // 浏览器相关方法
BI._.extend(BI, { import { isString } from "../../2.base";
isIE: function () {
if(!_global.navigator) {
return false;
}
if (this.__isIE == null) {
this.__isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase());
}
return this.__isIE;
},
getIEVersion: function () { let __isIE;
if(!_global.navigator) {
return 0;
}
if (this.__IEVersion != null) {
return this.__IEVersion;
}
var version = 0;
var agent = navigator.userAgent.toLowerCase();
var v1 = agent.match(/(?:msie\s([\w.]+))/);
var v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
if (v1 && v2 && v1[1] && v2[1]) {
version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
version = v1[1] * 1;
} else if (v2 && v2[1]) {
version = v2[1] * 1;
} else {
version = 0;
}
return this.__IEVersion = version;
},
isIE9Below: function () { export function isIE() {
if (!BI.isIE()) { if (!_global.navigator) {
return false; return false;
} }
return this.getIEVersion() < 9; if (!__isIE) {
}, __isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase());
}
isEdge: function () { return __isIE;
if(!_global.navigator) { }
return false;
}
return /edg/i.test(navigator.userAgent.toLowerCase());
},
isChrome: function () { let __IEVersion;
if(!_global.navigator) {
return false;
}
return /chrome/i.test(navigator.userAgent.toLowerCase());
},
isFireFox: function () { export function getIEVersion() {
if(!_global.navigator) { if (!_global.navigator) {
return false; return 0;
} }
return /firefox/i.test(navigator.userAgent.toLowerCase()); if (__IEVersion) {
}, return __IEVersion;
}
let version = 0;
const agent = navigator.userAgent.toLowerCase();
const v1 = agent.match(/(?:msie\s([\w.]+))/);
const v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
if (v1 && v2 && v1[1] && v2[1]) {
version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
version = v1[1] * 1;
} else if (v2 && v2[1]) {
version = v2[1] * 1;
} else {
version = 0;
}
__IEVersion = version;
isOpera: function () { return __IEVersion;
if(!_global.navigator) { }
return false;
}
return /opera/i.test(navigator.userAgent.toLowerCase());
},
isSafari: function () { export function isIE9Below() {
if(!_global.navigator) { if (!isIE()) {
return false; return false;
} }
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase());
},
isKhtml: function () { return getIEVersion() < 9;
if(!_global.navigator) { }
return false;
}
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
},
isMac: function () { export function isEdge() {
if(!_global.navigator) { if (!_global.navigator) {
return false; return false;
} }
return /macintosh|mac os x/i.test(navigator.userAgent);
},
isWindows: function () { return /edg/i.test(navigator.userAgent.toLowerCase());
if(!_global.navigator) { }
return false;
}
return /windows|win32/i.test(navigator.userAgent);
},
isSupportCss3: function (style) { export function isChrome() {
if(!_global.document) { if (!_global.navigator) {
return false; return false;
} }
var prefix = ["webkit", "Moz", "ms", "o"],
i, len,
humpString = [],
htmlStyle = document.documentElement.style,
_toHumb = function (string) {
if (!BI.isString(string)) {
return "";
}
return string.replace(/-(\w)/g, function ($0, $1) {
return $1.toUpperCase();
});
};
for ( i = 0; i < prefix.length; i++) {
humpString.push(_toHumb(prefix[i] + "-" + style));
}
humpString.push(_toHumb(style));
for (i = 0, len = humpString.length; i < len; i++) { return /chrome/i.test(navigator.userAgent.toLowerCase());
if (humpString[i] in htmlStyle) { }
return true;
} export function isFireFox() {
} if (!_global.navigator) {
return false;
}
return /firefox/i.test(navigator.userAgent.toLowerCase());
}
export function isOpera() {
if (!_global.navigator) {
return false;
}
return /opera/i.test(navigator.userAgent.toLowerCase());
}
export function isSafari() {
if (!_global.navigator) {
return false;
}
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase());
}
export function isKhtml() {
if (!_global.navigator) {
return false;
}
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
}
export function isMac() {
if (!_global.navigator) {
return false;
}
return /macintosh|mac os x/i.test(navigator.userAgent);
}
export function isWindows() {
if (!_global.navigator) {
return false; return false;
}, }
return /windows|win32/i.test(navigator.userAgent);
}
export function isSupportCss3(style) {
if (!_global.document) {
return false;
}
const prefix = ["webkit", "Moz", "ms", "o"];
const humpString = [];
const htmlStyle = document.documentElement.style;
let i;
let len;
getSafariVersion: function () { function _toHumb(string) {
if (!_global.navigator) { if (!isString(string)) {
return 0; return "";
} }
var agent = navigator.userAgent.toLowerCase();
var version = agent.match(/version\/([\d.]+)/); return string.replace(/-(\w)/g, ($0, $1) => $1.toUpperCase());
if (version && version[1]) { };
return version[1] * 1;
for (i = 0; i < prefix.length; i++) {
humpString.push(_toHumb(`${prefix[i]}-${style}`));
}
humpString.push(_toHumb(style));
for (i = 0, len = humpString.length; i < len; i++) {
if (humpString[i] in htmlStyle) {
return true;
} }
}
return false;
}
export function getSafariVersion() {
if (!_global.navigator) {
return 0; return 0;
}, }
const agent = navigator.userAgent.toLowerCase();
getMinimumFontSize: function () { const version = agent.match(/version\/([\d.]+)/);
// not work for firefox if (version && version[1]) {
const el = document.createElement('div'); return version[1] * 1;
el.style.fontSize = "1px"; }
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize; return 0;
el.remove(); }
return parseInt(size);
} export function getMinimumFontSize() {
}); // not work for firefox
const el = document.createElement("div");
el.style.fontSize = "1px";
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize;
el.remove();
return parseInt(size, 10);
}

7
src/core/platform/web/index.js

@ -0,0 +1,7 @@
export * as DOM from "./dom";
export * from "./detectElementResize";
export * from "./function";
export * from "./load";
import "./jquery/index";
import "./config";

11053
src/core/platform/web/jquery/_jquery.js vendored

File diff suppressed because it is too large Load Diff

4
src/core/platform/web/jquery/event.js vendored

@ -3,8 +3,8 @@
*/ */
BI.$.extend(BI.$.Event.prototype, { BI.$.extend(BI.$.Event.prototype, {
// event.stopEvent // event.stopEvent
stopEvent: function () { stopEvent() {
this.stopPropagation(); this.stopPropagation();
this.preventDefault(); this.preventDefault();
} },
}); });

465
src/core/platform/web/jquery/fn.js vendored

@ -1,247 +1,252 @@
if (BI.jQuery) { import { isIE, isIE9Below } from "../function";
(function ($) { import { htmlEncode } from "../../../func";
// richer:容器在其各个边缘留出的空间 import { toUpperCase, remove, camelize, isKey, isNull, isNotEmptyString, map, hyphenate } from "../../../2.base";
if (!$.fn.insets) { import { makeFirstPY } from "../../../utils";
$.fn.insets = function () { import { createWidget } from "../../../5.inject";
var p = this.padding(),
b = this.border(); BI.jQuery.fn.extend({
return {
top: p.top, insets() {
bottom: p.bottom + b.bottom + b.top, const p = this.padding(),
left: p.left, b = this.border();
right: p.right + b.right + b.left
}; return {
}; top: p.top,
} bottom: p.bottom + b.bottom + b.top,
left: p.left,
// richer:获取 && 设置jQuery元素的边界 right: p.right + b.right + b.left,
if (!$.fn.bounds) { };
$.fn.bounds = function (value) { },
var tmp = {hasIgnoredBounds: true};
bounds(value) {
if (value) { let tmp = { hasIgnoredBounds: true };
if (!isNaN(value.x)) {
tmp.left = value.x; if (value) {
} if (!isNaN(value.x)) {
if (!isNaN(value.y)) { tmp.left = value.x;
tmp.top = value.y;
}
if (value.width != null) {
tmp.width = (value.width - (this.outerWidth(true) - this.width()));
tmp.width = (tmp.width >= 0) ? tmp.width : value.width;
// fix chrome
// tmp.width = (tmp.width >= 0) ? tmp.width : 0;
}
if (value.height != null) {
tmp.height = value.height - (this.outerHeight(true) - this.height());
tmp.height = (tmp.height >= 0) ? tmp.height : value.height;
// fix chrome
// tmp.height = (tmp.height >= 0) ? tmp.height : value.0;
}
this.css(tmp);
return this;
}
// richer:注意此方法只对可见元素有效
tmp = this.position();
return {
x: tmp.left,
y: tmp.top,
// richer:这里计算外部宽度和高度的时候,都不包括边框
width: this.outerWidth(),
height: this.outerHeight()
};
};
}
})(BI.jQuery);
BI.extend(BI.jQuery.fn, {
destroy: function () {
this.remove();
if (BI.isIE() === true) {
this[0].outerHTML = "";
} }
}, if (!isNaN(value.y)) {
/** tmp.top = value.y;
* 高亮显示
* @param text 必需
* @param keyword
* @param py
* @returns {*}
* @private
* 原理:
* 1得到text的拼音py, 分别看是否匹配关键字keyword, 得到匹配索引tidx和pidx
* 2比较tidx和pidx, 取大于-1且较小的索引标红[索引索引 + keyword.length - 1]的文本
* 3text和py各自取tidx/pidx + keyword.length索引开始的子串作为新的text和py, 重复1, 直到text和py有一个为""
*/
__textKeywordMarked__: function (text, keyword, py) {
if (BI.isNull(text)) {
text = "";
} }
if (!BI.isKey(keyword) || (text + "").length > 100) { if (value.width != null) {
if (BI.isIE9Below()) { tmp.width = (value.width - (this.outerWidth(true) - this.width()));
return this.html(BI.htmlEncode(text)); tmp.width = (tmp.width >= 0) ? tmp.width : value.width;
} // fix chrome
// textContent性能更好,并且原生防xss // tmp.width = (tmp.width >= 0) ? tmp.width : 0;
this[0].textContent = text;
return this;
} }
keyword = keyword + ""; if (value.height != null) {
keyword = BI.toUpperCase(keyword); tmp.height = value.height - (this.outerHeight(true) - this.height());
var textLeft = text + ""; tmp.height = (tmp.height >= 0) ? tmp.height : value.height;
py = (py || BI.makeFirstPY(text, { // fix chrome
splitChar: "\u200b" // tmp.height = (tmp.height >= 0) ? tmp.height : value.0;
})) + ""; }
py = BI.toUpperCase(py); this.css(tmp);
this.empty();
// BI-48487 性能: makeFirstPY出来的py中包含多音字是必要的,但虽然此方法中做了限制。但是对于一个长度为60,包含14个多音字的字符串
// 获取的的py长度将达到1966080, 远超过text的长度,到后面都是在做"".substring的无用功,所以此循环应保证py和textLeft长度不为0
while (py.length > 0 && textLeft.length > 0) {
var tidx = BI.toUpperCase(textLeft).indexOf(keyword);
var pidx = py.indexOf(keyword);
if (pidx >= 0) {
pidx = (pidx - Math.floor(pidx / (textLeft.length + 1))) % textLeft.length;
}
// BI-56945 场景: 对'啊a'标红, a为keyword, 此时tidx为1, pidx为0, 此时使用tidx显然'啊'就无法标红了 return this;
if (tidx >= 0 && (pidx > tidx || pidx === -1)) { }
// 标红的text未encode
this.append(BI.htmlEncode(textLeft.substr(0, tidx))); // richer:注意此方法只对可见元素有效
this.append(BI.$("<span>").addClass("bi-keyword-red-mark") tmp = this.position();
.html(BI.htmlEncode(textLeft.substr(tidx, keyword.length))));
return {
textLeft = textLeft.substr(tidx + keyword.length); x: tmp.left,
if (BI.isNotEmptyString(py)) { y: tmp.top,
// 每一组拼音都应该前进,而不是只是当前的 // richer:这里计算外部宽度和高度的时候,都不包括边框
py = BI.map(py.split("\u200b"), function (idx, ps) { width: this.outerWidth(),
return ps.slice(tidx + keyword.length); height: this.outerHeight(),
}).join("\u200b"); };
} },
} else if (pidx >= 0) {
// BI-56386 这边两个pid / text.length是为了防止截取的首字符串不是完整的,但光这样做还不够,即时错位了,也不能说明就不符合条件 destroy() {
// 标红的text未encode this.remove();
this.append(BI.htmlEncode(textLeft.substr(0, pidx))); if (isIE() === true) {
this.append(BI.$("<span>").addClass("bi-keyword-red-mark") this[0].outerHTML = "";
.html(BI.htmlEncode(textLeft.substr(pidx, keyword.length)))); }
if (BI.isNotEmptyString(py)) { },
// 每一组拼音都应该前进,而不是只是当前的
py = BI.map(py.split("\u200b"), function (idx, ps) { /**
return ps.slice(pidx + keyword.length); * 高亮显示
}).join("\u200b"); * @param text 必需
} * @param keyword
textLeft = textLeft.substr(pidx + keyword.length); * @param py
} else { * @returns {*}
// 标红的text未encode * @private
this.append(BI.htmlEncode(textLeft)); * 原理:
break; * 1得到text的拼音py, 分别看是否匹配关键字keyword, 得到匹配索引tidx和pidx
} * 2比较tidx和pidx, 取大于-1且较小的索引标红[索引索引 + keyword.length - 1]的文本
* 3text和py各自取tidx/pidx + keyword.length索引开始的子串作为新的text和py, 重复1, 直到text和py有一个为""
*/
__textKeywordMarked__(text, keyword, py) {
if (isNull(text)) {
text = "";
}
if (!isKey(keyword) || (`${text}`).length > 100) {
if (isIE9Below()) {
return this.html(htmlEncode(text));
} }
// textContent性能更好,并且原生防xss
this[0].textContent = text;
return this; return this;
}, }
keyword = `${keyword}`;
getDomHeight: function (parent) { keyword = toUpperCase(keyword);
var clone = BI.$(this).clone(); let textLeft = `${text}`;
clone.appendTo(BI.$(parent || "body")); py = `${py || makeFirstPY(text, {
var height = clone.height(); splitChar: "\u200b",
clone.remove(); })}`;
return height; py = toUpperCase(py);
}, this.empty();
// BI-48487 性能: makeFirstPY出来的py中包含多音字是必要的,但虽然此方法中做了限制。但是对于一个长度为60,包含14个多音字的字符串
// 是否有竖直滚动条 // 获取的的py长度将达到1966080, 远超过text的长度,到后面都是在做"".substring的无用功,所以此循环应保证py和textLeft长度不为0
hasVerticalScroll: function () { while (py.length > 0 && textLeft.length > 0) {
return this.height() > 0 && this[0].clientWidth < this[0].offsetWidth; const tidx = toUpperCase(textLeft).indexOf(keyword);
}, let pidx = py.indexOf(keyword);
if (pidx >= 0) {
// 是否有水平滚动条 pidx = (pidx - Math.floor(pidx / (textLeft.length + 1))) % textLeft.length;
hasHorizonScroll: function () {
return this.width() > 0 && this[0].clientHeight < this[0].offsetHeight;
},
// 获取计算后的样式
getStyle: function (name) {
var node = this[0];
var computedStyle = void 0;
// W3C Standard
if (_global.getComputedStyle) {
// In certain cases such as within an iframe in FF3, this returns null.
computedStyle = _global.getComputedStyle(node, null);
if (computedStyle) {
return computedStyle.getPropertyValue(BI.hyphenate(name));
}
} }
// Safari
if (document.defaultView && document.defaultView.getComputedStyle) { // BI-56945 场景: 对'啊a'标红, a为keyword, 此时tidx为1, pidx为0, 此时使用tidx显然'啊'就无法标红了
computedStyle = document.defaultView.getComputedStyle(node, null); if (tidx >= 0 && (pidx > tidx || pidx === -1)) {
// A Safari bug causes this to return null for `display: none` elements. // 标红的text未encode
if (computedStyle) { this.append(htmlEncode(textLeft.substr(0, tidx)));
return computedStyle.getPropertyValue(BI.hyphenate(name)); this.append(BI.$("<span>").addClass("bi-keyword-red-mark")
.html(htmlEncode(textLeft.substr(tidx, keyword.length))));
textLeft = textLeft.substr(tidx + keyword.length);
if (isNotEmptyString(py)) {
// 每一组拼音都应该前进,而不是只是当前的
py = map(py.split("\u200b"), (idx, ps) => ps.slice(tidx + keyword.length)).join("\u200b");
} }
if (name === "display") { } else if (pidx >= 0) {
return "none"; // BI-56386 这边两个pid / text.length是为了防止截取的首字符串不是完整的,但光这样做还不够,即时错位了,也不能说明就不符合条件
// 标红的text未encode
this.append(htmlEncode(textLeft.substr(0, pidx)));
this.append(BI.$("<span>").addClass("bi-keyword-red-mark")
.html(htmlEncode(textLeft.substr(pidx, keyword.length))));
if (isNotEmptyString(py)) {
// 每一组拼音都应该前进,而不是只是当前的
py = map(py.split("\u200b"), (idx, ps) => ps.slice(pidx + keyword.length)).join("\u200b");
} }
textLeft = textLeft.substr(pidx + keyword.length);
} else {
// 标红的text未encode
this.append(htmlEncode(textLeft));
break;
} }
// Internet Explorer }
if (node.currentStyle) {
if (name === "float") { return this;
return node.currentStyle.cssFloat || node.currentStyle.styleFloat; },
}
return node.currentStyle[BI.camelize(name)]; getDomHeight(parent) {
const clone = BI.$(this).clone();
clone.appendTo(BI.$(parent || "body"));
const height = clone.height();
clone.remove();
return height;
},
// 是否有竖直滚动条
hasVerticalScroll() {
return this.height() > 0 && this[0].clientWidth < this[0].offsetWidth;
},
// 是否有水平滚动条
hasHorizonScroll() {
return this.width() > 0 && this[0].clientHeight < this[0].offsetHeight;
},
// 获取计算后的样式
getStyle(name) {
const node = this[0];
let computedStyle = void 0;
// W3C Standard
if (_global.getComputedStyle) {
// In certain cases such as within an iframe in FF3, this returns null.
computedStyle = _global.getComputedStyle(node, null);
if (computedStyle) {
return computedStyle.getPropertyValue(hyphenate(name));
}
}
// Safari
if (document.defaultView && document.defaultView.getComputedStyle) {
computedStyle = document.defaultView.getComputedStyle(node, null);
// A Safari bug causes this to return null for `display: none` elements.
if (computedStyle) {
return computedStyle.getPropertyValue(hyphenate(name));
}
if (name === "display") {
return "none";
}
}
// Internet Explorer
if (node.currentStyle) {
if (name === "float") {
return node.currentStyle.cssFloat || node.currentStyle.styleFloat;
} }
return node.style && node.style[BI.camelize(name)];
}, return node.currentStyle[camelize(name)];
}
__isMouseInBounds__: function (e) {
var offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset(); return node.style && node.style[camelize(name)];
var width = offset2Body.width || this.outerWidth(); },
var height = offset2Body.height || this.outerHeight();
// offset2Body.left的值可能会有小数,导致某点出现false __isMouseInBounds__(e) {
return !(e.pageX < Math.floor(offset2Body.left) || e.pageX > offset2Body.left + width const offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset();
|| e.pageY < Math.floor(offset2Body.top) || e.pageY > offset2Body.top + height); const width = offset2Body.width || this.outerWidth();
}, const height = offset2Body.height || this.outerHeight();
__hasZIndexMask__: function (zindex) { // offset2Body.left的值可能会有小数,导致某点出现false
return zindex && this.zIndexMask[zindex] != null; return !(e.pageX < Math.floor(offset2Body.left) || e.pageX > offset2Body.left + width
}, || e.pageY < Math.floor(offset2Body.top) || e.pageY > offset2Body.top + height);
},
__buildZIndexMask__: function (zindex, domArray) {
this.zIndexMask = this.zIndexMask || {};// 存储z-index的mask __hasZIndexMask__(zindex) {
this.indexMask = this.indexMask || [];// 存储mask return zindex && this.zIndexMask[zindex] != null;
var mask = BI.createWidget({ },
type: "bi.center_adapt",
cls: "bi-z-index-mask", __buildZIndexMask__(zindex, domArray) {
items: domArray this.zIndexMask = this.zIndexMask || {};// 存储z-index的mask
}); this.indexMask = this.indexMask || [];// 存储mask
const mask = createWidget({
mask.element.css({"z-index": zindex}); type: "bi.center_adapt",
BI.createWidget({ cls: "bi-z-index-mask",
type: "bi.absolute", items: domArray,
element: this, });
items: [{
mask.element.css({ "z-index": zindex });
createWidget({
type: "bi.absolute",
element: this,
items: [
{
el: mask, el: mask,
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }
}); ],
this.indexMask.push(mask); });
zindex && (this.zIndexMask[zindex] = mask); this.indexMask.push(mask);
return mask.element; zindex && (this.zIndexMask[zindex] = mask);
},
return mask.element;
__releaseZIndexMask__: function (zindex) { },
if (zindex && this.zIndexMask[zindex]) {
BI.remove(this.indexMask, this.zIndexMask[zindex]); __releaseZIndexMask__(zindex) {
this.zIndexMask[zindex].destroy(); if (zindex && this.zIndexMask[zindex]) {
return; remove(this.indexMask, this.zIndexMask[zindex]);
} this.zIndexMask[zindex].destroy();
this.indexMask = this.indexMask || [];
var indexMask = this.indexMask.pop(); return;
indexMask && indexMask.destroy();
} }
}); this.indexMask = this.indexMask || [];
} const indexMask = this.indexMask.pop();
indexMask && indexMask.destroy();
},
});

4
src/core/platform/web/jquery/index.js vendored

@ -0,0 +1,4 @@
import "./_jquery";
import "./event";
import "./fn";
import "./jquery.mousewheel";

107
src/core/platform/web/load.js

@ -1,55 +1,56 @@
BI._.extend(BI, { const _LOADED = {}; // alex:保存加载过的
$import: function () { function loadReady(src, must) {
var _LOADED = {}; // alex:保存加载过的 const $scripts = BI.$("head script, body script");
function loadReady (src, must) { BI.$.each($scripts, (i, item) => {
var $scripts = BI.$("head script, body script"); if (item.src.indexOf(src) !== -1) {
BI.$.each($scripts, function (i, item) { _LOADED[src] = true;
if (item.src.indexOf(src) != -1) {
_LOADED[src] = true;
}
});
var $links = BI.$("head link");
BI.$.each($links, function (i, item) {
if (item.href.indexOf(src) != -1 && must) {
_LOADED[src] = false;
BI.$(item).remove();
}
});
} }
});
const $links = BI.$("head link");
BI.$.each($links, (i, item) => {
if (item.href.indexOf(src) !== -1 && must) {
_LOADED[src] = false;
BI.$(item).remove();
}
});
}
// must=true 强行加载 /**
return function (src, ext, must) { *
loadReady(src, must); * @param src
// alex:如果已经加载过了的,直接return * @param ext
if (_LOADED[src] === true) { * @param must 强行加载
return; */
} export function $import(src, ext, must) {
if (ext === "css") { loadReady(src, must);
var link = document.createElement("link"); // alex:如果已经加载过了的,直接return
link.rel = "stylesheet"; if (_LOADED[src] === true) {
link.type = "text/css"; return;
link.href = src; }
var head = document.getElementsByTagName("head")[0]; if (ext === "css") {
head.appendChild(link); const link = document.createElement("link");
_LOADED[src] = true; link.rel = "stylesheet";
} else { link.type = "text/css";
// alex:这里用同步调用的方式,必须等待ajax完成 link.href = src;
BI.$.ajax({ const head = document.getElementsByTagName("head")[0];
url: src, head.appendChild(link);
dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情 _LOADED[src] = true;
async: false, } else {
cache: true, // alex:这里用同步调用的方式,必须等待ajax完成
complete: function (res, status) { BI.$.ajax({
/* url: src,
* alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情
* 所以当status为success时就不需要再把其中的内容加到script里面去了 async: false,
*/ cache: true,
if (status == "success") { complete(res, status) {
_LOADED[src] = true; /*
} * alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval
} * 所以当status为success时就不需要再把其中的内容加到script里面去了
}); */
} if (status === "success") {
}; _LOADED[src] = true;
}() }
}); },
});
}
}

5
src/less/case/calendar/calendar.less

@ -1,5 +0,0 @@
@import "../../index.less";
.bi-calendar-date-item.not-current-month-day {
color: @color-bi-text-disabled-button !important;
}
Loading…
Cancel
Save