Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12793 closed feature (wontfix)

.fadeToggle(boolean) and .slideToggle(boolean)

Reported by: david71rj Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


Accept .fadeToggle(boolean, ...) and .slideToggle(boolean, ...) to work similar to .toggle(boolean) and .toggleClass(string, boolean).

Currently it is possible with a workaround.

  // Somelines method
  if(theBoolean) $el.fadeIn('slow');
  else $el.fadeOut('slow');

  // Workaround method
  jQuery(el)[theBoolean ? 'fadeIn' : 'fadeOut']('slow');

I think that it is acceptable, once that both methods not accept a boolean in args.

  jQuery.fn.fadeToggle = function(
    optional mixed duration,
    optional string easing,
    optional function callback,
    optional boolean showOrHide
  ) {
    /* ... */

Change History (7)

comment:1 Changed 10 years ago by Rick Waldron

Resolution: wontfix
Status: newclosed

Good for a monkey patch, but core is going the way of less complexity

comment:2 Changed 10 years ago by david71rj

Hum... I guess that doesn't is a complexity, but a facility. If I need use a workaround to do it (with Core features), so Core is not suficient. Someone can post a third opinion (to tie), please? :)

Seems only that it is *incompatible* with jQuery source method to .fadeToggle(). (the bad part).


comment:3 Changed 10 years ago by Rick Waldron

Was this a feature or a bug fix? It was filed as a feature. If there is a bug, please identify and we'll re-open

Last edited 10 years ago by Rick Waldron (previous) (diff)

comment:4 Changed 10 years ago by david71rj

Well, currently it doesn't defined. For me is a improvement/feature. But I think it is need to Core, and the implementation is very easy. Don't will break jQuery too.

comment:5 Changed 10 years ago by Rick Waldron

Sorry, this isn't compelling enough to change the core library. Anytime a new method signature overload is introduced, it inevitably introduces bugs in existing code and requires maintenance.

comment:6 Changed 10 years ago by david71rj

A good reason to the jQuery Test Suite exists, not? :P

Well... I think that it probably will slowdown jQuery execution, really, with my tests, it'll slow between 0% to 3% (http://jsperf.com/new-argument-slowdown-sample) in 6 million executions. But on real, I think that you need to consider that jQuery animate in fade and slide by Core currently, and too have showOrHide arg in other methods (but with "static animation").

Well, I'll not to insist very much, only I think that need be part of Core (because of 1+1 sum above). But the jQuery Team need see the best to framework, and not to specifically *my problem* (hum, not is really a problem).

In .fadeToggle() page you can see an user told about this same feature request.

comment:7 Changed 10 years ago by dmethvin

This is digressing into a meta-discussion about API design.

It's not just about performance or whether it is technically possible to implement with a few lines of code inside jQuery core. It's about the benefit versus the complexity and size of code/documentation, the odds of breaking something, and the user's learning curve. If we (or JavaScript) provide a simple way to compose two things, that is often better than adding code and documentation to pre-compose them via complex signatures--even if it is slightly longer.

Complex APIs are difficult to document, hard to remember, and often have conflicting or non-intuitive results. For an example, see the 33 different options for $.ajax(), the 3 completely different semantics for $().toggle() or the 9 different signatures for $(). Try to figure out whether $(elem).load(x) will load content via AJAX or set an onload handler without knowing the data type of x. Go see what happened when we made .outerWidth() a setter in 1.8.

jQuery was meant to be easily extended by users so they can use it in a way that works for them. We should not be creating a complex API that reflects the union of all thoughts about how to use jQuery in all situations.

Note: See TracTickets for help on using tickets.