Files
ionic-framework/js/views/navBarView.js
2013-10-15 14:59:26 -05:00

55 lines
1.3 KiB
JavaScript

(function(ionic) {
'use strict';
ionic.views.NavBar = function(opts) {
this.el = opts.el;
this._titleEl = this.el.querySelector('.title');
if(opts.hidden) {
this.hide();
}
};
ionic.views.NavBar.prototype = {
hide: function() {
this.el.classList.add('hidden');
},
show: function() {
this.el.classList.remove('hidden');
},
shouldGoBack: function() {},
setTitle: function(title) {
if(!this._titleEl) {
return;
}
this._titleEl.innerHTML = title;
},
showBackButton: function(shouldShow) {
var _this = this;
if(!this._currentBackButton) {
var back = document.createElement('a');
back.className = 'button back';
back.innerHTML = 'Back';
this._currentBackButton = back;
this._currentBackButton.onclick = function(event) {
_this.shouldGoBack && _this.shouldGoBack();
};
}
if(shouldShow && !this._currentBackButton.parentNode) {
// Prepend the back button
this.el.insertBefore(this._currentBackButton, this.el.firstChild);
} else if(!shouldShow && this._currentBackButton.parentNode) {
// Remove the back button if it's there
this._currentBackButton.parentNode.removeChild(this._currentBackButton);
}
}
};
})(ionic);