Skip to content

Instantly share code, notes, and snippets.

@jschilli
Created August 22, 2011 19:54
Show Gist options
  • Save jschilli/1163349 to your computer and use it in GitHub Desktop.
Save jschilli/1163349 to your computer and use it in GitHub Desktop.
NavigationController stuff
<!-- HTML Snippet showing navigationView - renders navigation view content -->
<div id="nav" class="row">
<div class="col_12">
<div class="primary-nav">
{{#collection navigationView contentBinding="MyApp.Navigation.MainController" tagName="ul" itemClassBinding="content.isActive }}
{{content.title }}
{{/collection}}
</div>
</div>
</div>
<div id="main" class="row">
<div id="main-content" class="col_10 omega">
<div class="content-wrapper">
{{#view SC.ContainerView class="content" id="content-view"}}
{{/view}} <!-- content -->
</div> <!-- content-wrapper -->
</div> <!-- main-content -->
---- MyApp.NavigationController ---
MyApp.NavigationController = SC.ArrayProxy.extend(/** @scope MyApp.NavigationController.prototype */{
/**
A list of items to be displayed by the MyApp.NavigationController.
@type SC.Array
@default null
*/
content:null,
currentView:null,
/**
Called to change the content area controlled by this NavigationController
@param {String} aTarget
the target view to display
*/
switchToTarget: function(aView,aTarget){
// Indicate which tab is active
$.each(this.content,function(index,value){
set(value,'isActive', (value.target===aTarget));
});
var view = SC.View.views[aTarget];
this.set('currentView',view);
},
/**
@private
Controls the insertion/deletion of views into the content area
bound to the `currentView` field this function will be called when currentView changes.
*/
_currentViewDidChange:function(parent,key) {
var theContentView = SC.View.views[this.contentView];
if (get(theContentView,'childViews').length > 0) {
get(theContentView,'childViews').popObject();
}
var current = get(this,'currentView');
get(theContentView,'childViews').pushObject(current);
}.observes('currentView')
----- A navigation controller instance -----
MyApp.Navigation.MainController = MyApp.NavigationController.create({
contentView:'content-view',
currentView:undefined,
content: [
{title:'Checklist',target:'checklist-content'},
{title:'My Info',target:'myinfo-content'},
{title:'My Goals',target:'mygoals-content'},
{title:'My Risks',target:'myrisks-content'},
{title:'My Reports',target:'myreports-content'}
]
});
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment