diff --git a/www/index.php b/www/index.php index ae36a931b321d9034780c1403d19008cd5d84b6f..347755068619a6bc38411a4795b6580d285fd547 100644 --- a/www/index.php +++ b/www/index.php @@ -143,7 +143,7 @@ $maincontent .= renderTemplate($templatePath . 'search-results.tpl.php', array( $initialQuery = json_encode(isset($_GET['q']) ? $_GET['q'] : ''); $context = json_encode($context); -$maincontent .= renderTemplate('templates/end-scripts.tpl.php', array( +$maincontent .= renderTemplate($templatePath . 'end-scripts.tpl.php', array( 'localScriptUrl' => $localScriptUrl, 'googleLoaderUrl' => 'https://cse.google.com/cse.js?cx=' . $search_engine_id, 'initialQuery' => $initialQuery, diff --git a/www/templates/end-scripts.tpl.php b/www/templates/4.1/end-scripts.tpl.php similarity index 100% rename from www/templates/end-scripts.tpl.php rename to www/templates/4.1/end-scripts.tpl.php diff --git a/www/templates/5.0/end-scripts.tpl.php b/www/templates/5.0/end-scripts.tpl.php new file mode 100644 index 0000000000000000000000000000000000000000..a8ae6a8faecb0dc935492b83f7de7c9bb8dcaca8 --- /dev/null +++ b/www/templates/5.0/end-scripts.tpl.php @@ -0,0 +1,32 @@ +<script> +require(['jquery', '<?php echo $localScriptUrl ?>'], function($, UNLSearch) { + var gSearchDefer = $.Deferred(); + window.searchInit = function() { + window.searchInit = $.noop; + gSearchDefer.resolve(google); + }; + + window.__gcse = { + parsetags: 'explicit', + callback: window.searchInit + }; + + $('<script>', { + src: '<?php echo $googleLoaderUrl ?>', + async: 'async', + defer: 'defer', + type: 'text/javascript' + }).appendTo($('body')); + + var $localCss = $('<link>', { + 'href': './css/search-google.css?v=20170404' + }); + + gSearchDefer.done(function(google) { + // ensure this CSS is loaded AFTER google + require(['css!' + $localCss[0].href], function() { + UNLSearch.initialize(<?php echo $initialQuery ?>, <?php echo $localContext ?>) + }); + }); +}); +</script>