Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Toolbar: add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
arschmitz committed Apr 25, 2013
1 parent 7abc720 commit d333e8c
Showing 1 changed file with 115 additions and 0 deletions.
115 changes: 115 additions & 0 deletions js/widgets/toolbar.js
@@ -0,0 +1,115 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>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
//>>label: Toolbars: Fixed
//>>group: Widgets
//>>css.structure: ../css/structure/jquery.mobile.fixedToolbar.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

define( [ "jquery", "../jquery.mobile.widget", "../jquery.mobile.core", "../jquery.mobile.navigation", "./page", "../jquery.mobile.zoom" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {


$.widget( "mobile.toolbar", $.mobile.widget, {
options: {
theme: "a",
addBackBtn: false,
backBtnTheme: null,
backBtnText: "Back"
},

_create: function() {
var leftbtn, rightbtn, backBtn,
role = this.element.is( ":jqmData(role='header')" ) ? "header" : "footer",
page = this.element.closest(".ui-page");

if( page.length === 0 ){
page = false;
this._on($.mobile.document, {
"pageshow":"refresh"

});
}
$.extend( this, {
role:role,
page:page
})
this.element.attr( "role", role === "header" ? "banner" : "contentinfo" ).addClass("ui-"+role);

this._setOptions( this.options );
this.refresh();
},
_setOptions:function( o ){
if( o.addBackBtn !== undefined){
if( this.options.addBackBtn &&
this.role === "header" &&
$( ".ui-page" ).length > 1 &&
this.page[ 0 ].getAttribute( attrPrefix + "url" ) !== $.mobile.path.stripHash( location.hash ) &&
!leftbtn){
this._addBackButton();
} else {
this.element.find(".ui-toolbar-back-btn").remove();
}
}
if( o.backBtnTheme !== undefined){
this.element.find(".ui-toolbar-back-btn").attr( "data-"+ $.mobile.ns +"theme", o.theme).buttonMarkup();
}
if( o.backBtnText !== undefined){
this.element.find(".ui-toolbar-back-btn .ui-btn-text").text( o.backBtnText );
}
if( o.theme !== undefined ){
this.element.removeClass("ui-bar-" + this.options.theme ).addClass( "ui-bar-" + o.theme );
}
this._superApply( o );

},
refresh: function(){
if( this.role === "header") {
this._addHeaderButtonClasses();
}
if( !this.page ){
$("[data-role='page']").css({"position":"relative"});
//this.element.css({"position":"relative"});
if( this.role === "footer" ){
this.element.appendTo("body");
}
}
this._addHeadingClasses();
this._btnMarkup();
},
_btnMarkup: function(){
this.element.children("a").buttonMarkup({ theme:this.options.theme});
},
_addHeaderButtonClasses:function(){
var $headeranchors = this.element.children( "a, button" );
leftbtn = $headeranchors.hasClass( "ui-btn-left" );
rightbtn = $headeranchors.hasClass( "ui-btn-right" );

leftbtn = leftbtn || $headeranchors.eq( 0 ).not( ".ui-btn-right" ).addClass( "ui-btn-left" ).length;

rightbtn = rightbtn || $headeranchors.eq( 1 ).addClass( "ui-btn-right" ).length;
},
_addBackButton:function(){
backBtn = $( "<a href='javascript:void(0);' class='ui-btn-left ui-toolbar-back-btn' data-"+ $.mobile.ns +"rel='back' data-"+ $.mobile.ns +"icon='arrow-l'>"+ this.options.backBtnText +"</a>" )
// If theme is provided, override default inheritance
.attr( "data-"+ $.mobile.ns +"theme", this.options.backBtnTheme || this.options.theme )
.prependTo( this.element );
},
_addHeadingClasses:function(){
this.element.children( "h1, h2, h3, h4, h5, h6" )
.addClass( "ui-title" )
// Regardless of h element number in src, it becomes h1 for the enhanced page
.attr({
"role": "heading",
"aria-level": "1"
});
}
});
$.mobile.toolbar.initSelector = ":jqmData(role='footer'), :jqmData(role='header')";

$.mobile._enhancer.add( "mobile.toolbar");

})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");

0 comments on commit d333e8c

Please sign in to comment.