-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectmenu.js
77 lines (72 loc) · 2.1 KB
/
selectmenu.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
76
77
/*
Backbone-Forms jQuery UI selectmenu editor 1.0.0
Copyright (c) 2016 Tomasz Jakub Rup
https://github.com/tomi77/backbone-forms-jquery-ui
Released under the MIT license
*/
(function(root, factory) {
/* istanbul ignore next */
switch (false) {
case !(typeof define === 'function' && define.amd):
define(['underscore', 'backbone', 'backbone-forms', 'jquery-ui/widgets/selectmenu'], factory);
break;
case typeof exports !== 'object':
require('jquery-ui/widgets/selectmenu');
factory(require('underscore'), require('backbone'), require('backbone-forms'));
break;
default:
factory(root._, root.Backbone, root.Backbone.Form);
}
})(this, function(_, Backbone, Form) {
Form.editors['jqueryui.selectmenu'] = Form.editors.Select.extend({
className: 'bbf-jui-selectmenu',
events: {
'selectmenuopen': function() {
this.trigger('focus', this);
},
'selectmenuclose': function() {
this.trigger('blur', this);
},
'selectmenuselect': function() {
this.trigger('change', this);
}
},
initialize: function(options) {
var ref;
Form.editors.Select.prototype.initialize.call(this, options);
this.editorOptions = this.schema.editorOptions || {};
ref = [this.$el, Backbone.$('<div>')], this.$input = ref[0], this.$el = ref[1];
this.el = this.$el[0];
this.$el.html(this.$input);
},
renderOptions: function(options) {
var html;
html = this._getOptionsHtml(options);
this.$input.html(html);
this.$input.selectmenu(this.editorOptions);
this.setValue(this.value);
},
getValue: function() {
return this.$input.val();
},
setValue: function(val) {
this.$input.val(val);
this.$input.selectmenu('refresh');
},
focus: function() {
if (this.hasFocus) {
return;
}
this.$input.selectmenu('open');
},
blur: function() {
if (!this.hasFocus) {
return;
}
this.$input.selectmenu('close');
},
change: function() {
this.trigger('change', this);
}
});
});