PageSourceSearch

https://starrcompanies.com/-/media/Base-Themes/SearchTheme/Scripts/component-search-load-more.js

js starrcompanies.com collected 2026-09-24 19:06:03 UTC 4,650 bytes, 129 lines download raw bytes

1/**
2 * Loads more component functionality
3 * @module searchLoadMore
4 * @param  {jQuery} $ Instance of jQuery
5 * @param  {Document} document dom document object
6 * @return {Object} list of methods for working with load more component
7*/
8XA.component.search.loadMore = (function ($, document) {
9    /**
10    * This object stores all public api methods
11    * @type {Object.<Methods>}
12    * @memberOf module:searchFacetRangeSlider
13    */
14    var api = {},
15        SearchLoadMoreModel,
16        SearchLoadMoreView;
17    /**
18    * @name module:searchLoadMore.SearchLoadMoreModel
19    * @constructor
20    * @augments Backbone.Model
21    */
22    SearchLoadMoreModel = Backbone.Model.extend(
23        /** @lends module:searchLoadMore.SearchLoadMoreModel.prototype **/
24
25        {
26            /**
27            * Default model options
28            * @default
29            */
30            defaults: {
31                dataProperties: {},
32                sig: []
33            }
34        });
35    /**
36    * @name module:searchLoadMore.SearchLoadMoreView
37    * @constructor
38    * @augments Backbone.View
39    */
40    SearchLoadMoreView = Backbone.View.extend(
41        /** @lends module:searchLoadMore.SearchLoadMoreView.prototype **/
42        {
43            /**
44            * Initially sets data to model and watches events on which
45            * view should be updated
46            * @listens module:XA.component.search.vent~event:results-loaded
47            * @memberof module:searchLoadMore.SearchLoadMoreView
48            */
49            initialize: function () {
50                var dataProperties = this.$el.data(),
51                    that = this;
52
53                if (dataProperties.properties.searchResultsSignature === null) {
54                    dataProperties.properties.searchResultsSignature = "";
55                }
56
57                if (this.model) {
58                    this.model.set('sig', dataProperties.properties.searchResultsSignature.split(','));
59                }
60
61                XA.component.search.vent.on("results-loaded", function (results) {
62                    var sig = that.model.get('sig'),
63                        offset = typeof results.offset !== "undefined" ? results.offset : 0,
64                        i;
65
66                    for (i = 0; i < sig.length; i++) {
67                        if (sig[i] === results.searchResultsSignature) {
68                            if (results.pageSize >= results.dataCount || offset + results.pageSize >= results.dataCount) {
69                                that.$el.hide();
70                            } else {
71                                that.$el.show();
72                            }
73                        }
74                    }
75                });
76            },
77            /**
78            * list of events for Backbone View
79            * @memberof module:searchLoadMore.SearchLoadMoreView
80            * @alias module:searchLoadMore.SearchLoadMoreView#events
81            */
82            events: {
83                'mousedown input': 'loadMore'
84            },
85            /**
86           * Load more search results
87           * @fires  XA.component.search.vent~event:loadMore
88           * @listens module:XA.component.search.vent~event:results-loaded
89           * @memberof module:searchLoadMore.SearchLoadMoreView 
90           * @alias module:searchLoadMore.SearchLoadMoreView#loadMore 
91           */
92            loadMore: function () {
93                var sig = this.model.get('sig'),
94                    i;
95
96                for (i = 0; i < sig.length; i++) {
97                    XA.component.search.vent.trigger('loadMore', {
98                        sig: sig[i]
99                    });
100                }
101            }
102        });
103    /**
104    * For each search facet range slider component on a page creates instance of 
105    * ["SearchLoadMoreModel"]{@link module:searchLoadMore.SearchLoadMoreModel} and 
106    * ["SearchLoadMoreView"]{@link module:searchLoadMore.SearchLoadMoreView} 
107    * @memberOf module:searchLoadMore
108    * @alias module:searchLoadMore.init
109    */
110    api.init = function () {
111        if ($('body').hasClass('on-page-editor')) {
112            return;
113        }
114
115        var searchLoadMore = $('.load-more:not(.initialized)');
116
117        _.each(searchLoadMore, function (elem) {
118            var $el = $(elem),
119                view = new SearchLoadMoreView({ el: $el, model: new SearchLoadMoreModel() });
120
121            $el.addClass("initialized");
122        });
123    };
124
125    return api;
126
127}(jQuery, document));
128
129XA.register('searchLoadMore', XA.component.search.loadMore);

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.