1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-26 07:39:04 +02:00
keeweb/app/scripts/views/dropdown-view.js

44 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-10-17 23:49:24 +02:00
'use strict';
var Backbone = require('backbone');
var DropdownView = Backbone.View.extend({
2015-12-16 22:50:45 +01:00
template: require('templates/dropdown.hbs'),
2015-10-17 23:49:24 +02:00
events: {
'click .dropdown__item': 'itemClick'
},
initialize: function () {
this.bodyClick = this.bodyClick.bind(this);
$('body').on('click', this.bodyClick);
},
render: function (config) {
this.options = config.options;
this.renderTemplate(config);
this.$el.appendTo(document.body);
var ownRect = this.$el[0].getBoundingClientRect();
2016-03-05 09:35:22 +01:00
var left = config.position.left || (config.position.right - ownRect.right + ownRect.left);
this.$el.css({ top: config.position.top, left: left });
2015-10-17 23:49:24 +02:00
return this;
},
remove: function() {
$('body').off('click', this.bodyClick);
Backbone.View.prototype.remove.apply(this, arguments);
},
bodyClick: function() {
this.trigger('cancel');
},
itemClick: function(e) {
e.stopPropagation();
var selected = $(e.target).closest('.dropdown__item').data('value');
this.trigger('select', { item: selected });
}
});
module.exports = DropdownView;