-
Notifications
You must be signed in to change notification settings - Fork 0
/
bbf-chosen.js
75 lines (70 loc) · 1.89 KB
/
bbf-chosen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Backbone-Forms chosen editor 1.0.3
Copyright (c) 2017 Tomasz Jakub Rup
https://github.com/tomi77/backbone-forms-chosen
Released under the MIT license
*/
(function(root, factory) {
/* istanbul ignore next */
switch (false) {
case !(typeof define === 'function' && define.amd):
define(['backbone-forms', 'chosen'], factory);
break;
case typeof exports !== 'object':
require('chosen-js');
factory(require('backbone-forms'));
break;
default:
factory(root.Backbone.Form);
}
})(this, function(Form) {
var Select;
Select = Form.editors.Select;
Form.editors['chosen'] = Select.extend({
events: {
'change': function(event) {
this.trigger('change', this);
},
'chosen:showing_dropdown': function(event) {
this.trigger('focus', this);
},
'chosen:hiding_dropdown': function(event) {
this.trigger('blur', this);
}
},
initialize: function(options) {
var el;
Select.prototype.initialize.call(this, options);
this.editorOptions = options.schema.editorOptions || {};
el = this.$el;
this.$el = Backbone.$('<div>');
this.el = this.$el[0];
this.$el.html(el);
},
render: function() {
Select.prototype.render.call(this);
if (this.editorOptions.width != null) {
this.renderChosen();
} else {
setTimeout(this.renderChosen.bind(this), 10);
}
return this;
},
renderChosen: function() {
this.$('select').chosen(this.editorOptions);
},
renderOptions: function(options) {
var $select, html;
$select = this.$('select');
html = this._getOptionsHtml(options);
$select.html(html);
this.setValue(this.value);
},
getValue: function() {
return this.$('select').val();
},
setValue: function(value) {
this.$('select').val(value);
}
});
});