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

87.93
/js/widgets/toolbar.js
1
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2
//>>description: Behavior for "fixed" headers and footers - be sure to also include the item 'Browser specific workarounds for "fixed" headers and footers' when supporting Android 2.x or iOS 5
3
//>>label: Toolbars: Fixed
4
//>>group: Widgets
5
//>>css.structure: ../css/structure/jquery.mobile.fixedToolbar.css
6
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7

8
define( [
45×
9
        "jquery",
10
        "../widget",
11
        "../core",
12
        "../navigation",
13
        "../zoom" ], function( jQuery ) {
14
//>>excludeEnd("jqmBuildExclude");
15
(function( $, undefined ) {
45×
16

17
        $.widget( "mobile.toolbar", {
45×
18
                initSelector: ":jqmData(role='footer'), :jqmData(role='header')",
19

20
                options: {
21
                        theme: null,
22
                        addBackBtn: false,
23
                        backBtnTheme: null,
24
                        backBtnText: "Back"
25
                },
26

27
                _create: function() {
28
                        var leftbutton, rightbutton,
153×
29
                                role =  this.element.is( ":jqmData(role='header')" ) ? "header" : "footer",
30
                                page = this.element.closest( ".ui-page" );
31
                        if ( page.length === 0 ) {
153×
32
                                page = false;
14×
33
                                this._on( this.document, {
14×
34
                                        "pageshow": "refresh"
35
                                });
36
                        }
37
                        $.extend( this, {
153×
38
                                role: role,
39
                                page: page,
40
                                leftbutton: leftbutton,
41
                                rightbutton: rightbutton
42
                        });
43
                        this.element.attr( "role", role === "header" ? "banner" : "contentinfo" ).addClass( "ui-" + role );
153×
44
                        this.refresh();
153×
45
                        this._setOptions( this.options );
153×
46
                },
47
                _setOptions: function( o ) {
48
                        if ( o.addBackBtn !== undefined ) {
447×
49
                                this._updateBackButton();
153×
50
                        }
51
                        if ( o.backBtnTheme != null ) {
447×
52
                                this.element
!
53
                                        .find( ".ui-toolbar-back-button" )
54
                                        .addClass( "ui-button ui-button-" + o.backBtnTheme );
55
                        }
56
                        if ( o.backBtnText !== undefined ) {
447×
57
                                this.element.find( ".ui-toolbar-back-button .ui-button-text" ).text( o.backBtnText );
153×
58
                        }
59
                        if ( o.theme !== undefined ) {
447×
60
                                var currentTheme = this.options.theme ? this.options.theme : "inherit",
153×
61
                                        newTheme = o.theme ? o.theme : "inherit";
62

63
                                this.element.removeClass( "ui-bar-" + currentTheme ).addClass( "ui-bar-" + newTheme );
153×
64
                        }
65

66
                        this._super( o );
447×
67
                },
68
                refresh: function() {
69
                        if ( this.role === "header" ) {
153×
70
                                this._addHeaderButtonClasses();
87×
71
                        }
72
                        if ( !this.page ) {
153×
73
                                this._setRelative();
14×
74
                                if ( this.role === "footer" ) {
14×
75
                                        this.element.appendTo( "body" );
7×
76
                                } else if ( this.role === "header" ) {
7×
77
                                        this._updateBackButton();
7×
78
                                }
79
                        }
80
                        this._addHeadingClasses();
153×
81
                        this._buttonMarkup();
153×
82
                },
83

84
                //we only want this to run on non fixed toolbars so make it easy to override
85
                _setRelative: function() {
86
                        $( "[data-"+ $.mobile.ns + "role='page']" ).css({ "position": "relative" });
14×
87
                },
88

89
                // Deprecated in 1.4. As from 1.5 button classes have to be present in the markup.
90
                _buttonMarkup: function() {
91
                        this.element
153×
92
                                .children( "a" )
93
                                .filter( ":not([data-" + $.mobile.ns + "role='none'])" )
94
                                .attr( "data-" + $.mobile.ns + "role", "button" );
95
                        this.element.trigger( "create" );
153×
96
                },
97
                // Deprecated in 1.4. As from 1.5 ui-button-left/right classes have to be present in the markup.
98
                _addHeaderButtonClasses: function() {
99
                        var headerAnchors = this.element.children( "a, button" );
87×
100

101
                        // Do not mistake a back button for a left toolbar button
102
                        this.leftbutton = headerAnchors.hasClass( "ui-button-left" ) &&
87×
103
                                !headerAnchors.hasClass( "ui-toolbar-back-button" );
104

105
                        this.rightbutton = headerAnchors.hasClass( "ui-button-right" );
87×
106

107
                        // Filter out right buttons and back buttons
108
                        this.leftbutton = this.leftbutton ||
87×
109
                                headerAnchors.eq( 0 )
110
                                        .not( ".ui-button-right,.ui-toolbar-back-button" )
111
                                        .addClass( "ui-button-left" )
112
                                        .length;
113

114
                        this.rightbutton = this.rightbutton || headerAnchors.eq( 1 ).addClass( "ui-button-right" ).length;
87×
115
                },
116
                _updateBackButton: function() {
117
                        var backButton,
160×
118
                                options = this.options,
119
                                theme = options.backBtnTheme || options.theme;
120

121
                        // Retrieve the back button or create a new, empty one
122
                        backButton = this._backButton = ( this._backButton || {} );
160×
123

124
                        // We add a back button only if the option to do so is on
125
                        if ( this.options.addBackBtn &&
160×
126

127
                                        // This must also be a header toolbar
128
                                        this.role === "header" &&
129

130
                                        // There must be multiple pages in the DOM
131
                                        $( ".ui-page" ).length > 1 &&
132
                                        ( this.page ?
133

134
                                                // If the toolbar is internal the page's URL must differ from the hash
135
                                                ( this.page[ 0 ].getAttribute( "data-" + $.mobile.ns + "url" ) !==
136
                                                        $.mobile.path.stripHash( location.hash ) ) :
137

138
                                                // Otherwise, if the toolbar is external there must be at least one
139
                                                // history item to which one can go back
140
                                                ( $.mobile.navigate && $.mobile.navigate.history &&
141
                                                        $.mobile.navigate.history.activeIndex > 0 ) ) &&
142

143
                                        // The toolbar does not have a left button
144
                                        !this.leftbutton ) {
145

146
                                // Skip back button creation if one is already present
UNCOV
147
                                if ( !backButton.attached ) {
!
UNCOV
148
                                        this.backButton = backButton.element = ( backButton.element ||
!
149
                                                $( "<a role='button' href='javascript:void(0);' " +
150
                                                        "class='ui-button ui-corner-all ui-shadow ui-button-left " +
151
                                                                ( theme ? "ui-button-" + theme + " " : "" ) +
152
                                                                "ui-toolbar-back-button ui-icon-carat-l ui-icon-beginning' " +
153
                                                        "data-" + $.mobile.ns + "rel='back'>" + options.backBtnText +
154
                                                        "</a>" ) )
155
                                                        .prependTo( this.element );
UNCOV
156
                                        backButton.attached = true;
!
157
                                }
158

159
                        // If we are not adding a back button, then remove the one present, if any
160
                        } else if ( backButton.element ) {
160×
UNCOV
161
                                backButton.element.detach();
!
UNCOV
162
                                backButton.attached = false;
!
163
                        }
164
                },
165
                _addHeadingClasses: function() {
166
                        this.element.children( "h1, h2, h3, h4, h5, h6" )
153×
167
                                .addClass( "ui-title" )
168
                                // Regardless of h element number in src, it becomes h1 for the enhanced page
169
                                .attr({
170
                                        "role": "heading",
171
                                        "aria-level": "1"
172
                                });
173
                },
174
                _destroy: function() {
175
                        var currentTheme;
14×
176

177
                        this.element.children( "h1, h2, h3, h4, h5, h6" )
14×
178
                                .removeClass( "ui-title" )
179
                                .removeAttr( "role" )
180
                                .removeAttr( "aria-level" );
181

182
                        if ( this.role === "header" ) {
14×
183
                                this.element.children( "a, button" )
7×
184
                                        .removeClass( "ui-button-left ui-button-right ui-button ui-shadow ui-corner-all" );
185
                                if ( this.backButton) {
7×
186
                                        this.backButton.remove();
!
187
                                }
188
                        }
189

190
                        currentTheme = this.options.theme ? this.options.theme : "inherit";
14×
191
                        this.element.removeClass( "ui-bar-" + currentTheme );
14×
192

193
                        this.element.removeClass( "ui-" + this.role ).removeAttr( "role" );
14×
194
                }
195
        });
196

197
})( jQuery );
198
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
199
});
200
//>>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