PageSourceSearch

https://www.networkcomputerpros.com/wp-content/plugins/divi-table-…/D5/server/script/frontend.js

js networkcomputerpros.com collected 2026-09-30 04:34:53 UTC 19,239 bytes, 347 lines download raw bytes

1// This script is loaded both on the frontend page and in the Visual Builder.
2// import "./jquery.mark.min.js";
3jQuery(function($) {
4    // $('li div span[data-href="#pac_remove_first_heading"]').parent().parent().remove();
5    $('li div span[data-href="#NO"]').parent().parent().remove();
6
7    var schemaHeadings = jQuery('.divi_table_of_contents').find('a');
8
9    var schema = {
10        "@context": "https://schema.org",
11        "@type": "ItemList",
12        "name": "Table of Contents",
13        "itemListElement": []
14    };
15
16    schemaHeadings.each(function (i) {
17        var link = $(this);
18        schema.itemListElement.push({
19            "@type": "ListItem",
20            "position": i + 1,
21            "name": link.text().trim(),
22            "url": link.attr('href')
23        });
24    });
25
26    // Insert schema into head
27    var script = document.createElement("script");
28    script.type = "application/ld+json";
29    script.text = JSON.stringify(schema, null, 2);
30    document.head.appendChild(script);
31
32
33    if (window.location.href.indexOf("wp-admin") === -1 && new URLSearchParams(window.location.search).get("et_fb") === null) {
34        // Select all heading elements (h1 to h6)
35        $('h1, h2, h3, h4, h5, h6').each(function() {
36            var heading = $(this);
37            // Check if heading already has an id
38            if (!heading.attr('id') && heading.is(':hidden') === false) {
39                var innerContent = heading.text();
40                // Replace spaces with underscores and assign it as the id
41                var id = innerContent.trim().split(" ");
42                id = id.join("_");
43                id = id.replace(/4x4/g, "44");
44                id = $("<div>").html(id).text();
45                id = id.replace(/[^\p{L}\p{N}]/gu, '');
46                
47                heading.attr('id', id);
48            }
49        });
50        
51        $('.pac_dtoc_clear_keyword_input').click(function() {
52            $(this).hide();
53            $(this).parent().find('.pac_dtoc_search_input').val('');
54            $("body").unmark();
55        });
56
57        $('.pac_dtoc_main_container').each((i, el) => {
58            let toc = $(el);
59            let isMobile = window.matchMedia("screen and (max-width: 767px)").matches;
60            let isTablet = window.matchMedia("screen and (min-width: 768px) and (max-width: 980px)").matches;
61            let isDesktop = window.matchMedia("screen and (min-width: 981px)").matches;
62            if ((toc.data('allow_collapse_minimize') === 'on' && isDesktop) ||
63                (toc.data('allow_collapse_minimize_tablet') === 'on' && isTablet) ||
64                (toc.data('allow_collapse_minimize_phone') === 'on' && isMobile)) {
65                let title;
66                if (isDesktop) {
67                    title = toc.find('.pac_dtoc_title_area.click_on');
68                } else if (isTablet) {
69                    title = toc.find('.pac_dtoc_title_area.click_tablet_on');
70                } else if (isMobile) {
71                    title = toc.find('.pac_dtoc_title_area.click_phone_on');
72                }
73
74                let open = toc.find('.pac_dtoc_opened_icon');
75                let close = toc.find('.pac_dtoc_closed_icon');
76                let body = toc.find('.pac_dtoc_body_area');
77                let title_area = toc.find('.pac_dtoc_title_area');
78                let main_element = toc.parent();
79                let title_text = toc.find('.pac_dtoc_title');
80
81                function collapse_on_click(hide_title,df) {
82                    if (hide_title === 'on') {
83                        if(df === 'closed'){
84                            $(title_text).hide();
85                            $(title_area).css("width", "fit-content");
86                        }
87                        $(title).click(function() {
88                            $(open).toggle();
89                            $(close).toggle();
90                            if ($(body).css("display") === "block") {
91                                $(body).slideUp(750);
92                                $(title_text).hide(750);
93                                setTimeout(function() { $(title_area).css("width", "fit-content"); }, 750);
94                            } else {
95                                $(title_area).css("width", "auto");
96                                $(title_text).show(750);
97                                $(body).slideDown(750);
98                            }
99                        });
100                    } else {
101                        $(title).click(function() {
102                            $(open).toggle();
103                            $(close).toggle();
104                            if ($(body).css("display") === "block") {
105                                $(body).slideUp(750);
106                            } else {
107                                $(body).slideDown(750);
108                            }
109                        });
110                    }
111                }
112
113                function collapse_when_sticky(collapse_when_sticky, hide_title, default_state) {
114                    if (collapse_when_sticky === 'on') {
115                        let isAnimating = false; // Flag to track animation state
116                        $(window).scroll(function() {
117                            if (isAnimating) return; // Exit if animation is already in progress
118
119                            if (hide_title === 'on') {
120                                if (main_element.hasClass("et_pb_sticky--top") || main_element.hasClass("et_pb_sticky--bottom") || main_element.hasClass("et_pb_sticky--top_bottom")) {
121                                    if ($(body).css("display") === "block") {
122                                        isAnimating = true; // Set the flag to true
123                                        $(body).slideUp(750, function() {
124                                            isAnimating = false; // Reset the flag after animation completes
125                                        });
126                                        $(title_text).hide(750);
127                                        setTimeout(function() { 
128                                            $(main_element).css("width", "fit-content"); 
129                                        }, 750);
130                                        $(open).toggle();
131                                        $(close).toggle();
132                                    }
133                                } else {
134                                    if ($(body).css("display") === "none" && default_state === 'open') {
135                                        isAnimating = true; // Set the flag to true
136                                        $(title_text).show(750);
137                                        $(body).slideDown(750, function() {
138                                            isAnimating = false; // Reset the flag after animation completes
139                                        });
140                                        $(open).toggle();
141                                        $(close).toggle();
142                                    }
143                                }
144                            } else {
145                                if (main_element.hasClass("et_pb_sticky--top") || main_element.hasClass("et_pb_sticky--bottom") || main_element.hasClass("et_pb_sticky--top_bottom")) {
146                                    if ($(body).css("display") === "block") {
147                                        isAnimating = true; // Set the flag to true
148                                        $(body).slideUp(750, function() {
149                                            isAnimating = false; // Reset the flag after animation completes
150                                        });
151                                        $(open).toggle();
152                                        $(close).toggle();
153                                    }
154                                } else {
155                                    if ($(body).css("display") === "none" && default_state === 'open') {
156                                        isAnimating = true; // Set the flag to true
157                                        $(body).slideDown(750, function() {
158                                            isAnimating = false; // Reset the flag after animation completes
159                                        });
160                                        $(open).toggle();
161                                        $(close).toggle();
162                                    }
163                                }
164                            }
165                        });
166                    }
167                }
168                if (isDesktop) {
169                    collapse_on_click(toc.data('mtocai'),toc.data('ds'));
170                    collapse_when_sticky(toc.data('collapse_when_sticky'), toc.data('mtocai'), toc.data('ds'));
171                } else if (isTablet) {
172                    collapse_on_click(toc.data('mtocai_tablet'),toc.data('dst'));
173                    collapse_when_sticky(toc.data('collapse_when_sticky_tablet'), toc.data('mtocai_tablet'), toc.data('dst'));
174                } else if (isMobile) {
175                    collapse_on_click(toc.data('mtocai_phone'),toc.data('dsp'));
176                    collapse_when_sticky(toc.data('collapse_when_sticky_phone'), toc.data('mtocai_phone'), toc.data('dsp'));
177                }
178
179
180
181            }
182
183            if (toc.data('alh') === 'on') {
184                var isInViewport = function(elem) {
185                    if(elem === null){
186                        return false;
187                    }
188                    var distance = elem.getBoundingClientRect();
189                    return (
190                        distance.top >= 0 &&
191                        distance.left >= 0 &&
192                        distance.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
193                        distance.right <= (window.innerWidth || document.documentElement.clientWidth) &&
194                        (distance.top !== 0 | distance.left !== 0 | distance.bottom !== 0 | distance.right !== 0)
195                    );
196                };
197
198                var headings = jQuery('.divi_table_of_contents').find('span');
199                let condition = true;
200                let active_one = 1;
201                let active_top = -999999;
202                let active_ind;
203                for (var i = 0; i < headings.length; i++) {
204                    if(jQuery(headings[i]).attr('data-href') !== undefined && jQuery(headings[i]).attr('data-href') !== null){
205                        var elem = document.getElementById(jQuery(headings[i]).attr('data-href').substring(1));
206                        if(elem !== null){
207                            var distance = elem.getBoundingClientRect();
208                            if(distance.top === 0 && distance.bottom === 0 && distance.left === 0 && distance.right === 0 && distance.width === 0 && distance.height === 0){
209                                jQuery('ul li span[data-href="' + jQuery(headings[i]).attr('data-href') + '"]').parent().parent().hide();
210                            }
211                        }
212                        if (elem === null) {
213                            if(jQuery('h' + jQuery(headings[i]).attr('data-hl') + ':contains("' + jQuery(headings[i]).next().text() + '")').length > 0){
214                                jQuery('h' + jQuery(headings[i]).attr('data-hl') + ':contains("' + jQuery(headings[i]).next().text() + '")').attr('id', jQuery(headings[i]).attr('data-href').substring(1));
215                                var elem = document.getElementById(jQuery(headings[i]).attr('data-href').substring(1));
216                            }else{
217                                jQuery(headings[i]).parent().parent().remove();
218                            }
219                        }
220                        if (isInViewport(elem) & condition) {
221                            jQuery('ul li span[data-href="' + jQuery(headings[i]).attr("data-href") + '"]').parent().parent().addClass('active');
222                            condition = false;
223                            active_one = -10;
224                        } else {
225                            jQuery('ul li span[data-href="' + jQuery(headings[i]).attr('data-href') + '"]').parent().parent().removeClass('active');
226                            active_one++;
227                        }
228                        if (active_one === headings.length) {
229                            for (var j = 0; j < headings.length; j++) {
230                                var elemt = document.getElementById(jQuery(headings[j]).attr('data-href').substring(1));
231                                if (elemt !== null && elemt.getBoundingClientRect().top < 0 && active_top < elemt.getBoundingClientRect().top && jQuery('ul li span[data-href="' + jQuery(headings[j]).attr("data-href") + '"]').parent().parent().css('display') !== 'none') {
232                                    active_ind = j;
233                                }
234                            }
235                            jQuery('ul li span[data-href="' + jQuery(headings[active_ind]).attr("data-href") + '"]').parent().parent().addClass('active');
236                        }
237                    }
238                }
239                $(window).scroll(function() {
240                    active_one = 0;
241                    active_top = -999999;
242                    condition = true;
243                    for (var i = 0; i < headings.length; i++) {
244                        if(jQuery(headings[i]).attr('data-href') !== undefined && jQuery(headings[i]).attr('data-href') !== null){
245                            var elem = document.getElementById(jQuery(headings[i]).attr('data-href').substring(1));
246                            if (elem === null) {
247                                jQuery('h' + jQuery(headings[i]).attr('data-hl') + ':contains("' + jQuery(headings[i]).next().text() + '")').attr('id', jQuery(headings[i]).attr('data-href').substring(1));
248                                var elem = document.getElementById(jQuery(headings[i]).attr('data-href').substring(1));
249                            }
250                            if (isInViewport(elem) && condition && jQuery('ul li span[data-href="' + jQuery(headings[i]).attr("data-href") + '"]').parent().parent().css('display') !== 'none') {
251                                jQuery('ul li span[data-href="' + jQuery(headings[i]).attr("data-href") + '"]').parent().parent().addClass('active');
252                                condition = false;
253                                active_one = -10;
254                            } else {
255                                jQuery('ul li span[data-href="' + jQuery(headings[i]).attr('data-href') + '"]').parent().parent().removeClass('active');
256                                active_one++;
257                            }
258                            if (active_one === headings.length) {
259                                for (var j = 0; j < headings.length; j++) {
260                                    var elemt = document.getElementById(jQuery(headings[j]).attr('data-href').substring(1));
261                                    if (elemt !== null && elemt.getBoundingClientRect().top < 0 && active_top < elemt.getBoundingClientRect().top && jQuery('ul li span[data-href="' + jQuery(headings[j]).attr("data-href") + '"]').parent().parent().css('display') !== 'none') {
262                                        active_ind = j;
263                                    }
264                                }
265                                jQuery('ul li span[data-href="' + jQuery(headings[active_ind]).attr("data-href") + '"]').parent().parent().addClass('active');
266                            }
267                        }
268                    }
269                });
270            }
271            else{
272                var headings = jQuery('.divi_table_of_contents').find('span');
273                for (var i = 0; i < headings.length; i++) {
274                    var elem = document.getElementById(jQuery(headings[i]).attr('data-href').substring(1));
275                    if(elem !== null){
276                        var distance = elem.getBoundingClientRect();
277                        if(distance.top === 0 && distance.bottom === 0 && distance.left === 0 && distance.right === 0 && distance.width === 0 && distance.height === 0){
278                            jQuery('ul li span[data-href="' + jQuery(headings[i]).attr('data-href') + '"]').parent().parent().hide();
279                        }
280                    }
281                }
282            }
283
284            let logedin = (jQuery('body').hasClass('logged-in')) ? 32 : 0;
285            let moveHeading = toc.data('sah');
286            moveHeading = parseInt(moveHeading, 10) + logedin;
287
288            let max_scroll_time = toc.data('ss') < 100 ? 100 : toc.data('ss');
289            let body = jQuery("html, body");
290            let target = toc.find('span');
291            let clicked_element = null;
292            let check_ele = null;
293            $(target).click(function() {
294                let href = $(this).attr('data-href');
295                
296                check_ele = document.getElementById(href.substring(1)).getBoundingClientRect();
297                if (check_ele.x === 0 && check_ele.y === 0 && check_ele.width === 0 && check_ele.height === 0) {
298                    return;
299                }
300                
301                clicked_element = this;
302                let total = $(document).height();
303                let start = $(window).scrollTop();
304                let end = $(href).offset().top;
305                let diff = start >= end ? start - end : end - start;
306                let percentage = (diff * 100)/total;
307                let time = (percentage * parseInt(max_scroll_time, 10))/100;
308                body.stop().animate({ scrollTop: end - moveHeading }, {
309                    duration: time,
310                    done: function() {
311                        clicked_element = null;
312                    }
313                }, 'linear');
314            });
315
316            if (toc.data('skh') === 'on') {
317                $(function() {
318                    var mark = function() {
319                        $(".pac_dtoc_clear_keyword_input").show();
320
321                        // Read the keyword
322                        var keyword = $(".pac_dtoc_search_input").val();
323
324                        if (keyword === "") {
325                            $(".pac_dtoc_clear_keyword_input").hide();
326                        } else {
327                            $(".pac_dtoc_clear_keyword_input").show();
328                        }
329                        // Determine selected options
330                        var options = {};
331                        options['separateWordSearch'] = false;
332                        options['diacritics'] = false;
333                        options['debug'] = false;
334
335                        // Remove previous marked elements and mark the new keyword inside the context
336                        $("body").unmark({
337                            done: function() {
338                                $("body").mark(keyword, options);
339                            }
340                        });
341                    };
342                    $(".pac_dtoc_search_input").on("input", mark);
343                });
344            }
345        });
346    }
347});

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.