Skip to content

Commit

Permalink
Expanding/collapsing navbar.
Browse files Browse the repository at this point in the history
  • Loading branch information
beastaugh committed May 15, 2011
1 parent 6b62730 commit d2b8211
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
85 changes: 84 additions & 1 deletion app/js/tarski.dev.js
Expand Up @@ -3,6 +3,87 @@
**/
window.Tarski = {};

Tarski.Navbar = function(navbar) {
var self = this;

this._container = jQuery(navbar).addClass('expanded');
this._maxHeight = this._container.height();
this._container.removeClass('expanded').addClass('collapsed');
this._minHeight = this._container.height();
this._container.height(this._minHeight)

this._container.mouseenter(function() { self.expand(); });
this._container.mouseleave(function() { self.collapse(); });

this.setState('COLLAPSED');
};

Tarski.Navbar.prototype.expand = function(cb) {
var self = this;

if (this.isAnimating()) return;

this.setState('ANIMATING');

this._container
.removeClass('collapsed')
.addClass('expanded')
.animate(
{height: this._maxHeight},
500,
function() { self.setState('EXPANDED'); });

return this;
};

Tarski.Navbar.prototype.collapse = function(elem, cb) {
var self = this;

if (this.isAnimating()) return;

this.setState('ANIMATING');

this._container
.animate(
{height: this._minHeight},
500,
function() {
self._container
.removeClass('expanded')
.addClass('collapsed');

self.setState('COLLAPSED');
});

return this;
};

Tarski.Navbar.prototype.setNextAction = function(action) {
this._nextAction = action;
};

Tarski.Navbar.prototype.fireNextAction = function() {
if (Tarski.Navbar.ACTIONS.indexOf(this._nextAction) === 1) {
this[this._nextAction](function(self) {
self._nextAction = null;
});
}
};

Tarski.Navbar.prototype.isAnimating = function() {
return this.inState('ANIMATING');
};

Tarski.Navbar.prototype.inState = function(state) {
return this._state === state;
};

Tarski.Navbar.prototype.setState = function(state) {
this._state = state;
};

Tarski.Navbar.ACTIONS = ['expand', 'collapse'];

/**
* new Tarski.Searchbox(field, label)
* - field (HTMLElement): the search field
Expand Down Expand Up @@ -70,10 +151,12 @@ Tarski.Searchbox.PLACEHOLDER_SUPPORTED = (function() {
})();

jQuery(document).ready(function() {
var searchForm, searchField, searchLabel, searchBox;
var searchForm, searchField, searchLabel, searchBox, navbar;

jQuery('body').addClass('js');

navbar = new Tarski.Navbar(jQuery('#navigation'));

searchField = jQuery('#s');
searchLabel = jQuery('#searchlabel');

Expand Down
2 changes: 1 addition & 1 deletion app/js/tarski.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d2b8211

Please sign in to comment.