Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3. // Process any GET params set
  4. var filterableQueryString = false;
  5. var urlVars = getUrlVars();
  6.  
  7. if (urlVars.length > 0) {
  8. if (urlVars.indexOf('country') > -1) {
  9. if ($('#country option[value="' + urlVars['country'] + '"]').length > 0) {
  10. $('#country').val(urlVars['country']);
  11. filterableQueryString = true;
  12. }
  13. }
  14.  
  15. if (urlVars.indexOf('category') > -1) {
  16. if ($('#category option[value="' + urlVars['category'] + '"]').length > 0) {
  17. $('#category').val(urlVars['category']);
  18. filterableQueryString = true;
  19. }
  20. }
  21.  
  22. if (urlVars.indexOf('search') > -1) {
  23. $('#search').val(urlVars['search']);
  24. filterableQueryString = true;
  25. }
  26.  
  27. if (filterableQueryString) {
  28. applyFilterChange();
  29. }
  30. }
  31.  
  32. $('#sort').on('change', function() {
  33.  
  34. var sortBy = $(this).val();
  35. var itemsArray = [];
  36.  
  37. $('.exhibitor-column').each(function() {
  38. itemsArray.push($(this));
  39. });
  40.  
  41. itemsArray.sort(function(a, b) {
  42. if (sortBy == 'stand_number') {
  43. if (a.data('stand') === b.data('stand')) {
  44. return 0;
  45. } else if (a.data('stand') > b.data('stand')) {
  46. return 1;
  47. } else {
  48. return -1;
  49. }
  50. }
  51.  
  52. if (sortBy == 'company_name') {
  53. if (a.data('company') === b.data('company')) {
  54. return 0;
  55. } else if (a.data('company') > b.data('company')) {
  56. return 1;
  57. } else {
  58. return -1;
  59. }
  60. }
  61.  
  62. if (sortBy == 'country') {
  63. if(a.data('country') === b.data('country')) {
  64. return 0;
  65. } else if (a.data('country') > b.data('country')) {
  66. return 1;
  67. } else {
  68. return -1;
  69. }
  70. }
  71. });
  72.  
  73. for (i = 0; i < itemsArray.length; ++i) {
  74. $('#sortable').append(itemsArray[i]);
  75. }
  76.  
  77. applyFilterChange();
  78.  
  79. });
  80.  
  81. $('#country, #category').on('change', function() {
  82. applyFilterChange();
  83. });
  84.  
  85. $('#search').on('search input', function() {
  86. applyFilterChange();
  87. });
  88.  
  89. function applyFilterChange()
  90. {
  91. // Show all
  92. $('.exhibitor-column').show();
  93. $('#messages').text('').hide();
  94.  
  95. // Limit by country
  96. var country = $('#country').val();
  97.  
  98. if (country != 0) {
  99. $('.exhibitor-column').each(function() {
  100. var exhibCountry = $(this).data('country');
  101.  
  102. if (country != exhibCountry) {
  103. $(this).hide();
  104. }
  105. });
  106. }
  107.  
  108. var visibleExhibitors = recalculateVisibleExhibitors();
  109.  
  110. // Limit by category
  111. var category = $('#category').val();
  112.  
  113. if (category != 0) {
  114. $(visibleExhibitors).each(function() {
  115. var categories = $(this).data('categories').toString();
  116. var categoryArray = categories.split('|');
  117.  
  118. if (categoryArray.indexOf(category) == -1) {
  119. $(this).hide();
  120. }
  121. });
  122. }
  123.  
  124. visibleExhibitors = recalculateVisibleExhibitors();
  125.  
  126. // Limit by free text search
  127. var search = $('#search').val().toLowerCase();
  128.  
  129. if (search) {
  130. $(visibleExhibitors).each(function() {
  131. var textContent = $(this).text().toLowerCase();
  132.  
  133. if (textContent.indexOf(search) === -1) {
  134. $(this).hide();
  135. }
  136. });
  137. }
  138.  
  139. // Reset rows/columns
  140. $('.clearfix').remove();
  141. var columnCount = 0;
  142.  
  143. $('.exhibitor-column').each(function() {
  144. if ($(this).is(':visible')) {
  145. columnCount++;
  146.  
  147. if (columnCount % 3 == 0) {
  148. $(this).after('<div class="clearfix"></div>');
  149. }
  150. }
  151. });
  152.  
  153. visibleExhibitors = recalculateVisibleExhibitors();
  154.  
  155. // Display "no results" message on empty list
  156. if (!visibleExhibitors.length) {
  157. $('#messages').html('<em>There are no search results.</em>').show();
  158. }
  159. }
  160.  
  161. function recalculateVisibleExhibitors()
  162. {
  163. return $('.exhibitor-column').filter(':visible');
  164. }
  165.  
  166. function getUrlVars()
  167. {
  168. var vars = [], hash;
  169. var hashes = window.location.href.slice(
  170. window.location.href.indexOf('?') + 1
  171. ).split('&');
  172.  
  173. for (var i = 0; i < hashes.length; i++) {
  174. hash = hashes[i].split('=');
  175. vars.push(hash[0]);
  176. vars[hash[0]] = decodeURIComponent(hash[1]);
  177. }
  178.  
  179. return vars;
  180. }
  181.  
  182. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement