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

70 lines
1.4 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.container.addClass('charset');
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 => {
2014-12-07 22:38:24 +00:00
part.container = this.partContainer.group();
part.render();
}).bind(this));
},
position() {
var box, offset = 0;
2014-12-09 22:48:44 +00:00
_.each(this.parts.elements, (part => {
2014-12-07 22:38:24 +00:00
var box;
part.position();
part.container.transform(Snap.matrix()
.translate(0, offset));
2014-12-10 00:02:31 +00:00
box = part.getBBox();
2014-12-07 22:38:24 +00:00
offset += box.height + 5;
}).bind(this));
box = this.partContainer.getBBox();
2014-12-09 22:48:44 +00:00
_.each(this.parts.elements, (part => {
2014-12-10 00:02:31 +00:00
var partBox = part.getBBox();
2014-12-07 22:38:24 +00:00
part.container.transform(Snap.matrix()
.add(part.container.transform().localMatrix)
.translate(box.cx - partBox.cx, 0));
}).bind(this));
this.box.attr({
width: box.width + 10,
height: box.height + 10
});
this.partContainer.transform(Snap.matrix()
.translate(5, 5));
},
invert() {
return this._invert.textValue !== '';
}
});