site.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. $(function() {
  2. $("#newsletter").validate();
  3. var ads = [
  4. {
  5. quote: "Take your icon game to the next level. Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
  6. class: "fonticons",
  7. url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_1_next_level&utm_campaign=promo_4.3_update",
  8. btn_text: "Gimme Some!"
  9. },
  10. {
  11. quote: "Make your icons load 10x faster! Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
  12. class: "fonticons",
  13. url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_3_faster_loading&utm_campaign=promo_4.3_update",
  14. btn_text: "Gimme Some!"
  15. },
  16. {
  17. quote: "Looking for other great icon sets? Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
  18. class: "fonticons",
  19. url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_4_more_icons&utm_campaign=promo_4.3_update",
  20. btn_text: "Gimme Some!"
  21. },
  22. {
  23. quote: "Want to add your own icon? Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
  24. class: "fonticons",
  25. url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_6_your_own_icon&utm_campaign=promo_4.3_update",
  26. btn_text: "Gimme Some!"
  27. },
  28. {
  29. quote: "<strong>Black Tie</strong>, from the creator of Font Awesome. On sale at the Kickstarter price for a limited time.",
  30. class: "black-tie",
  31. url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_2_kickstarter&utm_campaign=promo_4.3_update",
  32. btn_text: "Check it Out!"
  33. },
  34. {
  35. quote: "Want clean, minimalist icons? Check out <strong>Black Tie</strong>, the new multi-weight icon font from the maker of Font Awesome.",
  36. class: "black-tie",
  37. url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_5_clean_minimalist&utm_campaign=promo_4.3_update",
  38. btn_text: "Check it Out!"
  39. }
  40. ];
  41. selectFonticonsAd();
  42. // start the icon carousel
  43. $('#icon-carousel').carousel({
  44. interval: 5000
  45. });
  46. $('[data-toggle="popover"]').popover();
  47. var $filter_by = $('#filter-by');
  48. // Filter icons
  49. if($filter_by.length) {
  50. var $filter_val = $('#filter-val');
  51. var $filter = $('#filter');
  52. var $other = $('#new, #web-application, #transportation, #gender, #form-control, #medical, #currency, #text-editor, #directional, #video-player, #brand, #file-type, #spinner, #payment, #chart');
  53. var $clear = $('#filter-clear');
  54. var $no_results = $('#no-search-results');
  55. var $icons = $('.filter-icon', $filter);
  56. // Add tab completion
  57. $filter_by.tabcomplete(filterSet, {
  58. arrowKeys: true
  59. });
  60. $clear.on('click', function(e) {
  61. e.preventDefault();
  62. $filter_by
  63. .val('')
  64. .trigger('input')
  65. .trigger('keyup')
  66. .focus();
  67. $clear.addClass('hide'); // Hide clear button
  68. });
  69. $filter_by.on('keyup', function() {
  70. var $this = $(this);
  71. var val = $this.val().toLowerCase();
  72. $filter.toggle(!!val);
  73. $other.toggle(!val);
  74. $clear.toggleClass('hide', !val);
  75. $filter_val.text(val);
  76. if(!val) return;
  77. var resultsCount = 0;
  78. $icons.each(function() {
  79. var filter = $(this).attr('data-filter').split('|');
  80. var show = inFilter(val, filter);
  81. if (!show) {
  82. if (val.slice(-1) === 's') {
  83. // Try to be smart. Make plural terms singular.
  84. show = inFilter(val.slice(0, -1), filter);
  85. }
  86. }
  87. if (show) resultsCount++;
  88. $(this).toggle(!!show);
  89. });
  90. if( resultsCount == 0 && val.length != 0 ) {
  91. $no_results.find('span').text(val);
  92. $no_results.show();
  93. } else {
  94. $no_results.hide();
  95. }
  96. });
  97. }
  98. function inFilter(val, filter) {
  99. for (var i = 0; i < filter.length; i++) {
  100. if (filter[i].match(val)) return true;
  101. }
  102. return false;
  103. }
  104. $filter_by
  105. .val('')
  106. .trigger('input')
  107. .trigger('keyup')
  108. .focus();
  109. if ($clear) {
  110. $clear.addClass('hide'); // Hide clear button
  111. }
  112. function selectFonticonsAd() {
  113. random_number = Math.floor( Math.random() * ads.length );
  114. random_ad = ads[random_number];
  115. $('#banner').addClass(random_ad.class);
  116. $('#rotating-message').html(random_ad.quote);
  117. $('#rotating-url').attr("href", random_ad.url);
  118. $('#rotating-url').html(random_ad.btn_text);
  119. $('#banner').collapse('show');
  120. }
  121. });