jQuery(function ($) {
  $(document).ready(function () {});

  (function (func) {
    $.fn.replaceWith = function () {
      var $element = this.parent();
      func.apply(this, arguments);
      $element.trigger("content_replaced", arguments);
      return this;
    };
  })($.fn.replaceWith);

  var addclosebutton = function () {
    var $search_result = $(".wpbs_s-search-widget-results");
    var $close_search_results = "<div class='close'>&#x2715</div>";
    $search_result.prepend($close_search_results);
    var search_result_trigger = $(".wpbs_s-search-widget-results .close");
    search_result_trigger.click(function () {
      $(this).parent().hide();
    });
  };

  addclosebutton();
  var $container = $(".search-wrapper");
  $container.on("content_replaced", function (e, args) {
    addclosebutton();
  });
});
