PageSourceSearch

https://www.caritas-zaragoza.org/main-files/themes/101wp-child/mod…/dynamic-content-build.js?ver=1.0.0

js caritas-zaragoza.org collected 2026-09-26 05:49:14 UTC 14,500 bytes, 401 lines download raw bytes

1(function () {
2    'use strict';
3
4    var DynamicContent = function () {
5
6        var $ = jQuery;    
7        var instances = [];
8        var html = [];
9
10        // Layout no-data html
11        html.basic = '<p>Ningún resultado para mostrar</p>';
12
13        var template = '<div class="pdfviewer" style="display: none;">'
14                     + ' <div class="wrapper"><a href="" class="close roll-rotate"><i class="icon icon-close-16x16"></i></a></div>'
15                     + '</div>';
16
17        /* ------------------------------------------------------------------
18         *  DOM READY
19         * ------------------------------------------------------------------ */
20        function onReady() {
21
22            if ($('.pdfviewer').length === 0) {
23                $('body').append(template);
24            }
25
26            $('.pdfviewer .close').on('click', function () {
27                $('.pdfviewer').fadeOut();
28                return false;
29            });
30
31            $('.module.dynamic-content').each(function () {
32                instances.push(initInstance($(this)));
33            });
34
35            setTimeout(function(){
36                Events.publish('EQUALIZE_COLS');
37            }, 1000);
38
39        }
40
41        /* ------------------------------------------------------------------
42         *  UNA INSTANCIA DE MÓDULO DINÁMICO
43         * ------------------------------------------------------------------ */
44        function initInstance(view) {
45
46            var $view, id, data, paged, params;
47
48            $view  = view;
49            id     = $view.data('id');
50            params = window.dataModules[id];
51            data   = window.dataModules[id];
52
53            /* ------------- 1. PUBLICATIONS CAROUSEL ----------------------- */
54            if (params.layout === 'publications') {
55                $view.find('.owl-carousel-content-publications').owlCarousel({
56                    items: 2,
57                    dots: false,
58                    nav: true,
59                    loop: false,
60                    margin: 15,
61                    stagePadding: 0,
62                    responsive: {
63                        0   : { items: 1 },
64                        800 : { items: 2 },
65                        960 : { items: 2 },
66                        1014: { items: 2 }
67                    },
68                    navText: [
69                        '<i class="icon icon-16x16-caritas05"></i>',
70                        '<i class="icon icon-16x16-caritas06"></i>'
71                    ]
72                });
73            }
74
75            /* ------------- 2. UTILIDADES ---------------------------------- */
76            function checkIfThereAreNewItems() {
77                // Find how many items are in total in the query->found_posts and check how many items are in page
78                var found_posts = $view.find("input#found_posts").val();
79                var load_more_items = $view.find( ".load-more-item" ).length;
80
81                // if the number of items is the same that founded post we hide the load more button
82                console.log(found_posts,load_more_items);
83                if(found_posts <= load_more_items) {
84                    $view.find("#load-more").css('display', 'none');
85                    $view.find("#load-more-text").css('display', 'none');
86                }
87                else {
88                    $view.find("#load-more").css('display', 'block');
89                    $view.find("#load-more-text").css('display', 'block');
90                }
91            }
92
93            function openPdfViewer(e) {
94                e.preventDefault();
95                var id = $(this).data('viewer');
96                $('.pdfviewer .wrapper iframe').remove();
97                $('.pdfviewer .wrapper')
98                    .append('<iframe width="400" height="300" src="//e.issuu.com/embed.html#' + id + '" frameborder="0" allowfullscreen></iframe>');
99                $('.pdfviewer').fadeIn();
100            }
101
102            /* ------------- 3. RENDER (MODIFICADO) -------------------------- */
103            function render(responseHtml, filter) {
104                var $response  = $(responseHtml || '');
105                var $container = $view.find('.items-container');
106                var $newItems  = $response.find('.items-container .load-more-container');
107                var isMasonry  = ($response.data('layout') === 'masonry');
108
109                if (filter) $container.empty();
110                if (filter && responseHtml === '') $container.append(html[params.layout]);
111
112                // actualizar contador total
113                var $fTotal = $response.find('input#found_posts');
114                if ($fTotal.length) {
115                    $view.find('input#found_posts').val($fTotal.val());
116                }
117
118                if (responseHtml && $newItems.length > 0) {
119                    $newItems.each(function () {
120    var id = $(this).attr('id');
121    if (!id || $container.find('#' + id).length === 0) {
122        $container.append($(this));
123    }
124});
125
126                    if (isMasonry)  Events.publish('MASONRY_RELOAD');
127                    else            Events.publish('EQUALIZE_COLS');
128
129                    $view.find('.end-results').hide();
130                } else {
131                    // *** CAMBIO IMPORTANTE: recargar si no llega nada nuevo
132                    console.warn('No se han cargado nuevos ítems; recargando página.');
133                    location.reload();
134                }
135
136                checkIfThereAreNewItems();
137            }
138
139            /* ------------- 4. PETICIÓN AJAX ------------------------------- */
140            function sendData(filter) {
141                var $button = $view.find('#load-more').addClass('deactivate loading');
142
143                params.action = 'dynamic_content';
144                if (params.content.split(',').length && !isNaN(params.content.split(',')[0])) {
145                    params.content = params.content
146                        .split(',')
147                        .filter(function (_, i) {
148                            return i >= Number(params.fields_count) * (params.paged - 1);
149                        })
150                        .join(',');
151                }
152
153                $.ajax({
154                    url : params.url,
155                    type: 'POST',
156                    dataType: 'html',
157                    data: params,
158                    beforeSend: function () {
159                        $view.find('[class^=filter_]').removeClass('loading');
160                        $view.find('select[name], input[name]').each(function () {
161                            if ($(this).val()) $(this).closest('[class^=filter_]').addClass('loading');
162                        });
163                    },
164                    complete: function () {
165                        $view.find('[class^=filter_]').removeClass('loading');
166                    }
167                })
168                .done(function (htmlResponse) {
169                    var errObj;
170                    try { errObj = JSON.parse(htmlResponse); } catch (_) { errObj = {}; }
171
172                    if (!errObj.error) {
173                        render(htmlResponse, filter);
174                        $button.removeClass('loading deactivate');
175                        equalizeDynamicCols();
176                    } else {
177                        $button.removeClass('loading');
178                        render(false, filter);
179                    }
180                })
181                .fail(function () {
182                    $button.removeClass('loading deactivate');
183                });
184            }
185
186            /* ------------- 5. FILTROS ------------------------------------- */
187            function filterHasChange() {
188                if (params.show_category_description === 'show_descriptions' &&
189                    $view.find("select[name='category']").val()) {
190
191                    $.post(params.url,
192                           { action: 'show_me_term_info', term_id: $view.find("select[name='category']").val() })
193                    .done(function (html) {
194                        $view.find('#category-description-text').html('<p>' + html + '</p>');
195                        $view.find('.category-description').show();
196                        equalizeDynamicCols();
197                    });
198                }
199                filterLoadContent($(this).attr('name'));
200            }
201
202            function buttonSearchSelected() {
203                if ($view.find('.filters-container input[name="search"]').val()) filterLoadContent();
204            }
205
206            function filterLoadContent(trigger) {
207                params.paged     = 1;
208                params.load_more = false;
209
210                $view.find('.filters-container').find('select, input').each(function () {
211                    var name = $(this).attr('name');
212                    var val  = $(this).val();
213
214                    if (val && parseInt(val) !== 0) {
215                        params[name] = val;
216                    } else {
217                        if (trigger === name) params[name] = 'any';
218                        else delete params[name];
219                    }
220                });
221
222                sendData(true);
223            }
224
225            /* ------------- 6. LOAD-MORE ----------------------------------- */
226            function onLoadMoreClick(e) {
227                e.preventDefault();
228                var $btn = $(this);
229                if ($btn.hasClass('deactivate')) return;
230
231                paged++;
232                params.paged     = paged;
233                params.load_more = true;
234
235                sendData();
236            }
237
238            /* ------------- 7. EQUALIZE COLS ------------------------------- */
239            function equalizeDynamicCols() {
240                var sets = ['.cooperacion-item-container', '.campaigns-item-container'];
241                sets.forEach(function (sel) {
242                    var $cols = $view.find(sel);
243                    if (!$cols.length) return;
244                    var max = 0;
245                    $cols.each(function () {
246                        max = Math.max(max, $(this).find(sel.replace('-container', '-content')).height());
247                    });
248                    $cols.find(sel.replace('-container', '-content')).height(max);
249                });
250            }
251
252            /* ------------- 8. INIT ---------------------------------------- */
253            function init() {
254                $view.find('.filters-container').children()
255                      .find('select, input').on('change', filterHasChange);
256                $view.find('.filters-container button.search').on('click', buttonSearchSelected);
257                $view.find('.items-container').on('click', '[data-viewer]', openPdfViewer);
258
259                paged = params.paged || 1;
260                $view.find('#load-more').on('click', onLoadMoreClick);
261
262                equalizeDynamicCols();
263            }
264
265            init(); // ← ejecutamos la instancia
266        }
267
268        /* ------------------------------------------------------------------
269         *  INICIALIZAR EL MÓDULO GLOBAL
270         * ------------------------------------------------------------------ */
271        $(onReady);
272    };
273
274    DynamicContent();
275
276
277/* ========================================================================
278 *  MASONRY MODULE
279 * ===================================================================== */
280})(jQuery);
281
282'use strict';
283
284var MasonryModule = function () {
285
286    var $ = jQuery;
287    var instances = [];
288
289    function onReady() {
290        $('.dynamic-content[data-layout=masonry]').each(function () {
291            instances.push(initInstance($(this)));
292        });
293    }
294
295    function initInstance(view) {
296        var $view = view;
297        var msnry;
298
299        var instance = {
300            init: function () {
301                msnry = new Masonry($view.find('.items-container')[0], {
302                    itemSelector: '.dynamic-content-masonry',
303                    columnWidth : '.grid-sizer',
304                    gutter      : '.gutter-sizer'
305                });
306            },
307            reload: function () {
308                msnry = null;
309                msnry = new Masonry($view.find('.items-container')[0], {
310                    itemSelector: '.dynamic-content-masonry',
311                    columnWidth : '.grid-sizer',
312                    gutter      : '.gutter-sizer'
313                });
314            }
315        };
316
317        Events.subscribe('MASONRY_RELOAD', instance.reload);
318        instance.init();
319        return instance;
320    }
321
322    $(onReady);
323};
324
325MasonryModule();
326
327
328/* ========================================================================
329 *  TICKER MODULE
330 * ===================================================================== */
331'use strict';
332
333var Ticker = function () {
334
335    var $ = jQuery;
336    var instances = [];
337
338    var TICKER_SPEED            = 4000;
339    var TICKER_INTERACTION_WAIT = 10000;
340
341    function onReady() {
342        $('.dynamic-content[data-layout=ticker]').each(function () {
343            instances.push(initInstance($(this)));
344        });
345    }
346
347    function initInstance(view) {
348
349        var $view = view;
350        var interval;
351        var $items;
352
353        var instance = {
354            init: function () {
355                $items = $view.find('.items .item');
356
357                $view.find('.next').on('click', function () {
358                    resetInterval(); next(); return false;
359                });
360                $view.find('.prev').on('click', function () {
361                    resetInterval(); prev(); return false;
362                });
363
364                startInterval();
365            }
366        };
367
368        function next() {
369            var $current = $items.filter(':visible').first();
370            var $next    = $current.next('.item');
371            if (!$next.length) $next = $items.first();
372
373            $current.fadeOut().promise().then(function () { $next.fadeIn(); });
374        }
375
376        function prev() {
377            var $current = $items.filter(':visible').first();
378            var $prev    = $current.prev('.item');
379            if (!$prev.length) $prev = $items.last();
380
381            $current.fadeOut().promise().then(function () { $prev.fadeIn(); });
382        }
383
384        function startInterval() {
385            clearInterval(interval);
386            interval = setInterval(next, TICKER_SPEED);
387        }
388
389        function resetInterval() {
390            clearInterval(interval);
391            setTimeout(startInterval, TICKER_INTERACTION_WAIT);
392        }
393
394        instance.init();
395        return instance;
396    }
397
398    $(onReady);
399};
400
401Ticker();

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.