Permalink
Browse files

fix no conflict

add spec for no conflict
  • Loading branch information...
1 parent 94cb648 commit 98da56041cdb09544938fc3127461c24ff7b1277 @fat fat committed Apr 6, 2011
Showing with 31 additions and 16 deletions.
  1. +2 −2 klass.js
  2. +1 −1 klass.min.js
  3. +2 −2 src/klass.js
  4. +8 −0 test/test.html
  5. +18 −11 test/tests.js
View
@@ -80,9 +80,9 @@
if (typeof module !== 'undefined' && module.exports) {
module.exports = klass;
} else {
- var old = klass;
+ var old = context.klass;
klass.noConflict = function () {
- context.klass = klass;
+ context.klass = old;
return this;
};
context.klass = klass;
View
@@ -5,4 +5,4 @@
* Follow our software http://twitter.com/dedfat :)
* MIT License
*/
-!function(a,b){function j(a,c){d[e]=this[e];var g=this,h=new d,j=typeof a==b,k=j?a:this,l=j?{}:a,m=function(){c||f(a)&&g.apply(this,arguments),k.apply(this,arguments),this.initialize&&this.initialize.apply(this,arguments)};m.methods=function(a){i(h,a,g),m[e]=h;return this},m.methods.call(m,l).prototype.constructor=m,m.extend=arguments.callee,m[e].implement=m.statics=function(a,b){a=typeof a=="string"?function(){var c={};c[a]=b;return c}():a,i(this,a,g);return this};return m}function i(a,d,f){for(var g in d)d.hasOwnProperty(g)&&(a[g]=typeof d[g]==b&&typeof f[e][g]==b&&c.test(d[g])?h(g,d[g],f):d[g])}function h(a,b,c){return function(){var d=this.supr;this.supr=c[e][a];var f=b.apply(this,arguments);this.supr=d;return f}}function g(a){return j.call(typeof a==b?a:d,a,1)}var c=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,d=function(){},e="prototype",f=function(a){return typeof a===b};if(typeof module!="undefined"&&module.exports)module.exports=g;else{var k=g;g.noConflict=function(){a.klass=g;return this},a.klass=g}}(this,"function")
+!function(a,b){function j(a,c){d[e]=this[e];var g=this,h=new d,j=typeof a==b,k=j?a:this,l=j?{}:a,m=function(){c||f(a)&&g.apply(this,arguments),k.apply(this,arguments),this.initialize&&this.initialize.apply(this,arguments)};m.methods=function(a){i(h,a,g),m[e]=h;return this},m.methods.call(m,l).prototype.constructor=m,m.extend=arguments.callee,m[e].implement=m.statics=function(a,b){a=typeof a=="string"?function(){var c={};c[a]=b;return c}():a,i(this,a,g);return this};return m}function i(a,d,f){for(var g in d)d.hasOwnProperty(g)&&(a[g]=typeof d[g]==b&&typeof f[e][g]==b&&c.test(d[g])?h(g,d[g],f):d[g])}function h(a,b,c){return function(){var d=this.supr;this.supr=c[e][a];var f=b.apply(this,arguments);this.supr=d;return f}}function g(a){return j.call(typeof a==b?a:d,a,1)}var c=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,d=function(){},e="prototype",f=function(a){return typeof a===b};if(typeof module!="undefined"&&module.exports)module.exports=g;else{var k=a.klass;g.noConflict=function(){a.klass=k;return this},a.klass=g}}(this,"function")
View
@@ -73,9 +73,9 @@
if (typeof module !== 'undefined' && module.exports) {
module.exports = klass;
} else {
- var old = klass;
+ var old = context.klass;
klass.noConflict = function () {
- context.klass = klass;
+ context.klass = old;
return this;
};
context.klass = klass;
View
@@ -5,7 +5,15 @@
<title>klass tests</title>
<link rel="stylesheet" href="../build/sink/src/sink.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script src="../build/sink/src/sink.js"></script>
+ <script>
+ var klass = function () {
+ return 'success';
+ }
+ </script>
<script src="../src/klass.js"></script>
+ <script>
+ $k = klass.noConflict();
+ </script>
</head>
<body>
<h1>Klass tests</h1>
View
@@ -2,21 +2,28 @@ if (typeof module !== 'undefined' && module.exports) {
var sink = require('../build/sink'),
start = sink.start,
sink = sink.sink;
- var klass = require('../src/klass');
+ var $k = require('../src/klass');
+}
+else {
+ sink('no conflict', function (test, ok) {
+ test('should return old klass back to context', 1, function () {
+ ok(klass() == 'success', 'old klass called');
+ });
+ });
}
sink('klass', function (test, ok, before, after) {
var Base;
before(function () {
- Base = klass(function (n) {
+ Base = $k(function (n) {
this.n = n;
});
});
test('should not call constructor twice', 2, function () {
var called = 0;
- var thing = klass(function () {
+ var thing = $k(function () {
ok(++called == 1, 'constructor called only once');
if (called == 2) {
clearTimeout(timer);
@@ -36,7 +43,7 @@ sink('klass', function (test, ok, before, after) {
});
test('should allow optional hash as constructor for methods', 1, function () {
- var objectKlass = klass({
+ var objectKlass = $k({
get: function () {
return this.foo;
},
@@ -211,7 +218,7 @@ sink('klass', function (test, ok, before, after) {
test('base constructor not called twice when no constructor used in sub', 2, function () {
var called = 0;
- var Base = klass(function () {
+ var Base = $k(function () {
ok(++called == 1, 'called only once');
if (called > 1) {
clearTimeout(timer);
@@ -228,7 +235,7 @@ sink('klass', function (test, ok, before, after) {
test('base constructor not called twice when object used in sub', 2, function () {
var called = 0;
- var Base = klass(function () {
+ var Base = $k(function () {
ok(++called == 1, 'called only once');
if (called > 1) {
clearTimeout(timer);
@@ -249,7 +256,7 @@ sink('klass', function (test, ok, before, after) {
});
test('should inherit super method', 1, function () {
- var Base = klass(function() {});
+ var Base = $k(function() {});
Base.methods({
foo: function () {
ok(true, 'called super method');
@@ -265,7 +272,7 @@ sink('klass', function (test, ok, before, after) {
});
test('can use strings as names for ... bla', 2, function () {
- var Thing = klass().statics('foo', 5).methods({
+ var Thing = $k().statics('foo', 5).methods({
getFoo: function () {
return this.constructor.foo
}
@@ -276,7 +283,7 @@ sink('klass', function (test, ok, before, after) {
});
test('can access constructor from within constructor', 1, function () {
- var Base = klass(function () {
+ var Base = $k(function () {
ok(this.constructor.foo == 'boosh', 'accessed this.constructor.foo');
})
.statics('foo', 'boosh');
@@ -286,7 +293,7 @@ sink('klass', function (test, ok, before, after) {
});
test('can access statics from statics', 1, function () {
- var Base = klass().statics({
+ var Base = $k().statics({
baz: function () {
return this.thunk;
},
@@ -298,7 +305,7 @@ sink('klass', function (test, ok, before, after) {
test('Object Literal Syntax', 6, function () {
- var Foo = klass({
+ var Foo = $k({
foo: 0,
bar: 2,

0 comments on commit 98da560

Please sign in to comment.