(function($) {

  $(document).on("turbolinks:load", function() {
    $(".recipe-view ul.ingredients").checkable();
    $(".recipe-view div.steps ol").checkable();

    var $searchBtn = $("#recipe_index_search_button");

    if ($searchBtn.length) {
        var $form = $("#search_form");
        var $nameInput = $("#name_search");
        var $tagsInput = $("#tags_search");

        $form.submit(function() {
            $("#criteria_name").val($nameInput.val());
            $("#criteria_tags").val($tagsInput.val());
        });

        $searchBtn.click(function(evt) {
            $form.submit();
        });

        $nameInput.add($tagsInput).on('keydown', function(evt) {
            if (evt.which == 13) {
                console.log('keydown enter pressed');
                $form.submit();
            }
        });

    }
  });

})(jQuery);
