Browse Source

KERNEL-14041 feat: core/platform文件夹

es6
zsmj 2 years ago
parent
commit
720ae1260b
  1. 3
      src/core/index.js
  2. 3
      src/core/platform/web/index.js
  3. 4
      src/core/platform/web/jquery/event.js
  4. 161
      src/core/platform/web/jquery/fn.js
  5. 4
      src/core/platform/web/jquery/index.js

3
src/core/index.js

@ -16,6 +16,7 @@ import * as constant from "./constant";
import * as logic from "./logic"; 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 platform from "./platform/web";
export * from "./decorator"; export * from "./decorator";
export * from "./2.base"; export * from "./2.base";
@ -31,6 +32,7 @@ export * from "./h";
export * from "./constant"; export * from "./constant";
export * from "./logic"; export * from "./logic";
export * from "./utils"; export * from "./utils";
export * from "./platform/web";
export { export {
StyleLoaderManager, StyleLoaderManager,
@ -60,4 +62,5 @@ Object.assign(BI, {
useInWorker, useInWorker,
...h, ...h,
...utils, ...utils,
...platform,
}); });

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

@ -2,3 +2,6 @@ export * as DOM from "./dom";
export * from "./detectElementResize"; export * from "./detectElementResize";
export * from "./function"; export * from "./function";
export * from "./load"; export * from "./load";
import "./jquery/index";
import "./config";

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();
} },
}); });

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

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