Created
November 13, 2015 18:24
-
-
Save evaldosantos/a70dde76e8edf3933d78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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