1'use strict'; 2 3/* ===================================================================================== @preserve = 4 ___ _ _ _ 5/ || | | | | | 6\__ | | | | | | __ 7/ |/ |/_) |/ / \_/\/ 8\___/|__/| \_/|__/\__/ /\_/ 9 |\ 10 |/ 11Ajaxinate 12version v2.0.11 13https://github.com/Elkfox/Ajaxinate 14Copyright (c) 2017 Elkfox Co Pty Ltd 15https://elkfox.com 16MIT License 17================================================================================================= */ 18 19var Ajaxinate = function ajaxinateConstructor(config) { 20 var settings = config || {}; 21 /* 22 pagination: Selector of pagination container 23 method: [options are 'scroll', 'click'] 24 container: Selector of repeating content 25 offset: 0, offset the number of pixels before the bottom to start loading more on scroll 26 loadingText: 'Loading', The text changed during loading 27 callback: null, function to callback after a new page is loaded 28 */ 29 var defaultSettings = { 30 pagination: '#AjaxinatePagination', 31 method: 'scroll', 32 container: '#AjaxinateLoop', 33 offset: 0, 34 loadingText: 'Loading', 35 callback: null 36 }; 37 // Merge configs 38 this.settings = Object.assign(defaultSettings, settings); 39 40 // Bind 'this' to applicable prototype functions 41 this.addScrollListeners = this.addScrollListeners.bind(this); 42 this.addClickListener = this.addClickListener.bind(this); 43 this.checkIfPaginationInView = this.checkIfPaginationInView.bind(this); 44 this.stopMultipleClicks = this.stopMultipleClicks.bind(this); 45 this.destroy = this.destroy.bind(this); 46 47 // Set up our element selectors 48 this.containerElement = document.querySelector(this.settings.container); 49 this.paginationElement = document.querySelector(this.settings.pagination); 50 51 this.initialize(); 52}; 53 54Ajaxinate.prototype.initialize = function initializeTheCorrectFunctionsBasedOnTheMethod() { 55 // Find and initialise the correct function based on the method set in the config 56 if (this.containerElement) { 57 var initializers = { 58 click: this.addClickListener, 59 scroll: this.addScrollListeners 60 }; 61 initializers[this.settings.method](); 62 } 63}; 64 65Ajaxinate.prototype.addScrollListeners = function addEventListenersForScrolling() { 66 67 if (this.paginationElement) { 68 document.addEventListener('scroll', this.checkIfPaginationInView); 69 window.addEventListener('resize', this.checkIfPaginationInView); 70 window.addEventListener('orientationchange', this.checkIfPaginationInView); 71 } 72}; 73 74Ajaxinate.prototype.addClickListener = function addEventListenerForClicking() { 75 if (this.paginationElement) { 76 this.nextPageLinkElement = this.paginationElement.querySelector('a'); 77 this.clickActive = true; 78 if (this.nextPageLinkElement !== null) { 79 this.nextPageLinkElement.addEventListener('click', this.stopMultipleClicks); 80 } 81 } 82}; 83 84Ajaxinate.prototype.stopMultipleClicks = function handleClickEvent(event) { 85 event.preventDefault(); 86 if (this.clickActive) { 87 this.nextPageLinkElement.innerHTML = this.settings.loadingText; 88 this.nextPageUrl = this.nextPageLinkElement.href; 89 this.clickActive = false; 90 this.loadMore(); 91 } 92}; 93 94Ajaxinate.prototype.checkIfPaginationInView = function handleScrollEvent() { 95 var top = this.paginationElement.getBoundingClientRect().top - this.settings.offset; 96 var bottom = this.paginationElement.getBoundingClientRect().bottom + this.settings.offset; 97 if (top <= window.innerHeight && bottom >= 0) { 98 this.nextPageLinkElement = this.paginationElement.querySelector('a'); 99 this.removeScrollListener(); 100 if (this.nextPageLinkElement) { 101 this.nextPageLinkElement.innerHTML = this.settings.loadingText; 102 this.nextPageUrl = this.nextPageLinkElement.href; 103 this.loadMore(); 104 } 105 } 106}; 107 108Ajaxinate.prototype.loadMore = function getTheHtmlOfTheNextPageWithAnAjaxRequest() { 109 this.request = new XMLHttpRequest(); 110 this.request.onreadystatechange = function success() { 111 if (this.request.readyState === 4 && this.request.status === 200) { 112 var newContainer = this.request.responseXML.querySelectorAll(this.settings.container)[0]; 113 var newPagination = this.request.responseXML.querySelectorAll(this.settings.pagination)[0]; 114 this.containerElement.insertAdjacentHTML('beforeend', newContainer.innerHTML); 115 this.paginationElement.innerHTML = newPagination.innerHTML; 116 if (this.settings.callback && typeof this.settings.callback === 'function') { 117 this.settings.callback(this.request.responseXML); 118 } 119 this.initialize(); 120 console.log('load2') 121 reviewLoadMore(); 122 } 123 }.bind(this); 124 this.request.open('GET', this.nextPageUrl); 125 this.request.responseType = 'document'; 126 this.request.send(); 127 128}; 129 130Ajaxinate.prototype.removeClickListener = function removeClickEventListener() { 131 this.nextPageLinkElement.addEventListener('click', this.stopMultipleClicks); 132}; 133 134Ajaxinate.prototype.removeScrollListener = function removeScrollEventListener() { 135 document.removeEventListener('scroll', this.checkIfPaginationInView); 136 window.removeEventListener('resize', this.checkIfPaginationInView); 137 window.removeEventListener('orientationchange', this.checkIfPaginationInView); 138}; 139 140Ajaxinate.prototype.destroy = function removeEventListenersAndReturnThis() { 141 // This method is used to unbind event listeners from the DOM 142 // This function is called manually to destroy "this" Ajaxinate instance 143 var destroyers = { 144 click: this.removeClickListener, 145 scroll: this.removeScrollListener 146 }; 147 destroyers[this.settings.method](); 148 return this; 149};
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.