Advertisement
brilliantmojo

Search.js

Jan 30th, 2020
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function(){
  2.  
  3.     //Close other tabs on click
  4.     $('.ItemSearch').click(function() {
  5.                
  6.         $('input[name="Tabs"]').prop('checked', false);
  7.                
  8.     });
  9.    
  10.     //Change icon on focus and change icon back on blur
  11.     $('#ItemSearch').focus(function(){
  12.         $('.mdi-magnify').css('display', 'none');
  13.         $('.mdi-pound').css('display', 'block');
  14.     });
  15.     $('#ItemSearch').blur(function(){
  16.         $('.mdi-magnify').css('display', 'block');
  17.         $('.mdi-pound').css('display', 'none');
  18.     });
  19.    
  20.     //Called when key is pressed in text box
  21.     $('.ItemSearch').keypress(function(e) {
  22.        
  23.         //If the letter is not digit then display error and don't type anything
  24.         if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
  25.            
  26.             //Display error message
  27.             $(this).attr('placeholder', 'Numbers Only');
  28.             $(this).addClass('ItemSearchError');
  29.             $('.mdi-pound').css('color', '#e60000');
  30.             $('.mdi-magnify').css('color', '#e60000');
  31.             $(this).css('border-color', '#e60000');
  32.             $(this).css('background-color', '#ffe6e6');
  33.             return false;
  34.            
  35.             //Reset error message after 1.25 seconds
  36.             setTimeout(function() {
  37.                 $('.ItemSearch').attr('placeholder', 'Item Number');
  38.                 $('.ItemSearch').removeClass('ItemSearchError');
  39.                 $('.mdi-pound').css('color', '#0006ff');
  40.                 $('.mdi-magnify').css('color', '#0006ff');
  41.                 $('.ItemSearch').css('border-color', '#0006ff');
  42.                 $('.ItemSearch').css('background-color', '#e8e8ff');
  43.             }, 1250);
  44.            
  45.         }
  46.        
  47.     });
  48.    
  49. });
  50.  
  51. //Search AJAX call
  52. function searchFilter() {
  53.  
  54.     var ItemSearch = $('#ItemSearch').val();
  55.  
  56.     var url;
  57.     var data;
  58.     var success;
  59.    
  60.     //If the search box [value] is empty
  61.     if (ItemSearch == 0) {
  62.        
  63.         data = {};
  64.         success =
  65.        
  66.             function(html) {
  67.                
  68.                 $('#Loader').show();   //Show infinite scroll
  69.                
  70.             };
  71.        
  72.     } else {
  73.        
  74.         url = 'vendors/php/Filters/SearchData.php';
  75.         data = {
  76.             ItemSearch: ItemSearch
  77.         };
  78.         success =
  79.        
  80.             function(html) {
  81.                
  82.                 $('#StoneContainer').html(html);
  83.                 $('#Loader').hide();   //Hide infinite scroll
  84.                
  85.             };
  86.        
  87.     }
  88.    
  89.     $.ajax({
  90.        
  91.         type: 'POST',
  92.         url: url,
  93.         data: data,
  94.         success: success
  95.        
  96.     });
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement