Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created July 10, 2014 11:59
Show Gist options
  • Select an option

  • Save tommcfarlin/821b7ab36571f63b47e8 to your computer and use it in GitHub Desktop.

Select an option

Save tommcfarlin/821b7ab36571f63b47e8 to your computer and use it in GitHub Desktop.
[WordPress] JavaScript helper function for making Customizer code less redundant. In this example, it's for toggling the visibility of a social icon.
function toggleSocialIconVisibility( $, sId, sControlId ) {
'use strict';
// Toggle the visibility based on the string value of element
wp.customize( sControlId, function( value ) {
value.bind( function( to ) {
if ( 0 < $.trim( to ).length ) {
$( sId ).removeClass( 'hidden' );
} else {
$( sId ).addClass( 'hidden' );
}
});
});
}
(function( $ ) {
'use strict';
$(function() {
toggleSocialIconVisibility( $, '#facebook', 'mayer_facebook_url' );
});
})( jQuery );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment