[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentytwentyone/assets/js/ -> editor-dark-mode-support.js (source)

   1  /* global twentytwentyoneIsDarkMode, setTimeout */
   2  
   3  // Check the color scheme preference and inject the classes if necessary.
   4  if ( document.body.classList.contains( 'twentytwentyone-supports-dark-theme' ) ) {
   5      twentytwentyoneDarkModeEditorInit();
   6  }
   7  
   8  /**
   9   * Once the editor loads, add the dark mode class.
  10   *
  11   * Wait for the editor to load by periodically checking for an element, then we add the classes.
  12   *
  13   * @since Twenty Twenty-One 1.0
  14   *
  15   * @param {number} attempt Track the number of tries
  16   * @return {void}
  17   */
  18  function twentytwentyoneDarkModeEditorInit( attempt ) {
  19      var container = document.querySelector( '.block-editor__typewriter' ),
  20          maxAttempts = 8;
  21  
  22      // Set the initial attempt if it's undefined.
  23      attempt = attempt || 0;
  24  
  25      if ( twentytwentyoneIsDarkMode() ) {
  26          if ( null === container ) {
  27              // Try again.
  28              if ( attempt < maxAttempts ) {
  29                  setTimeout(
  30                      function() {
  31                          twentytwentyoneDarkModeEditorInit( attempt + 1 );
  32                      },
  33                      // Double the delay, give the server some time to breathe.
  34                      25 * Math.pow( 2, attempt )
  35                  );
  36              }
  37              return;
  38          }
  39  
  40          document.body.classList.add( 'is-dark-theme' );
  41          document.documentElement.classList.add( 'is-dark-theme' );
  42          container.classList.add( 'is-dark-theme' );
  43      }
  44  }


Generated: Fri Nov 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1