jquery/jquery — pull request #1271 by jbedard (2013-05-16 16:28:35+00:00)
Title: make toggle(true/fales) and toggleClass("...", true/false) shortcut to show/hide and add/removeClass

The .toggle methods both construct new jQuery objects for each element to test the current state, but in the case where a boolean is passed this isn't needed.

This change avoids the new jQuery objects for cases where a boolean is passed to the toggle methods.

It adds a few bytes in its current state, and adds an extra code path, but it also simplifies the loops a bit since the boolean case no longer goes into the loops. This will also remove a closure from .toggle() and will pass all the elements at once to showHide() which minimizes reflow when you pass multiple elements.

raw gz Compared to master
+122 +16 dist/jquery.js
+50 +3 dist/jquery.min.js

The +3 can probably be removed. For example, inlining the "var type = typeof value" actually makes it smaller but then does a typeof within the .each (which might be fine..?):

raw gz Compared to master
+121 +6 dist/jquery.js
+60 -3 dist/jquery.min.js