Creating Base module and extracting placeholder rendering

This commit is contained in:
Jeff Avallone 2014-11-30 14:10:27 -05:00
parent 4decff56e7
commit 30d88810d0
3 changed files with 50 additions and 29 deletions

View File

@ -0,0 +1,41 @@
export default {
render_label(container, text) {
var group = container.group();
group.rect().attr({
rx: 10,
ry: 10
});
group.text().attr({
text: text
});
return group;
},
position_label(group) {
var text = group.select('text'),
rect = group.select('rect'),
box = text.getBBox(),
margin = 5;
text.transform(Snap.matrix()
.translate(margin, box.height + margin));
rect.attr({
width: box.width + 2 * margin,
height: box.height + 2 * margin
});
},
render(container) {
container.attr({ 'class': 'placeholder' });
this.label = this.render_label(container, this.textValue);
},
position() {
this.position_label(this.label);
}
};

View File

@ -1,4 +1,7 @@
export default { import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
matches() { matches() {
if (this.elements[1].regexp) { if (this.elements[1].regexp) {
return [this.match].concat(this.elements[1].regexp.matches()); return [this.match].concat(this.elements[1].regexp.matches());
@ -6,4 +9,4 @@ export default {
return [this.match]; return [this.match];
} }
} }
}; });

View File

@ -1,30 +1,7 @@
export default { import _ from 'lodash';
render(container) { import Base from './base.js';
container.attr({ 'class': 'placeholder' });
this.rect = container.rect().attr({
rx: 10,
ry: 10
});
this.text = container.text().attr({
text: this.textValue
});
},
position() {
var box = this.text.getBBox(),
margin = 5;
this.text.transform(Snap.matrix()
.translate(margin, box.height + margin));
this.rect.attr({
width: box.width + 2 * margin,
height: box.height + 2 * margin
});
},
export default _.extend({}, Base, {
flags() { flags() {
var flags; var flags;
@ -48,4 +25,4 @@ export default {
return this; return this;
} }
} }
}; });