Browse Source

Few updates on inputs

no-jquery
Artur Arseniev 9 years ago
parent
commit
1a7f238d85
  1. 17
      src/domain_abstract/ui/Input.js
  2. 32
      src/domain_abstract/ui/InputColor.js
  3. 8
      src/style_manager/view/PropertyColorView.js

17
src/domain_abstract/ui/Input.js

@ -6,12 +6,17 @@ module.exports = Backbone.View.extend({
'change': 'handleChange', 'change': 'handleChange',
}, },
initialize(opts) { template() {
var opt = opts || {}; const holderClass = this.holderClass;
var ppfx = opt.ppfx || ''; return `<span class="${holderClass}"></span>`;
this.target = opt.target || {}; },
initialize(opts = {}) {
const ppfx = opts.ppfx || '';
this.target = opts.target || {};
this.inputClass = ppfx + 'field'; this.inputClass = ppfx + 'field';
this.inputHolderClass = ppfx + 'input-holder'; this.inputHolderClass = ppfx + 'input-holder';
this.holderClass = `${ppfx}input-holder`;
this.ppfx = ppfx; this.ppfx = ppfx;
this.listenTo(this.model, 'change:value', this.handleModelChange); this.listenTo(this.model, 'change:value', this.handleModelChange);
}, },
@ -66,9 +71,9 @@ module.exports = Backbone.View.extend({
render() { render() {
const el = this.$el; const el = this.$el;
const ppfx = this.ppfx; const ppfx = this.ppfx;
const holderClass = `${ppfx}input-holder`; const holderClass = this.holderClass;
el.addClass(this.inputClass); el.addClass(this.inputClass);
el.html(`<span class="${holderClass}"></span>`); el.html(this.template());
el.find(`.${holderClass}`).append(this.getInputEl()); el.find(`.${holderClass}`).append(this.getInputEl());
return this; return this;
} }

32
src/domain_abstract/ui/InputColor.js

@ -5,17 +5,21 @@ const $ = Backbone.$;
module.exports = Input.extend({ module.exports = Input.extend({
template: _.template(` template() {
<div class='<%= ppfx %>input-holder'></div> const ppfx = this.ppfx;
<div class="<%= ppfx %>field-colorp"> return `
<div class="<%= ppfx %>field-colorp-c"> <div class="${ppfx}input-holder"></div>
<div class="<%= ppfx %>checker-bg"></div> <div class="${ppfx}field-colorp">
</div> <div class="${ppfx}field-colorp-c">
</div>`), <div class="${ppfx}checker-bg"></div>
</div>
</div>
`;
},
initialize(opts) { initialize(opts) {
Input.prototype.initialize.apply(this, arguments); Input.prototype.initialize.apply(this, arguments);
var ppfx = this.ppfx; const ppfx = this.ppfx;
this.colorCls = `${ppfx}field-color-picker`; this.colorCls = `${ppfx}field-color-picker`;
this.inputClass = `${ppfx}field ${ppfx}field-color`; this.inputClass = `${ppfx}field ${ppfx}field-color`;
this.colorHolderClass = `${ppfx}field-colorp-c`; this.colorHolderClass = `${ppfx}field-colorp-c`;
@ -57,14 +61,10 @@ module.exports = Input.extend({
const self = this; const self = this;
var model = this.model; var model = this.model;
var colorEl = $(`<div class="${this.colorCls}">`); var colorEl = $(`<div class="${this.colorCls}"></div>`);
var cpStyle = colorEl.get(0).style; var cpStyle = colorEl.get(0).style;
var elToAppend = this.target && this.target.config ? this.target.config.el : ''; var elToAppend = this.target && this.target.config ? this.target.config.el : '';
if (typeof colorEl.spectrum == 'undefined') {
throw 'Spectrum missing, probably you load jQuery twice';
}
const getColor = color => { const getColor = color => {
let cl = color.getAlpha() == 1 ? color.toHexString() : color.toRgbString(); let cl = color.getAlpha() == 1 ? color.toHexString() : color.toRgbString();
return cl.replace(/ /g, ''); return cl.replace(/ /g, '');
@ -113,9 +113,9 @@ module.exports = Input.extend({
return this.colorEl; return this.colorEl;
}, },
render(...args) { render() {
Input.prototype.render.apply(this, args); Input.prototype.render.apply(this, arguments);
this.$el.find('.' + this.colorHolderClass).html(this.getColorEl()); this.$el.find(`.${this.colorHolderClass}`).append(this.getColorEl());
return this; return this;
} }

8
src/style_manager/view/PropertyColorView.js

@ -1,5 +1,4 @@
var Backbone = require('backbone'); const InputColor = require('domain_abstract/ui/InputColor');
var InputColor = require('domain_abstract/ui/InputColor');
module.exports = require('./PropertyIntegerView').extend({ module.exports = require('./PropertyIntegerView').extend({
@ -10,13 +9,14 @@ module.exports = require('./PropertyIntegerView').extend({
onRender() { onRender() {
if (!this.input) { if (!this.input) {
const ppfx = this.ppfx;
const inputColor = new InputColor({ const inputColor = new InputColor({
target: this.target, target: this.target,
model: this.model, model: this.model,
ppfx: this.ppfx ppfx
}); });
const input = inputColor.render(); const input = inputColor.render();
this.$el.append(input.$el); this.el.querySelector(`.${ppfx}fields`).appendChild(input.el);
this.$input = input.inputEl; this.$input = input.inputEl;
this.$color = input.colorEl; this.$color = input.colorEl;
this.input = this.$input.get(0); this.input = this.$input.get(0);

Loading…
Cancel
Save