regexper-static/src/js/parser/javascript/charset.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

import _ from 'lodash';
import Base from './base.js';
export default _.extend({}, Base, {
2014-12-07 22:38:24 +00:00
type: 'charset',
render() {
this.label = this.container.text()
2014-12-10 00:03:50 +00:00
.addClass('charset-label')
2014-12-07 22:38:24 +00:00
.attr({
text: this.invert() ? 'None of:' : 'One of:'
2014-12-09 22:48:44 +00:00
});
2014-12-07 22:38:24 +00:00
this.box = this.container.rect()
.addClass('charset-box')
.attr({
rx: 3,
ry: 3
});
this.partContainer = this.container.group();
2014-12-09 22:48:44 +00:00
_.each(this.parts.elements, (part => {
part.setContainer(this.partContainer.group());
2014-12-07 22:38:24 +00:00
part.render();
}).bind(this));
},
position() {
var box;
2014-12-07 22:38:24 +00:00
_.invoke(this.parts.elements, 'position');
2014-12-07 22:38:24 +00:00
this.spaceVertically(this.parts.elements, {
padding: 5
});
2014-12-07 22:38:24 +00:00
box = this.label.getBBox();
this.label.transform(Snap.matrix()
.translate(0, box.height));
this.partContainer.transform(Snap.matrix()
.translate(5, 5 + box.height));
this.box.transform(Snap.matrix()
.translate(0, box.height));
2014-12-07 22:38:24 +00:00
box = this.partContainer.getBBox();
this.box.attr({
width: box.width + 10,
height: box.height + 10
});
},
invert() {
return this._invert.textValue !== '';
}
});