Skip to content

Commit

Permalink
Navbar: Classes Option
Browse files Browse the repository at this point in the history
  • Loading branch information
cgack committed Sep 30, 2015
1 parent 8a6d363 commit 446f489
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
2 changes: 2 additions & 0 deletions build/tasks/options/jscs.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module.exports = {
"js/widgets/listview.backcompat.js",
"js/widgets/listview.hidedividers.js",
"js/widgets/listview.js",
"js/widgets/navbar.js",
"js/widgets/navbar.morebutton.js",

// Tests
"tests/integration/listview/autodividers_core.js",
Expand Down
77 changes: 37 additions & 40 deletions js/widgets/navbar.morebutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
"./navbar",
"./popup",
"./listview",
"../widget"], factory );
"../widget" ], factory );
} else {

// Browser globals
factory( jQuery );
}
} )( function( $ ) {


return $.widget( "mobile.navbar", $.mobile.navbar, {

options: {
Expand All @@ -43,7 +42,7 @@ return $.widget( "mobile.navbar", $.mobile.navbar, {
_create: function() {

this._super();
if ( this.options.morebutton && this.numButtons > this.maxButton) {
if ( this.options.morebutton && this.numButtons > this.maxButton ) {
this._createNavPopup();
}
},
Expand All @@ -52,22 +51,21 @@ return $.widget( "mobile.navbar", $.mobile.navbar, {
return ( this.element.attr( "id" ) || ( this.widgetName + this.uuid ) );
},

_createNavRows: function () {
_createNavRows: function() {
if ( this.options.morebutton ) {
return;
}

this._super();
},

_createNavPopup: function(){
_createNavPopup: function() {
var popupDiv, popupNav, moreButton, pos, buttonItem, id,
navItems = this.navbar.find( "li" ),
buttonCount = navItems.length,
maxButton = this.maxButton,
iconpos = this.iconpos,
icon = this.options.morebuttonicon,
classes = "ui-button";
icon = this.options.morebuttonicon;

id = this._id() + "-popup";

Expand All @@ -76,13 +74,13 @@ return $.widget( "mobile.navbar", $.mobile.navbar, {
.appendTo( popupDiv );

// enhance buttons and move to new rows
for( pos = 0; pos < buttonCount; pos++ ) {
buttonItem = navItems.eq(pos);
this._makeNavButton(buttonItem.find("a"), iconpos);
if (pos + 1 === maxButton) {
for ( pos = 0; pos < buttonCount; pos++ ) {
buttonItem = navItems.eq( pos );
this._makeNavButton( buttonItem.find( "a" ), iconpos );
if ( pos + 1 === maxButton ) {

moreButton = $( "<li></li>" ).append( $( "<a></a>" )
.attr( "href", "#" + id)
.attr( "href", "#" + id )
.attr( "data-rel", "popup" )
.button( {
icon: icon,
Expand All @@ -102,63 +100,62 @@ return $.widget( "mobile.navbar", $.mobile.navbar, {
popupDiv.appendTo( this.navbar );
popupDiv.popup();

$.extend(this, {
$.extend( this, {
moreButton: moreButton,
popupDiv: popupDiv
});
} );
},

refresh: function() {
var newitems,
var newitems,
self = this,
iconpos = self.iconpos;
if (!self.options.morebutton) {
self._super();
return;
}
iconpos = self.iconpos;
if ( !self.options.morebutton ) {
self._super();
return;
}

if ( self.popupDiv ) {
newitems = self.moreButton.parent().nextAll();
newitems.find("a").each(function() {
self._makeNavButton(this, iconpos);
});
newitems.appendTo(self.popupDiv.find("ul"));
}
newitems = self.moreButton.parent().nextAll();
newitems.find( "a" ).each( function() {
self._makeNavButton( this, iconpos );
} );
newitems.appendTo( self.popupDiv.find( "ul" ) );
}
self._createNavPopup();
},

_destroy: function() {
var navitems,
self = this;


if (!self.options.morebutton) {
if ( !self.options.morebutton ) {
self._super();
return;
}

if ( self.popupDiv ) {
navitems = self.popupDiv.find("li").detach();
navitems = self.popupDiv.find( "li" ).detach();
self.popupDiv.remove();
self.moreButton.parent().remove();
self.navbar.find("ul").append(navitems);
self.navbar.find( "ul" ).append( navitems );
self.navbar.removeClass( "ui-navbar" );
self.navButtons = self.navbar.find("a");
self.navButtons.each(function() {
self.navButtons = self.navbar.find( "a" );
self.navButtons.each( function() {
var icon = $.mobile.getAttribute( this, "icon" ),
theme = $.mobile.getAttribute( this, "theme" ),
classes = "ui-btn";
classes = "ui-button";

if ( theme ) {
classes += " ui-btn-" + theme;
classes += " ui-button-" + theme;
}
if ( icon ) {
classes += " ui-icon-" + icon + " ui-btn-icon-" + self.iconpos;
classes += " ui-icon-" + icon + " ui-button-icon-" + self.iconpos;
}
$( this ).removeClass( classes );
});
} );
}
}
});
});
} );

} );

0 comments on commit 446f489

Please sign in to comment.