r108275 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108274‎ | r108275 | r108276 >
Date:20:04, 6 January 2012
Author:rmoen
Status:ok (Comments)
Tags:
Comment:
only allow one secondary checkbox to be checked at one time due them cancelling each other out
Modified paths:
  • /trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MoodBar/modules/ext.moodBar.dashboard/ext.moodBar.dashboard.js
@@ -509,7 +509,6 @@
510510 wikitext = wikitext.replace(/~{3,5}/g, '') + "\n\n~~~~"; //remove and add signature for
511511 parseWikiText($item, wikitext);
512512 });
513 -
514513 }
515514 e.preventDefault();
516515 }
@@ -613,8 +612,8 @@
614613 )
615614 )
616615 );
617 - $item
618 - .append( tooltip );
 616+ $item.append( tooltip );
 617+ //close event, closure remembers object
619618 $( '.fbd-tooltip-close' )
620619 .live( 'click' , function() {
621620 tooltip.remove();
@@ -712,7 +711,17 @@
713712 $(this).prop('checked', true);
714713 }
715714 });
 715+
 716+ //only allow one of the secondary filters to be checked
 717+ $( 'input[type=checkbox].fbd-filters-check').click(function(){
 718+ var count = $( 'input[type=checkbox].fbd-filters-check').length;
 719+ if(count > 1) {
 720+ $( 'input[type=checkbox].fbd-filters-check').prop('checked', false);
 721+ $(this).prop('checked', true);
 722+ }
716723
 724+ });
 725+
717726 $( '#fbd-list' ).delegate( '.fbd-item', 'hover', function (){
718727 $(this).toggleClass('fbd-hover');
719728 });

Follow-up revisions

RevisionCommit summaryAuthorDate
r108523simplify secondary filter checkbox handling. follow up r108275 and r108299rmoen17:54, 10 January 2012

Comments

#Comment by Catrope (talk | contribs)   16:17, 10 January 2012
+		var count = $( 'input[type=checkbox].fbd-filters-check').length;
+		if(count > 1) {

Does this work properly? It seems to rely on the state of the checkbox to have switched to 'checked' prior to the click handler being executed. It would be simpler to just unconditionally uncheck all checkboxes except 'this', like so:

	$( 'input[type=checkbox].fbd-filters-check' ).click( function() {
		$( 'input[type=checkbox].fbd-filters-check' ).not( this ).prop( 'checked', false );
	} );

then it doesn't matter when the checkbox changes state, and you're not trying to set checked to true while the browser will already do that for you.

#Comment by Robmoen (talk | contribs)   17:38, 10 January 2012

Ahh very cool. I knew there was an easier way :) Thanks

#Comment by Robmoen (talk | contribs)   17:40, 10 January 2012

Also, you were correct. On this revision it wasn't working correctly.

Status & tagging log