This repository has been archived by the owner on Mar 20, 2021. It is now read-only.
/
cheerio-shim.js
100 lines (89 loc) · 2.19 KB
/
cheerio-shim.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var _ = require('lodash'),
Cheerio = require('cheerio');
Cheerio.prototype.appendTo = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.append(this);
return this;
};
Cheerio.prototype.insertAfter = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.after(this);
return this;
};
Cheerio.prototype.insertBefore = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.before(this);
return this;
};
Cheerio.prototype.prependTo = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.prepend(this);
return this;
};
Cheerio.prototype.replaceAll = function(relative) {
if (!relative.cheerio) {
relative = this._$(relative);
}
relative.replaceWith(this);
return this;
};
Cheerio.prototype.bind = Cheerio.prototype.unbind =
Cheerio.prototype.on = Cheerio.prototype.off =
Cheerio.prototype.live = Cheerio.prototype.die =
Cheerio.prototype.delegate = Cheerio.prototype.undelegate =
Cheerio.prototype.one = function() {
return this;
};
Cheerio.prototype.forEach = function(callback, scope) {
var elements = this;
elements.each(function(index) {
callback.call(scope || elements, this, index);
});
return this;
};
Cheerio.prototype.detach = Cheerio.prototype.remove;
Cheerio.prototype.toggle = function(toggle) {
if (toggle === undefined) {
toggle = this.css('display') === 'none';
}
this[toggle ? 'show' : 'hide']();
return this;
};
Cheerio.prototype.show = function() {
this.css('display', '');
return this;
};
Cheerio.prototype.hide = function() {
this.css('display', 'none');
return this;
};
Cheerio.prototype.focus = function() {
this.attr('autofocus', 'autofocus');
return this;
};
Cheerio.prototype.blur = function() {
this.removeAttr('autofocus');
return this;
};
Cheerio.prototype.animate = function(properties) {
this.css(properties);
var callback = arguments[arguments.length-1];
if (callback && callback.callback) {
callback = callback.callback;
}
if (callback.call) {
var el = this;
setImmediate(function() {
callback.call(el);
});
}
return this;
};