")
- $("#weird").window_bind();
- $(window).trigger('resize')
- ok(called,"got window resize event");
-
- $("#qunit-test-area").html("")
+ var called = false;
+ jQuery.Controller.extend("WindowBind",{
+ "{window} resize" : function() {
+ called = true;
+ }
+ })
+ $("#qunit-test-area").html("
")
+ $("#weird").window_bind();
+ $(window).trigger('resize')
+ ok(called,"got window resize event");
+
+ $("#qunit-test-area").html("")
})
-// this.delegate(this.cached.header.find('tr'), "th", "mousemove", "th_mousemove");
+// this.delegate(this.cached.header.find('tr'), "th", "mousemove", "th_mousemove");
test("delegate", function(){
- var called = false;
- jQuery.Controller.extend("DelegateTest",{
- click: function() {}
- })
- var els = $("
").appendTo($("#qunit-test-area"))
- var c = els.delegate_test();
- c.controller().delegate(els.find("span"), "a", "click", function(){
- called = true;
- })
- els.find("a").trigger('click')
- ok(called, "delegate works")
- $("#qunit-test-area").html("")
+ var called = false;
+ jQuery.Controller.extend("DelegateTest",{
+ click: function() {}
+ })
+ var els = $("
").appendTo($("#qunit-test-area"))
+ var c = els.delegate_test();
+ c.controller().delegate(els.find("span"), "a", "click", function(){
+ called = true;
+ })
+ els.find("a").trigger('click')
+ ok(called, "delegate works")
+ $("#qunit-test-area").html("")
})
test("inherit", function(){
- var called = false;
- $.Controller.extend( "Parent", {
- click: function(){
- called = true;
- }
- })
- Parent.extend( "Child", {
-
- })
- var els = $("
").appendTo($("#qunit-test-area"))
- els.child();
- els.find("a").trigger('click')
- ok(called, "inherited the click method")
- $("#qunit-test-area").html("")
+ var called = false;
+ $.Controller.extend( "Parent", {
+ click: function(){
+ called = true;
+ }
+ })
+ Parent.extend( "Child", {
+
+ })
+ var els = $("
").appendTo($("#qunit-test-area"))
+ els.child();
+ els.find("a").trigger('click')
+ ok(called, "inherited the click method")
+ $("#qunit-test-area").html("")
});
test("objects in action", function(){
- $.Controller('Thing',{
- "{item} someEvent" : function(thing, ev){
- ok(true, "called");
- equals(ev.type, "someEvent","correct event")
- equals(this.constructor.fullName, "Thing", "This is a controller isntance")
- equals(thing.name,"Justin","Raw, not jQuery wrapped thing")
- }
- });
-
- var thing1 = {name: "Justin"};
-
- var ta = $("
").appendTo( $("#qunit-test-area") )
- ta.thing({item : thing1});
-
- $(thing1).trigger("someEvent");
-
- $("#qunit-test-area").html("");
-
+ $.Controller('Thing',{
+ "{item} someEvent" : function(thing, ev){
+ ok(true, "called");
+ equals(ev.type, "someEvent","correct event")
+ equals(this.constructor.fullName, "Thing", "This is a controller isntance")
+ equals(thing.name,"Justin","Raw, not jQuery wrapped thing")
+ }
+ });
+
+ var thing1 = {name: "Justin"};
+
+ var ta = $("
").appendTo( $("#qunit-test-area") )
+ ta.thing({item : thing1});
+
+ $(thing1).trigger("someEvent");
+
+ $("#qunit-test-area").html("");
+
});
test("dot",function(){
- $.Controller("Dot",{
- "foo.bar" : function(){
- ok(true,'called')
- }
- });
-
- var ta = $("
").appendTo( $("#qunit-test-area") );
- ta.dot().trigger("foo.bar");
- $("#qunit-test-area").html("");
+ $.Controller("Dot",{
+ "foo.bar" : function(){
+ ok(true,'called')
+ }
+ });
+
+ var ta = $("
").appendTo( $("#qunit-test-area") );
+ ta.dot().trigger("foo.bar");
+ $("#qunit-test-area").html("");
})
// HTMLFormElement[0] breaks
test("the right element", 1, function(){
- $.Controller('FormTester',{
- init : function(){
- equals(this.element[0].nodeName.toLowerCase(), "form" )
- }
- })
- $("
").appendTo( $("#qunit-test-area") )
- .form_tester();
- $("#qunit-test-area").html("")
+ $.Controller('FormTester',{
+ init : function(){
+ equals(this.element[0].nodeName.toLowerCase(), "form" )
+ }
+ })
+ $("
").appendTo( $("#qunit-test-area") )
+ .form_tester();
+ $("#qunit-test-area").html("")
})
test("pluginName", function() {
- // Testing for controller pluginName fixes as reported in
- // http://forum.javascriptmvc.com/#topic/32525000000253001
- // http://forum.javascriptmvc.com/#topic/32525000000488001
- expect(6);
-
- $.Controller("PluginName", {
- pluginName : "my_plugin"
- }, {
- method : function(arg) {
- ok(true, "Method called");
- },
-
- update : function(options) {
- this._super(options);
- ok(true, "Update called");
- },
-
- destroy : function() {
- ok(true, "Destroyed");
- this._super();
- }
- });
-
- var ta = $("
").addClass('existing_class').appendTo( $("#qunit-test-area") );
- ta.my_plugin(); // Init
- ok(ta.hasClass("my_plugin"), "Should have class my_plugin");
- ta.my_plugin(); // Update
- ta.my_plugin("method"); // method()
- ta.controller().destroy(); // destroy
- ok(!ta.hasClass("my_plugin"), "Shouldn't have class my_plugin after being destroyed");
- ok(ta.hasClass("existing_class"), "Existing class should still be there");
+ // Testing for controller pluginName fixes as reported in
+ // http://forum.javascriptmvc.com/#topic/32525000000253001
+ // http://forum.javascriptmvc.com/#topic/32525000000488001
+ expect(6);
+
+ $.Controller("PluginName", {
+ pluginName : "my_plugin"
+ }, {
+ method : function(arg) {
+ ok(true, "Method called");
+ },
+
+ update : function(options) {
+ this._super(options);
+ ok(true, "Update called");
+ },
+
+ destroy : function() {
+ ok(true, "Destroyed");
+ this._super();
+ }
+ });
+
+ var ta = $("
").addClass('existing_class').appendTo( $("#qunit-test-area") );
+ ta.my_plugin(); // Init
+ ok(ta.hasClass("my_plugin"), "Should have class my_plugin");
+ ta.my_plugin(); // Update
+ ta.my_plugin("method"); // method()
+ ta.controller().destroy(); // destroy
+ ok(!ta.hasClass("my_plugin"), "Shouldn't have class my_plugin after being destroyed");
+ ok(ta.hasClass("existing_class"), "Existing class should still be there");
})
test("inherit defaults", function() {
@@ -242,27 +296,27 @@ test("inherit defaults", function() {
});
test("update rebinding", 2, function(){
- var first = true;
- $.Controller("Rebinder", {
- "{item} foo" : function(item, ev){
- if(first){
- equals(item.id, 1, "first item");
- first = false;
- } else {
- equals(item.id, 2, "first item");
- }
- }
- });
-
- var item1 = {id: 1},
- item2 = {id: 2},
- el = $('
').rebinder({item: item1})
-
- $(item1).trigger("foo")
-
- el.rebinder({item: item2});
-
- $(item2).trigger("foo")
+ var first = true;
+ $.Controller("Rebinder", {
+ "{item} foo" : function(item, ev){
+ if(first){
+ equals(item.id, 1, "first item");
+ first = false;
+ } else {
+ equals(item.id, 2, "first item");
+ }
+ }
+ });
+
+ var item1 = {id: 1},
+ item2 = {id: 2},
+ el = $('
').rebinder({item: item1})
+
+ $(item1).trigger("foo")
+
+ el.rebinder({item: item2});
+
+ $(item2).trigger("foo")
})