Created
September 18, 2012 12:18
-
-
Save aschempp/3742809 to your computer and use it in GitHub Desktop.
Custom Contao form styling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
window.addEvent('domready', function() { | |
document.getElements('.tableless .formbody').each( function(form) { | |
// Style radio containers | |
form.getElements('.radio_container span').each( function(radio) { | |
radio.addEvent('click', function() { | |
radio.getSiblings('span').removeClass('active').each( function(el) { | |
if (el.getElement('input.radio').checked) radio.addClass('active'); | |
}); | |
}); | |
if (radio.getElement('input.radio').checked) radio.addClass('active'); | |
}); | |
// Style checkbox containers | |
form.getElements('.checkbox_container span').each( function(checkbox) { | |
checkbox.addEvent('click', function() { | |
checkbox.getElement('input.checkbox').checked ? checkbox.addClass('active') : checkbox.removeClass('active'); | |
}); | |
if (checkbox.getElement('input.checkbox').checked) checkbox.addClass('active'); | |
}); | |
// Style select menus | |
form.getElements('select').each( function(select) { | |
var label = new Element('span') | |
new Element('div', {'class':'select_container'}).inject(select, 'before').adopt(label, select); | |
select.setStyle('opacity',0).addEvent('change', function() { | |
label.set('text', select.getChildren()[select.selectedIndex].get('text')); | |
}); | |
label.setStyle('position','absolute').set('text', select.getChildren()[select.selectedIndex].get('text')); | |
}); | |
form.addClass('styled'); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment