focusin.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. define( [
  2. "../core",
  3. "../data/var/dataPriv",
  4. "./support",
  5. "../event",
  6. "./trigger"
  7. ], function( jQuery, dataPriv, support ) {
  8. "use strict";
  9. // Support: Firefox <=44
  10. // Firefox doesn't have focus(in | out) events
  11. // Related ticket - https://bugzilla.mozilla.org/show_bug.cgi?id=687787
  12. //
  13. // Support: Chrome <=48 - 49, Safari <=9.0 - 9.1
  14. // focus(in | out) events fire after focus & blur events,
  15. // which is spec violation - http://www.w3.org/TR/DOM-Level-3-Events/#events-focusevent-event-order
  16. // Related ticket - https://bugs.chromium.org/p/chromium/issues/detail?id=449857
  17. if ( !support.focusin ) {
  18. jQuery.each( { focus: "focusin", blur: "focusout" }, function( orig, fix ) {
  19. // Attach a single capturing handler on the document while someone wants focusin/focusout
  20. var handler = function( event ) {
  21. jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ) );
  22. };
  23. jQuery.event.special[ fix ] = {
  24. setup: function() {
  25. var doc = this.ownerDocument || this,
  26. attaches = dataPriv.access( doc, fix );
  27. if ( !attaches ) {
  28. doc.addEventListener( orig, handler, true );
  29. }
  30. dataPriv.access( doc, fix, ( attaches || 0 ) + 1 );
  31. },
  32. teardown: function() {
  33. var doc = this.ownerDocument || this,
  34. attaches = dataPriv.access( doc, fix ) - 1;
  35. if ( !attaches ) {
  36. doc.removeEventListener( orig, handler, true );
  37. dataPriv.remove( doc, fix );
  38. } else {
  39. dataPriv.access( doc, fix, attaches );
  40. }
  41. }
  42. };
  43. } );
  44. }
  45. return jQuery;
  46. } );