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

jquery / jquery-mobile / 2313

5 Feb 2015 - 11:04 coverage increased (+0.009%) to 82.482%
2313

Pull #7953

travis-ci

Acabeff49b5ba95a8e94de9445175f56?size=18&default=identicongabrielschulhof
Textinput: Update comment regarding deprecated style options
Pull Request #7953: Textinput: Implement classes option

3503 of 4247 relevant lines covered (82.48%)

924.16 hits per line

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

97.14
/js/events/navigate.js
1
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2
//>>description: Provides a wrapper around hashchange and popstate
3
//>>label: Navigate
4
//>>group: Events
5

6
// TODO break out pushstate support test so we don't depend on the whole thing
7
define([
303×
8
        "jquery",
9
        "./../ns",
10
        "./../support" ], function( jQuery ) {
11
//>>excludeEnd("jqmBuildExclude");
12

13
(function( $, undefined ) {
303×
14
        var $win = $.mobile.window, self,
303×
15
                dummyFnToInitNavigate = function() {
16
                };
17

18
        $.event.special.beforenavigate = {
303×
19
                setup: function() {
20
                        $win.on( "navigate", dummyFnToInitNavigate );
171×
21
                },
22

23
                teardown: function() {
24
                        $win.off( "navigate", dummyFnToInitNavigate );
171×
25
                }
26
        };
27

28
        $.event.special.navigate = self = {
303×
29
                bound: false,
30

31
                pushStateEnabled: true,
32

33
                originalEventName: undefined,
34

35
                // If pushstate support is present and push state support is defined to
36
                // be true on the mobile namespace.
37
                isPushStateEnabled: function() {
38
                        return $.support.pushState &&
6,429×
39
                                $.mobile.pushStateEnabled === true &&
40
                                this.isHashChangeEnabled();
41
                },
42

43
                // !! assumes mobile namespace is present
44
                isHashChangeEnabled: function() {
45
                        return $.mobile.hashListeningEnabled === true;
7,836×
46
                },
47

48
                // TODO a lot of duplication between popstate and hashchange
49
                popstate: function( event ) {
50
                        var newEvent = new $.Event( "navigate" ),
1,174×
51
                                beforeNavigate = new $.Event( "beforenavigate" ),
52
                                state = event.originalEvent.state || {};
53

54
                        beforeNavigate.originalEvent = event;
1,174×
55
                        $win.trigger( beforeNavigate );
1,174×
56

57
                        if ( beforeNavigate.isDefaultPrevented() ) {
1,174×
58
                                return;
171×
59
                        }
60

61
                        if ( event.historyState ) {
1,003×
62
                                $.extend(state, event.historyState);
930×
63
                        }
64

65
                        // Make sure the original event is tracked for the end
66
                        // user to inspect incase they want to do something special
67
                        newEvent.originalEvent = event;
1,003×
68

69
                        // NOTE we let the current stack unwind because any assignment to
70
                        //      location.hash will stop the world and run this event handler. By
71
                        //      doing this we create a similar behavior to hashchange on hash
72
                        //      assignment
73
                        setTimeout(function() {
1,003×
74
                                $win.trigger( newEvent, {
1,003×
75
                                        state: state
76
                                });
77
                        }, 0);
78
                },
79

80
                hashchange: function( event /*, data */ ) {
81
                        var newEvent = new $.Event( "navigate" ),
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
82
                                beforeNavigate = new $.Event( "beforenavigate" );
83

84
                        beforeNavigate.originalEvent = event;
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
85
                        $win.trigger( beforeNavigate );
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
86

87
                        if ( beforeNavigate.isDefaultPrevented() ) {
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
UNCOV
88
                                return;
!
89
                        }
90

91
                        // Make sure the original event is tracked for the end
92
                        // user to inspect incase they want to do something special
93
                        newEvent.originalEvent = event;
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
94

95
                        // Trigger the hashchange with state provided by the user
96
                        // that altered the hash
97
                        $win.trigger( newEvent, {
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 112×
98
                                // Users that want to fully normalize the two events
99
                                // will need to do history management down the stack and
100
                                // add the state to the event before this binding is fired
101
                                // TODO consider allowing for the explicit addition of callbacks
102
                                //      to be fired before this value is set to avoid event timing issues
103
                                state: event.hashchangeState || {}
104
                        });
105
                },
106

107
                // TODO We really only want to set this up once
108
                //      but I'm not clear if there's a beter way to achieve
109
                //      this with the jQuery special event structure
110
                setup: function( /* data, namespaces */ ) {
111
                        if ( self.bound ) {
302×
112
                                return;
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 8×
113
                        }
114

115
                        self.bound = true;
294×
116

117
                        if ( self.isPushStateEnabled() ) {
294×
118
                                self.originalEventName = "popstate";
270×
119
                                $win.bind( "popstate.navigate", self.popstate );
270×
120
                        } else if ( self.isHashChangeEnabled() ) {
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 24×
121
                                self.originalEventName = "hashchange";
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 8×
122
                                $win.bind( "hashchange.navigate", self.hashchange );
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 8×
123
                        }
124
                }
125
        };
126
})( jQuery );
127

128
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
129
});
130
//>>excludeEnd("jqmBuildExclude");
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc