Source: components/filter/filter-result/filter-result-element/pagination/search-display-pagination.js

import jQ from 'jquery';
import ProductPagination from "./product-pagination";
import Selector from "../../../../../helpers/selector";
import FilterApi from "../../../../../api/filter-api";
import Globals from "../../../../../helpers/globals";
import SearchResultPanelItem from '../search-result-panel-item';
import SearchResultPanels from '../search-result-panels';
import ProductPaginationDefault from './product-pagination-default';

/**
 * Product pagination default
 * @extends ProductPagination
 */
class SearchDisplayPagination extends ProductPaginationDefault {
	/**
	 * @constructs
	 */
	constructor(element, type) {
		super();
		if (!element) {
			element = Selector.searchPagePagination;
		}
		this.type = type;

		this.$element = jQ(element);
		this.$productList = jQ(Selector.products);
		this.filterResult = this.parent;
	}

	isRender() {
		return Globals.hasOwnProperty('searchDisplay') && Globals.searchDisplay === this.type;
	}

	/**
	 * Render pagination - default type
	 */
	render() {
		this.$element.html(this.compileTemplate());
	}

	/**
	 * Bind the events on the parination - default
	 */
	bindEvents() {
		// Display the pagination block
		this.$element.show();
		// Unbind default event on pagination
		this.$element.find('a').unbind('click');
		this.$element.find('a').on('click', this._onClickEvent.bind(this));
	}

	setData(data, totalProduct, limit, page) {
		if (data) {
			this.data = data;
		}

		var panels = this.parent.searchResultPanels.children;
		var _type = this.type;
		this.panelItem = panels.find((panel) => {
			return panel.type == _type;
		});
		
		this.totalProduct = totalProduct;
		this.limit = limit;
		this.page = page;
		this.paginationType = Settings.getSettingValue('general.paginationType');
	}

	/**
	 * Bind the click event on the pagination link
	 */
	_onClickEvent(event) {
		event.preventDefault();
		Globals.internalClick = true;
		var pageUrl = jQ(event.currentTarget).attr('href');
		// Apply filter
		FilterApi.updateParamsFromUrl(pageUrl);
		FilterApi.setParam('limit', this.limit);
		// Apply filter
		FilterApi.getFilterData('search', this.panelItem._searchPanelCallback.bind(this.panelItem));
		
		// Scroll to top of product list
		jQ('body,html').animate({
			scrollTop: this.$productList.offset().top - 50
		}, 600);
	}
}

export default SearchDisplayPagination;