Skip to content

Commit 039e6f5

Browse files
Andrew Dupontsavetheclocktower
authored andcommitted
Ensure that Sizzle loads properly in RequireJS or CommonJS environments.
[close prototypejs#203]
1 parent 6de3ea4 commit 039e6f5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

vendor/sizzle/selector_engine.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
Prototype._original_property = window.Sizzle;
2+
3+
;(function () {
4+
function fakeDefine(fn) {
5+
Prototype._actual_sizzle = fn();
6+
}
7+
fakeDefine.amd = true;
8+
9+
if (typeof define !== 'undefined' && define.amd) {
10+
// RequireJS is loaded. We need to pretend to be `define` while Sizzle
11+
// runs.
12+
Prototype._original_define = define;
13+
Prototype._actual_sizzle = null;
14+
window.define = fakeDefine;
15+
}
16+
})();
17+
218
//= require "repository/dist/sizzle"
319

20+
;(function() {
21+
if (typeof Sizzle !== 'undefined') {
22+
// Sizzle was properly defined.
23+
return;
24+
}
25+
26+
if (typeof define !== 'undefined' && define.amd) {
27+
// RequireJS.
28+
// We should find Sizzle where we put it. And we need to restore the original `define`.
29+
window.Sizzle = Prototype._actual_sizzle;
30+
window.define = Prototype._original_define;
31+
delete Prototype._actual_sizzle;
32+
delete Prototype._original_define;
33+
// TODO: Should we make our own `define` call here?
34+
} else if (typeof module !== 'undefined' && module.exports) {
35+
// Sizzle saw that it's in a CommonJS environment and attached itself to
36+
// `module.exports` instead.
37+
window.Sizzle = module.exports;
38+
// Reset `module.exports`.
39+
module.exports = {};
40+
}
41+
})();
42+
443
;(function(engine) {
544
var extendElements = Prototype.Selector.extendElements;
645

0 commit comments

Comments
 (0)