Last active
December 30, 2017 17:28
-
-
Save biswajitpaul01/fe551307eeb6f454e42243c62ae1b932 to your computer and use it in GitHub Desktop.
Multiple click state with icon changes
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 lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Triple State Checkbox</title> | |
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"> | |
<style type="text/css"> | |
.fancy-checkbox:hover{cursor:pointer} | |
.fancy-checkbox:before{content:'\f10c';font-family:FontAwesome} | |
.fancy-checkbox[data-need="1"]:before{content:'\f06a'} | |
.fancy-checkbox[data-have="1"]:before{content:'\f058'} | |
.fancy-checkbox[data-done="1"]:before{content:'\f0b1'} | |
</style> | |
</head> | |
<body> | |
<label class="fancy-checkbox" data-need="0" data-have="0" data-done="0"> Item One</label> | |
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('.fancy-checkbox').click(() => { | |
let clicked = $('.fancy-checkbox'), | |
s1 = parseInt( clicked.attr('data-need') ), | |
s2 = parseInt( clicked.attr('data-have') ), | |
s3 = parseInt( clicked.attr('data-done') ); | |
//console.log('before status: ' + s1 + ' : ' + s2 + ' : ' + s3); | |
if( !s1 && !s2 && !s3 ) { //console.log('rule 1'); | |
clicked.attr({'data-need': 1, 'data-have': 0, 'data-done': 0}); | |
} | |
if( s1 && !s2 && !s3 ) { //console.log('rule 2'); | |
clicked.attr({'data-need': 0, 'data-have': 1, 'data-done': 0}); | |
} | |
if( !s1 && s2 && !s3 ) { //console.log('rule 3'); | |
clicked.attr({'data-need': 0, 'data-have': 0, 'data-done': 1}); | |
} | |
if( !s1 && !s2 && s3 ) { //console.log('rule 4'); | |
clicked.attr({'data-need': 0, 'data-have': 0, 'data-done': 0}); | |
} | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment