; jQuery.fn.selectFilter = function(options) { var defaults = { callBack: function(res) {} }; var ops = $.extend({}, defaults, options); var selectList = $(this).find('select option'); var that = this; var html = ''; html += ''; $(that).append(html); $(that).find('select').hide(); $(that).on('click', '.sz_filter-text', function() { $(that).find('.sz_filter-list').slideToggle(100); $(that).find('.sz_filter-list').toggleClass('filter-open'); $(that).find('.fa-caret-down').toggleClass('filter-show'); }); $(that).find('.sz_filter-list li').not('.filter-disabled').on('click', function() { var val = $(this).data('value'); var valText = $(this).find('a').html(); $(that).find('.sz_filter-title').val(valText); $(that).find('.fa-caret-down').toggleClass('filter-show'); $(this).addClass('filter-selected').siblings().removeClass('filter-selected'); $(this).parent().slideToggle(50); for (var i = 0; i < selectList.length; i++) { var selectVal = selectList.eq(i).val(); if (val == selectVal) { $(that).find('select').val(val); }; }; ops.callBack(val); }); $(document).on('mousedown', function(e) { closeSelect(that, e); }); $(document).on('touchstart', function(e) { closeSelect(that, e); }); function closeSelect(that, e) { var filter = $(that).find('.sz_filter-list'), filterEl = $(that).find('.sz_filter-list')[0]; var filterBoxEl = $(that)[0]; var target = e.target; if (filterEl !== target && !$.contains(filterEl, target) && !$.contains(filterBoxEl, target)) { filter.slideUp(50); $(that).find('.sz_filter-list').removeClass('filter-open'); $(that).find('.fa-caret-down').removeClass('filter-show'); }; } }; jQuery.fn.selectFilter1 = function(options) { var defaults = { callBack: function(res) {} }; var ops = $.extend({}, defaults, options); var selectList = $(this).find('select option'); var that = this; var html = ''; html += ''; $(that).append(html); $(that).find('select').hide(); $(that).on('click', '.sz_filter-text', function() { $(that).find('.sz_filter-list').slideToggle(100); $(that).find('.sz_filter-list').toggleClass('filter-open'); $(that).find('.fa-caret-down').toggleClass('filter-show'); }); $(that).find('.sz_filter-list li').not('.filter-disabled').on('click', function() { var val = $(this).data('value'); var valText = $(this).find('a').html(); $(that).find('.sz_filter-title').val(valText); $(that).find('.fa-caret-down').toggleClass('filter-show'); $(this).addClass('filter-selected').siblings().removeClass('filter-selected'); $(this).parent().slideToggle(50); for (var i = 0; i < selectList.length; i++) { var selectVal = selectList.eq(i).val(); if (val == selectVal) { $(that).find('select').val(val); }; }; ops.callBack(val); }); $(document).on('mousedown', function(e) { closeSelect(that, e); }); $(document).on('touchstart', function(e) { closeSelect(that, e); }); function closeSelect(that, e) { var filter = $(that).find('.sz_filter-list'), filterEl = $(that).find('.sz_filter-list')[0]; var filterBoxEl = $(that)[0]; var target = e.target; if (filterEl !== target && !$.contains(filterEl, target) && !$.contains(filterBoxEl, target)) { filter.slideUp(50); $(that).find('.sz_filter-list').removeClass('filter-open'); $(that).find('.fa-caret-down').removeClass('filter-show'); }; } };