PageSourceSearch

https://www.grantforward.com/public/js/part/search/sponsor_filter/EventHandlers.js?v=284

js grantforward.com collected 2026-09-24 18:37:25 UTC 9,192 bytes, 246 lines download raw bytes

1var SponsorFilterEventHandlers = SponsorFilterEventHandlers || function(rootOb) {
2	//var dataHandler = rootOb.dataHandler;
3	//var renderer = rootOb.renderer;
4	var eventHandlers = {
5		midleware: function(e, callback) {
6      var target = $(e.target);
7      var rootPanel = target.closest(rootOb.elements['selectedsponsorsList']);
8      var rootPanelID = rootPanel? $(rootPanel).attr('id') : '';
9      //check which panel the target belong to: exclude or include
10      if (rootPanelID == 'included-sponsor-list') {
11        rootOb.workingOnExclude = false;
12        rootOb.currentContext = rootOb.context.included;
13      } else if (rootPanelID == 'excluded-sponsor-list') {
14        rootOb.workingOnExclude = true;
15        rootOb.currentContext = rootOb.context.excluded;
16      }
17      //if call back then call back
18      if (typeof(callback) == 'function') {
19        callback(e);
20      }
21    },
22    forceSearch: function() {
23      //call the method to force the search on the interface
24      if (rootOb.noreactive) return;
25      rootOb.query.remove_offset();
26      $(document).trigger('force_search');
27    },
28    onListButtonClick: function(e) {
29      //open the list
30      var btnElm = e.target;
31      if ($(btnElm).hasClass('disabled')) {
32        return;
33      }
34      _trackGSEvent(
35        rootOb.eventCategory,
36        'sponsor_list_opened',
37        ''
38      );
39      // process for include content data
40      rootOb.pendingContent = rootOb.getSelectedContent();
41      rootOb.pendingContentCount = 0;
42      for (var item in rootOb.pendingContent) {
43        if (!rootOb.pendingContent.hasOwnProperty(item)) {
44          continue;
45        }
46        rootOb.pendingContentCount++;
47      }
48      rootOb.renderer.renderCounter();
49      //clear all filter
50      rootOb.elm('popup.filter.name').val('');
51      rootOb.elm('popup.filter.type').val('');
52      rootOb.dataHandler.resetSponsorPageState();
53      rootOb.renderer.renderChildNav();
54      eventHandlers.loadPage(1);
55
56      if ( rootOb.workingOnExclude === true ){
57        rootOb.elm('popup.result.add').text('Exclude').attr('aria-label', 'Exclude Selected Items and Close Sponsor List');
58      }else{
59        rootOb.elm('popup.result.add').text('Include').attr('aria-label', 'Include Selected Items and Close Sponsor List');
60      }
61      rootOb.elm('popupModal').modal('show');
62    },
63    onClearButtonClick: function(e) {
64      rootOb.dataHandler.removeAll();
65      rootOb.renderer.renderAllTags();
66      //check selected entry number to display/hide clear button
67      rootOb.renderer.renderButtonByStatus();
68      rootOb.dataHandler.syncToQueryObject();
69      eventHandlers.forceSearch();
70    },
71    onSubmitSponsor: function() {
72      //save to selected things
73      rootOb.updateSelectedContent();
74      eventHandlers._fireGAEvent(rootOb.pendingContent);
75      //render items
76      rootOb.renderer.renderAllTags();
77      //check selected entry number to display/hide clear button
78      rootOb.renderer.renderButtonByStatus();
79      //change query object and search
80      rootOb.dataHandler.syncToQueryObject();
81      eventHandlers.forceSearch();
82      //close popup
83      rootOb.elm('popupModal').modal('hide');
84    },
85    onRemoveSponsor: function(e) {
86      var currentElm = $(e.currentTarget);
87      var code = currentElm.attr('js-code');
88      _trackGSEvent(
89        rootOb.eventCategory,
90        'sponsor_removed',
91        code
92      );
93      currentElm.closest(rootOb.elements['item']).remove();
94      rootOb.dataHandler.removeSponsorEntry(code, eventHandlers.forceSearch);
95    },
96    _fireGAEvent: function(sponsors) {
97      var results = [];
98      if (typeof(sponsors) == 'object') {
99        for (var i in sponsors) {
100          if (!sponsors.hasOwnProperty(i)) {
101            continue;
102          }
103          results.push(i);
104        }
105      } else {
106        results.push(sponsors);
107      }
108      _trackGSEvent(
109        rootOb.eventCategory,
110        'sponsor_added',
111        results.join(', ')
112      );
113    },
114    onClickExclude: function(event, noFocus) {
115      if ( rootOb.elm('exclude.container').hasClass('hidden') ){
116        eventHandlers._showExcludePanel();
117        setTimeout(function(){
118          rootOb.elm('autocompleteInputExclude').focus();
119        }, 200);
120      }else{
121        eventHandlers._hideExcludePanel();
122      }
123    },
124      _showExcludePanel: function(){
125        rootOb.elm('exclude.container').removeClass('hidden');
126        rootOb.elm("btnExclude").text("Hide Exclusion Search");
127      },
128      _hideExcludePanel: function(){
129        rootOb.elm('exclude.container').addClass('hidden');
130        rootOb.elm("btnExclude").text("Show Exclusion Search");
131      },
132    onPageChange: function(e, originalEvent, type, page) {
133      eventHandlers.loadPage(page);
134    },
135    loadPage: function(number, parentId, parentName, direction) {
136      clearTimeout(rootOb.sponsorFilterTimeout);
137      rootOb.sponsorFilterTimeout = setTimeout(function() {
138        rootOb.dataHandler.loadSponsorPage(
139          number,
140          eventHandlers.beforePageLoaded,
141          eventHandlers.onPageLoaded,
142          eventHandlers.onLoadPageNoResult,
143          eventHandlers.onLoadPageError,
144          eventHandlers.onLoadPageComplete,
145          parentId,
146          parentName,
147          direction
148        );
149      }, 400);
150    },
151    beforePageLoaded: function() {
152      rootOb.elm('popup.result.paginator').addClass('hidden');
153      rootOb.elm('popup.result.noResult').addClass('hidden');
154      rootOb.elm('popup.result.loading').removeClass('hidden');
155      rootOb.elm('popup.result.content').html('');
156    },
157    onPageLoaded: function(data, count, page) {
158      rootOb.renderer.populateSponsorResult(data);
159      var totalPageNum = Math.ceil(count / rootOb.config.SPONSOR_PER_PAGE);
160      if (totalPageNum > 0) {
161        rootOb.elm('popup.result.paginator').bootstrapPaginator({
162          currentPage: page,
163          totalPages: totalPageNum,
164          bootstrapMajorVersion: 3,
165          onPageClicked: eventHandlers.onPageChange,
166          pageUrl: '#sponsor-query-table'
167        });
168        rootOb.elm('popup.result.paginatorCont').removeClass('hidden');
169      }
170    },
171    onLoadPageError: function() {
172      rootOb.elm('popup.result.noResult').html('There are some problems getting the Sponsor entries! Please try again in a short while!').removeClass('hidden');
173    },
174    onLoadPageNoResult: function() {
175      rootOb.elm('popup.result.noResult').html('No Sponsor matched your criteria! Please try again!').removeClass('hidden');
176    },
177    onLoadPageComplete: function() {
178      rootOb.elm('popup.result.loading').addClass('hidden');
179    },
180    onFilterNameChange: function() {
181      rootOb.filterQuery.sname = jQuery.trim(rootOb.elm('popup.filter.name').val());
182      eventHandlers.loadPage(1);
183    },
184    onFilterTypeChange: function() {
185      rootOb.filterQuery.positive = jQuery.trim(rootOb.elm('popup.filter.type').val());
186      eventHandlers.loadPage(1);
187    },
188    onResultRowClick: function(e) {
189      e.stopPropagation();
190      var currentElm = $(e.currentTarget);
191      var rowElm = currentElm.closest(rootOb.elements['popup.result.content.item']);
192      var checkboxElm = rowElm.find(rootOb.elements['popup.result.checkedIcon']);
193      var code = rowElm.attr('js-code');
194      var popupSelectedSponsorClass = rootOb.currentContext.popupSelectedSponsorClass;
195      if (rowElm.hasClass(popupSelectedSponsorClass)) {
196        rowElm.removeClass(popupSelectedSponsorClass);
197        currentElm.attr('aria-checked', 'false');
198        checkboxElm.addClass('hidden');
199        //this is a deselection, we will remove this from the temporary content
200        if (typeof(rootOb.pendingContent[code]) != 'undefined') {
201          delete rootOb.pendingContent[code];
202          rootOb.pendingContentCount--;
203        }
204        rootOb.renderer.renderCounter();
205      } else {
206        rowElm.addClass(popupSelectedSponsorClass);
207        currentElm.attr('aria-checked', 'true');
208        checkboxElm.removeClass('hidden');
209        //and this is the reverse
210        rootOb.pendingContent[code] = rootOb.currentContext.itemValue;
211        rootOb.pendingContentCount++;
212        rootOb.renderer.renderCounter();
213      }
214      currentElm.blur().focus();
215    },
216    onSubItemClick: function(e) {
217      e.stopPropagation();
218    	var currentElm = $(e.target);
219      if(!currentElm.hasClass('js-sponsor-picker-subitem')){
220        currentElm = currentElm.closest('.js-sponsor-picker-subitem');
221      }
222    	var parentId = currentElm.attr('js-parent');
223    	var parentName = currentElm.attr('js-parent-name');
224    	var direction = 'down';
225    	if (parentId && parentName) {
226    		eventHandlers.loadPage(1, parentId, parentName, direction);
227    	}
228    },
229    onUpButtonClick: function(e) {
230    	var direction = 'up';
231    	eventHandlers.loadPage(page=1, null, null, direction);
232    },
233    onTopButtonClick: function(e) {
234    	var direction = '__top__';
235    	eventHandlers.loadPage(page=1, null, null, direction);
236    },
237    onPopupModalClose: function(e){
238      if ( rootOb.workingOnExclude === false ){
239        rootOb.elm('selectBtns').focus();
240      }else{
241        rootOb.elm('selectBtns').focus();
242      }
243    }
244	};
245	return eventHandlers;
246};

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.