Skip to content

Instantly share code, notes, and snippets.

@mildfuzz
Created August 20, 2014 07:30
Show Gist options
  • Select an option

  • Save mildfuzz/bdd00547f3fe382fea84 to your computer and use it in GitHub Desktop.

Select an option

Save mildfuzz/bdd00547f3fe382fea84 to your computer and use it in GitHub Desktop.
//styles form padding offset
(function() {
var offset, $input, spanWidth,
$inputs = document.getElementsByClassName('input-wrapper');
for(var i = 0; i < $inputs.length; i++) {
spanWidth = Math.round($inputs[i].childNodes[0].getBoundingClientRect().width);
inoutTextOffset = (spanWidth + 7) + 'px';
$input = $inputs[i].childNodes[1];
$input.style.paddingLeft = inoutTextOffset;
}
})();
//week menu
(function assignDropDowns(){
var $this, listHeight, subjectHeight,
offset = 10,
$subjects = document.getElementsByClassName('subject');
for (var i = 0; i < $subjects.length; i++) {
$subject = $subjects[i];
$subject.style.height = $subject.childNodes[1].getBoundingClientRect().height + 27 + 'px';
subjectHeight = $subject.childNodes[1].getBoundingClientRect().height + 27;
listHeight = $subject.children[1].getBoundingClientRect().height;
$subject.dataset.fullHeight = listHeight + subjectHeight + offset;
$subject.dataset.startHeight = subjectHeight;
$subject.style.height = $subject.childNodes[1].getBoundingClientRect().height + 27 + 'px';
$subject.addEventListener('click', function(e) {
var $subject = e.currentTarget;
if ($subject.classList.contains('active')) {
$subject.classList.remove('active');
$subject.style.height = $subject.dataset.startHeight + 'px';
} else {
$subject.classList.add('active');
$subject.style.height = $subject.dataset.fullHeight + 'px';
}
})
}
window.addEventListener('resize',assignDropDowns);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment