namespace handling improvements, spec for noConflict
This commit is contained in:
parent
9d4e335fe0
commit
ada607fa2f
@ -7,7 +7,11 @@
|
|||||||
<script type="text/javascript" src="../lib/jasmine/jasmine-html.js"></script>
|
<script type="text/javascript" src="../lib/jasmine/jasmine-html.js"></script>
|
||||||
|
|
||||||
<!-- source files -->
|
<!-- source files -->
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
L = 'test'; //to test L#noConflict later
|
||||||
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript" src="../src/env.js"></script>
|
<script type="text/javascript" src="../src/env.js"></script>
|
||||||
|
|
||||||
<!-- /core -->
|
<!-- /core -->
|
||||||
@ -20,6 +24,8 @@
|
|||||||
<script type="text/javascript" src="../src/geometry/Transformation.js"></script>
|
<script type="text/javascript" src="../src/geometry/Transformation.js"></script>
|
||||||
|
|
||||||
<!-- spec files -->
|
<!-- spec files -->
|
||||||
|
|
||||||
|
<script type="text/javascript" src="suites/envSpec.js"></script>
|
||||||
|
|
||||||
<!-- /core -->
|
<!-- /core -->
|
||||||
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
||||||
|
15
spec/suites/envSpec.js
Normal file
15
spec/suites/envSpec.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
describe('L#noConflict', function() {
|
||||||
|
it('should restore the previous L value and return Leaflet namespace', function(){
|
||||||
|
|
||||||
|
expect(L.version).toBeDefined();
|
||||||
|
|
||||||
|
var L2 = L.noConflict();
|
||||||
|
|
||||||
|
expect(L).toEqual('test');
|
||||||
|
expect(L2.version).toBeDefined();
|
||||||
|
|
||||||
|
this.after(function() {
|
||||||
|
window.L = L2;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
21
src/env.js
21
src/env.js
@ -1,11 +1,16 @@
|
|||||||
/*
|
/*
|
||||||
* Leaflet namespace config, allows using any global variable instead of L
|
* Leaflet namespace config, allows using any global variable instead of L & restoring the original value
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var originalL = window.L,
|
(function() {
|
||||||
L = {};
|
var originalL = window.L;
|
||||||
|
|
||||||
L.noConflict = function() {
|
L = {
|
||||||
window.L = originalL;
|
version: '0.0.1'
|
||||||
return this;
|
};
|
||||||
};
|
|
||||||
|
L.noConflict = function() {
|
||||||
|
window.L = originalL;
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
})();
|
Loading…
Reference in New Issue
Block a user