Skip to content

Commit 440fcd2

Browse files
committed
update.
1 parent 836916b commit 440fcd2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+15020
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# jquery-sourcecode-analysis
2+
23
Jquery2.2.4 源码分析

build/data.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
(function () {
2+
var content = [];
3+
4+
var escapeHtml = function (html) {
5+
let str = html;
6+
str = str.replace(/&/g, '&');
7+
str = str.replace(/</g, '&lt;');
8+
str = str.replace(/>/g, '&gt;');
9+
str = str.replace(/"/g, '&quot;');
10+
str = str.replace(/'/g, '&#039;');
11+
return str;
12+
}
13+
14+
var clearHtml = function(html) {
15+
let str = html;
16+
str = str.replace(/&amp;/g, '');
17+
str = str.replace(/&lt;/g, '');
18+
str = str.replace(/&gt;/g, '');
19+
str = str.replace(/&quot;/g, '');
20+
str = str.replace(/&#039;/g, '');
21+
return str;
22+
}
23+
24+
var randStr = function () {
25+
return Math.random().toString(36).substr(2);
26+
};
27+
28+
var findTitle = function (ele) {
29+
var findPrevs = function (ele) {
30+
var children = $(ele).parent().children();
31+
var prevs = [];
32+
var findIt = false;
33+
children = Array.prototype.slice.call(children);
34+
children.forEach(function (subEle) {
35+
if ($(subEle).is($(ele))) {
36+
findIt = true;
37+
}
38+
if (findIt === false && $(subEle).text() != "") {
39+
prevs.push(subEle);
40+
}
41+
});
42+
return prevs;
43+
};
44+
45+
var findH = function (eles) {
46+
var _eles = Array.prototype.slice.call(eles);
47+
_eles.reverse();
48+
var title = "";
49+
var id = "";
50+
_eles.forEach(function (item) {
51+
if (!title) {
52+
if (item.nodeName[0] === "H") {
53+
title = $(item).text();
54+
id = $(item).attr("id");
55+
}
56+
}
57+
});
58+
return {
59+
text: title,
60+
id: id
61+
};
62+
};
63+
var prevs = findPrevs(ele);
64+
if (prevs.length) {
65+
return findH(prevs);
66+
}
67+
};
68+
69+
window.searchData = function (keyword) {
70+
var searchResult = [];
71+
content.forEach(function (item, index) {
72+
var tempHtml = "<div id='" + randStr() + "'></div>";
73+
var tempEle = $(tempHtml);
74+
var findArray = [];
75+
tempEle.html(clearHtml(item.content));
76+
findArray = tempEle.find(":contains('" + keyword + "')");
77+
findArray = Array.prototype.slice.call(findArray);
78+
if (findArray.length) {
79+
findArray.forEach(function (ele) {
80+
var findContent = $(ele).text();
81+
findContent = findContent[0] === "<" ? $(findContent).text() : findContent;
82+
findContent = escapeHtml(findContent);
83+
findContent = findContent.replace(new RegExp(keyword, 'g'), "<b>" + keyword + "</b>");
84+
var hObj = findTitle(ele);
85+
if (hObj) {
86+
searchResult.push({
87+
context: item.context,
88+
title: hObj.text,
89+
hid: hObj.id,
90+
findContent: findContent
91+
});
92+
}
93+
});
94+
}
95+
});
96+
return searchResult;
97+
};
98+
})();

0 commit comments

Comments
 (0)