namespace handling improvements, spec for noConflict

This commit is contained in:
mourner 2010-09-03 19:49:32 +03:00
parent 9d4e335fe0
commit ada607fa2f
3 changed files with 35 additions and 9 deletions

View File

@ -8,6 +8,10 @@
<!-- source files -->
<script type="text/javascript">
L = 'test'; //to test L#noConflict later
</script>
<script type="text/javascript" src="../src/env.js"></script>
<!-- /core -->
@ -21,6 +25,8 @@
<!-- spec files -->
<script type="text/javascript" src="suites/envSpec.js"></script>
<!-- /core -->
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
<script type="text/javascript" src="suites/core/ClassSpec.js"></script>

15
spec/suites/envSpec.js Normal file
View 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;
});
});
});

View File

@ -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,
L = {};
(function() {
var originalL = window.L;
L.noConflict = function() {
window.L = originalL;
return this;
};
L = {
version: '0.0.1'
};
L.noConflict = function() {
window.L = originalL;
return this;
};
})();