mirror of https://github.com/artf/grapesjs.git
5 changed files with 100 additions and 95 deletions
File diff suppressed because one or more lines are too long
@ -1,63 +1,67 @@ |
|||||
define(['backbone','./PropertyView', 'text!./../templates/propertyRadio.html'], |
define(['backbone','./PropertyView', 'text!./../templates/propertyRadio.html'], |
||||
function (Backbone, PropertyView, propertyTemplate) { |
function (Backbone, PropertyView, propertyTemplate) { |
||||
/** |
/** |
||||
* @class PropertyRadioView |
* @class PropertyRadioView |
||||
* */ |
* */ |
||||
return PropertyView.extend({ |
return PropertyView.extend({ |
||||
|
|
||||
template: _.template(propertyTemplate), |
template: _.template(propertyTemplate), |
||||
|
|
||||
initialize: function(options) { |
initialize: function(options) { |
||||
PropertyView.prototype.initialize.apply(this, arguments); |
PropertyView.prototype.initialize.apply(this, arguments); |
||||
this.list = this.model.get('list') || []; |
this.list = this.model.get('list') || []; |
||||
this.className = this.className + ' '+ this.pfx +'list'; |
this.className = this.className + ' '+ this.pfx +'list'; |
||||
}, |
}, |
||||
|
|
||||
/** @inheritdoc */ |
/** @inheritdoc */ |
||||
renderInput: function() { |
renderInput: function() { |
||||
var pfx = this.pfx; |
var pfx = this.pfx; |
||||
var ppfx = this.ppfx; |
var ppfx = this.ppfx; |
||||
var itemCls = ppfx + 'radio-item-label'; |
var itemCls = ppfx + 'radio-item-label'; |
||||
if(!this.$input){ |
var prop = this.property; |
||||
if(this.list && this.list.length){ |
|
||||
this.input = ''; |
if(!this.$input) { |
||||
_.each(this.list,function(el){ |
if(this.list && this.list.length) { |
||||
var cl = el.className ? el.className + ' ' + pfx + 'icon ' + itemCls : '', |
var input = ''; |
||||
id = this.property + '-' + el.value, |
_.each(this.list, function(el) { |
||||
labelTxt = el.name ? el.name : el.value; |
var cl = el.className ? el.className + ' ' + pfx + 'icon ' + itemCls : '', |
||||
titleAttr = el.title ? 'title="' + el.title + '"': ''; |
id = prop + '-' + el.value, |
||||
this.input += '<div class="' + ppfx + 'radio-item">'+ |
labelTxt = el.name ? el.name : el.value; |
||||
'<input class="'+pfx+'radio" type="radio" id="'+ id +'" name="'+this.property+'" value="'+el.value+'" />'+ |
titleAttr = el.title ? 'title="' + el.title + '"': ''; |
||||
'<label class="'+(cl ? cl : itemCls)+'" ' + titleAttr + ' for="'+ id +'">' + (cl ? '' : labelTxt) + '</label></div>'; |
input += '<div class="' + ppfx + 'radio-item">'+ |
||||
},this); |
'<input class="'+pfx+'radio" type="radio" id="'+ id +'" name="'+prop+'" value="'+el.value+'" />'+ |
||||
this.$inputEl = $(this.input); |
'<label class="'+(cl ? cl : itemCls)+'" ' + titleAttr + ' for="'+ id +'">' + (cl ? '' : labelTxt) + '</label></div>'; |
||||
this.$el.find('#'+ pfx +'input-holder').html(this.$inputEl); |
}); |
||||
this.$input = this.$inputEl.find('input[name="'+this.property+'"]'); |
this.input = input; |
||||
} |
this.$inputEl = $(this.input); |
||||
} |
this.$el.find('#'+ pfx +'input-holder').html(this.$inputEl); |
||||
this.setValue(this.componentValue); |
this.$input = this.$inputEl.find('input[name="'+this.property+'"]'); |
||||
}, |
} |
||||
|
} |
||||
/** |
|
||||
* Returns value from input |
this.setValue(this.componentValue); |
||||
* @return {string} |
}, |
||||
*/ |
|
||||
getInputValue: function(){ |
/** |
||||
return this.$input ? this.$el.find('input:checked').val() : ''; |
* Returns value from input |
||||
}, |
* @return {string} |
||||
|
*/ |
||||
/** @inheritdoc */ |
getInputValue: function(){ |
||||
setValue: function(value){ |
return this.$input ? this.$el.find('input:checked').val() : ''; |
||||
var v = this.model.get('value') || this.defaultValue; |
}, |
||||
|
|
||||
if(value) |
/** @inheritdoc */ |
||||
v = value; |
setValue: function(value){ |
||||
|
var v = this.model.get('value') || this.defaultValue; |
||||
if(this.$input) |
|
||||
this.$input.filter('[value="'+v+'"]').prop('checked', true); |
if(value) |
||||
|
v = value; |
||||
this.model.set({value: v},{silent: true}); |
|
||||
}, |
if(this.$input) |
||||
|
this.$input.filter('[value="'+v+'"]').prop('checked', true); |
||||
}); |
|
||||
|
this.model.set({value: v},{silent: true}); |
||||
|
}, |
||||
|
|
||||
|
}); |
||||
}); |
}); |
||||
|
|||||
@ -1,38 +1,39 @@ |
|||||
define(['backbone','./PropertyView', 'text!./../templates/propertySelect.html'], |
define(['backbone','./PropertyView', 'text!./../templates/propertySelect.html'], |
||||
function (Backbone, PropertyView, propertyTemplate) { |
function (Backbone, PropertyView, propertyTemplate) { |
||||
/** |
/** |
||||
* @class PropertySelectView |
* @class PropertySelectView |
||||
* */ |
* */ |
||||
return PropertyView.extend({ |
return PropertyView.extend({ |
||||
|
|
||||
template: _.template(propertyTemplate), |
template: _.template(propertyTemplate), |
||||
|
|
||||
initialize: function(options) { |
initialize: function(options) { |
||||
PropertyView.prototype.initialize.apply(this, arguments); |
PropertyView.prototype.initialize.apply(this, arguments); |
||||
this.list = this.model.get('list') || []; |
this.list = this.model.get('list') || []; |
||||
}, |
}, |
||||
|
|
||||
/** @inheritdoc */ |
/** @inheritdoc */ |
||||
renderInput: function() { |
renderInput: function() { |
||||
var pfx = this.pfx; |
var pfx = this.pfx; |
||||
if(!this.$input){ |
if(!this.$input){ |
||||
this.input = '<select>'; |
var input = '<select>'; |
||||
|
|
||||
if(this.list && this.list.length){ |
if (this.list && this.list.length) { |
||||
_.each(this.list,function(el){ |
_.each(this.list, function(el) { |
||||
var name = el.name ? el.name : el.value; |
var name = el.name ? el.name : el.value; |
||||
var style = el.style ? el.style.replace(/"/g,'"') : ''; |
var style = el.style ? el.style.replace(/"/g,'"') : ''; |
||||
var styleAttr = style ? 'style="' + style + '"' : ''; |
var styleAttr = style ? 'style="' + style + '"' : ''; |
||||
this.input += '<option value="'+el.value.replace(/"/g,'"')+'" ' + styleAttr + '>'+name+'</option>'; |
input += '<option value="'+el.value.replace(/"/g,'"')+'" ' + styleAttr + '>'+name+'</option>'; |
||||
}, this); |
}); |
||||
} |
} |
||||
|
|
||||
this.input += '</select>'; |
input += '</select>'; |
||||
this.$input = $(this.input); |
this.input = input; |
||||
this.$el.find('#'+ pfx +'input-holder').html(this.$input); |
this.$input = $(this.input); |
||||
} |
this.$el.find('#'+ pfx +'input-holder').html(this.$input); |
||||
this.setValue(this.componentValue, 0); |
} |
||||
}, |
this.setValue(this.componentValue, 0); |
||||
|
}, |
||||
|
|
||||
}); |
}); |
||||
}); |
}); |
||||
|
|||||
Loading…
Reference in new issue