2.0_beta sync to rsa
[framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.1.0 / js / jquery.mobile.navbar.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Formats groups of links as horizontal navigation bars.
3 //>>label: Navbars
4 //>>group: Widgets
5 //>>css: ../css/themes/default/jquery.mobile.theme.css, ../css/structure/jquery.mobile.navbar.css
6
7
8 define( [ "jquery", "./jquery.mobile.widget", "./jquery.mobile.buttonMarkup", "./jquery.mobile.grid" ], function( $ ) {
9 //>>excludeEnd("jqmBuildExclude");
10 (function( $, undefined ) {
11
12 $.widget( "mobile.navbar", $.mobile.widget, {
13         options: {
14                 iconpos: "top",
15                 grid: null,
16                 initSelector: ":jqmData(role='navbar')"
17         },
18
19         _create: function(){
20
21                 var $navbar = this.element,
22                         $navbtns = $navbar.find( "a" ),
23                         iconpos = $navbtns.filter( ":jqmData(icon)" ).length ?
24                                                                         this.options.iconpos : undefined;
25
26                 $navbar.addClass( "ui-navbar" )
27                         .attr( "role","navigation" )
28                         .find( "ul" )
29                         .jqmEnhanceable()
30                         .grid({ grid: this.options.grid });
31
32                 if ( !iconpos ) {
33                         $navbar.addClass( "ui-navbar-noicons" );
34                 }
35
36                 $navbtns.buttonMarkup({
37                         corners:        false,
38                         shadow:         false,
39                         inline:     true,
40                         iconpos:        iconpos
41                 });
42
43                 $navbar.delegate( "a", "vclick", function( event ) {
44                         if( !$(event.target).hasClass("ui-disabled") ) {
45                                 $navbtns.removeClass( $.mobile.activeBtnClass );
46                                 $( this ).addClass( $.mobile.activeBtnClass );
47                         }
48                 });
49
50                 // Buttons in the navbar with ui-state-persist class should regain their active state before page show
51                 $navbar.closest( ".ui-page" ).bind( "pagebeforeshow", function() {
52                         $navbtns.filter( ".ui-state-persist" ).addClass( $.mobile.activeBtnClass );
53                 });
54         }
55 });
56
57 //auto self-init widgets
58 $( document ).bind( "pagecreate create", function( e ){
59         $.mobile.navbar.prototype.enhanceWithin( e.target );
60 });
61
62 })( jQuery );
63 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
64 });
65 //>>excludeEnd("jqmBuildExclude");