From f095e6df4b4c0a88420ba146fa098ff2d4420a52 Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Tue, 2 Apr 2013 22:28:08 +0200 Subject: [PATCH 1/2] jquery.makeCollapsible: use 'mw-collapsible' event namespace For consistency with the module name. Change-Id: Ied13e5abdec107771e80418feb4bb3b2f0d54567 --- RELEASE-NOTES-1.22 | 2 ++ resources/jquery/jquery.makeCollapsible.js | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 9b562ae5e6e..4366d0daac3 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -27,6 +27,8 @@ changes to languages because of Bugzilla reports. * redirect.php was removed. It was unused. * BREAKING CHANGE: Legacy skins Simple, MySkin and Standard were all removed. Nostalgia was moved to an extension. +* Event namespace used by jquery.makeCollapsible has been changed from + 'mw-collapse' to 'mw-collapsible' for consistency with the module name. == Compatibility == diff --git a/resources/jquery/jquery.makeCollapsible.js b/resources/jquery/jquery.makeCollapsible.js index 630002d3dfd..3600c5d6d60 100644 --- a/resources/jquery/jquery.makeCollapsible.js +++ b/resources/jquery/jquery.makeCollapsible.js @@ -274,7 +274,7 @@ .parent() .prepend( ' [' ) .append( '] ' ) - .on( 'click.mw-collapse', function ( e, opts ) { + .on( 'click.mw-collapsible', function ( e, opts ) { opts = $.extend( { toggleText: { collapseText: collapsetext, expandText: expandtext } }, options, opts ); toggleLinkDefault( $(this), e, opts ); } ); @@ -298,7 +298,7 @@ // Bind the custom togglers if ( $customTogglers && $customTogglers.length ) { - $customTogglers.on( 'click.mw-collapse', function ( e, opts ) { + $customTogglers.on( 'click.mw-collapsible', function ( e, opts ) { opts = $.extend( {}, options, opts ); toggleLinkCustom( $(this), e, opts, $collapsible ); } ); @@ -324,7 +324,7 @@ if ( !$toggle.length ) { $firstItem.eq(-1).prepend( $toggleLink ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { + $toggleLink = $toggle.off( 'click.mw-collapsible' ).on( 'click.mw-collapsible', function ( e, opts ) { opts = $.extend( {}, options, opts ); toggleLinkPremade( $toggle, e, opts ); } ); @@ -346,7 +346,7 @@ } $collapsible.prepend( $toggleLink.wrap( '
  • ' ).parent() ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { + $toggleLink = $toggle.off( 'click.mw-collapsible' ).on( 'click.mw-collapsible', function ( e, opts ) { opts = $.extend( {}, options, opts ); toggleLinkPremade( $toggle, e, opts ); } ); @@ -366,7 +366,7 @@ if ( !$toggle.length ) { $collapsible.prepend( $toggleLink ); } else { - $toggleLink = $toggle.off( 'click.mw-collapse' ).on( 'click.mw-collapse', function ( e, opts ) { + $toggleLink = $toggle.off( 'click.mw-collapsible' ).on( 'click.mw-collapsible', function ( e, opts ) { opts = $.extend( {}, options, opts ); toggleLinkPremade( $toggle, e, opts ); } ); From f4d8165c9e54725f9fce8780e300991e36dad55c Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Mon, 25 Mar 2013 20:16:07 +0100 Subject: [PATCH 2/2] jquery.makeCollapsible: basic test suite For now it just verifies that the very basic synchronous functionality of the module works; not much more is possible without triggering some events to hook to, and currently jquery.makeCollapsible doesn't trigger any. Change-Id: Icdd8f392e4921007a6bdfb3ae934949e4c875232 --- tests/qunit/QUnitTestResources.php | 2 + .../jquery/jquery.makeCollapsible.test.js | 51 +++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js diff --git a/tests/qunit/QUnitTestResources.php b/tests/qunit/QUnitTestResources.php index 01072d83c4f..1cc7fc32a5a 100644 --- a/tests/qunit/QUnitTestResources.php +++ b/tests/qunit/QUnitTestResources.php @@ -16,6 +16,7 @@ return array( 'tests/qunit/suites/resources/jquery/jquery.hidpi.test.js', 'tests/qunit/suites/resources/jquery/jquery.highlightText.test.js', 'tests/qunit/suites/resources/jquery/jquery.localize.test.js', + 'tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js', 'tests/qunit/suites/resources/jquery/jquery.mwExtension.test.js', 'tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js', 'tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js', @@ -45,6 +46,7 @@ return array( 'jquery.hidpi', 'jquery.highlightText', 'jquery.localize', + 'jquery.makeCollapsible', 'jquery.mwExtension', 'jquery.tabIndex', 'jquery.tablesorter', diff --git a/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js new file mode 100644 index 00000000000..082d86b4517 --- /dev/null +++ b/tests/qunit/suites/resources/jquery/jquery.makeCollapsible.test.js @@ -0,0 +1,51 @@ +( function ( mw, $ ) { + var loremIpsum = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit.'; + + QUnit.module( 'jquery.makeCollapsible', QUnit.newMwEnvironment() ); + + function prepareCollapsible( html, options ) { + return $( $.parseHTML( html ) ) + .appendTo( '#qunit-fixture' ) + // options might be undefined here - this is okay + .makeCollapsible( options ); + } + + QUnit.test( 'basic operation with instantHide (synchronous test)', 2, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
    ' + loremIpsum + '
    ', + { instantHide: true } + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + assert.assertTrue( $content.is( ':visible' ), 'content is visible' ); + + $collapsible.find( '.mw-collapsible-toggle' ).trigger( 'click' ); + + assert.assertTrue( $content.is( ':hidden' ), 'after collapsing: content is hidden' ); + } ); + + QUnit.test( 'initially collapsed - mw-collapsed class', 1, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
    ' + loremIpsum + '
    ' + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + // Synchronous - mw-collapsed should cause instantHide: true to be used on initial collapsing + assert.assertTrue( $content.is( ':hidden' ), 'content is hidden' ); + } ); + + QUnit.test( 'initially collapsed - options', 1, function ( assert ) { + var $collapsible, $content; + $collapsible = prepareCollapsible( + '
    ' + loremIpsum + '
    ', + { collapsed: true } + ); + $content = $collapsible.find( '.mw-collapsible-content' ); + + // Synchronous - collapsed: true should cause instantHide: true to be used on initial collapsing + assert.assertTrue( $content.is( ':hidden' ), 'content is hidden' ); + } ); + +}( mediaWiki, jQuery ) );