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

96.08
/js/navigation/history.js
1
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2
//>>description: Manages a stack of history entries. Used exclusively by the Navigation Manager
3
//>>label: History Manager
4
//>>group: Navigation
5
define([ "jquery", "./../ns", "./path" ], function( jQuery ) {
303×
6
//>>excludeEnd("jqmBuildExclude");
7

8
(function( $, undefined ) {
303×
9
        $.mobile.History = function( stack, index ) {
303×
10
                this.stack = stack || [];
303×
11
                this.activeIndex = index || 0;
303×
12
        };
13

14
        $.extend($.mobile.History.prototype, {
303×
15
                getActive: function() {
16
                        return this.stack[ this.activeIndex ];
6,526×
17
                },
18

19
                getLast: function() {
20
                        return this.stack[ this.previousIndex ];
1,180×
21
                },
22

23
                getNext: function() {
24
                        return this.stack[ this.activeIndex + 1 ];
1,925×
25
                },
26

27
                getPrev: function() {
28
                        return this.stack[ this.activeIndex - 1 ];
!
29
                },
30

31
                // addNew is used whenever a new page is added
32
                add: function( url, data ) {
33
                        data = data || {};
1,925×
34

35
                        //if there's forward history, wipe it
36
                        if ( this.getNext() ) {
1,925×
37
                                this.clearForward();
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 276×
38
                        }
39

40
                        // if the hash is included in the data make sure the shape
41
                        // is consistent for comparison
42
                        if ( data.hash && data.hash.indexOf( "#" ) === -1) {
1,925×
43
                                data.hash = "#" + data.hash;
455×
44
                        }
45

46
                        data.url = url;
1,925×
47
                        this.stack.push( data );
1,925×
48
                        this.activeIndex = this.stack.length - 1;
1,925×
49
                },
50

51
                //wipe urls ahead of active index
52
                clearForward: function() {
53
                        this.stack = this.stack.slice( 0, this.activeIndex + 1 );
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 276×
54
                },
55

56
                find: function( url, stack, earlyReturn ) {
57
                        stack = stack || this.stack;
1,005×
58

59
                        var entry, i, length = stack.length, index;
1,005×
60

61
                        for ( i = 0; i < length; i++ ) {
1,005×
62
                                entry = stack[i];
1,982×
63

64
                                if ( decodeURIComponent(url) === decodeURIComponent(entry.url) ||
1,982×
65
                                        decodeURIComponent(url) === decodeURIComponent(entry.hash) ) {
66
                                        index = i;
159×
67

68
                                        if ( earlyReturn ) {
159×
UNCOV
69
                                                return index;
!
70
                                        }
71
                                }
72
                        }
73

74
                        return index;
1,005×
75
                },
76

77
                _findById: function( id ) {
78
                        var stackIndex,
538×
79
                                stackLength = this.stack.length;
80

81
                        for ( stackIndex = 0 ; stackIndex < stackLength ; stackIndex++ ) {
538×
82
                                if ( this.stack[ stackIndex ].id === id ) {
2,649×
83
                                        break;
459×
84
                                }
85
                        }
86

87
                        return ( stackIndex < stackLength ? stackIndex : undefined );
538×
88
                },
89

90
                closest: function( url, id ) {
91
                        var closest = ( id === undefined ? undefined : this._findById( id ) ),
1,033×
92
                                a = this.activeIndex;
93

94
                        // First, we check whether we've found an entry by id. If so, we're done.
95
                        if ( closest !== undefined ) {
1,033×
96
                                return closest;
459×
97
                        }
98

99
                        // Failing that take the slice of the history stack before the current index and search
100
                        // for a url match. If one is found, we'll avoid avoid looking through forward history
101
                        // NOTE the preference for backward history movement is driven by the fact that
102
                        //      most mobile browsers only have a dedicated back button, and users rarely use
103
                        //      the forward button in desktop browser anyhow
104
                        closest = this.find( url, this.stack.slice(0, a) );
574×
105

106
                        // If nothing was found in backward history check forward. The `true`
107
                        // value passed as the third parameter causes the find method to break
108
                        // on the first match in the forward history slice. The starting index
109
                        // of the slice must then be added to the result to get the element index
110
                        // in the original history stack :( :(
111
                        //
112
                        // TODO this is hyper confusing and should be cleaned up (ugh so bad)
113
                        if ( closest === undefined ) {
574×
114
                                closest = this.find( url, this.stack.slice(a), true );
431×
115
                                closest = closest === undefined ? closest : closest + a;
431×
116
                        }
117

118
                        return closest;
574×
119
                },
120

121
                direct: function( opts ) {
122
                        var newActiveIndex = this.closest( opts.url, opts.id ), a = this.activeIndex;
1,033×
123

124
                        // save new page index, null check to prevent falsey 0 result
125
                        // record the previous index for reference
126
                        if ( newActiveIndex !== undefined ) {
1,033×
127
                                this.activeIndex = newActiveIndex;
602×
128
                                this.previousIndex = a;
602×
129
                        }
130

131
                        // invoke callbacks where appropriate
132
                        //
133
                        // TODO this is also convoluted and confusing
134
                        if ( newActiveIndex < a ) {
1,033×
135
                                ( opts.present || opts.back || $.noop )( this.getActive(), "back" );
586×
136
                        } else if ( newActiveIndex > a ) {
447×
137
                                ( opts.present || opts.forward || $.noop )( this.getActive(), "forward" );
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 16×
138
                        } else if ( newActiveIndex === undefined && opts.missing ) {
431×
139
                                opts.missing( this.getActive() );
all except TYPES=unit JQUERIES=1.8.3, TYPES=unit JQUERIES=1.11.1, and TYPES=unit JQUERIES=2.1.1 - 48×
140
                        }
141
                }
142
        });
143
})( jQuery );
144

145
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
146
});
147
//>>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