1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-13 15:05:30 +00:00
seahub/static/scripts/app/views/group-nav.js
2015-04-22 15:31:46 +08:00

63 lines
1.9 KiB
JavaScript

define([
'jquery',
'underscore',
'backbone',
'common',
'app/collections/groups'
], function($, _, Backbone, Common, GroupCollection, GroupNavTemplate) {
'use strict';
var GroupNavView = Backbone.View.extend({
el: '#header-inner',
template: _.template($('#group-nav-tmpl').html()),
initialize: function(options) {
this.$topNavGrp = this.$('#top-nav-grp');
this.groups = new GroupCollection();
this.listenTo(this.groups, 'reset', this.render);
this.groups.fetch({reset: true});
},
initializeGroups: function() {
this.$groupInfo= this.$('#top-nav-grp-info');
},
events: {
'mouseenter .nav-item-group': 'showGroupInfo',
'mouseleave .nav-item-group': 'hideGroupInfo',
'mouseenter #top-nav-grp-list .item': 'highLightItem',
'mouseleave #top-nav-grp-list .item': 'notHighLightItem',
'click #top-nav-grp-list .item': 'enterGroup'
},
showGroupInfo: function() {
this.$groupInfo.removeClass('hide');
},
hideGroupInfo: function(e) {
this.$groupInfo.addClass('hide');
},
highLightItem: function(e) {
$(e.currentTarget).addClass('hl').children('.a').removeClass('vh');
},
notHighLightItem: function(e) {
$(e.currentTarget).removeClass('hl').children('.a').addClass('vh');
},
render: function() {
this.$topNavGrp.after(this.template({groups: this.groups.toJSON()}));
this.initializeGroups();
this.$groupInfo.css({'right': (this.$topNavGrp.outerWidth() - this.$groupInfo.outerWidth())/6 * 5});
},
enterGroup: function(e) {
location.href = $(e.currentTarget).attr('data-url');
},
});
return GroupNavView;
});