Skip to content

Commit

Permalink
Move javascript that was sitting in application.css into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Dec 26, 2014
1 parent da4e665 commit e9cd1db
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 24 deletions.
24 changes: 0 additions & 24 deletions app/assets/javascripts/application.js
Expand Up @@ -33,27 +33,3 @@
//= require dataTables/bootstrap/3/jquery.dataTables.bootstrap
//= require_tree .
//= require jquery_nested_form

$(document).ready(function () {
if ($(window).height() < $('html').height()) {
$('footer').show();
}

function matchHeights ($element) {
var maxHeight;
var items = $element.find('.js-match-height-item');
items.css('min-height', 0);
maxHeight = Math.max.apply(Math, _.map(items, function(item) {
return $(item).outerHeight();
}));
items.css({ 'min-height': maxHeight });
}

$(window).resize(function() {
if ($(document).width() > 768) {
matchHeights($('.upcoming-events'));
}
});

matchHeights($('.upcoming-events'));
});
5 changes: 5 additions & 0 deletions app/assets/javascripts/services/footer.js
@@ -0,0 +1,5 @@
$(document).ready(function () {
if ($(window).height() < $('html').height()) {
$('footer').show();
}
});
23 changes: 23 additions & 0 deletions app/assets/javascripts/services/matchHeights.js
@@ -0,0 +1,23 @@
$(document).ready(function () {
function matchHeights ($element) {
var items = $element.find('.js-match-height-item');
items.css('min-height', 0);

var maxHeight = Math.max.apply(Math, _.map(items, function(item) {
return $(item).outerHeight();
}));
items.css('min-height', maxHeight);
}

function setupHeightMatching ($element) {
$(window).resize(_.debounce(function() {
if ($(document).width() > 768) {
matchHeights($element);
}
}, 100));

matchHeights($element);
}

setupHeightMatching($('body'));
});

0 comments on commit e9cd1db

Please sign in to comment.