X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/c224cdef02533a5a5962fa25f1a76f86c0d60005..23a68120c494341344d4728c5fc4528c94d5c53d:/src/editor/views/openSelect/openSelect.js?ds=sidebyside diff --git a/src/editor/views/openSelect/openSelect.js b/src/editor/views/openSelect/openSelect.js index 451570e..ef5b94a 100644 --- a/src/editor/views/openSelect/openSelect.js +++ b/src/editor/views/openSelect/openSelect.js @@ -19,19 +19,37 @@ var OpenSelect = Backbone.View.extend({ this.$el.append(_.template(template)({value: this.options.value || ''})); this.$('.toggle').dropdown(); this.menu = this.$('.dropdown-menu'); + this.toggleHandler(false); if(this.options.inputTemplate) { this.input = $(this.options.inputTemplate); this.$('.input-wrapper').append(this.input); } + if(this.options.maxHeight) { + this.menu.css('max-height', this.options.maxHeight); + } + if(this.options.maxWidth) { + this.menu.css('max-width', this.options.maxWidth); + } + }, + toggleHandler: function(toggle) { + this.$('.toggle').css('visibility', toggle ? 'inherit' : 'hidden'); }, addItem: function(value) { this.menu.append(_.template(itemTemplate)({value: value})); + this.toggleHandler(true); }, - onSelection: function(e) { - var val = $(e.target).text(); + clearItems: function() { + this.menu.empty(); + this.toggleHandler(false); + }, + setInput: function(value) { if(this.options.setInput) { - this.options.setInput(this.input, val); + this.options.setInput(this.input, value); } + }, + onSelection: function(e) { + var val = $(e.target).text(); + this.setInput(val); this.trigger('itemSelected', this.input.val()); } });