Team:WITS-CSIR SA/client/SideMenu.js

From 2011.igem.org

Revision as of 10:26, 3 September 2011 by Nkruger (Talk | contribs)

/// <reference path="../../js/lib/backbone.js" /> /// <reference path="../../js/lib/underscore.js" /> /// <reference path="../../js/lib/jlayout.border.js" /> /// <reference path="../../js/lib/jquery-1.5.1.min.js" /> /// <reference path="../../js/lib/jquery-ui-1.8.14.custom.min.js" /> /// <reference path="../../js/lib/jQuery.BlockUI.js" /> /// <reference path="../../js/lib/jquery.fling.js" /> /// <reference path="../../js/lib/jquery.jlayout.js" /> /// <reference path="../../js/lib/jquery.sizes.js" /> /// <reference path="../../js/lib/modernizr-1.7.min.js" /> /// <reference path="../../js/lib/sammy-latest.min.js" /> /// <reference path="../../js/common.js" />

var SideMenuItem = null, SideMenuItems = null, SideMenuView = null;

$(function () {

   SideMenuItem = Backbone.Model.extend({
       initialize: function () {
       },
       text: null,
       path: null
   });
   SideMenuItems = Backbone.Collection.extend({
       initialize: function (models, options) {
       }
   });
   SideMenuView = Backbone.View.extend({
       el: null,
       initialize: function (element) {
           this.el = element;
           this.items = new SideMenuItems(null, { view: this });
this.template = '
    ' + ' <% _.forEach(models, function(model) { %><li onclick="location=\'<%= model.get(\'path\') %>\';"><a <%= (location.toString().indexOf(model.get(\'name\')) > -1) ? \'class="current"\' : \'\' %> href="<%= model.get(\'path\') %>"><%= model.get(\'text\') %></a><% }); %>' + '
';
       },
       add: function (text, path) {
           this.items.add(new SideMenuItem({ text: text, path: path }));
       },
       render: function () {
           var html = _.template(this.template, this.items);
           this.el.html(html);
           var str = location.toString();
           str = str.substr(str.indexOf('Team:WITS-CSIR_SA/') + 'Team:WITS-CSIR_SA/'.length, str.length);
           $('ul.sideMenu > li > a').each(function () {
               if ($(this).attr('href').toLowerCase().indexOf(str.toLowerCase()) > -1) {
                   $(this).parent().addClass('current');
               }
           });
           FormatButtons();
           layout();
       }
   });
   $.fling('subscribe', 'ready', function () {
       if (location.toString().toLowerCase().indexOf('diary') > -1) BuildDiaryMenu();
       if (location.toString().toLowerCase().indexOf('aboutus') > -1) BuildAboutUsMenu();
       if (location.toString().toLowerCase().indexOf('project') > -1) BuildProjectMenu();
       if (location.toString().toLowerCase().indexOf('outreach') > -1) BuildOutreachMenu();
   });

});

function BuildDiaryMenu() {

   var menu = new SideMenuView($('.west'));
   menu.add('Minutes', 'http://www.biotweet.org/diary/minutes.htm');
   menu.add('Gallery', 'http://www.biotweet.org/diary/gallery.htm');
   menu.add('Videos', 'http://www.biotweet.org/diary/videos.htm');
   menu.render();

}

function BuildAboutUsMenu() {

   var menu = new SideMenuView($('.west'));
   menu.add('Meet The Team', 'http://www.biotweet.org/aboutus/meettheteam.htm');
   menu.add('Meet Our Bugs!', 'http://www.biotweet.org/aboutus/meetourbugs.htm');
   menu.add('Contact Us', 'http://www.biotweet.org/aboutus/contactus.htm');
   menu.render();

}

function BuildProjectMenu() {

   var menu = new SideMenuView($('.west'));
   menu.add('Concept', 'http://www.biotweet.org/project/concept.htm');
   menu.add('Bacterial Motility', 'http://www.biotweet.org/project/motility.htm');
   menu.add('Potential Applications', 'http://www.biotweet.org/project/applications.htm');
   menu.add('Project Send', 'http://www.biotweet.org/project/send.htm');
   menu.add('Project Receive', 'http://www.biotweet.org/project/receive.htm');
   menu.add('Modelling', 'http://www.biotweet.org/project/modelling.htm');
   menu.add('Parts Submitted', 'http://www.biotweet.org/project/parts.htm');
   menu.add('Characterization', 'http://www.biotweet.org/project/characterization.htm');
   menu.add('Lab Notebook', 'http://www.biotweet.org/project/notebook.htm');
   menu.add('Safety', 'http://www.biotweet.org/project/safety.htm');
   menu.add('Protocols', 'http://www.biotweet.org/project/protocols.htm');
   menu.render();

}

function BuildOutreachMenu() {

   var menu = new SideMenuView($('.west'));
   menu.add('Workshop', 'http://www.biotweet.org/outreach/workshop.htm');
   menu.add('Presentation', 'http://www.biotweet.org/outreach/presentation.htm');
   menu.add('Survey', 'http://www.biotweet.org/outreach/survey.htm');
   menu.render();

}