Browse Source

More updates on Style Properties refactoring

pull/330/head
Artur Arseniev 9 years ago
parent
commit
bbbcb6cc26
  1. 2
      index.html
  2. 12
      src/style_manager/view/PropertyCompositeView.js
  3. 22
      src/style_manager/view/PropertyRadioView.js
  4. 26
      src/style_manager/view/PropertySelectView.js
  5. 32
      src/style_manager/view/PropertyView.js

2
index.html

@ -1320,7 +1320,7 @@
console.log('STORE ', e); console.log('STORE ', e);
}) })
editor.on('styleManager:change:text-shadow', function(view) { editor.on('styleManager:change:border-width', function(view) {
var model = view.model; var model = view.model;
let targetValue = view.getTargetValue({ignoreDefault: 1}); let targetValue = view.getTargetValue({ignoreDefault: 1});
let computedValue = view.getComputedValue(); let computedValue = view.getComputedValue();

12
src/style_manager/view/PropertyCompositeView.js

@ -29,8 +29,10 @@ module.exports = PropertyView.extend({
var self = this; var self = this;
if (props.length) { if (props.length) {
if(!this.$input) if (!this.$input) {
this.$input = $('<input>', {value: 0, type: 'hidden' }); this.$input = $('<input>', {value: 0, type: 'hidden' });
this.input = this.$input.get(0);
}
if (!this.props) { if (!this.props) {
this.props = model.get('properties'); this.props = model.get('properties');
@ -102,9 +104,13 @@ module.exports = PropertyView.extend({
// to get the value of the sub-property // to get the value of the sub-property
if (targetValue) { if (targetValue) {
const values = targetValue.split(' '); const values = targetValue.split(' ');
value = view ? view.model.parseValue(values[index]) : values[index]; value = values[index];
} else { } else {
value = view.getTargetValue({ignoreCustomValue: 1}); value = view && view.getTargetValue({ignoreCustomValue: 1, ignoreDefault: 1});
}
if (view) {
value = view.model.parseValue(value);
} }
return value; return value;

22
src/style_manager/view/PropertyRadioView.js

@ -24,46 +24,38 @@ module.exports = require('./PropertyView').extend({
if(!this.$input) { if(!this.$input) {
if(this.list && this.list.length) { if(this.list && this.list.length) {
var input = ''; let inputStr = '';
_.each(this.list, el => { _.each(this.list, el => {
var cl = el.className ? el.className + ' ' + pfx + 'icon ' + itemCls : '', var cl = el.className ? el.className + ' ' + pfx + 'icon ' + itemCls : '',
id = prop + '-' + el.value, id = prop + '-' + el.value,
labelTxt = el.name ? el.name : el.value; labelTxt = el.name ? el.name : el.value;
var titleAttr = el.title ? 'title="' + el.title + '"': ''; var titleAttr = el.title ? 'title="' + el.title + '"': '';
input += '<div class="' + ppfx + 'radio-item">'+ inputStr += '<div class="' + ppfx + 'radio-item">'+
'<input class="'+pfx+'radio" type="radio" id="'+ id +'" name="'+prop+'" value="'+el.value+'" />'+ '<input class="'+pfx+'radio" type="radio" id="'+ id +'" name="'+prop+'" value="'+el.value+'" />'+
'<label class="'+(cl ? cl : itemCls)+'" ' + titleAttr + ' for="'+ id +'">' + (cl ? '' : labelTxt) + '</label></div>'; '<label class="'+(cl ? cl : itemCls)+'" ' + titleAttr + ' for="'+ id +'">' + (cl ? '' : labelTxt) + '</label></div>';
}); });
this.input = input; this.$inputEl = $(inputStr);
this.$inputEl = $(this.input); this.input = this.$inputEl.get(0);
this.$el.find('#'+ pfx +'input-holder').html(this.$inputEl); this.$el.find('#'+ pfx +'input-holder').html(this.$inputEl);
this.$input = this.$inputEl.find('input[name="'+this.property+'"]'); this.$input = this.$inputEl.find('input[name="'+this.property+'"]');
} }
} }
this.setValue(this.componentValue);
}, },
/**
* Returns value from input
* @return {string}
*/
getInputValue() { getInputValue() {
return this.$input ? this.$el.find('input:checked').val() : ''; return this.$input ? this.$el.find('input:checked').val() : '';
}, },
/** @inheritdoc */
setValue(value) { setValue(value) {
const model = this.model; const model = this.model;
var v = model.get('value') || model.getDefaultValue(); var v = model.get('value') || model.getDefaultValue();
if(value) if (value) {
v = value; v = value;
}
if(this.$input) if(this.$input)
this.$input.filter('[value="'+v+'"]').prop('checked', true); this.$input.filter(`[value="${v}"]`).prop('checked', true);
model.set({value: v}, {silent: true});
}, },
}); });

26
src/style_manager/view/PropertySelectView.js

@ -20,22 +20,22 @@ module.exports = require('./PropertyView').extend({
onRender() { onRender() {
var pfx = this.pfx; var pfx = this.pfx;
const options = this.list;
if (!this.$input) { if (!this.$input) {
var input = '<select>'; let optionsStr = '';
if (this.list && this.list.length) { options.forEach(option => {
_.each(this.list, el => { let name = option.name || option.value;
var name = el.name ? el.name : el.value; let style = option.style ? option.style.replace(/"/g,'&quot;') : '';
var style = el.style ? el.style.replace(/"/g,'&quot;') : ''; let styleAttr = style ? `style="${style}"` : '';
var styleAttr = style ? 'style="' + style + '"' : ''; let value = option.value.replace(/"/g,'&quot;');
input += '<option value="'+el.value.replace(/"/g,'&quot;')+'" ' + styleAttr + '>'+name+'</option>'; optionsStr += `<option value="${value}" ${styleAttr}>${name}</option>`;
}); });
}
input += '</select>'; this.$input = $(`<select>${optionsStr}</select>`);
this.input = input; this.input = this.$input.get(0);
this.$input = $(this.input); this.$el.find(`#${pfx}input-holder`).html(this.$input);
this.$el.find('#'+ pfx +'input-holder').html(this.$input);
} }
}, },

32
src/style_manager/view/PropertyView.js

@ -121,11 +121,10 @@ module.exports = Backbone.View.extend({
/** /**
* Returns selected target which should have 'style' property * Returns selected target which should have 'style' property
* @deprecated
* @return {Model|null} * @return {Model|null}
*/ */
getTarget() { getTarget() {
return this.propTarget && this.propTarget.model; return this.getTargetModel();
}, },
/** /**
@ -283,7 +282,8 @@ module.exports = Backbone.View.extend({
* @return {string} * @return {string}
*/ */
getInputValue() { getInputValue() {
return this.$input ? this.$input.val() : ''; const input = this.getInputEl();
return input ? input.value : '';
}, },
/** /**
@ -299,7 +299,7 @@ module.exports = Backbone.View.extend({
const value = model.getFullValue(); const value = model.getFullValue();
const target = this.getTarget(); const target = this.getTarget();
const onChange = this.onChange; const onChange = this.onChange;
this.setValue(value); this.setRawValue(value);
// Check if component is allowed to be styled // Check if component is allowed to be styled
if (!target || !this.isTargetStylable() || !this.isComponentStylable()) { if (!target || !this.isTargetStylable() || !this.isComponentStylable()) {
@ -380,6 +380,18 @@ module.exports = Backbone.View.extend({
return stylable; return stylable;
}, },
/**
* Passed a raw value you have to update the input element, generally
* is the value fetched from targets, so you can receive values with
* functions, units, etc. (eg. `rotateY(45deg)`)
* get also
* @param {string} value
* @private
*/
setRawValue(value) {
this.setValue(this.model.parseValue(value));
},
/** /**
* Set the value to property input * Set the value to property input
* @param {String} value * @param {String} value
@ -396,8 +408,16 @@ module.exports = Backbone.View.extend({
v = value; v = value;
} }
const input = this.$input; const input = this.getInputEl();
input && input.val(v); input && (input.value = v);
},
getInputEl() {
if (!this.input) {
this.input = this.el.querySelector('input');
}
return this.input;
}, },
updateVisibility() { updateVisibility() {

Loading…
Cancel
Save