{"size": 2655, "ext": "js", "max_stars_repo_path": "build/assets/bieAutocomplete.unminified.js", "max_stars_repo_name": "gbiffrance/gbiftogo-hub-", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "build/assets/bieAutocomplete.unminified.js", "max_issues_repo_name": "gbiffrance/gbiftogo-hub-", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "build/assets/bieAutocomplete.unminified.js", "max_forks_repo_name": "gbiffrance/gbiftogo-hub-", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 33.6075949367, "max_line_length": 136, "alphanum_fraction": 0.5758945386}
/* 
 *  Copyright (C) 2011 Atlas of Living Australia
 *  All Rights Reserved.
 * 
 *  The contents of this file are subject to the Mozilla Public
 *  License Version 1.1 (the "License"); you may not use this file
 *  except in compliance with the License. You may obtain a copy of
 *  the License at http://www.mozilla.org/MPL/
 * 
 *  Software distributed under the License is distributed on an "AS
 *  IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 *  implied. See the License for the specific language governing
 *  rights and limitations under the License.
 *
 * // require jquery
//= require_self
 */

/**
 * JQuery on document ready callback
 */
jQuery(document).ready(function() {
    // Autocomplete
    var bieBaseUrl = BC_CONF.bieWebServiceUrl;
    var bieParams = { limit: 100 };
    var autoHints = BC_CONF.autocompleteHints; // expects { fq: "kingdom:Plantae" }
    $.extend( bieParams, autoHints ); // merge autoHints into bieParams
    jQuery(":input#taxaQuery, :input#solrQuery, :input#taxa, :input.name_autocomplete").autocomplete(bieBaseUrl + '/search/auto.json', {
        extraParams: bieParams,
        dataType: 'json',
        parse: function(data) {
            var rows = new Array();
            data = data.autoCompleteList;
            for(var i=0; i<data.length; i++){
                rows[i] = {
                    data:data[i],
                    value: data[i].guid,
                    result: data[i].matchedNames[0]
                };
            }
            return rows;
        },
        matchSubset: false,
        formatItem: function(row, i, n) {
            return row.matchedNames[0];
            //return row.name;
        },
        cacheLength: 10,
        minChars: 3,
        scroll: false,
        max: 10,
        selectFirst: false
    }).result(function(event, item) {
        // user has selected an autocomplete item
        //console.log("item", item);
        $('input#lsid').val(item.guid);
    });

    // search submit
    jQuery("#solrSearchFormOFF").submit(function(e) {
        e.preventDefault();
        var lsid = $("input#lsid").val();
        var query = $("input#solrQuery").val();
        // add q param to current URL hash for back button support
        var hash = window.location.hash;
        window.location.hash = hash + "/q=" + query;
        var url;
        if (lsid) {
            // redirect to taxon search if lsid
            url = contextPath + "/occurrences/taxa/" + lsid;
        } else {
            // normal full text search
            url = contextPath + "/occurrences/search?q=" + query;
        }
        window.location.href = url;
    });
});

