focusin.js 1.4 KB

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