Skip to content

Instantly share code, notes, and snippets.

@evaldosantos
Created November 13, 2015 18:24
Show Gist options
  • Save evaldosantos/a70dde76e8edf3933d78 to your computer and use it in GitHub Desktop.
Save evaldosantos/a70dde76e8edf3933d78 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button id="decrement">-</button>
<input type="text" />
<button id="increment">+</button>
<script type="text/javascript">
var $ = function(elem) {
return document.querySelector(elem)
}
function Thumb(initial) {
var initial = initial;
var increment = function() {
initial++;
}
var decrement = function() {
initial--;
}
var getCurrentValue = function() {
return initial;
}
return {
increment: increment,
decrement: decrement,
getCurrentValue: getCurrentValue,
setPristine: function() {
initial = 0;
}
}
}
var SuperThumb = function(btnInc, btnDec, input, thumb) {
input.value = thumb.getCurrentValue();
btnDec.onclick = function() {
//console.log('decrement clicked')
//$('input').value = parseInt($('input').value, 10) - 1;
//$('input').value = $('input').value -1 ;
thumb.decrement();
input.value = thumb.getCurrentValue();
};
btnInc.onclick = function() {
//console.log('increment clicked');
//$('input').value = parseInt($('input').value, 10) + 1;
//$('input').value = $('input').value + 1;
thumb.increment();
if(thumb.getCurrentValue()==25) {
thumb.setPristine()
}
input.value = thumb.getCurrentValue();
};
}
new SuperThumb($("#increment"), $("#decrement"), $('input'), Thumb(20));
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment