function generate_custom_footer_js() { global $post; if ($this->is_plugin_deactivated_on()) { return; } $cache_slug = "essb-js-footer"; if (count($this->js_social_apis) > 0) { if (!ESSBCoreHelper::is_module_deactivate_on('native')) { foreach ($this->js_social_apis as $network => $loaded) { $this->load_social_api_code($network); } } } // load of static scripts async or deferred if (count($this->js_static) > 0) { if ($this->js_defer || $this->js_async) { $js_code_patterns = array(); $load_mode = $this->js_async ? "po.async=true;" : "po.defer=true;"; foreach ($this->js_static as $key => $file) { $js_code_patterns[] = sprintf(' (function() { var po = document.createElement(\'script\'); po.type = \'text/javascript\'; %2$s; po.src = \'%1$s\'; var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s); })();', $file, $load_mode); } printf('<script type="text/javascript">%1$s</script>', implode(" ", $js_code_patterns)); } else { if ($this->js_delayed) { // delayed script loading $js_code_patterns = array(); $load_mode = "po.async=true;"; foreach ($this->js_static as $key => $file) { $js_code_patterns[] = sprintf(' (function() { var po = document.createElement(\'script\'); po.type = \'text/javascript\'; %2$s; po.src = \'%1$s\'; var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s); })();', $file, $load_mode); } printf('<script type="text/javascript">jQuery( document ).ready(function() { setTimeout(function() { %1$s }, 2000); });</script>', implode(" ", $js_code_patterns)); } } } if (count($this->js_static_footer)) { if ($this->js_defer || $this->js_async) { $js_code_patterns = array(); $load_mode = $this->js_async ? "po.async=true;" : "po.defer=true;"; foreach ($this->js_static_footer as $key => $file) { $js_code_patterns[] = sprintf(' (function() { var po = document.createElement(\'script\'); po.type = \'text/javascript\'; %2$s; po.src = \'%1$s\'; var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s); })();', $file, $load_mode); } printf('<script type="text/javascript">%1$s</script>', implode(" ", $js_code_patterns)); } else { if ($this->js_delayed) { // delayed script loading $js_code_patterns = array(); $load_mode = "po.async=true;"; foreach ($this->js_static_footer as $key => $file) { $js_code_patterns[] = sprintf(' (function() { var po = document.createElement(\'script\'); po.type = \'text/javascript\'; %2$s; po.src = \'%1$s\'; var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s); })();', $file, $load_mode); } printf('<script type="text/javascript">jQuery( document ).ready(function() { setTimeout(function() { %1$s }, 2000); });</script>', implode(" ", $js_code_patterns)); } else { foreach ($this->js_static_footer as $key => $file) { //wp_enqueue_script ( $key, $file, array ( 'jquery' ), $this->resource_version, false ); $this->manual_script_load($key, $file); } } } } if (count($this->js_static_noasync_footer)) { foreach ($this->js_static_noasync_footer as $key => $file) { //wp_enqueue_script ( $key, $file, array ( 'jquery' ), $this->resource_version, true ); $this->manual_script_load($key, $file); } } if (count($this->js_code_noncachable)) { // load non cachable javascript code echo implode(" ", $this->js_code_noncachable); } // dynamic footer javascript that can be cached $cache_slug = "essb-js-footer"; if (isset($post)) { if (defined('ESSB3_CACHE_ACTIVE_RESOURCE')) { $cache_key = $cache_slug . $post->ID; $cached_data = ESSBDynamicCache::get_resource($cache_key, 'js'); if ($cached_data != '') { echo "<script type='text/javascript' src='" . $cached_data . "' defer></script>"; return; } } } //$js_code = implode(" ", $this->js_code); $js_code = ''; foreach ($this->js_code as $single) { $js_code .= $single; } if (isset($post)) { if (defined('ESSB3_CACHE_ACTIVE_RESOURCE')) { $cache_key = $cache_slug . $post->ID; ESSBDynamicCache::put_resource($cache_key, $js_code, 'js'); $cached_data = ESSBDynamicCache::get_resource($cache_key, 'js'); if ($cached_data != '') { echo "<script type='text/javascript' src='" . $cached_data . "' defer></script>"; return; } } } echo '<script type="text/javascript">'; echo $js_code; echo '</script>'; }