r101275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101274‎ | r101275 | r101276 >
Date:18:06, 29 October 2011
Author:liangent
Status:deferred
Tags:
Comment:
* Followup r101263: Fix the bug that if there're more than one custom toggles for one collapsible element,
display of collapsetext/expandtext on two toggles are not sync'ed.
* Merge two kinds of custom toggles, in order to avoid code redundant; by the way,
it's now supported mixed use of two kinds of custom toggles on one collapsible element because of this merge.
Modified paths:
  • /branches/liangent/makeCollapsible_custom/phase3/resources/jquery/jquery.makeCollapsible.js (modified) (history)

Diff [purge]

Index: branches/liangent/makeCollapsible_custom/phase3/resources/jquery/jquery.makeCollapsible.js
@@ -200,7 +200,7 @@
201201 return;
202202 },
203203 // Toggles customcollapsible
204 - toggleLinkCustom = function( $that, e, $collapsible ) {
 204+ toggleLinkCustom = function( $that, e, $collapsible, $customTogglers ) {
205205 var instantHide = true;
206206 // For the initial state call of customtogglers there is no event passed
207207 if (e) {
@@ -213,14 +213,14 @@
214214 // It's expanded right now
215215 if ( $collapsible.hasClass( 'mw-collapsed' ) ) {
216216 // Change text to "Show"
217 - $( '.mw-customtoggletext', $that ).text( expandtext );
 217+ $( '.mw-customtoggletext', $customTogglers ).text( expandtext );
218218 // Collapse element
219219 toggleElement( $collapsible, 'collapse', $that, instantHide );
220220
221221 // It's collapsed right now
222222 } else {
223223 // Change text to "Hide"
224 - $( '.mw-customtoggletext', $that ).text( collapsetext );
 224+ $( '.mw-customtoggletext', $customTogglers ).text( collapsetext );
225225 // Expand element
226226 toggleElement( $collapsible, 'expand', $that, instantHide );
227227 }
@@ -257,63 +257,46 @@
258258 // Check if this element has a custom position for the toggle link
259259 // (ie. outside the container or deeper inside the tree)
260260 // Then: Locate the custom toggle link(s) and bind them
261 - if ( ( $that.attr( 'id' ) || '' ).indexOf( 'mw-customcollapsible-' ) === 0 ) {
 261+ if ( ( $that.attr( 'id' ) || '' ).indexOf( 'mw-customcollapsible-' ) === 0
 262+ || $that.hasClass( 'mw-customcollapsiblechildren' ) ) {
262263
263 - var thatId = $that.attr( 'id' ),
264 - $customTogglers = $( '.' + thatId.replace( 'mw-customcollapsible', 'mw-customtoggle' ) );
265 - mw.log( _fn + 'Found custom collapsible: #' + thatId );
 264+ var $customTogglers = $();
266265
267 - // Double check that there is actually a customtoggle link
268 - if ( $customTogglers.length ) {
269 - $customTogglers.bind( 'click.mw-collapse', function( e ) {
270 - toggleLinkCustom( $(this), e, $that );
271 - } );
272 -
273 - // If there's no link for users using keyboard navigation
274 - if ( !$customTogglers.is( 'a' ) && !$customTogglers.find( 'a' ).length ) {
275 - $customTogglers.attr( 'tabindex', '0' ).bind( 'keydown.mw-collapse', function( e ) {
276 - if ( e.which === 13 ) { // Enter key
277 - toggleLinkCustom( $(this), e, $that );
278 - }
279 - } );
280 - }
281 - } else {
282 - mw.log( _fn + '#' + thatId + ': Missing toggler!' );
 266+ // Custom toggle link specified by id/class name match
 267+ if ( ( $that.attr( 'id' ) || '' ).indexOf( 'mw-customcollapsible-' ) === 0 ) {
 268+ var thatId = $that.attr( 'id' );
 269+ $customTogglers = $customTogglers.add(
 270+ '.' + thatId.replace( 'mw-customcollapsible', 'mw-customtoggle' ) );
 271+ mw.log( _fn + 'Found custom collapsible: #' + thatId );
283272 }
284273
285 - // Initial state
286 - if ( $that.hasClass( 'mw-collapsed' ) ) {
287 - toggleLinkCustom( $customTogglers, null, $that );
288 - } else {
289 - $( '.mw-customtoggletext', $customTogglers ).text( collapsetext );
 274+ // Custom toggle link specified by children with a certain class
 275+ if ( $that.hasClass( 'mw-customcollapsiblechildren' ) ) {
 276+ $customTogglers = $customTogglers.add( $( '.mw-customtoggle', $that ) );
 277+ mw.log( _fn + 'Found custom collapsible: <children>' );
290278 }
291279
292 - // Custom toggle link specified by children with a certain class
293 - } else if ( $that.hasClass( 'mw-customcollapsiblechildren' ) ) {
294 -
295 - var $customTogglers = $( '.mw-customtoggle', $that );
296 -
297280 // Double check that there is actually a customtoggle link
298281 if ( $customTogglers.length ) {
299282 $customTogglers.bind( 'click.mw-collapse', function( e ) {
300 - toggleLinkCustom( $(this), e, $that );
 283+ toggleLinkCustom( $(this), e, $that, $customTogglers );
301284 } );
302285
303286 // If there's no link for users using keyboard navigation
304287 if ( !$customTogglers.is( 'a' ) && !$customTogglers.find( 'a' ).length ) {
305288 $customTogglers.attr( 'tabindex', '0' ).bind( 'keydown.mw-collapse', function( e ) {
306289 if ( e.which === 13 ) { // Enter key
307 - toggleLinkCustom( $(this), e, $that );
 290+ toggleLinkCustom( $(this), e, $that, $customTogglers );
308291 }
309292 } );
310293 }
311294 } else {
312 - mw.log( _fn + '.mw-customcollapsiblechildren: Missing toggler!' );
 295+ mw.log( _fn + 'mw-customcollapsible: Missing toggler!' );
313296 }
314297
315298 // Initial state
316299 if ( $that.hasClass( 'mw-collapsed' ) ) {
317 - toggleLinkCustom( $customTogglers, null, $that );
 300+ toggleLinkCustom( $customTogglers, null, $that, $customTogglers );
318301 } else {
319302 $( '.mw-customtoggletext', $customTogglers ).text( collapsetext );
320303 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101263* Followup r101262: Fix the bug that .mw-customcollapsiblechildren does not w...liangent14:39, 29 October 2011

Status & tagging log