twitter-timeline-admin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. jQuery( function( $ ) {
  2. function twitterWidgetTypeChanged( widgetTypeSelector ) {
  3. var selectedType = $( widgetTypeSelector ).val();
  4. $( widgetTypeSelector )
  5. .closest( '.jetpack-twitter-timeline-widget-type-container' )
  6. .next( '.jetpack-twitter-timeline-widget-id-container' )
  7. .find( 'label' )
  8. .css( 'display', function() {
  9. var labelType = $( this ).data( 'widget-type' );
  10. if ( selectedType === labelType ) {
  11. return '';
  12. } else {
  13. return 'none';
  14. }
  15. } );
  16. }
  17. // We could either be in wp-admin/widgets.php or the Customizer.
  18. var $container = $( '#customize-controls' );
  19. if ( ! $container.length ) {
  20. $container = $( '#wpbody' );
  21. }
  22. // Observe widget settings for 'change' events of the 'type' property for
  23. // current and future Twitter timeline widgets.
  24. $container.on( 'change', '.jetpack-twitter-timeline-widget-type', function() {
  25. twitterWidgetTypeChanged( this );
  26. } );
  27. // Set the labels for currently existing widgets (including the "template"
  28. // version that is copied when a new widget is added).
  29. $container.find( '.jetpack-twitter-timeline-widget-type' ).each( function() {
  30. twitterWidgetTypeChanged( this );
  31. } );
  32. } );