JSFiddle - React, Tailwind, and code Playground
by jtree5757
HTML
<script src="http://cdn.jsdelivr.net/jquery.mixitup/latest/jquery.mixitup.min.js"></script>
<script src="http://tammymealplan.com/wp-content/themes/gridster-child/js/jquery.nouislider.js"></script>
<link rel="stylesheet" href="http://tammymealplan.com/wp-content/themes/gridster-child/jquery.nouislider.css">
<form class="controls" id="Filters">
<!-- We can add an unlimited number of "filter groups" using the following format: -->
<fieldset>
<h4>Range Slider</h4>
<div id="sample-showcase" class="noUi-target noUi-ltr noUi-horizontal noUi-background"></div>
<div id="rangespan-container">
<span id="min-value-span" class="range-spans"></span>
<span class="range-spans">g</span>
<span id="max" class="range-spans"> - </span>
<span id="max-value-span" class="range-spans"></span>
<span class="range-spans">g</span>
<div class="checkbox range-button">
<input type="checkbox" class="rangecheck" />
<label>Activate</label>
</div>
</div>
</fieldset>
<fieldset>
<h4>Meal Time</h4>
<div class="checkbox">
<input type="checkbox" value=".breakfast" class="checkbox1" />
<label>Breakfast</label>
</div>
<div class="checkbox">
<input type="checkbox" value=".lunch" class="checkbox2" />
<label>Lunch</label>
</div>
<div class="checkbox">
<input type="checkbox" value=".dinner" class="checkbox3" />
<label>Dinner</label>
</div>
<div class="checkbox">
<input type="checkbox" value=".snacks" class="checkbox4" />
<label>Snacks</label>
</div>
</fieldset>
<button id="Reset">Clear Filters</button>
</form>
<div id="Container" class="container">
<div class="fail-message"><span>No items were found matching the selected filters</span>
</div>
<div class="mix breakfast 20">breakfast
<br>20</div>
<div...
CSS
body {
background: #68b8c4;
}
body, button {
font-family:'Helvetica Neue', arial, sans-serif;
color: white;
-webkit-font-smoothing: antialiased;
}
/**
* Form & Checkbox Styles
*/
h4 {
font-weight: 700;
margin-bottom: .5em;
}
label {
font-weight: 300;
}
button {
display: inline-block;
vertical-align: top;
padding: .4em .8em;
margin: 0;
background: #68b8c4;
border: 0;
color: #333;
font-size: 16px;
font-weight: 700;
border-radius: 4px;
cursor: pointer;
}
button:focus {
outline: 0 none;
}
.controls {
background: #333;
padding: 2%;
}
fieldset {
display: inline-block;
vertical-align: top;
margin: 0 1em 0 0;
background: #666;
padding: .5em;
border-radius: 3px;
}
.checkbox {
display: block;
position: relative;
cursor: pointer;
margin-bottom: 8px;
}
.checkbox input[type="checkbox"] {
position: absolute;
display: block;
top: 0;
left: 0;
height: 100%;
width: 100%;
cursor: pointer;
margin: 0;
opacity: 0;
z-index: 1;
}
.checkbox label {
display: inline-block;
vertical-align: top;
text-align: left;
padding-left: 1.5em;
}
.checkbox label:before, .checkbox label:after {
content:'';
display: block;
position: absolute;
}
.checkbox label:before {
left: 0;
top: 0;
width: 18px;
height: 18px;
margin-right: 10px;
background: #ddd;
border-radius: 3px;
}
.checkbox label:after {
content:'';
position: absolute;
top: 4px;
left: 4px;
width: 10px;
height: 10px;
border-radius: 2px;
background: #68b8c4;
opacity: 0;
pointer-events: none;
}
.checkbox input:checked ~ label:after {
opacity: 1;
}
.checkbox input:focus ~ label:before {
background: #eee;
}
/**
* Container/Target Styles
*/
.container {
padding: 2%;
min-height: 400px;
text-align: justify;
position: relative;
}
.container .mix, .container .gap {
...
JavaScript
// To keep our code clean and modular, all custom functionality will be contained inside a single object literal called "checkboxFilter".
var checkboxFilter = {
// Declare any variables we will need as properties of the object
$filters: null,
$reset: null,
groups: [],
outputArray: [],
outputString: '',
// The "init" method will run on document ready and cache any jQuery objects we will need.
init: function () {
var self = this; // As a best practice, in each method we will asign "this" to the variable "self" so that it remains scope-agnostic. We will use it to refer to the parent "checkboxFilter" object so that we can share methods and properties between all parts of the object.
self.$filters = $('#Filters');
self.$reset = $('#Reset');
self.$container = $('#Container');
self.$filters.find('fieldset').each(function () {
self.groups.push({
$inputs: $(this).find('input'),
active: [],
tracker: false
});
});
self.bindHandlers();
},
// The "bindHandlers" method will listen for whenever a form value changes.
bindHandlers: function () {
var self = this;
self.$filters.on('change', function () {
self.parseFilters();
});
self.$reset.on('click', function () {
self.$filters[0].reset();
self.parseFilters();
});
},
// The parseFilters method checks which filters are active in each group:
parseFilters: function () {
var self = this;
// loop through each filter group and add active filters to arrays
for (var i = 0, group; group = self.groups[i]; i++) {
group.active = []; // reset arrays
group.$inputs.each(function () {
$(this).is(':checked') && group.active.push(this.value);
});
group.active.length && (group.tracker =...