src/jquery.azuresearch.js
//Load the facets according to the results
Load the facets according to the results
Load the facets according to the results
function loadFacets(data) {
        var fs = ls.facets;
        var c = $(fs.container);
        if (!c || !data["@search.facets"])
            return;
        c.html('');
        $(ls.searchParms.facets).each(function (i, v) {
            if (v.indexOf(',') != -1)
                v = v.split(',')[0];
            if (data["@search.facets"][v]) {
                var tt = ls.facetsDictionary && ls.facetsDictionary[v] ?
                    ls.facetsDictionary[v] : v;
                var title = $(fs.title).addClass(fs.titleClass).text(tt);
                if (fs.titleWrapper) {
                    title = $(fs.titleWrapper).addClass(fs.titleWrapperClass).append(title);
                }
                c.append(title);
                title.on('click', fs.titleOnClick);
                var w = $(fs.wrapperContainer).addClass(fs.wrapperContainerClass);
                c.append(w);
                var countFacets = 0;
                $(data["@search.facets"][v]).each(function (j, k) {                    
                    var facetLabel = k.value != '' ? k.value : fs.emptyFacetText;
                    var f = $(fs.facet)
                        .addClass(fs.facetClass)
                        .html(facetLabel)
                        .on('click', fs.facetOnClick)
                        .data('azuresearchFacetName', v)
                        .data('azuresearchFacetValue', k.value);
                    if (fs.showCount && ls.facets.countWrapper) {
                        $(ls.facets.countWrapper)
                            .text("(" + k.count + ")")
                            .addClass(ls.facets.countWrapperClass)
                            .appendTo(f);
                    } else if (fs.showCount) {
                        f.append(" (" + k.count + ")");
                    }
                    if (ls.facetsSelected.indexOf(v + '|' + k.value) != -1)
                        return true;
                    if (fs.wrapper)
                        $(fs.wrapper).addClass(fs.wrapperClass).append(f).appendTo(w);
                    else
                        w.append(f);
                    countFacets++;
                });
                if (fs.groupWrapper) {
                    var gw = $(fs.groupWrapper).addClass(fs.groupWrapperClass);
                    c.append(gw);
                    title.appendTo(gw);
                    w.appendTo(gw);
                }
                if (countFacets == 0)
                    title.remove();
            }
        });
    }
function loadFacets ( data ) { var fs = ls . facets ; var c = $ ( fs . container ) ; if ( ! c || ! data [ "@search.facets" ] ) return ; c . html ( '' ) ; $ ( ls . searchParms . facets ) . each ( function ( i , v ) { if ( v . indexOf ( ',' ) != - 1 ) v = v . split ( ',' ) [ 0 ] ; if ( data [ "@search.facets" ] [ v ] ) { var tt = ls . facetsDictionary && ls . facetsDictionary [ v ] ? ls . facetsDictionary [ v ] : v ; var title = $ ( fs . title ) . addClass ( fs . titleClass ) . text ( tt ) ; if ( fs . titleWrapper ) { title = $ ( fs . titleWrapper ) . addClass ( fs . titleWrapperClass ) . append ( title ) ; } c . append ( title ) ; title . on ( 'click' , fs . titleOnClick ) ; var w = $ ( fs . wrapperContainer ) . addClass ( fs . wrapperContainerClass ) ; c . append ( w ) ; var countFacets = 0 ; $ ( data [ "@search.facets" ] [ v ] ) . each ( function ( j , k ) { var facetLabel = k . value != '' ? k . value : fs . emptyFacetText ; var f = $ ( fs . facet ) . addClass ( fs . facetClass ) . html ( facetLabel ) . on ( 'click' , fs . facetOnClick ) . data ( 'azuresearchFacetName' , v ) . data ( 'azuresearchFacetValue' , k . value ) ; if ( fs . showCount && ls . facets . countWrapper ) { $ ( ls . facets . countWrapper ) . text ( "(" + k . count + ")" ) . addClass ( ls . facets . countWrapperClass ) . appendTo ( f ) ; } else if ( fs . showCount ) { f . append ( " (" + k . count + ")" ) ; } if ( ls . facetsSelected . indexOf ( v + '|' + k . value ) != - 1 ) return true ; if ( fs . wrapper ) $ ( fs . wrapper ) . addClass ( fs . wrapperClass ) . append ( f ) . appendTo ( w ) ; else w . append ( f ) ; countFacets ++ ; } ) ; if ( fs . groupWrapper ) { var gw = $ ( fs . groupWrapper ) . addClass ( fs . groupWrapperClass ) ; c . append ( gw ) ; title . appendTo ( gw ) ; w . appendTo ( gw ) ; } if ( countFacets == 0 ) title . remove ( ) ; } } ) ; }
Load the facets according to the results
Load the facets according to the results
//Check if the containers was defiend and if the facets were part of the results //Ignore the faceting options if any //Facet's Title //Facets container //Facets //Create the facet //Counter //Do not display selected facets //Group Wrapper