Browse Source

Add fixed values to style manager properties

pull/36/head
Artur Arseniev 9 years ago
parent
commit
e34f4c42fe
  1. 4
      src/block_manager/view/BlocksView.js
  2. 4
      src/editor/config/config.js
  3. 7
      src/style_manager/model/Property.js
  4. 10
      src/style_manager/model/PropertyFactory.js
  5. 35
      src/style_manager/view/PropertyIntegerView.js
  6. 6
      src/style_manager/view/PropertyView.js

4
src/block_manager/view/BlocksView.js

@ -69,7 +69,7 @@ function(Backbone, BlockView) {
el.className += ' ' + this.ppfx + 'bdrag';
this.helper = el;
document.body.appendChild(el);
$(this.em.get('Canvas').getBody()).on('mousemove', this.moveHelper);
$(this.em.get('Canvas').getBody().ownerDocument).on('mousemove', this.moveHelper);
$(document).on('mousemove', this.moveHelper);
},
@ -137,4 +137,4 @@ function(Backbone, BlockView) {
},
});
});
});

4
src/editor/config/config.js

@ -242,7 +242,7 @@ define(function () {
width: '615px',
}
},
}/*,{
},{
id: 'table',
label: 'Table',
attributes: {class:'fa fa-table'},
@ -252,7 +252,7 @@ define(function () {
rows: 5,
style: {height: '150px', width: '100%'}
},
}*/],
}],
},
};

7
src/style_manager/model/Property.js

@ -4,7 +4,7 @@ define(['backbone', './Layers', 'require'],
return Backbone.Model.extend({
defaults: {
name : '',
name: '',
property: '',
type: '',
units: [],
@ -15,10 +15,11 @@ define(['backbone', './Layers', 'require'],
icon: '',
preview: false,
detached: false,
functionName: '',
functionName: '',
properties: [],
layers: [],
list: [],
fixedValues: ['initial', 'inherit'],
},
initialize: function(opt) {
@ -48,7 +49,7 @@ define(['backbone', './Layers', 'require'],
* @return {string} Value
* @private
*/
getValue: function(){
getValue: function() {
var result = '';
var type = this.get('type');

10
src/style_manager/model/PropertyFactory.js

@ -11,6 +11,7 @@ define(['backbone'],
*/
build: function(props){
var objs = [];
var dftFixedValues = ['initial', 'inherit'];
if(typeof props === 'string')
props = [props];
@ -27,6 +28,13 @@ define(['backbone'],
break;
}
// Fixed values
switch(prop){
case 'margin-top': case 'margin-right': case 'margin-bottom': case 'margin-left':
obj.fixedValues = ['initial', 'inherit', 'auto'];
break;
}
// Type
switch(prop){
case 'float': case 'position':
@ -448,4 +456,4 @@ define(['backbone'],
};
};
});
});

35
src/style_manager/view/PropertyIntegerView.js

@ -150,18 +150,27 @@ define(['backbone','./PropertyView', 'text!./../templates/propertyInteger.html']
/** @inheritdoc */
setValue: function(value){
var u = this.unit,
v = this.model.get('value') || this.defaultValue;
if(value){
// Make it suitable for replace
value += '';
v = parseFloat(value.replace(',', '.'));
v = !isNaN(v) ? v : this.defaultValue;
var uN = value.replace(v,'');
// Check if exists as unit
if(_.indexOf(this.units, uN) > -1)
u = uN;
var model = this.model;
var u = this.unit;
var v = model.get('value') || this.defaultValue;
var fixed = model.get('fixedValues') || [];
if (value) {
// If the value is one of the fixed values I leave it as it is
var regFixed = new RegExp('^' + fixed.join('|'), 'g');
if (fixed.length && regFixed.test(value)) {
v = value.match(regFixed)[0];
u = '';
} else {
// Make it suitable for replace
value += '';
v = parseFloat(value.replace(',', '.'));
v = !isNaN(v) ? v : this.defaultValue;
var uN = value.replace(v, '');
// Check if exists as unit
if(_.indexOf(this.units, uN) > -1)
u = uN;
}
}
if(this.$input)
@ -169,7 +178,7 @@ define(['backbone','./PropertyView', 'text!./../templates/propertyInteger.html']
if(this.$unit)
this.$unit.val(u);
this.model.set({value: v, unit: u,}, {silent: true});
model.set({value: v, unit: u,}, {silent: true});
},
});

6
src/style_manager/view/PropertyView.js

@ -215,11 +215,11 @@ define(['backbone', 'text!./../templates/propertyLabel.html', 'text!./../templat
* @param {Boolean} force
* */
setValue: function(value, force){
var f = force === 0 ? 0 : 1;
var f = force === 0 ? 0 : 1;
var def = this.model.get('defaults');
var v = this.model.get('value') || def;
var v = this.model.get('value') || def;
if(value || f){
v = value;
v = value;
}
if(this.$input)
this.$input.val(v);

Loading…
Cancel
Save