Crochet Companion

Keeps track of row/stitch for particular crochet project.

HTML

<body>
  <div id="mainContainer">

  </div>
</body>

CSS

@import url("https://fonts.googleapis.com/css?family=Sofia");

body,
html {
  height: 100%;
  background: #E6C5FD;
}

section {
  text-align: center;
}

#mainContainer {
  display: flex;
  background: #E6C5FD;
  max-height: 100%;
  font-family: 'Sofia', cursive;
  color: #5806c3;
  max-width: 100%;
  margin: auto;
}

div[class^="widgetContainer"] {
  width: 100%;
}

.title {
  font-weight: normal;
  display: inline-flex;
  font-size: 2em;
  margin: 0;
}

.clear {
  font-family: 'Sofia', cursive;
  background: transparent;
  border: 0px solid;
  border-radius: 15px;
  font-size: 1.5em;
  padding: 10px;
  color: #5806c3;
}

.clear:active {
  background: #ECD4FD;
}

.clear:focus {
  outline: 0;
}

.display {
  font-size: 4em;
  display: flex;
  justify-content: space-between;
}

.number {
  margin: .5em;
}

.arrow {
  font-family: 'Sofia', cursive;
  color: #5806c3;
  background: #E6C5FD;
  border: none;
  border-radius: 60px;
  width: 100%;
  max-width: 200px;
  font-size: 1.233333em;
}

.arrow:active {
  background: #ECD4FD;
}

.arrow:focus {
  outline: 0;
}

JavaScript

'use strict'
// counter object constructor
function Counter() {
  this.currentNumber = 0;
}

Counter.prototype.down = function() {
  if (this.currentNumber) {
    this.currentNumber--;
  }
}

Counter.prototype.up = function() {
  this.currentNumber++;
}

Counter.prototype.clear = function() {
  this.currentNumber = 0;
}

// display object constructor
function Display(x, title) {
  this.num = x;
  this.title = title;
  this.row = new Counter();
  this.stitch = new Counter();
  this.html = `
	<div class="widgetContainer${this.num}">
		<h1>${title}</h1>
		<section class="row">
			<h1 class="title">row</h1>
			<br>
			<button class="rowClear clear title">clear</button>
			<div class="display">
				<button class="rowDown arrow"><</button>
				<div class="rowNumber">
				</div>
				<button class="rowUp arrow">></button>
			</div>
		</section>
		<section class="stitch">
			<h1 class="title">stitch</h1>
			<br>
			<button class="stitchClear clear title">clear</button>
			<div class="display">
				<button class="stitchDown arrow"><</button>
				<div class="stitchNumber">
				</div>
				<button class="stitchUp arrow">></button>
			</div>
		</section>
	</div>`;
}

Display.prototype.render = function() {
  let mainContainer = document.getElementById('mainContainer')
  let widgetCons = mainContainer.getElementsByClassName('widgetContainer' + this.num);

  mainContainer.insertAdjacentHTML('beforeend', this.html);

  for (let i = 0; i < widgetCons.length; i++) {
    this.bindButtons(widgetCons[i], 'row');
    this.bindButtons(widgetCons[i], 'stitch');
  }
}

Display.prototype.bindButtons = function(el, pre) {
  let main = el.querySelector('section.' + pre);
  let up = main.querySelector('button.' + pre + 'Up');
  let down = main.querySelector('button.' + pre + 'Down');
  let clear = main.querySelector('button.' + pre + 'Clear');
  let number = main.querySelector('div.' + pre + 'Number')


  switch (pre) {
    case 'row':
      number.innerText = this.row.currentNumber

     ...