You are here

class SnippetGenerator in Drupal 8 Google Optimize Hide Page 8

Implements Snippet Generator class.

Hierarchy

Expanded class hierarchy of SnippetGenerator

2 files declare their use of SnippetGenerator
d8_google_optimize_hide_page.module in ./d8_google_optimize_hide_page.module
d8_google_optimize_hide_page.module
GoogleOptimizeHidePageController.php in src/Controller/GoogleOptimizeHidePageController.php

File

src/Util/SnippetGenerator.php, line 8

Namespace

Drupal\d8_google_optimize_hide_page\Util
View source
class SnippetGenerator {

  /**
   * Generate the JS snippet.
   *
   * @return string
   *   JS snippet.
   */
  public function getSnippet() : string {
    $container_ids = d8_google_optimize_hide_page_container_ids();
    $class_name = d8_google_optimize_hide_page_class_name();
    $timeout = d8_google_optimize_hide_page_timeout();
    $container_ids = array_map(function ($value) {
      return "'" . trim($value) . "':true";
    }, $container_ids);
    $container_str = implode(',', $container_ids);
    return sprintf("(function(a,s,y,n,c,h,i,d,e){s.className+=' '+y;h.start=1*new Date;\n          h.end=i=function(){s.className=s.className.replace(RegExp(' ?'+y),'')};\n          (a[n]=a[n]||[]).hide=h;setTimeout(function(){i();h.end=null},c);h.timeout=c;\n          })(window,document.documentElement,'%s','dataLayer',%d,\n          {%s});", $class_name, $timeout, $container_str);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SnippetGenerator::getSnippet public function Generate the JS snippet.