2019-10-14 20:00:42 +02:00
|
|
|
let t_count = 0;
|
|
|
|
|
|
|
|
function text(parent, value) {
|
|
|
|
//letiables
|
|
|
|
this.parent = parent;
|
|
|
|
this.val = value;
|
|
|
|
this.id = t_count.toString() + "text";
|
|
|
|
t_count++;
|
|
|
|
this.name = "#" + this.id;
|
|
|
|
|
|
|
|
//adding the text to the SVG
|
|
|
|
let g = document.createElementNS('http://www.w3.org/2000/svg', 'g');
|
|
|
|
$(g).attr({
|
2018-06-22 16:09:43 +02:00
|
|
|
width: "100%",
|
|
|
|
height: "100%"
|
|
|
|
});
|
2019-10-14 20:00:42 +02:00
|
|
|
let el = $(document.createElementNS('http://www.w3.org/2000/svg', 'text')).attr({
|
2018-06-22 16:09:43 +02:00
|
|
|
x: "50",
|
2019-10-14 20:00:42 +02:00
|
|
|
y: "50",
|
2018-06-22 16:09:43 +02:00
|
|
|
id: this.id,
|
2019-10-14 20:00:42 +02:00
|
|
|
fill: "white",
|
|
|
|
stroke: "black"
|
2018-06-22 16:09:43 +02:00
|
|
|
});
|
2019-10-14 20:00:42 +02:00
|
|
|
$(el).text(value);
|
|
|
|
$(el).attr("class", "heavy");
|
|
|
|
$(g).append(el);
|
|
|
|
let elem = document.getElementById("svg1");
|
2018-06-22 16:09:43 +02:00
|
|
|
elem.appendChild(g);
|
2019-10-14 20:00:42 +02:00
|
|
|
this.rep = el;
|
|
|
|
$((this.rep)).on("click touchstart", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
});
|
|
|
|
|
|
|
|
//updating
|
|
|
|
this.update = function() {
|
|
|
|
$((this.name)).attr("x", (parseFloat($((this.parent)).attr("x")) + 15).toString());
|
|
|
|
$((this.name)).attr("y", (parseFloat($((this.parent)).attr("y")) + 25).toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
//beeing sure it would be updated
|
|
|
|
pieces[pieces.length] = this;
|
2018-06-22 16:09:43 +02:00
|
|
|
}
|