Zhenfei.Li-李振飞
2 years ago
16 changed files with 1530 additions and 13041 deletions
@ -1,151 +1,170 @@
|
||||
// 浏览器相关方法
|
||||
BI._.extend(BI, { |
||||
isIE: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
if (this.__isIE == null) { |
||||
this.__isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase()); |
||||
} |
||||
return this.__isIE; |
||||
}, |
||||
import { isString } from "../../2.base"; |
||||
|
||||
getIEVersion: function () { |
||||
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; |
||||
}, |
||||
let __isIE; |
||||
|
||||
isIE9Below: function () { |
||||
if (!BI.isIE()) { |
||||
return false; |
||||
} |
||||
return this.getIEVersion() < 9; |
||||
}, |
||||
export function isIE() { |
||||
if (!_global.navigator) { |
||||
return false; |
||||
} |
||||
if (!__isIE) { |
||||
__isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase()); |
||||
} |
||||
|
||||
isEdge: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /edg/i.test(navigator.userAgent.toLowerCase()); |
||||
}, |
||||
return __isIE; |
||||
} |
||||
|
||||
isChrome: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /chrome/i.test(navigator.userAgent.toLowerCase()); |
||||
}, |
||||
let __IEVersion; |
||||
|
||||
isFireFox: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /firefox/i.test(navigator.userAgent.toLowerCase()); |
||||
}, |
||||
export function getIEVersion() { |
||||
if (!_global.navigator) { |
||||
return 0; |
||||
} |
||||
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 () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /opera/i.test(navigator.userAgent.toLowerCase()); |
||||
}, |
||||
return __IEVersion; |
||||
} |
||||
|
||||
isSafari: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase()); |
||||
}, |
||||
export function isIE9Below() { |
||||
if (!isIE()) { |
||||
return false; |
||||
} |
||||
|
||||
isKhtml: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent); |
||||
}, |
||||
return getIEVersion() < 9; |
||||
} |
||||
|
||||
isMac: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /macintosh|mac os x/i.test(navigator.userAgent); |
||||
}, |
||||
export function isEdge() { |
||||
if (!_global.navigator) { |
||||
return false; |
||||
} |
||||
|
||||
isWindows: function () { |
||||
if(!_global.navigator) { |
||||
return false; |
||||
} |
||||
return /windows|win32/i.test(navigator.userAgent); |
||||
}, |
||||
return /edg/i.test(navigator.userAgent.toLowerCase()); |
||||
} |
||||
|
||||
isSupportCss3: function (style) { |
||||
if(!_global.document) { |
||||
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)); |
||||
export function isChrome() { |
||||
if (!_global.navigator) { |
||||
return false; |
||||
} |
||||
|
||||
for (i = 0, len = humpString.length; i < len; i++) { |
||||
if (humpString[i] in htmlStyle) { |
||||
return true; |
||||
} |
||||
} |
||||
return /chrome/i.test(navigator.userAgent.toLowerCase()); |
||||
} |
||||
|
||||
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 /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 () { |
||||
if (!_global.navigator) { |
||||
return 0; |
||||
function _toHumb(string) { |
||||
if (!isString(string)) { |
||||
return ""; |
||||
} |
||||
var agent = navigator.userAgent.toLowerCase(); |
||||
var version = agent.match(/version\/([\d.]+)/); |
||||
if (version && version[1]) { |
||||
return version[1] * 1; |
||||
|
||||
return string.replace(/-(\w)/g, ($0, $1) => $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++) { |
||||
if (humpString[i] in htmlStyle) { |
||||
return true; |
||||
} |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
export function getSafariVersion() { |
||||
if (!_global.navigator) { |
||||
return 0; |
||||
}, |
||||
|
||||
getMinimumFontSize: function () { |
||||
// 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); |
||||
} |
||||
}); |
||||
} |
||||
const agent = navigator.userAgent.toLowerCase(); |
||||
const version = agent.match(/version\/([\d.]+)/); |
||||
if (version && version[1]) { |
||||
return version[1] * 1; |
||||
} |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
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); |
||||
} |
||||
|
@ -0,0 +1,7 @@
|
||||
export * as DOM from "./dom"; |
||||
export * from "./detectElementResize"; |
||||
export * from "./function"; |
||||
export * from "./load"; |
||||
|
||||
import "./jquery/index"; |
||||
import "./config"; |
File diff suppressed because it is too large
Load Diff
@ -1,247 +1,252 @@
|
||||
if (BI.jQuery) { |
||||
(function ($) { |
||||
// richer:容器在其各个边缘留出的空间
|
||||
if (!$.fn.insets) { |
||||
$.fn.insets = function () { |
||||
var p = this.padding(), |
||||
b = this.border(); |
||||
return { |
||||
top: p.top, |
||||
bottom: p.bottom + b.bottom + b.top, |
||||
left: p.left, |
||||
right: p.right + b.right + b.left |
||||
}; |
||||
}; |
||||
} |
||||
|
||||
// richer:获取 && 设置jQuery元素的边界
|
||||
if (!$.fn.bounds) { |
||||
$.fn.bounds = function (value) { |
||||
var tmp = {hasIgnoredBounds: true}; |
||||
|
||||
if (value) { |
||||
if (!isNaN(value.x)) { |
||||
tmp.left = value.x; |
||||
} |
||||
if (!isNaN(value.y)) { |
||||
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 = ""; |
||||
import { isIE, isIE9Below } from "../function"; |
||||
import { htmlEncode } from "../../../func"; |
||||
import { toUpperCase, remove, camelize, isKey, isNull, isNotEmptyString, map, hyphenate } from "../../../2.base"; |
||||
import { makeFirstPY } from "../../../utils"; |
||||
import { createWidget } from "../../../5.inject"; |
||||
|
||||
BI.jQuery.fn.extend({ |
||||
|
||||
insets() { |
||||
const p = this.padding(), |
||||
b = this.border(); |
||||
|
||||
return { |
||||
top: p.top, |
||||
bottom: p.bottom + b.bottom + b.top, |
||||
left: p.left, |
||||
right: p.right + b.right + b.left, |
||||
}; |
||||
}, |
||||
|
||||
bounds(value) { |
||||
let tmp = { hasIgnoredBounds: true }; |
||||
|
||||
if (value) { |
||||
if (!isNaN(value.x)) { |
||||
tmp.left = value.x; |
||||
} |
||||
}, |
||||
/** |
||||
* 高亮显示 |
||||
* @param text 必需 |
||||
* @param keyword |
||||
* @param py |
||||
* @returns {*} |
||||
* @private |
||||
* 原理: |
||||
* 1、得到text的拼音py, 分别看是否匹配关键字keyword, 得到匹配索引tidx和pidx |
||||
* 2、比较tidx和pidx, 取大于-1且较小的索引,标红[索引,索引 + keyword.length - 1]的文本 |
||||
* 3、text和py各自取tidx/pidx + keyword.length索引开始的子串作为新的text和py, 重复1, 直到text和py有一个为"" |
||||
*/ |
||||
__textKeywordMarked__: function (text, keyword, py) { |
||||
if (BI.isNull(text)) { |
||||
text = ""; |
||||
if (!isNaN(value.y)) { |
||||
tmp.top = value.y; |
||||
} |
||||
if (!BI.isKey(keyword) || (text + "").length > 100) { |
||||
if (BI.isIE9Below()) { |
||||
return this.html(BI.htmlEncode(text)); |
||||
} |
||||
// textContent性能更好,并且原生防xss
|
||||
this[0].textContent = text; |
||||
return this; |
||||
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;
|
||||
} |
||||
keyword = keyword + ""; |
||||
keyword = BI.toUpperCase(keyword); |
||||
var textLeft = text + ""; |
||||
py = (py || BI.makeFirstPY(text, { |
||||
splitChar: "\u200b" |
||||
})) + ""; |
||||
py = BI.toUpperCase(py); |
||||
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; |
||||
} |
||||
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); |
||||
|
||||
// BI-56945 场景: 对'啊a'标红, a为keyword, 此时tidx为1, pidx为0, 此时使用tidx显然'啊'就无法标红了
|
||||
if (tidx >= 0 && (pidx > tidx || pidx === -1)) { |
||||
// 标红的text未encode
|
||||
this.append(BI.htmlEncode(textLeft.substr(0, tidx))); |
||||
this.append(BI.$("<span>").addClass("bi-keyword-red-mark") |
||||
.html(BI.htmlEncode(textLeft.substr(tidx, keyword.length)))); |
||||
|
||||
textLeft = textLeft.substr(tidx + keyword.length); |
||||
if (BI.isNotEmptyString(py)) { |
||||
// 每一组拼音都应该前进,而不是只是当前的
|
||||
py = BI.map(py.split("\u200b"), function (idx, ps) { |
||||
return ps.slice(tidx + keyword.length); |
||||
}).join("\u200b"); |
||||
} |
||||
} else if (pidx >= 0) { |
||||
// BI-56386 这边两个pid / text.length是为了防止截取的首字符串不是完整的,但光这样做还不够,即时错位了,也不能说明就不符合条件
|
||||
// 标红的text未encode
|
||||
this.append(BI.htmlEncode(textLeft.substr(0, pidx))); |
||||
this.append(BI.$("<span>").addClass("bi-keyword-red-mark") |
||||
.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"); |
||||
} |
||||
textLeft = textLeft.substr(pidx + keyword.length); |
||||
} else { |
||||
// 标红的text未encode
|
||||
this.append(BI.htmlEncode(textLeft)); |
||||
break; |
||||
} |
||||
return this; |
||||
} |
||||
|
||||
// richer:注意此方法只对可见元素有效
|
||||
tmp = this.position(); |
||||
|
||||
return { |
||||
x: tmp.left, |
||||
y: tmp.top, |
||||
// richer:这里计算外部宽度和高度的时候,都不包括边框
|
||||
width: this.outerWidth(), |
||||
height: this.outerHeight(), |
||||
}; |
||||
}, |
||||
|
||||
destroy() { |
||||
this.remove(); |
||||
if (isIE() === true) { |
||||
this[0].outerHTML = ""; |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* 高亮显示 |
||||
* @param text 必需 |
||||
* @param keyword |
||||
* @param py |
||||
* @returns {*} |
||||
* @private |
||||
* 原理: |
||||
* 1、得到text的拼音py, 分别看是否匹配关键字keyword, 得到匹配索引tidx和pidx |
||||
* 2、比较tidx和pidx, 取大于-1且较小的索引,标红[索引,索引 + keyword.length - 1]的文本 |
||||
* 3、text和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; |
||||
}, |
||||
|
||||
getDomHeight: function (parent) { |
||||
var clone = BI.$(this).clone(); |
||||
clone.appendTo(BI.$(parent || "body")); |
||||
var height = clone.height(); |
||||
clone.remove(); |
||||
return height; |
||||
}, |
||||
|
||||
// 是否有竖直滚动条
|
||||
hasVerticalScroll: function () { |
||||
return this.height() > 0 && this[0].clientWidth < this[0].offsetWidth; |
||||
}, |
||||
|
||||
// 是否有水平滚动条
|
||||
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)); |
||||
} |
||||
} |
||||
keyword = `${keyword}`; |
||||
keyword = toUpperCase(keyword); |
||||
let textLeft = `${text}`; |
||||
py = `${py || makeFirstPY(text, { |
||||
splitChar: "\u200b", |
||||
})}`;
|
||||
py = toUpperCase(py); |
||||
this.empty(); |
||||
// BI-48487 性能: makeFirstPY出来的py中包含多音字是必要的,但虽然此方法中做了限制。但是对于一个长度为60,包含14个多音字的字符串
|
||||
// 获取的的py长度将达到1966080, 远超过text的长度,到后面都是在做"".substring的无用功,所以此循环应保证py和textLeft长度不为0
|
||||
while (py.length > 0 && textLeft.length > 0) { |
||||
const tidx = toUpperCase(textLeft).indexOf(keyword); |
||||
let pidx = py.indexOf(keyword); |
||||
if (pidx >= 0) { |
||||
pidx = (pidx - Math.floor(pidx / (textLeft.length + 1))) % textLeft.length; |
||||
} |
||||
// 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(BI.hyphenate(name)); |
||||
|
||||
// BI-56945 场景: 对'啊a'标红, a为keyword, 此时tidx为1, pidx为0, 此时使用tidx显然'啊'就无法标红了
|
||||
if (tidx >= 0 && (pidx > tidx || pidx === -1)) { |
||||
// 标红的text未encode
|
||||
this.append(htmlEncode(textLeft.substr(0, tidx))); |
||||
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") { |
||||
return "none"; |
||||
} else if (pidx >= 0) { |
||||
// 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 node.currentStyle.cssFloat || node.currentStyle.styleFloat; |
||||
} |
||||
return node.currentStyle[BI.camelize(name)]; |
||||
} |
||||
|
||||
return this; |
||||
}, |
||||
|
||||
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)]; |
||||
}, |
||||
|
||||
__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(); |
||||
// offset2Body.left的值可能会有小数,导致某点出现false
|
||||
return !(e.pageX < Math.floor(offset2Body.left) || e.pageX > offset2Body.left + width |
||||
|| e.pageY < Math.floor(offset2Body.top) || e.pageY > offset2Body.top + height); |
||||
}, |
||||
|
||||
__hasZIndexMask__: function (zindex) { |
||||
return zindex && this.zIndexMask[zindex] != null; |
||||
}, |
||||
|
||||
__buildZIndexMask__: function (zindex, domArray) { |
||||
this.zIndexMask = this.zIndexMask || {};// 存储z-index的mask
|
||||
this.indexMask = this.indexMask || [];// 存储mask
|
||||
var mask = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
cls: "bi-z-index-mask", |
||||
items: domArray |
||||
}); |
||||
|
||||
mask.element.css({"z-index": zindex}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this, |
||||
items: [{ |
||||
|
||||
return node.currentStyle[camelize(name)]; |
||||
} |
||||
|
||||
return node.style && node.style[camelize(name)]; |
||||
}, |
||||
|
||||
__isMouseInBounds__(e) { |
||||
const offset2Body = this.get(0).getBoundingClientRect ? this.get(0).getBoundingClientRect() : this.offset(); |
||||
const width = offset2Body.width || this.outerWidth(); |
||||
const height = offset2Body.height || this.outerHeight(); |
||||
|
||||
// offset2Body.left的值可能会有小数,导致某点出现false
|
||||
return !(e.pageX < Math.floor(offset2Body.left) || e.pageX > offset2Body.left + width |
||||
|| e.pageY < Math.floor(offset2Body.top) || e.pageY > offset2Body.top + height); |
||||
}, |
||||
|
||||
__hasZIndexMask__(zindex) { |
||||
return zindex && this.zIndexMask[zindex] != null; |
||||
}, |
||||
|
||||
__buildZIndexMask__(zindex, domArray) { |
||||
this.zIndexMask = this.zIndexMask || {};// 存储z-index的mask
|
||||
this.indexMask = this.indexMask || [];// 存储mask
|
||||
const mask = createWidget({ |
||||
type: "bi.center_adapt", |
||||
cls: "bi-z-index-mask", |
||||
items: domArray, |
||||
}); |
||||
|
||||
mask.element.css({ "z-index": zindex }); |
||||
createWidget({ |
||||
type: "bi.absolute", |
||||
element: this, |
||||
items: [ |
||||
{ |
||||
el: mask, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
this.indexMask.push(mask); |
||||
zindex && (this.zIndexMask[zindex] = mask); |
||||
return mask.element; |
||||
}, |
||||
|
||||
__releaseZIndexMask__: function (zindex) { |
||||
if (zindex && this.zIndexMask[zindex]) { |
||||
BI.remove(this.indexMask, this.zIndexMask[zindex]); |
||||
this.zIndexMask[zindex].destroy(); |
||||
return; |
||||
} |
||||
this.indexMask = this.indexMask || []; |
||||
var indexMask = this.indexMask.pop(); |
||||
indexMask && indexMask.destroy(); |
||||
bottom: 0, |
||||
} |
||||
], |
||||
}); |
||||
this.indexMask.push(mask); |
||||
zindex && (this.zIndexMask[zindex] = mask); |
||||
|
||||
return mask.element; |
||||
}, |
||||
|
||||
__releaseZIndexMask__(zindex) { |
||||
if (zindex && this.zIndexMask[zindex]) { |
||||
remove(this.indexMask, this.zIndexMask[zindex]); |
||||
this.zIndexMask[zindex].destroy(); |
||||
|
||||
return; |
||||
} |
||||
}); |
||||
} |
||||
this.indexMask = this.indexMask || []; |
||||
const indexMask = this.indexMask.pop(); |
||||
indexMask && indexMask.destroy(); |
||||
}, |
||||
}); |
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
import "./_jquery"; |
||||
import "./event"; |
||||
import "./fn"; |
||||
import "./jquery.mousewheel"; |
@ -1,55 +1,56 @@
|
||||
BI._.extend(BI, { |
||||
$import: function () { |
||||
var _LOADED = {}; // alex:保存加载过的
|
||||
function loadReady (src, must) { |
||||
var $scripts = BI.$("head script, body script"); |
||||
BI.$.each($scripts, function (i, item) { |
||||
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 _LOADED = {}; // alex:保存加载过的
|
||||
function loadReady(src, must) { |
||||
const $scripts = BI.$("head script, body script"); |
||||
BI.$.each($scripts, (i, item) => { |
||||
if (item.src.indexOf(src) !== -1) { |
||||
_LOADED[src] = true; |
||||
} |
||||
}); |
||||
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); |
||||
// alex:如果已经加载过了的,直接return
|
||||
if (_LOADED[src] === true) { |
||||
return; |
||||
} |
||||
if (ext === "css") { |
||||
var link = document.createElement("link"); |
||||
link.rel = "stylesheet"; |
||||
link.type = "text/css"; |
||||
link.href = src; |
||||
var head = document.getElementsByTagName("head")[0]; |
||||
head.appendChild(link); |
||||
_LOADED[src] = true; |
||||
} else { |
||||
// alex:这里用同步调用的方式,必须等待ajax完成
|
||||
BI.$.ajax({ |
||||
url: src, |
||||
dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情
|
||||
async: false, |
||||
cache: true, |
||||
complete: function (res, status) { |
||||
/* |
||||
* alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval |
||||
* 所以当status为success时就不需要再把其中的内容加到script里面去了 |
||||
*/ |
||||
if (status == "success") { |
||||
_LOADED[src] = true; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
}; |
||||
}() |
||||
}); |
||||
/** |
||||
* |
||||
* @param src |
||||
* @param ext |
||||
* @param must 强行加载 |
||||
*/ |
||||
export function $import(src, ext, must) { |
||||
loadReady(src, must); |
||||
// alex:如果已经加载过了的,直接return
|
||||
if (_LOADED[src] === true) { |
||||
return; |
||||
} |
||||
if (ext === "css") { |
||||
const link = document.createElement("link"); |
||||
link.rel = "stylesheet"; |
||||
link.type = "text/css"; |
||||
link.href = src; |
||||
const head = document.getElementsByTagName("head")[0]; |
||||
head.appendChild(link); |
||||
_LOADED[src] = true; |
||||
} else { |
||||
// alex:这里用同步调用的方式,必须等待ajax完成
|
||||
BI.$.ajax({ |
||||
url: src, |
||||
dataType: "script", // alex:指定dataType为script,jquery会帮忙做globalEval的事情
|
||||
async: false, |
||||
cache: true, |
||||
complete(res, status) { |
||||
/* |
||||
* alex:发现jquery会很智能地判断一下返回的数据类型是不是script,然后做一个globalEval |
||||
* 所以当status为success时就不需要再把其中的内容加到script里面去了 |
||||
*/ |
||||
if (status === "success") { |
||||
_LOADED[src] = true; |
||||
} |
||||
}, |
||||
}); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue