Skip to content

Commit

Permalink
Core: Add Sizzle.noConflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Saptak Sengupta authored and gibson042 committed Dec 7, 2015
1 parent c2fb973 commit 0561fc3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ Kevin Kirsche <Kev.Kirsche+GitHub@gmail.com>
Steve Mao <maochenyan@gmail.com>
Tom von Clef <thomas.vonclef@gmail.com>
Josh Soref <apache@soref.com>
Saptak Sengupta <saptak.tech193@gmail.com>
11 changes: 10 additions & 1 deletion dist/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Released under the MIT license
* http://jquery.org/license
*
* Date: 2015-11-06
* Date: 2015-12-05
*/
(function( window ) {

Expand Down Expand Up @@ -34,6 +34,7 @@ var i,

// Instance-specific data
expando = "sizzle" + 1 * new Date(),
_sizzle = window.Sizzle,
preferredDoc = window.document,
dirruns = 0,
done = 0,
Expand Down Expand Up @@ -2136,6 +2137,14 @@ if ( typeof define === "function" && define.amd ) {
} else {
window.Sizzle = Sizzle;
}

Sizzle.noConflict = function() {
if ( window.Sizzle === Sizzle ) {
window.Sizzle = _sizzle;
}

return Sizzle;
};
// EXPOSE

})( window );
2 changes: 1 addition & 1 deletion dist/sizzle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/sizzle.min.map

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions src/sizzle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var i,

// Instance-specific data
expando = "sizzle" + 1 * new Date(),
_sizzle = window.Sizzle,
preferredDoc = window.document,
dirruns = 0,
done = 0,
Expand Down Expand Up @@ -2136,6 +2137,14 @@ if ( typeof define === "function" && define.amd ) {
} else {
window.Sizzle = Sizzle;
}

Sizzle.noConflict = function() {
if ( window.Sizzle === Sizzle ) {
window.Sizzle = _sizzle;
}

return Sizzle;
};
// EXPOSE

})( window );
33 changes: 33 additions & 0 deletions test/data/noConflict.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>var QUnit = parent.QUnit</script>
<script src="testinit.js"></script>
<script src="../../dist/sizzle.js"></script>
<script>
var Sizzle1 = Sizzle;
</script>
<script src="../../dist/sizzle.js"></script>
<script>
var Sizzle2 = Sizzle;
</script>
</head>
<body>
<script>
var doc = parent.document,
selection = Sizzle( "html > *" );

window.parent.iframeCallback( function( QUnit ) {
QUnit.deepEqual( selection, [ document.documentElement.firstChild, document.body ], "selection sanity check" );
QUnit.notStrictEqual( Sizzle, Sizzle1, "first Sizzle overwritten by second" );
QUnit.deepEqual( Sizzle( "html > *" ), Sizzle1( "html > *" ), "second Sizzle selects identically" );
var replaced = Sizzle.noConflict();
QUnit.strictEqual( Sizzle, Sizzle1, "first Sizzle restored by noConflict" );
QUnit.strictEqual( replaced, Sizzle2, "second Sizzle returned by noConflict" );
QUnit.deepEqual( Sizzle( "html > *" ), Sizzle2( "html > *" ), "both Sizzles still select identically" );
QUnit.deepEqual( Sizzle( "html > *" ), selection, "Sizzle still selects correctly" );
});
</script>
</body>
</html>
10 changes: 9 additions & 1 deletion test/karma/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ module.exports = function( config ) {
pattern: "test/data/mixed_sort.html",
watched: false,
included: false
},

// For iframe tests
{
pattern: "test/data/noConflict.html",
watched: false,
included: false
}
],

preprocessors: {

// mixed_sort.html downloaded through iframe inclusion
// mixed_sort.html, noConflict.html downloaded through iframe inclusion
// so it should not be preprocessed
"test/data/mixed_sort.html": [],
"test/data/noConflict.html": [],
"test/data/fixtures.html": [ "html2js" ]
},

Expand Down
1 change: 1 addition & 0 deletions test/unit/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ test("Sizzle.uniqueSort", function() {
});

testIframeWithCallback( "Sizzle.uniqueSort works cross-window (jQuery #14381)", "mixed_sort.html", deepEqual );
testIframeWithCallback( "Sizzle.noConflict", "noConflict.html", function( reporter ) { reporter( QUnit ); } );

0 comments on commit 0561fc3

Please sign in to comment.