var load = require('load');

/*global google */

function search(cx) {

  function render() {
    var cse = google.search.cse,
      searchBox = document.getElementById('cseSearchBox'),
      searchResults = document.getElementById('cseSearchResults');

    if (searchBox) {
      cse.element.render({
        div: searchBox,
        tag: 'searchbox-only',
        attributes: {
          resultsUrl: '/search.html'
        }
      });
    }
    if (searchResults) {
      cse.element.render({
        div: searchResults,
        tag: 'searchresults-only',
        attributes: {
          linkTarget: '_top' // open links in the same window
        }
      });
    }
  }

  window.__gcse = {
    parsetags: 'explicit',
    callback: function() {
      if (document.readyState == 'complete') {
        render();
      } else {
        google.setOnLoadCallback(render, true);
      }
    }
  };

  load('//www.google.com/cse/cse.js?cx=' + cx, true);
}

module.exports = search;
@@ -68,69 +68,13 @@
 ) %7B%0A
-%0A  function render() %7B%0A    var cse = google.search.cse,%0A     
+  var
  sea
@@ -123,18 +123,16 @@
 hBox'),%0A
-  
     sear
@@ -189,16 +189,73 @@
 lts');%0A%0A
+%0A  function render() %7B%0A    var cse = google.search.cse;%0A%0A
     if (
@@ -664,16 +664,71 @@
  %7D%0A  %7D%0A%0A
+  if (!searchBox && !searchResults) %7B%0A    return;%0A  %7D%0A%0A
   window

fix loading script if not css elements presents