PageSourceSearch

https://www.saint-erblon.fr/wp-content/themes/noyau/assets/js/PostsQuery/posts_pagination.js?ver=6.8.7

js saint-erblon.fr collected 2026-10-02 20:49:40 UTC 11,735 bytes, 270 lines download raw bytes

1ready(() => {
2
3    // Get params from WordPress wp_localize_script (Noyau\Script)
4    let currentPage = Number(PostsQueryParams.current_page)
5
6    // Get the containers' ID
7    let loadMoreBTN = document.getElementById('load-older-posts')
8    let listingContainer = document.getElementById('post_publications')
9    let countPostPerPage = document.getElementById('posts_per_page')
10    let $archiveInformation = document.getElementById('archivePage')
11    let $customFilters = document.querySelectorAll('.filter_custom .filter__custom-container ul')
12    // Lire postsPerPage depuis data-postsperpage si disponible,
13    // sinon depuis #posts_per_page au chargement (= taille de page avant tout clic)
14    let postsPerPage = 10
15    if ($archiveInformation) {
16        postsPerPage = parseInt($archiveInformation.dataset.postsperpage) || 10
17    } else if (countPostPerPage) {
18        postsPerPage = parseInt(countPostPerPage.innerHTML) || 10
19    }
20
21    let consultationState = ''
22    if (!!$archiveInformation) {
23        consultationState = $archiveInformation.dataset.state
24    }
25
26    // Get all the filters posts by categorie buttons
27    let categoryButtons = document.getElementsByClassName('button--filter')
28
29    // Get the page CPT
30    if (!!listingContainer) {
31        let cpt = listingContainer.dataset.cpt
32
33
34        // Get the href of the next page only to know if the button should be
35        // displayed or not
36        let nextPage
37        if (loadMoreBTN) {
38            nextPage = loadMoreBTN.dataset.href
39        }
40
41        // Init the PostsQuery Class
42        let Query = new PostsQuery()
43        Query._APIRoute = 'postsQuery'
44        if (cpt) {
45            Query.URLQuery = `?systemeParams=${cpt}`
46        } else {
47            Query.URLQuery = '?'
48        }
49
50        // Execute the fetch API on click on loadMoreBTN
51        !!loadMoreBTN && (
52            loadMoreBTN.addEventListener('click', async () => {
53                if (nextPage.length > 0 || true) {
54
55
56                    // Get the parameter 'page' inside the URL
57                    const queryString = window.location.search
58                    const urlParams = new URLSearchParams(queryString)
59                    let urlPage = urlParams.get('pages')
60                    // Increment the currentPage each time the button is clicked
61                    urlPage = urlPage ? parseInt(urlPage) : 1
62                    currentPage = urlPage + 1
63
64                    // Get the first number of posts (before fetching
65                    // on API)
66                    let countPostPerPage_HTML = countPostPerPage.innerHTML
67                    let countPostPerPage_INT = parseInt(countPostPerPage_HTML)
68                    let category = cpt === 'post' || urlParams.get('category') ? urlParams.get('category') : urlParams.get(cpt + '_category')
69
70
71                    // Init the params to build the API endpoint (= url)
72                    let orderBy = 'post_date'
73                    if (cpt === "documents") {
74                        orderBy = 'meta_value'
75                    }
76
77                    const params = {
78                        pages: currentPage,
79                        cpt: cpt,
80                        numberPosts: postsPerPage,
81                        orderBy: orderBy,
82                        order: 'DESC',
83                        post_status: ['publish'],
84                    }
85
86
87                    // Utiliser la catégorie forcée si présente (page restreinte sans ?category= dans l'URL)
88                    if ($archiveInformation && $archiveInformation.dataset.forcedCategory && !category) {
89                        category = $archiveInformation.dataset.forcedCategory
90                    }
91
92                    if (category) {
93                        params.category = category
94                    }
95
96                    // Add specific filters (date, subcategories....)
97                    let subCategories = urlParams.get('subCategories')
98                    if (subCategories) {
99                        params.subCategories = subCategories
100                    }
101
102                    let months = urlParams.get('months')
103                    if (months) {
104                        params.months = months
105                    }
106
107                    let years = urlParams.get('years')
108                    if (years) {
109                        params.years = years
110                    }
111
112                    let dateRange = urlParams.get('date')
113                    if (dateRange) {
114                        params.date = dateRange
115                    }
116
117                    let startDate = urlParams.get('startDate')
118                    if (startDate) {
119                        params.startDate = startDate
120                    }
121
122                    let endDate = urlParams.get('endDate')
123                    if (endDate) {
124                        params.endDate = endDate
125                    }
126
127                    let keyword = urlParams.get('keyword')
128                    if (keyword) {
129                        params.keyword = keyword
130                    }
131
132                    if (!!$customFilters) {
133                        $customFilters.forEach(function ($customFilter) {
134                            let filterParam = $customFilter.closest('.filter_custom').querySelector('.filter__input-container input').getAttribute('id')
135                            let filterParamValue = urlParams.get(filterParam)
136                            if (filterParamValue) {
137                                params[filterParam] = filterParamValue
138                            }
139                        })
140                    }
141
142                    if (!!$archiveInformation) {
143                        params.orderBy = $archiveInformation.dataset.orderby
144                        params.order = $archiveInformation.dataset.order ?? ''
145                        let $metakey = $archiveInformation.dataset.metakey
146                        if ($metakey) {
147                            params.metaKey = $metakey
148                        }
149                    }
150
151                    if (consultationState) {
152                        params.state = consultationState
153                    }
154
155                    // Get API endpoint (= url)
156                    let URL = Query.getURL(params)
157
158                    // Fetch on the API
159                    const fetchAPI = Query.fetchAPI(URL, 'GET').then(
160                        data => {
161                            // Store the pagination_infos' elements inside variables
162                            let postsPerPage = data.pagination_infos.postsPerPage
163                            let foundPosts = data.pagination_infos.foundPosts
164                            let pages = data.pagination_infos.pages
165                            let postCount = data.pagination_infos.postCount
166
167                            // Get the postCount after the fetch and display it
168                            countPostPerPage.innerHTML = Query.getCount(
169                                postCount, countPostPerPage_INT, true)
170
171                            // Get the value of canPaginate function (true/false)
172                            let canPaginate = Query.canPaginate(postsPerPage, foundPosts, pages)
173
174                            // Delete the load more button
175                            if (loadMoreBTN) {
176                                if (canPaginate === false) {
177                                    Query.fadeOut(loadMoreBTN)
178                                } else {
179                                    Query.fadeIn(loadMoreBTN)
180                                }
181                            }
182
183                            // Append posts
184                            Query.appendPosts(data.posts, listingContainer, true)
185
186                            // Push args in URL
187                            // Init the Query.URLArgs object with the sub-category entry
188                            Query.URLArgs.pages = {}
189                            Query.URLArgs.pages.parameterValue = [pages]
190
191                            //let category = window.categoryID ? [window.categoryID] : [urlParams.get('category')]
192                            let subCategories = urlParams.get('subCategories')
193
194                            if (category) {
195                                Query.URLArgs.category = {}
196                                Query.URLArgs.category.parameterValue = category
197                            } else {
198                                delete Query.URLArgs.category
199                            }
200
201                            if (subCategories) {
202                                Query.URLArgs.subCategories = {}
203                                Query.URLArgs.subCategories.parameterValue = subCategories
204                            }
205
206                            let months = urlParams.get('months')
207                            if (months) {
208                                Query.URLArgs.months = {}
209                                Query.URLArgs.months.parameterValue = months
210                            }
211
212                            let years = urlParams.get('years')
213                            if (years) {
214                                Query.URLArgs.years = {}
215                                Query.URLArgs.years.parameterValue = years
216                            }
217
218                            let dateRange = urlParams.get('date')
219                            if (dateRange) {
220                                Query.URLArgs.date = {}
221                                Query.URLArgs.date.parameterValue = dateRange
222                            }
223
224                            let startDate = urlParams.get('startDate')
225                            if (startDate) {
226                                Query.URLArgs.startDate = {}
227                                Query.URLArgs.startDate.parameterValue = startDate
228                            }
229
230                            let endDate = urlParams.get('endDate')
231                            if (endDate) {
232                                Query.URLArgs.endDate = {}
233                                Query.URLArgs.endDate.parameterValue = endDate
234                            }
235
236                            let keyword = urlParams.get('keyword')
237                            if (keyword) {
238                                Query.URLArgs.keyword = {}
239                                Query.URLArgs.keyword.parameterValue = keyword
240                            }
241
242                            if (!!$customFilters) {
243                                $customFilters.forEach(function ($customFilter) {
244                                    let filterParam = $customFilter.closest('.filter_custom').querySelector('.filter__input-container input').getAttribute('id')
245                                    let filterParamValue = urlParams.get(filterParam)
246                                    if (filterParamValue) {
247                                        Query.URLArgs[filterParam] = {}
248                                        Query.URLArgs[filterParam].parameterValue = filterParamValue
249                                    }
250                                })
251                            }
252
253                            document.querySelectorAll('main a[href^="mailto:"]:not(.share-mail)').forEach(e => {
254                                e.href = e.href.replace('[^@]', '@')
255                                e.title = e.title.replace('[^@]', '@')
256                            });
257
258
259                            // Push args in URL
260                            Query.pushSearchArgsInUrl()
261                        },
262                    ).catch(err => {
263                        // TODO handle error to send
264                        console.log(err)
265                    })
266                }
267            })
268        )
269    }
270})

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.