1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-20 10:58:33 +00:00
Files
seahub/static/scripts/app/views/widgets/dropdown.js

79 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-03-21 21:29:14 +08:00
define([
'jquery',
'underscore',
'backbone',
'common',
], function($, _, Backbone, Common) {
'use strict';
/*
* Dropdown View.
*/
// There can be only one visible dropdown view
$(document).click(function(e) {
var view = app.ui.currentDropdown;
var target = e.target || event.srcElement;
if (!view) {
return true;
}
2016-03-31 21:32:00 +08:00
if (!view.$('.dropdown-menu').is(target)
&& !view.$('.dropdown-menu').find('*').is(target))
2016-03-21 21:29:14 +08:00
{
view.hide();
if (app.ui.currentHighlightedItem) {
app.ui.currentHighlightedItem.rmHighlight();
}
}
return true;
});
var DropdownView = Backbone.View.extend({
2016-03-31 21:05:46 +08:00
defaultOptions: {
'left': '0px'
},
2016-03-21 21:29:14 +08:00
initialize: function(options) {
2016-03-31 21:32:00 +08:00
this.$el.on('click', '.dropdown-toggle', _.bind(this.toggleDropdown, this));
2016-03-31 21:05:46 +08:00
this.options = {};
_.extend(this.options, this.defaultOptions, options);
2016-03-21 21:29:14 +08:00
},
hide: function() {
app.ui.currentDropdown = null;
2016-03-31 21:32:00 +08:00
this.$('.dropdown-menu').addClass('hide');
2016-03-21 21:29:14 +08:00
},
show: function() {
2016-03-31 21:32:00 +08:00
var $menu = this.$('.dropdown-menu');
2016-03-21 21:29:14 +08:00
app.ui.currentDropdown = this;
2016-03-31 21:05:46 +08:00
if (this.options.right) {
$menu.css('right', this.options.right);
} else {
$menu.css('left', this.options.left);
}
2016-03-31 21:32:00 +08:00
this.$('.dropdown-menu').removeClass('hide');
2016-03-21 21:29:14 +08:00
},
toggleDropdown: function() {
if (app.ui.currentDropdown && app.ui.currentDropdown != this) {
app.ui.currentDropdown.hide();
}
2016-03-31 21:32:00 +08:00
if (this.$('.dropdown-menu').is(':hidden')) {
2016-03-21 21:29:14 +08:00
this.show();
} else {
this.hide();
}
return false;
}
});
return DropdownView;
});