PageSourceSearch

https://immersivejournalism.com/wp-content/themes/newsmatic/assets/js/theme.js?ver=1.3.13

js immersivejournalism.com collected 2026-10-03 19:21:28 UTC 16,097 bytes, 389 lines download raw bytes

1/**
2 * Handles theme general events
3 * 
4 * @package Newsmatic
5 * @since 1.0.0
6 */
7jQuery(document).ready(function($) {
8    "use strict"
9    var ajaxUrl = newsmaticObject.ajaxUrl, _wpnonce = newsmaticObject._wpnonce, sttOption = newsmaticObject.stt, query_vars = newsmaticObject.query_vars, paged = newsmaticObject.paged,  stickeyHeader = newsmaticObject.stickey_header;
10    
11    setTimeout(function() {
12        $('body .newsmatic_loading_box').hide();
13    }, 3000);
14
15    var nrtl = false
16    var ndir = "left"
17    if ($('body').hasClass("rtl")) {
18        nrtl = true;
19        ndir = "right";
20    };
21    
22    // theme trigger modal close
23    function newsmaticclosemodal( elm, callback ) {
24        $(document).mouseup(function (e) {
25            var container = $(elm);
26            if (!container.is(e.target) && container.has(e.target).length === 0) callback();
27        });
28    }
29
30    // ticker news slider events
31    var tc = $( ".ticker-news-wrap" );
32    if( tc.length ) {
33        var tcM = tc.find( ".ticker-item-wrap" ).marquee({
34            duration: 15000,
35            gap: 0,
36            delayBeforeStart: 0,
37            direction: ndir,
38            duplicated: true,
39            startVisible: true,
40            pauseOnHover: true,
41        });
42        tc.on( "click", ".newsmatic-ticker-pause", function() {
43            $(this).find( "i" ).toggleClass( "fa-pause fa-play" )
44            tcM.marquee( "toggle" );
45        })
46    }
47
48    // top date time
49    var timeElement = $( ".top-date-time .time" )
50    if( timeElement.length > 0 ) {
51        setInterval(function() {
52            timeElement.html(new Date().toLocaleTimeString())
53        },1000);
54    }
55    
56    // search form and sidebar toggle trigger
57    $( "#masthead" ).on( "click", ".sidebar-toggle-trigger", function() {
58        // $(this).next().addClass('toggle_show');
59        $(this).addClass('slideshow');
60        $('body').addClass('body_show_sidetoggle');
61    });
62    $( "#masthead" ).on( "click", ".sidebar-toggle-trigger.slideshow, .sidebar-toggle .sidebar-toggle-close", function() {
63        // $(this).next().removeClass('toggle_show');
64        $('.sidebar-toggle-trigger').removeClass('slideshow');
65        $('body').removeClass('body_show_sidetoggle');
66    });
67
68    // search form 
69    $( "#masthead" ).on( "click", ".search-trigger", function() {
70        $(this).next().slideDown('slow');
71        $(this).addClass('slideshow');
72        $('#masthead .search-wrap input[type="search"]').focus()
73    });
74    $( "#masthead" ).on( "click", ".search-trigger.slideshow", function() {
75        $(this).next().slideUp('slow');
76        $(this).removeClass('slideshow');
77    });
78
79    // live search
80    if( newsmaticObject.livesearch ) {
81        var searchContainer = $("#masthead .search-wrap")
82        if( searchContainer.length > 0 ) {
83            var searchFormContainer = searchContainer.find("form")
84            searchContainer.on( 'change, keyup', 'input[type="search"]', function() {
85                var searchKey = $(this).val()
86                if(searchKey) {
87                    $.ajax({
88                        method: 'post',
89                        url: ajaxUrl,
90                        data: {
91                            action: 'newsmatic_search_posts_content',
92                            search_key : searchKey.trim(),
93                            _wpnonce: _wpnonce
94                        },
95                        beforeSend: function() {
96                            searchFormContainer.addClass( 'retrieving-posts' );
97                            searchFormContainer.removeClass( 'results-loaded' )
98                        },
99                        success : function(res) {
100                            var parsedRes = JSON.parse(res)
101                                searchContainer.find(".search-results-wrap").remove()
102                                searchFormContainer.after(parsedRes.posts)
103                                searchFormContainer.removeClass( 'retrieving-posts' ).addClass( 'results-loaded' );
104                        },
105                        complete: function() {
106                            // render search content here
107                        }
108                    })
109                } else {
110                    searchContainer.find(".search-results-wrap").remove()
111                    searchFormContainer.removeClass( 'results-loaded' )
112                }
113            })
114        }
115    }
116
117    newsmaticclosemodal( $( ".search-wrap" ), function () {
118        $( ".search-wrap .search-trigger" ).removeClass( "slideshow" );
119        $( ".search-form-wrap" ).slideUp();
120        $("#masthead .search-wrap").find(".search-results-wrap").remove()
121        $("#masthead .search-wrap").removeClass( 'results-loaded' )
122    }); // trigger search close
123    newsmaticclosemodal( $( ".sidebar-toggle-wrap" ), function () {
124        $( ".sidebar-toggle-wrap .sidebar-toggle-trigger" ).removeClass( "slideshow" );
125        $('body').removeClass('body_show_sidetoggle');
126    }); // trigger htsidebar close
127
128    // top header ticker news slider events
129    var thtn = $( ".top-ticker-news" );
130    if( thtn.length ) {
131        var thtnitems = thtn.find( ".ticker-item-wrap" )
132        thtnitems.slick({
133            dots: false,
134            infinite: true,
135            rtl: nrtl,
136            vertical: true,
137            arrows: true,
138            autoplay: true,
139            nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
140            prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`,
141        });
142    }
143
144    // main banner slider events
145    var bc = $( "#main-banner-section" );
146    if( bc.length ) {
147        var bic = bc.find( ".main-banner-slider" )
148        var bAuto = bic.data( "auto" )
149        var bArrows = bic.data( "arrows" )
150        bic.slick({
151            dots: false,
152            infinite: true,
153            rtl: nrtl,
154            arrows: bArrows,
155            autoplay: false,
156            autoplay: bAuto,
157            nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
158            prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`,
159        });
160    }
161
162    // news carousel events
163    var nc = $( ".newsmatic-section .news-carousel .news-carousel-post-wrap" );
164    if( nc.length ) {
165        nc.each(function() {
166            var _this = $(this)
167            var ncDots= _this.data("dots") == '1'
168            var ncLoop= _this.data("loop") == '1'
169            var ncArrows= _this.data("arrows") == '1'
170            var ncAuto  = _this.data("auto") == '1'
171            var ncColumns  = _this.data("columns")
172            _this.slick({
173                dots: ncDots,
174                infinite: ncLoop,
175                arrows: ncArrows,
176                autoplay: ncAuto,
177                rtl: nrtl,
178                slidesToShow: ncColumns,
179                nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
180                prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`,
181                responsive: [
182                  {
183                    breakpoint: 1100,
184                    settings: {
185                      slidesToShow: 3,
186                    },
187                  },
188                  {
189                    breakpoint: 768,
190                    settings: {
191                      slidesToShow: 2,
192                    },
193                  },
194                  {
195                    breakpoint: 640,
196                    settings: {
197                      slidesToShow: 1,
198                    },
199                  }
200                ]
201            });
202        })
203    }
204
205    // Filter posts
206     $( ".newsmatic-section .news-filter" ).each(function() {
207        var $scope = $(this), $scopeOptions = $scope.data("args"), newTabs = $scope.find( ".filter-tab-wrapper" ), newTabsContent = $scope.find( ".filter-tab-content-wrapper" );
208        newTabs.on( "click", ".tab-title", function() {
209          var a = $(this), aT = a.data("tab")
210          a.addClass( "isActive" ).siblings().removeClass( "isActive" );
211          if( newTabsContent.find( ".tab-content.content-" + aT ).length < 1 ) {
212            $scopeOptions.category_name = aT
213            $.ajax({
214                method: 'get',
215                url: ajaxUrl,
216                data: {
217                    action: 'newsmatic_filter_posts_load_tab_content',
218                    options : JSON.stringify( $scopeOptions ),
219                    _wpnonce: _wpnonce
220                },
221                beforeSend: function() {
222                    $scope.addClass( 'retrieving-posts' );
223                },
224                success : function(res) {
225                    var parsedRes = JSON.parse(res)
226                    if( parsedRes.loaded ) {
227                        newTabsContent.append(parsedRes.posts)
228                        $scope.removeClass( 'retrieving-posts' );
229                    }
230                },
231                complete: function() {
232                    newTabsContent.find( ".tab-content.content-" + aT ).show().siblings().hide()
233                }
234            })
235          } else {
236            newTabsContent.find( ".tab-content.content-" + aT ).show().siblings().hide()
237          }
238        })
239    })
240
241    // popular posts widgets
242    var ppWidgets = $( ".newsmatic-widget-popular-posts" )
243    ppWidgets.each(function() {
244        var _this = $(this), parentWidgetContainerId = _this.parents( ".widget.widget_newsmatic_popular_posts_widget" ).attr( "id" ), parentWidgetContainer = $( "#" + parentWidgetContainerId )
245        var ppWidget = parentWidgetContainer.find( ".popular-posts-wrap" );
246        if( ppWidget.length > 0 ) {
247            var ppWidgetAuto = ppWidget.data( "auto" )
248            var ppWidgetArrows = ppWidget.data( "arrows" )
249            var ppWidgetLoop = ppWidget.data( "loop" )
250            var ppWidgetVertical = ppWidget.data( "vertical" )
251            if( ppWidgetVertical == 'vertical' ) {
252                ppWidget.slick({
253                    vertical: true,
254                    slidesToShow: 4,
255                    dots: false,
256                    infinite: ppWidgetLoop,
257                    arrows: ppWidgetArrows,
258                    autoplay: ppWidgetAuto,
259                    nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
260                    prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`
261                })
262            } else {
263                ppWidget.slick({
264                    dots: false,
265                    infinite: ppWidgetLoop,
266                    rtl: nrtl,
267                    arrows: ppWidgetArrows,
268                    autoplay: ppWidgetAuto,
269                    nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
270                    prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`
271                })
272            }  
273        }
274    })
275
276    // carousel posts widgets
277    var cpWidgets = $( ".newsmatic-widget-carousel-posts" )
278    cpWidgets.each(function() {
279        var _this = $(this), parentWidgetContainerId = _this.parents( ".widget.widget_newsmatic_carousel_widget" ).attr( "id" ), parentWidgetContainer
280        if( typeof parentWidgetContainerId != 'undefined' ) {
281            parentWidgetContainer = $( "#" + parentWidgetContainerId )
282            var ppWidget = parentWidgetContainer.find( ".carousel-posts-wrap" );
283        } else {
284            var ppWidget = _this;
285        }
286        if( ppWidget.length > 0 ) {
287            var ppWidgetAuto = ppWidget.data( "auto" )
288            var ppWidgetArrows = ppWidget.data( "arrows" )
289            var ppWidgetLoop = ppWidget.data( "loop" )
290            var ppWidgetVertical = ppWidget.data( "vertical" )
291            if( ppWidgetVertical == 'vertical' ) {
292                ppWidget.slick({
293                    vertical: true,
294                    dots: false,
295                    infinite: ppWidgetLoop,
296                    arrows: ppWidgetArrows,
297                    autoplay: ppWidgetAuto,
298                    nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
299                    prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`
300                })
301            } else {
302                ppWidget.slick({
303                    dots: false,
304                    infinite: ppWidgetLoop,
305                    rtl: nrtl,
306                    arrows: ppWidgetArrows,
307                    autoplay: ppWidgetAuto,
308                    nextArrow: `<button type="button" class="slick-next"><i class="fas fa-chevron-right"></i></button>`,
309                    prevArrow: `<button type="button" class="slick-prev"><i class="fas fa-chevron-left"></i></button>`
310                })
311            }  
312        }
313    })
314
315    // tabbed posts
316    var tabpWidgets = $( ".newsmatic-tabbed-widget-tabs-wrap" )
317    tabpWidgets.each(function() {
318        var _this = $(this), parentWidgetContainerId = _this.parents( ".widget.widget_newsmatic_tabbed_posts_widget" ).attr( "id" ), parentWidgetContainer
319        if( typeof parentWidgetContainerId != 'undefined' ) {
320            parentWidgetContainer = $( "#" + parentWidgetContainerId )
321            var tabpWidget = parentWidgetContainer.find( ".newsmatic-tabbed-widget-tabs-wrap" );
322        } else {
323            var tabpWidget = _this;
324        }
325        if( tabpWidget.length > 0 ) {
326            tabpWidget.on( "click", ".tabbed-widget-tabs li.tabbed-widget", function() {
327                var _this = $(this), tabItem = _this.attr( "tab-item" );
328                _this.addClass( "active" ).siblings().removeClass( "active" );
329                tabpWidget.find( '.widget-tabs-content div[tab-content="' + tabItem + '"]' ).addClass( "active" ).siblings().removeClass( "active" );
330            })
331        }
332    })
333
334    // handle theme mode toggle
335    $( ".mode_toggle_wrap" ).on( "click", function() {
336        var _this = $(this)
337        $( "body" ).toggleClass( "newsmatic_dark_mode" )
338        if( _this.find( "input:checked" ).length > 0 && $( "body" ).hasClass( "newsmatic_dark_mode" ) ) {
339            $.cookie( "themeMode", "dark", { path: '/' } );
340            $("body").removeClass("newsmatic_main_body");
341        } else {
342            $.cookie( "themeMode", "light", { path: '/' } );
343            $("body").addClass("newsmatic_main_body");
344        }
345    });
346
347
348    // header sticky
349    if( stickeyHeader ) {
350        var lastScroll = 0;
351        $(window).on('scroll',function() {  
352            var scroll = $(window).scrollTop();
353            if(scroll > 50){        
354                if(lastScroll - scroll > 0) {
355                    $(".main-header .menu-section").addClass("fixed_header");
356                } else {
357                    $(".main-header .menu-section").removeClass("fixed_header");
358                }
359                lastScroll = scroll;
360            }else{
361                $(".main-header .menu-section").removeClass("fixed_header");
362            }
363        });
364    }
365
366    // back to top script
367    if( sttOption && $( "#newsmatic-scroll-to-top" ).length ) {
368        var scrollContainer = $( "#newsmatic-scroll-to-top" );
369        $(window).scroll(function() {
370            if ( $(this).scrollTop() > 800 ) {
371                scrollContainer.addClass('show');
372            } else {
373                scrollContainer.removeClass('show');
374            }
375        });
376        scrollContainer.click(function(event) {
377            event.preventDefault();
378            // Animate the scrolling motion.
379            $("html, body").animate({scrollTop:0},"slow");
380        });
381    }
382
383    // category archive hide featured post in list
384    var featuredPost = $( ".archive.category .featured-post.is-sticky" )
385    if( featuredPost.length > 0 ) {
386        var postHide = "#post-" + featuredPost.data("id")
387        $(postHide).addClass( "sticky-hide" );
388    }
389})

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.