fedidwgugl-generator/index.html

138 lines
3.5 KiB
HTML
Raw Normal View History

2017-06-24 22:49:27 +02:00
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>#fedidwgugl Generator</title>
2017-06-25 00:58:44 +02:00
<link rel="stylesheet" href="css/font/font.css">
2017-06-24 22:49:27 +02:00
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/milligram.min.css">
<style>
#canvas {
width: inherit;
}
.button-black {
background-color: #282727;
border-color: #282727;
}
2017-06-25 00:58:44 +02:00
.invisible-font-loader {
font-family: 'DejaVu Sans Book';
}
2017-06-24 22:49:27 +02:00
</style>
</head>
<body>
<br/>
<br/>
<div class="row">
<div class="column column-33 column-offset-33"><h1>#fedidwgugl Generator</h1></div>
</div>
<div class="row">
<div class="column column-33 column-offset-33"><canvas id="canvas"></canvas></div>
</div>
<div class="row">
<div class="column column-33 column-offset-33">
<form>
<fieldset>
<label for="slogan-field">Slogan</label>
<textarea placeholder="Hier könnte ihr Slongan stehen..." id="slogan-field"></textarea>
<a id="save-button" class="button button-black" href="#" target="_blank">Abspeichern</a>
</fieldset>
</form>
</div>
</div>
<div class="row">
<div class="column column-33 column-offset-33">
<small>
2017-06-25 00:58:44 +02:00
Der Betreiber dieses Generators distanziert sich ausdrücklich von der
2017-06-24 22:49:27 +02:00
Partei CDU, deren politischen Inhalten und ihrer miserablen PR-Abteilung.
Der Gebrauch dieses Generators zu Wahlkampfzwecken
(unabhängig von der Partei) ist nicht gestattet.
</small>
</div>
</div>
2017-06-25 00:58:44 +02:00
<div class="invisible-font-loader">&nbsp;</div>
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
<script type="text/javascript">
(function() {
var boxOversize = 50;
var boxSpacing = 75;
var textHeight = 90;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
var background = new Image();
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
var sloganField = document.getElementById('slogan-field');
var saveButton = document.getElementById('save-button');
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
function redraw() {
ctx.drawImage(background, 0, 0);
var slogan = sloganField.value;
if(slogan === "") {
slogan = sloganField.placeholder;
}
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
ctx.font = 'bold ' + textHeight + 'px DejaVu Sans Book';
ctx.textBaseline = 'middle';
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
var lines = slogan.split('\n');
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
totalTextHeight = lines.length * (textHeight + boxOversize + boxSpacing);
textStartY = canvas.height / 2 - totalTextHeight / 2;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
for(lineNum = 0; lineNum < lines.length; lineNum++) {
var line = lines[lineNum];
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
var textWidth = ctx.measureText(line).width;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
console.log(textWidth);
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
textX = canvas.width / 2 - textWidth / 2;
textY = textStartY + lineNum * (textHeight + boxOversize + boxSpacing / 2) +
(textHeight + boxOversize + boxSpacing) / 2;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
boxPosX = textX - boxOversize / 2;
boxWidth = textWidth + boxOversize;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
boxPosY = textY - (textHeight + boxOversize) / 2;
boxHeight = textHeight + boxOversize;
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
ctx.fillStyle = 'white';
ctx.fillRect(boxPosX, boxPosY, boxWidth, boxHeight);
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
ctx.fillStyle = 'black';
ctx.fillText(line, textX, textY);
}
2017-06-24 22:49:27 +02:00
}
2017-06-25 00:58:44 +02:00
function saveCanvas() {
redraw();
this.href= canvas.toDataURL('image/png');
}
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
background.addEventListener('load', function() {
2017-06-24 22:49:27 +02:00
canvas.width = background.width;
canvas.height = background.height;
sloganField.addEventListener('change', redraw, false);
sloganField.addEventListener('keyup', redraw, false);
saveButton.addEventListener('click', saveCanvas, false);
redraw();
2017-06-25 00:58:44 +02:00
}, false);
2017-06-24 22:49:27 +02:00
2017-06-25 00:58:44 +02:00
background.src = 'background.png'
})();
</script>
2017-06-24 22:49:27 +02:00
</body>
</html>