PageSourceSearch

http://www.edukenya.org/Search/js/frontend/modules/SearchResults.js?1790831603

js edukenya.org collected 2026-10-04 05:43:54 UTC 6,432 bytes, 168 lines download raw bytes

1/**
2 * @author Softped Development Team <[email protected]>
3 */
4jQuery.namespace( 'SS.com.Search.frontend.modules' );
5
6/**
7 * Control the search module form
8 * @param formName - The name of the search form
9 * @constructor
10 */
11
12SS.com.Search.frontend.modules.SearchResults = function( formName ){
13    var me = this;
14    this.form = $('form[name="' + formName + '"]');
15    this.formHelper = this.form.data('formHelper');
16    this.fieldsContainer = this.form.parents('.search-modules-results-fields');
17    this.field = this.form.find('input[name="query"]');
18    this.init();
19};
20
21SS.com.Search.frontend.modules.SearchResults.prototype = {
22
23    /**
24     * Init event listeners
25     */
26    init: function()
27    {
28        var me = this;
29        // submit the search form when search button is pressed
30        this.field.siblings('.form-field-button.search').on('click',function(){
31            me.form.submit();
32        });
33
34        // show the clear button on keyup
35        if(this.field.val() && this.field.val().length > 0){
36            me.field.siblings('.form-field-button.reset').fadeIn(200);
37        }
38        this.field.on('keyup',function(){
39            var queryVal = me.field.val();
40            if(queryVal.length > 0){
41                me.field.siblings('.form-field-button.reset').fadeIn(200);
42            }else{
43                me.field.siblings('.form-field-button.reset').fadeOut(200);
44            }
45        });
46        
47        // enable autocomplete
48        if (this.field.hasClass('autocomplete')) {
49            var cache = {};
50            this.field.autocomplete({
51                minLength: 3,
52                source: function( request, response ) {
53                    var term = request.term;
54                    if ( term in cache ) {
55                        response( cache[ term ] );
56                        return;
57                    }
58                    
59                    var data = $.extend(request, {_moduleItemId: me.fieldsContainer.data('module-item-id')});
60                    $.getJSON( SS.route('Search', 'Search', 'autocomplete', null), data, function( data, status, xhr ) {
61                        var records = data.records;
62                        cache[ term ] = records;
63                        response( records );
64                    });
65                },
66                select: function( event, ui ) {
67                    window.location.href = ui.item.url;
68                    return false;
69                }
70            }).data("ui-autocomplete")._renderItem = function (ul, item) {
71                return $( "<li>" )
72                    .append( $( "<a>" ).html( item.label ) )
73                    .appendTo( ul );
74            };
75            
76        }
77
78        // toggle checked CSS class on checkbox labels
79        this.form.find('[type="checkbox"]').on('change', function(){
80            if($(this).prop('checked')){
81                $(this).closest('label').addClass('checked');
82            }else{
83                $(this).closest('label').removeClass('checked');
84            }
85        });
86
87        // Submit search when dropdown filter is changed (if it's configured like that in module settings)
88        this.form.find('.page-load-on-filter-change .form-input-holder select').on("change",function(){
89            setTimeout(function() {
90                me.form.submit();
91            },500);
92        });
93
94        // Submit search when multiselect filter is changed (if it's configured like that in module settings)
95        // Note: Pretty bad solution because tags are loaded with ajax so it's hard to add events to them
96        this.form.find('.page-load-on-filter-change .multiselect-options').on("click",function(e){
97            if ($(e.target).is("label") || $(e.target).is("input[type=checkbox]")) {
98                setTimeout(function() {
99                    me.form.submit();
100                },500);
101            }
102        });
103
104        // Reload page when page limit is changed
105        this.form.find('.filters-actions select[name="limit"]').on('change', function(event){
106            setTimeout(function() {
107                me.form.submit();
108            },500);
109        });
110    },
111
112    reloadPage: function() {
113        this.form.submit();
114    },
115
116    clearCheckboxes: function(el) {
117        $(el).parent('.form-input-holder').find('input[type=checkbox]:checked').removeAttr('checked');
118        this.reloadPage();
119    },
120
121    // For displaying custom tag name based on tags aggregation
122    // when displaying tags with Ajax from SS.com.Tags.frontend.form.Helper.
123    // Tags should be displayed directly in the view not through Ajax so this might not be used at all.
124    tagLabelCallback: function(label, record, metaData) {
125        var id = record[metaData.record].id,
126            count = SS.com.Search.frontend.modules.SearchResults.prototype.getTagCount(id);
127        if (count === null) {
128            return label;
129        }
130        return label + ' (' + count + ')';
131    },
132    getTagCount: function(tagId) {
133        if (typeof(SS.com.Search.frontend.modules.SearchResults.prototype.tagsCount[tagId]) != 'undefined') {
134            return parseInt(SS.com.Search.frontend.modules.SearchResults.prototype.tagsCount[tagId]);
135        }
136        return null;
137    },
138    tagsCount: {}
139};
140
141
142SS.com.Search.frontend.modules.ResetSearch = function( module_id, settings ) {
143    if(settings == 1) {
144
145        $(document).find('.reset-search-icon').bind('click', function( event ) {
146
147            var url = SS.route('Search', 'Search', 'resultsModule', null, false) + '?_moduleItemId=' + module_id;
148
149            $('.search-modules-results-container').html(__d('search','Loading...'));
150            $('.search-modules-results-container').addClass('content-loading');
151
152            $.ajax( {
153                url: url
154            })
155                .done(function( data ) {
156                    $('.search-modules-results-container').removeClass('content-loading');
157                    $('.search-modules-results-default-view .search-modules-results-fields').html( data );
158
159//                    $('.search-modules-results-container').html( data );
160
161                    // $('.infinite-container').waypoint('infinite');
162                    $('.search-modules-results-container').html(
163                        $('.search-modules-results-default-view .search-modules-results-fields .search-modules-results-container').html()
164                    );                 
165                });
166        });
167    }
168}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.