class SnippetGenerator in Drupal 8 Google Optimize Hide Page 8
Implements Snippet Generator class.
Hierarchy
- class \Drupal\d8_google_optimize_hide_page\Util\SnippetGenerator
Expanded class hierarchy of SnippetGenerator
2 files declare their use of SnippetGenerator
File
- src/
Util/ SnippetGenerator.php, line 8
Namespace
Drupal\d8_google_optimize_hide_page\UtilView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SnippetGenerator:: |
public | function | Generate the JS snippet. |