forked from GrapesJS/grapesjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTraitSelectView.js
50 lines (46 loc) · 1.43 KB
/
TraitSelectView.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
define(['backbone','./TraitView'],
function (Backbone, TraitView) {
return TraitView.extend({
initialize: function(o) {
TraitView.prototype.initialize.apply(this, arguments);
var ppfx = this.ppfx;
this.fieldClass += ' ' + ppfx + 'select';
this.tmpl = '<div class="' + this.fieldClass +'"><div class="' + this.inputhClass +'"></div>'+
'<div class="' + ppfx + 'sel-arrow"><div class="' + ppfx + 'd-s-arrow"></div></div> </div>';
},
/**
* Returns input element
* @return {HTMLElement}
* @private
*/
getInputEl: function() {
if(!this.$input){
var md = this.model;
var opts = md.get('options') || [];
this.input = '<select>';
if(opts.length){
_.each(opts, function(el){
var name, value, style;
var attrs = '';
if(typeof el === 'string'){
name = el;
value = el;
}else{
name = el.name ? el.name : el.value;
value = el.value.replace(/"/g,'"');
style = el.style ? el.style.replace(/"/g,'"') : '';
attrs += style ? 'style="' + style + '"' : '';
}
this.input += '<option value="' + value + '" ' + attrs + '>' + name + '</option>';
}, this);
}
this.input += '</select>';
this.$input = $(this.input);
var val = md.get('value');
if(val)
this.$input.val(val);
}
return this.$input.get(0);
},
});
});