📜 ⬆️ ⬇️

JQuery 3.0 alpha and jQuery Compat 3.0 alpha published

(Translation of this story from the authors of the most popular library would be very instructive for anyone who would like to keep abreast of browser tectonics in the light of the solvable problems with DOM parsing at this stage.)

Much water has flowed since the last major release, and you certainly deserve updates. Therefore, we are pleased to announce the release of the first alpha version of jQuery!

Despite the version number 3.0, we expect that this release will not cause too much trouble when upgrading the code. Yes, there are several critical changes, which is justified by the change of the older index version, but we hope that these modifications will not affect many. The jQuery Migrate plugin will help identify code compatibility issues. Also, your opinions about this alpha will help us a lot, so please try it on existing code and plugins!
')
The first release, jQuery 3.0 , is supported by new browsers and IE 9+. The second, jQuery Compat 3.0 , is supported in IE 8+. As a bonus, both releases will be supported by a Yandex browser released in 2012. You can get files from jQuery CDN or direct links:

code.jquery.com/jquery-3.0.0-alpha1.js

code.jquery.com/jquery-compat-3.0.0-alpha1.js

You can install them via npm :
npm install jquery@3.0.0-alpha1 

  npm install jquery-compat@3.0.0-alpha1 



Major changes



Here are discussed only the main of the new features, changes and corrections. The full list of changes is shown below and is tracked on our GitHub account without any problems. On GitHub, in addition, you can see not yet implemented functions that are planned in later beta and final versions.


Simplified methods .show () and .hide ()


The whole point of .hide () in jQuery is to set the 'display: none' property in CSS. Accordingly, .show () will refresh the screen so that the item is displayed again (provided that its parents are not hidden). It's simple, right?

Okay, not everything. In fact, there are many difficult special cases that people have asked us to “fix” over the years, which have found themselves in a tangled tangle of principles. For example, what if an element is not set to display: none in the style sheet? jQuery will try to determine its force setting display: block on the element. Well, but what if the default block element <li> was set to display: inline in another style sheet rule? What about the case when you call these methods on an element before it is added to the document, and we don't know what value the display will have? Identifying all of this creates additional work. Sometimes we are still based on assumptions, and the result is not so.

Because these methods add a style attribute to an element, they will not work well with techniques such as responsive design, where the visibility of elements may depend on media queries. This leads to the need for jQuery handlers that listen for orientationchange or resize events to manually hide or display portions of the page; this destroys the elegance of the decision that they tried to make through media queries.

You can see that jQuery is already halfway to total madness, and there is no point in completing the journey. Special cases and checks would not only be complex and incomplete, but would also cause significant performance problems on large pages.

Instead, we experimentally ignore the evolution of these methods and return to the simple initial model. This will break some code. If you have elements whose styles have display: none , the .show () method will not override this property. So the most important rule for switching to jQuery 3.0 is: Do not use style sheets to set the default display: none , and then try to use .show () - or another method that shows the elements - .slideDown () or .fadeIn () - to make it visible.

If you need an element that will be hidden by default, it is better to add the class name of the type “hidden” to the element and determine that the class will be display: none in styles. You can then add or remove this class, using the .addClass () and .removeClass () methods in jQuery to control visibility. In addition, you can have the .hide () call handler on elements before they are displayed on the page. Or, if you really need to store the default styles, you can use .css (“display”, “block”) (or another display value) to override the styles.

We know that this will probably be one of the most controversial and complex changes in jQuery 3.0, so we wanted to put it into release as early as possible to see the effect. Please let us know how it affects your code and what needs to be changed in order to work with this new model.

github.com/jquery/jquery/issues/1767
github.com/jquery/jquery/issues/2057
github.com/jquery/jquery/issues/2308


Special case with names in .data ()


We updated our implementation of .data () to better comply with the HTML5 data specification . All keys are converted from kebab-case to camelCase, regardless of the access method, and the numbers no longer participate in the conversion. For example, we do not distinguish between "foo-bar" and "fooBar", but distinguish between "foo-42" and "foo42". These changes will mainly play a role when retrieving all data using a .data () call with no arguments or trying to access data using the converted .data key (“foo42”) instead of the original .data (“foo-42”).

github.com/jquery/jquery/issues/1751


jQuery.Deferred is now compatible with Promises / A +


JQuery.Deferred objects have been updated for compatibility with Promises / A + and ES2015 Promises, checked by Promises / A + Compliance Test Suite . This means the introduction of the .catch () method and several major changes in the .then () method:

Consider the following code, in which the Deferred parent is rejected, and the child callback throws an exception:

 var parent = jQuery.Deferred(); var child = parent.then( null, function() { return "bar"; }); var callback = function( state ) { return function( value ) { console.log( state, value ); throw new Error( "baz" ); }; }; var grandchildren = [ child.then( callback( "fulfilled" ), callback( "rejected" ) ), child.then( callback( "fulfilled" ), callback( "rejected" ) ) ]; parent.reject( "foo" ); console.log( "parent resolved" ); 


In jQuery 3.0, this will give out “parent resolved” before calling any callback, each child of the callback will return “fulfilled bar”, and the grandchildren will be rejected with the error “baz”. In previous versions, the rejected bar would be issued (the Deferred child was rejected instead of fulfilled) once, and then the execution would stop due to the unresolved baz error (parent resolved is not displayed and the grandchildren remain unfulfilled).

While caught exceptions were an advantage to debug in the browser, this is a much more declarative (that is, explicit) way to handle them with a failback callback. Keep in mind that it requires you to always add at least one such callback when working with promises. Otherwise, any errors will go unnoticed.

Old behavior can be restored by replacing .then () with the now obsolete .pipe () method (which has the same signature).

jQuery.when has also been updated to accept any thenable object that includes native promises.

github.com/jquery/jquery/issues/1722
github.com/jquery/jquery/issues/2102


Removed special states of Deferred methods in jQuery.ajax


The jqXHR object is a promise (Promise), but it has additional methods, such as .abort (), so you can stop the request after it has been made.

Since users are increasingly choosing the Promise template for asynchronous AJAX work, the idea of ​​returning special states for Promise from jQuery.ajax is not very good.

success, error, complete
done, fail, always

Please note that this does not affect all callbacks with the same name that continue to exist and are not considered obsolete. This only affects promis methods!

github.com/jquery/jquery/issues/2084


Do not ignore errors


Perhaps in deep reasoning you asked the question “What is a window displacement?” Then you probably understood that it was a crazy question - how can you give a window a shift at all?

Previously, jQuery sometimes tried in such cases to return something meaningful, and not to expose errors. In this case, when requesting a window offset, the answer was {top: 0, left: 0}. In this jQuery 3.0 alpha, we experiment with the idea of ​​generating errors in such cases so as not to ignore meaningless requests. Please try alpha and see if there is any jQuery dependent code that hides problems with the wrong code.

github.com/jquery/jquery/issues/1784


.width (), .height (), .css ("width"), and .css ("height") began to return fractional values ​​(if the browser allows)


Previously, jQuery returned rounded widths and heights. Some browsers return sub-pixel values ​​— such as IE and Firefox — and sometimes users need this accuracy. We do not expect this change to have a big impact on your code, but let us know if this happens.

github.com/jquery/jquery/issues/1724


Removed obsolete event aliases


.load , .unload and .error are deprecated since jQuery 1.8. Use .on () to register handlers.

github.com/jquery/jquery/issues/2286


jQuery.swap, jQuery.buildFragment and jQuery.domManip are no longer available.


These methods have always been for internal use only and have not been documented. We finally made them private to avoid confusion.

github.com/jquery/jquery/issues/2224
github.com/jquery/jquery/issues/2225

Animations now use requestAnimationFrame



On platforms that support the requestAnimationFrame API , except IE8-9, jQuery now uses this API for animation. This should give smoother animations, use less CPU time and save battery on mobile devices.

jQuery tried to implement requestAnimationFrame a few years ago, but then there were serious compatibility issues with existing code. We think we have solved most of these issues by pausing the animation when the browser tab is closed. However, any code that depends on the animation and runs in almost real time makes this assumption wrong.


.unwrap (selector)


Before jQuery 3.0, the .unwrap () method took no arguments. The selector argument indicates which wrappers to remove.

github.com/jquery/jquery/issues/1744


Significant acceleration for some native jQuery selectors


Thanks to some Paul Irish research work at Google, we’ve identified some cases where we could miss a lot of extra work, when the selectors like : visible are used many times in a document. It sometimes improves speed up to 17 times!

Keep in mind that even with this improvement, selectors like : visible and : hidden can be expensive because they depend on the browser to determine whether elements are displayed on the page. This may require, at worst, a full CSS recalculation and page layout! We, without interfering with their use, we recommend checking the pages with such selectors for performance.

github.com/jquery/jquery/issues/2042


Thanks


Many thanks to everyone who participated in testing this release, reporting bugs, or providing patches, including by name:
Chris Antaki, Jason Bedard, Leonardo Braga, Bastian Buchholz and 10+ more lines of names
Chris Antaki, Jason Bedard, Leonardo Braga, Bastian Buchholz, Anne-Gaelle Colom, David Corbacho, Brenard Cubacub, Hamish Dickson, Ben Edelman, Stephen Edgar, elas7, flexphperia, Corey Frang, Xue Fuqiao, Oleg Gaidarenko, Richard Gibson, Michałyławy, elf7 , Scott González, goob, Veaceslav Grimalschi, Mu Haibao, Dan Hart, Frederic Hemberger, Nicolas Henry, Daniel Herman, Jon Hester, Victor Homyakov, Winston Howes, Daniel Husar, Essam Al Joubori, Veres Lajos, George Mauer, Richard McDaniel, Merchant, Calvin Metcalf, Dave Methvin, MightyBranch, Nazar Mokrynskyi, Matthew Mueller, Martin Naumann, Alexander O'Mara, Randson Oliveira, Gilad Peleg, James Pearce, PJ, Senya Pugach, Aditya Raghavan, Chris Rebert, Aurelio De Rosa; , Mike Sidorov, Nick Stefan, Arthur Stolyar, Timo Tijhof, Ben Toews, Thomas Tortorini, Shivaji Varma, Arthur Verschaeve, Rick Waldron, Bin Xin, Imran M Yousuf, Jörn Zaefferer.



All changes


Here is a complete list of changes since the last official releases (1.11.3 and 2.1.4).


Common to both jQuery and jQuery Compat releases


Ajax



Attributes



Callbacks



Core



CSS



Data



Deferred



Dimensions



Documents



Effects



Developments



Manipulation (DOM)



Offset



Selector/Sizzle



Wrap




, : Readme, Build, Test, ...

miscellanea



«Readme»



Build



Release



Support



Tests






jQuery 3.0


Ajax



CSS



Data





Offset




, : , Readme, Build, Tests

miscellanea



Documents



«Readme»


  • selector-native.js . randsonjs! ( cfe2eae )

Build



Tests






jQuery Compat 3.0


Ajax



Attributes







CSS



Data



Deferred



Effects



Developments



DOM



Offset



Traversing



, : , Build,

Documents



Build



miscellanea



Tests


  • IE8 (Sinon IE HTML5 Shiv) ( 0b07c65 )

Source: https://habr.com/ru/post/262727/


All Articles