Followup r104671: fix regression in jquery.delayedBind() due to change in param proce...
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 2 Dec 2011 21:47:46 +0000 (21:47 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 2 Dec 2011 21:47:46 +0000 (21:47 +0000)
Problem was per CR comment https://www.mediawiki.org/wiki/Special:Code/MediaWiki/104671#c26836 -- parameter count check changed in upstream jquery.bind(), causing the way we passed params to break if the optional 'data' parameter was left out.

Added QUnit test cases for jquery.delayedBind() with and without the optional 'data' parameter.
Undoes r104671 since the issue it was working around is fixed.

resources/jquery/jquery.collapsibleTabs.js
resources/jquery/jquery.delayedBind.js
tests/qunit/index.html
tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js [new file with mode: 0644]

index df7a935..1784f86 100644 (file)
@@ -24,7 +24,7 @@
                // if we haven't already bound our resize hanlder, bind it now
                if( !$.collapsibleTabs.boundEvent ) {
                        $( window )
-                               .delayedBind( '500', 'resize', null, function( ) { $.collapsibleTabs.handleResize(); } );
+                               .delayedBind( '500', 'resize', function( ) { $.collapsibleTabs.handleResize(); } );
                }
                // call our resize handler to setup the page
                $.collapsibleTabs.handleResize();
index 6d97299..d84ee26 100644 (file)
@@ -19,6 +19,11 @@ $.fn.extend( {
         * @param callback Function to call
         */
        delayedBind: function( timeout, event, data, callback ) {
+               if ( arguments.length == 3 ) {
+                       // Shift optional parameter down
+                       callback = data;
+                       data = undefined;
+               }
                var encEvent = encodeEvent( event );
                return this.each( function() {
                        var that = this;
index 9187186..ac80872 100644 (file)
@@ -62,6 +62,7 @@
        <script src="../../resources/jquery/jquery.byteLength.js"></script>
        <script src="../../resources/jquery/jquery.byteLimit.js"></script>
        <script src="../../resources/jquery/jquery.colorUtil.js"></script>
+       <script src="../../resources/jquery/jquery.delayedBind.js"></script>
        <script src="../../resources/jquery/jquery.getAttrs.js"></script>
        <script src="../../resources/jquery/jquery.highlightText.js"></script>
        <script src="../../resources/jquery/jquery.localize.js"></script>
@@ -91,6 +92,7 @@
        <script src="suites/resources/jquery/jquery.byteLength.test.js"></script>
        <script src="suites/resources/jquery/jquery.byteLimit.test.js"></script>
        <script src="suites/resources/jquery/jquery.colorUtil.test.js"></script>
+       <script src="suites/resources/jquery/jquery.delayedBind.test.js"></script>
        <script src="suites/resources/jquery/jquery.getAttrs.test.js"></script>
        <script src="suites/resources/jquery/jquery.highlightText.test.js"></script>
        <script src="suites/resources/jquery/jquery.localize.test.js"></script>
diff --git a/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js b/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
new file mode 100644 (file)
index 0000000..8688f12
--- /dev/null
@@ -0,0 +1,41 @@
+test('jquery.delayedBind with data option', function() {
+       var $fixture = $('<div>').appendTo('body'),
+               data = { magic: "beeswax" },
+               delay = 50;
+
+       $fixture.delayedBind(delay, 'testevent', data, function(event) {
+               start(); // continue!
+               ok(true, 'testevent fired');
+               ok(event.data === data, 'data is passed through delayedBind');
+       });
+
+       expect(2);
+       stop(); // async!
+
+       // We'll trigger it thrice, but it should only happen once.
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+});
+
+test('jquery.delayedBind without data option', function() {
+       var $fixture = $('<div>').appendTo('body'),
+               data = { magic: "beeswax" },
+               delay = 50;
+
+       $fixture.delayedBind(delay, 'testevent', function(event) {
+               start(); // continue!
+               ok(true, 'testevent fired');
+       });
+
+       expect(1);
+       stop(); // async!
+
+       // We'll trigger it thrice, but it should only happen once.
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+       $fixture.trigger('testevent', {});
+});
+