Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jquery / jquery-migrate / 149

5 Aug 2016 - 21:50 coverage: 87.288% (-0.2%) from 87.5%
149

Pull #217

travis-ci

9181eb84f9c35729a3bad740fb7f9d93?size=18&default=identiconweb-flow
Event: Warn about late use of $(window).on("load"...)

Fixes #200
Pull Request #217: Event: Warn about late use of $(window).on("load"...)

3 of 4 new or added lines in 1 file covered. (75.0%)

206 of 236 relevant lines covered (87.29%)

8.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.72
/src/event.js
1
var oldLoad = jQuery.fn.load,
1×
2
        oldEventAdd = jQuery.event.add,
3
        originalFix = jQuery.event.fix;
4

5
jQuery.event.props = [];
1×
6
jQuery.event.fixHooks = {};
1×
7

8
migrateWarnProp( jQuery.event.props, "concat", jQuery.event.props.concat,
1×
9
        "jQuery.event.props.concat() is deprecated and removed" );
10

11
jQuery.event.fix = function( originalEvent ) {
1×
12
        var event,
6×
13
                type = originalEvent.type,
14
                fixHook = this.fixHooks[ type ],
15
                props = jQuery.event.props;
16

17
        if ( props.length ) {
6×
18
                migrateWarn( "jQuery.event.props are deprecated and removed: " + props.join() );
!
19
                while ( props.length ) {
!
20
                        jQuery.event.addProp( props.pop() );
!
21
                }
22
        }
23

24
        if ( fixHook && !fixHook._migrated_ ) {
6×
25
                fixHook._migrated_ = true;
!
26
                migrateWarn( "jQuery.event.fixHooks are deprecated and removed: " + type );
!
27
                if ( ( props = fixHook.props ) && props.length ) {
!
28
                        while ( props.length ) {
!
29
                           jQuery.event.addProp( props.pop() );
!
30
                        }
31
                }
32
        }
33

34
        event = originalFix.call( this, originalEvent );
6×
35

36
        return fixHook && fixHook.filter ? fixHook.filter( event, originalEvent ) : event;
6×
37
};
38

39
jQuery.event.add = function( elem, types ) {
1×
40

41
        // This misses the multiple-types case but that seems awfully rare
42
        if ( elem === window && types === "load" && document.readyState === "complete" ) {
6×
NEW
43
                migrateWarn( "$(window).on('load'...) called after load event occurred" );
!
44
        }
45
        return oldEventAdd.apply( this, arguments );
6×
46
};
47

48
jQuery.each( [ "load", "unload", "error" ], function( _, name ) {
1×
49

50
        jQuery.fn[ name ] = function() {
3×
51
                var args = Array.prototype.slice.call( arguments, 0 );
10×
52

53
                // If this is an ajax load() the first arg should be the string URL;
54
                // technically this could also be the "Anything" arg of the event .load()
55
                // which just goes to show why this dumb signature has been deprecated!
56
                // jQuery custom builds that exclude the Ajax module justifiably die here.
57
                if ( name === "load" && typeof args[ 0 ] === "string" ) {
10×
58
                        return oldLoad.apply( this, args );
1×
59
                }
60

61
                migrateWarn( "jQuery.fn." + name + "() is deprecated" );
9×
62

63
                args.splice( 0, 0, name );
9×
64
                if ( arguments.length ) {
9×
65
                        return this.on.apply( this, args );
3×
66
                }
67

68
                // Use .triggerHandler here because:
69
                // - load and unload events don't need to bubble, only applied to window or image
70
                // - error event should not bubble to window, although it does pre-1.7
71
                // See http://bugs.jquery.com/ticket/11820
72
                this.triggerHandler.apply( this, args );
6×
73
                return this;
6×
74
        };
75

76
} );
77

78
// Trigger "ready" event only once, on document ready
79
jQuery( function() {
1×
80
        jQuery( document ).triggerHandler( "ready" );
1×
81
} );
82

83
jQuery.event.special.ready = {
1×
84
        setup: function() {
85
                if ( this === document ) {
1×
86
                        migrateWarn( "'ready' event is deprecated" );
!
87
                }
88
        }
89
};
90

91
jQuery.fn.extend( {
1×
92

93
        bind: function( types, data, fn ) {
94
                migrateWarn( "jQuery.fn.bind() is deprecated" );
1×
95
                return this.on( types, null, data, fn );
1×
96
        },
97
        unbind: function( types, fn ) {
98
                migrateWarn( "jQuery.fn.unbind() is deprecated" );
1×
99
                return this.off( types, null, fn );
1×
100
        },
101
        delegate: function( selector, types, data, fn ) {
102
                migrateWarn( "jQuery.fn.delegate() is deprecated" );
1×
103
                return this.on( types, selector, data, fn );
1×
104
        },
105
        undelegate: function( selector, types, fn ) {
106
                migrateWarn( "jQuery.fn.undelegate() is deprecated" );
1×
107
                return arguments.length === 1 ?
1×
108
                        this.off( selector, "**" ) :
109
                        this.off( types, selector || "**", fn );
110
        }
111
} );
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2023 Coveralls, Inc