Last active
June 7, 2018 03:14
-
-
Save antonybudianto/0a1d00129197980f1ce71f3c6cf8e7cf 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
var leaveTypes = ['Cuti tahunan', 'Cuti sakit', 'Remote', 'Cuti tidak berbayar', 'Maternity Leave'] | |
$('#see-more-list').append('<input style="border:1px solid gray; margin:10px" id="slksearch" type="text" placeholder="Search by name" />') | |
$('#see-more-list').append('<select id="slktype"><option>All</option>'+ leaveTypes.map(l => '<option>'+l+'</option>').join('')+'</select>') | |
$('#see-more-list').append('<span style="margin: 5px" id="slktotal"></span>') | |
$("#slksearch").on('input', () => { | |
var val = $('#slksearch').val() | |
handleOnChange(val, $('#slktype').val()) | |
}) | |
$('#slktype').on('change', () => { | |
var val = $('#slktype').val() | |
handleOnChange($('#slksearch').val(), val) | |
}) | |
$('a.fc-more').on('click', () => { | |
$('#slktotal').text('') | |
}) | |
function handleOnChange(val, type) { | |
var total = 0 | |
$('#see-more-list ul li').each(function () { | |
var txt = $(this).find('div.left-side span:nth-of-type(2) span:first-child').text() | |
var typeSpan = $(this).find('div.left-side span:nth-of-type(2) span:nth-child(2)').text() | |
var toggle = txt.toLowerCase().indexOf(val.toLowerCase()) !== -1 && (typeSpan === type || type === 'All') | |
total += toggle ? 1 : 0 | |
$(this).toggle(toggle) | |
}) | |
$('#slktotal').text(total + ' people') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment