Fork-Awesome/src/assets/js/site.js

142 lines
4.5 KiB
JavaScript
Raw Normal View History

$(function() {
2015-01-21 19:09:39 +01:00
var ads = [
2015-03-24 15:32:12 +01:00
{
quote: "Take your icon game to the next level. Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
class: "fonticons",
url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_1_next_level&utm_campaign=promo_4.3_update",
btn_text: "Gimme Some!"
},
{
quote: "Make your icons load 10x faster! Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
class: "fonticons",
url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_3_faster_loading&utm_campaign=promo_4.3_update",
btn_text: "Gimme Some!"
},
{
quote: "Looking for other great icon sets? Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
class: "fonticons",
url: "https://fonticons.com/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_4_more_icons&utm_campaign=promo_4.3_update",
btn_text: "Gimme Some!"
},
{
quote: "Want to add your own icon? Check out <strong>Fonticons</strong>, from the maker of Font Awesome.",
2015-03-24 15:32:12 +01:00
class: "fonticons",
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",
2015-03-24 15:32:12 +01:00
btn_text: "Gimme Some!"
},
{
quote: "<strong>Black Tie</strong>, from the creator of Font Awesome. On sale at the Kickstarter price for a limited time.",
class: "black-tie",
2015-03-24 15:58:59 +01:00
url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_2_kickstarter&utm_campaign=promo_4.3_update",
btn_text: "Check it Out!"
2015-03-24 15:32:12 +01:00
},
{
quote: "Want clean, minimalist icons? Check out <strong>Black Tie</strong>, the new multi-weight icon font from the maker of Font Awesome.",
class: "black-tie",
2015-03-24 15:58:59 +01:00
url: "http://blacktie.io/?utm_source=font_awesome_homepage&utm_medium=display&utm_content=ad_5_clean_minimalist&utm_campaign=promo_4.3_update",
btn_text: "Check it Out!"
2015-03-24 15:32:12 +01:00
}
2015-01-21 19:09:39 +01:00
];
selectFonticonsAd();
2015-01-21 17:51:10 +01:00
// start the icon carousel
2013-10-05 21:40:57 +02:00
$('#icon-carousel').carousel({
interval: 5000
});
2013-11-19 20:24:23 +01:00
$('[data-toggle="popover"]').popover();
2014-10-25 03:38:27 +02:00
var $filter_by = $('#filter-by');
2013-11-19 20:24:23 +01:00
// Filter icons
2014-10-25 03:38:27 +02:00
if($filter_by.length) {
2013-11-19 20:24:23 +01:00
var $filter_val = $('#filter-val');
var $filter = $('#filter');
var $other = $('#new, #web-application, #transportation, #gender, #form-control, #medical, #currency, #text-editor, #directional, #video-player, #brand, #file-type, #spinner, #payment, #chart');
2013-11-19 20:24:23 +01:00
var $clear = $('#filter-clear');
var $no_results = $('#no-search-results');
2013-11-19 20:24:23 +01:00
var $icons = $('.filter-icon', $filter);
2014-11-01 23:45:08 +01:00
// Add tab completion
$filter_by.tabcomplete(filterSet, {
arrowKeys: true
});
$clear.on('click', function(e) {
2013-11-19 20:24:23 +01:00
e.preventDefault();
$filter_by
.val('')
.trigger('input')
.trigger('keyup')
.focus();
$clear.addClass('hide'); // Hide clear button
2013-11-19 20:24:23 +01:00
});
$filter_by.on('keyup', function() {
2013-11-19 20:24:23 +01:00
var $this = $(this);
2014-11-01 23:45:08 +01:00
var val = $this.val().toLowerCase();
2013-11-19 20:24:23 +01:00
$filter.toggle(!!val);
$other.toggle(!val);
$clear.toggleClass('hide', !val);
2013-11-19 20:24:23 +01:00
$filter_val.text(val);
if(!val) return;
var resultsCount = 0;
2013-11-19 20:24:23 +01:00
$icons.each(function() {
2014-10-21 01:53:52 +02:00
var filter = $(this).attr('data-filter').split('|');
var show = inFilter(val, filter);
if (!show) {
if (val.slice(-1) === 's') {
// Try to be smart. Make plural terms singular.
2014-10-21 01:53:52 +02:00
show = inFilter(val.slice(0, -1), filter);
}
}
if (show) resultsCount++;
2013-11-19 20:24:23 +01:00
$(this).toggle(!!show);
});
if( resultsCount == 0 && val.length != 0 ) {
$no_results.find('span').text(val);
$no_results.show();
} else {
$no_results.hide();
}
});
2013-11-19 20:24:23 +01:00
}
2014-10-21 01:53:52 +02:00
function inFilter(val, filter) {
for (var i = 0; i < filter.length; i++) {
if (filter[i].match(val)) return true;
2014-10-21 01:53:52 +02:00
}
return false;
2014-10-21 01:53:52 +02:00
}
$filter_by
.val('')
.trigger('input')
.trigger('keyup');
2015-01-21 17:54:29 +01:00
if ($clear) {
$clear.addClass('hide'); // Hide clear button
}
2015-01-21 19:09:39 +01:00
function selectFonticonsAd() {
random_number = Math.floor( Math.random() * ads.length );
random_ad = ads[random_number];
2015-01-21 18:05:34 +01:00
2015-03-24 15:32:12 +01:00
$('#banner').addClass(random_ad.class);
2015-01-21 19:09:39 +01:00
$('#rotating-message').html(random_ad.quote);
2015-03-24 15:32:12 +01:00
$('#rotating-url').attr("href", random_ad.url);
$('#rotating-url').html(random_ad.btn_text);
$('#banner').collapse('show');
2015-01-21 19:09:39 +01:00
}
});