PageSourceSearch

https://www.marqueze.net/wp-content/plugins/wp-post-modal/public/js/wp-post-modal-public.js?ver=1.0.18

js marqueze.net collected 2026-09-24 10:09:01 UTC 15,070 bytes, 370 lines download raw bytes

1(function ($) {
2    'use strict';
3
4    // added to support accessibility for screen reader users
5    var clickedURL;
6
7    /**
8     * Check if URL is external function
9     *
10     * @returns {boolean}
11     */
12    $.fn.isExternal = function () {
13        var host = window.location.hostname;
14        var link = $('<a>', {
15            href: this.attr('href')
16        })[0].hostname;
17        return (link !== host);
18
19    };
20
21    /**
22     * Trapping user in modal for web accessibility
23     */
24    function trapFocus() {
25        $('.close-modal').focus();
26
27        var focusableEls = document.querySelectorAll('.modal a[href]:not([disabled]), .modal button:not([disabled]), .modal textarea:not([disabled]), .modal input[type="text"]:not([disabled]), .modal input[type="radio"]:not([disabled]), .modal input[type="checkbox"]:not([disabled]), .modal select:not([disabled])'),
28            firstFocusableEl = focusableEls[0],
29            lastFocusableEl = focusableEls[focusableEls.length - 1];
30        
31        document.addEventListener('keydown', function (e) {
32            var isTabPressed = (e.key === 'Tab' || e.keyCode === 9);
33
34            if (!isTabPressed) return;
35
36            if (e.shiftKey && isTabPressed) /* shift + tab */ {
37                if (document.activeElement === firstFocusableEl) {
38                    lastFocusableEl.focus();
39                    e.preventDefault();
40                }
41            } else if (isTabPressed) /* tab */ {
42                if (document.activeElement === lastFocusableEl) {
43                    firstFocusableEl.focus();
44                    e.preventDefault();
45                }
46            }
47        });
48    }
49
50    /**
51     * Check if modal is open
52     */
53    function popupOpen() {
54        return $('.modal-wrapper').hasClass('show');
55    }
56
57    /**
58     * Basename function for JS
59     *
60     * @param path
61     * @param suffix
62     * @returns {*}
63     */
64    function basename(path, suffix) {
65        var b = path;
66        var lastChar = b.charAt(b.length - 1);
67        if (lastChar === '/' || lastChar === '\\') {
68            b = b.slice(0, -1);
69        }
70        b = b.replace(/^.*[/\\]/g, '');
71        if (typeof suffix === 'string' && b.substr(b.length - suffix.length) === suffix) {
72            b = b.substr(0, b.length - suffix.length);
73        }
74        return b;
75    }
76
77    /**
78     * Get URL Paramenters
79     *
80     * @param sParam
81     * @returns {*}
82     */
83    var getUrlParameter = function getUrlParameter(sParam) {
84        var sPageURL = decodeURIComponent(window.location.search.substring(1)),
85            sURLVariables = sPageURL.split('&'),
86            sParameterName,
87            i;
88
89        for (i = 0; i < sURLVariables.length; i++) {
90            sParameterName = sURLVariables[i].split('=');
91
92            if (sParameterName[0] === sParam) {
93                return sParameterName[1] === undefined ? true : sParameterName[1];
94            }
95        }
96    };
97
98    /**
99     * Suppress modal link redirect in WP Customizer
100     */
101    function modalCustomizer() {
102        if (typeof wp.customize !== 'undefined') {
103            var body = $('body');
104            body.off('click.preview');
105
106            body.on('click.preview', 'a[href]:not(.modal-link)', function (e) {
107                var link = $(this);
108                e.preventDefault();
109                wp.customize.preview.send('scroll', 0);
110                wp.customize.preview.send('url', link.prop('href'));
111            });
112        }
113    }
114
115    // Document Ready
116    $(function () {
117
118        // Detect windows width function
119        var $window = $(window),
120            $document = $(document),
121            scrollPos,
122            currentURL = window.location.pathname,
123            disablePopup = !!window.MSInputMethodContext && !!document.documentMode;
124
125        /**
126         * Show modal functionality
127         */
128        function showModal(postLink, external) {
129            scrollPos = window.pageYOffset;
130            if (fromPHP.disableScrolling) $('body, html').addClass('no-scroll');
131            $('.modal-wrapper').addClass('show');
132            $('.modal').addClass('show');
133
134            // trap focus inside modal
135            setTimeout(function () {
136                trapFocus();
137            }, 1000);
138
139            // update address bar to show url of popup content page
140            if (postLink) {
141                if (postLink.length > 0 && !external) {
142                    history.replaceState('', '', postLink);
143                }
144            }
145        }
146
147        /**
148         * Close modal functionality
149         */
150        function hideModal(currentURL) {
151            var body = $('body');
152
153            // handle scrolling
154            if (body.hasClass('no-scroll')) {
155                body.removeClass('no-scroll');
156                $('html').removeClass('no-scroll');
157                window.scroll(0, scrollPos);
158            }
159
160            // hide popup
161            $('.modal-wrapper').removeClass('show').hide();
162            $('.modal').removeClass('show');
163            $('#modal-content').empty();
164
165            // return to previous tab location for screen reader users
166            clickedURL.focus();
167
168            // return original page url in address bar
169            if (window.location.pathname !== currentURL) {
170                history.replaceState('', '', currentURL);
171            }
172        }
173
174        $document
175            .keyup(function (e) {
176                // close modal when pressing esc
177                if (e.keyCode === 27 && $('.modal-wrapper').hasClass('show')) hideModal(currentURL);
178            })
179            // Close modal when clicking on close button
180            .on('click', '.close-modal', function () {
181                hideModal(currentURL);
182            });
183            // when clicking outside of modal
184            //.on('click', '.modal', function (e) {
185            //    e.stopPropagation();
186            //});
187
188
189        // when clicking outside of modal
190        //$(window).on('click', function () {
191        //    if (popupOpen()) hideModal(currentURL);
192        //});
193
194        /**
195         * Check width
196         */
197        function initModal() {
198            // if the window is greater than breakpoint then show modal, otherwise go to linked page as normal
199            if ($window.width() >= fromPHP.breakpoint) {
200                var modalUrl = getUrlParameter('modal-link');
201
202                // if using URL parameter to open modal
203                if (modalUrl) {
204                    // show loading animation if styling is turned on
205                    if (fromPHP.loader) {
206                        $('#modal-content').html('<img class="loading" src="' + fromPHP.pluginUrl + '/images/loading.gif" />');
207                    }
208
209                    $.get(
210                        modalUrl,
211                        function (html) {
212                            var htmlContent = (html.indexOf('<html') > -1) ? $(html).find(fromPHP.containerID).html() : html;
213
214                            $('#modal-content').html(htmlContent);
215                        });
216
217                    // show modal
218                    $('.modal-wrapper').fadeIn('fast', showModal);
219                }
220
221
222                /**
223                 * When clicking a modal-link
224                 */
225                $('body').on('click', '.modal-link', function (e) {
226                    // Define variables
227                    var modalContent = $('#modal-content');
228                    var $this = $(this);
229
230                    if( $this.data('href') ){
231                        var postLink = window.atob( $this.data('href') );
232                    }else{
233                        var $this = ($(this).attr('href') != null) ? $(this) : $(this).children('a').first();
234                        var postLink = $this.attr('href');
235                    }
236
237                    var postSlug = postLink.lastIndexOf('/#') > -1 ? basename(postLink.substring(0, postLink.lastIndexOf('/#'))) + basename(postLink) : basename(postLink);
238                    var postAnchor = postSlug.lastIndexOf('#') !== -1 ? postSlug.substring(postSlug.lastIndexOf('#')) : false;
239                    var dataDivID = $this.attr('data-div') ? ('#' + $this.attr('data-div')) : fromPHP.containerID;
240                    var dataBuddypress = $this.attr('data-buddypress');
241                    var loader = '<img class="loading" src="' + fromPHP.pluginUrl + '/images/loading.gif" />';
242                    clickedURL = document.activeElement;
243
244                    // prevent link from being followed
245                    e.preventDefault();
246
247                    // display loading animation or in this case static content
248                    if (fromPHP.loader) {
249                        modalContent.html(loader);
250                    }
251
252
253                    var is_external = postLink.indexOf( window.location.hostname ) == -1;
254
255
256                    // Load content from external
257                    if ( is_external ) {
258                        // load external content using iframe method
259                        if ($(this).hasClass('iframe') || fromPHP.iframe) {
260                            var iframeCode = '<iframe src="' + $(this).attr('href') + '" width="100%"' +
261                                ' height="600px" frameborder="0"></iframe>';
262                            modalContent.html(iframeCode);
263                        }
264                        // load external content normally
265                        else {
266                            $.ajaxPrefilter(function (options) {
267                                if (options.crossDomain && jQuery.support.cors) {
268                                    var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
269                                    options.url = http + '//cors-anywhere.herokuapp.com/' + options.url;
270                                    //options.url = "http://cors.corsproxy.io/url=" + options.url;
271                                }
272                            });
273
274                            $.get(
275                                postLink,
276                                function (html) {
277                                    modalContent.html($(html).find(dataDivID).html());
278                                });
279                        }
280                    }
281                    // Load content from internal page
282                    else {
283                        // when loading buddy press profile
284                        if (dataBuddypress) {
285                            modalContent.load(postLink + ' #buddypress');
286                        }
287                        // load internal content using iframe method
288                        else if ($(this).hasClass('iframe')) {
289                            var iframeCode = '<iframe src="' + $(this).attr('href') + '" width="100%"' +
290                                ' height="600px" frameborder="0"></iframe>';
291                            modalContent.html(iframeCode);
292                        }
293                        // when loading any other type of content
294                        else {
295                            // use the rest method
296                            if (fromPHP.restMethod || $(this).hasClass('rest')) {
297                                $.get(
298                                    fromPHP.siteUrl + '/wp-json/wp-post-modal/v1/any-post-type?slug=' + postSlug,
299                                    function (response) {
300                                        $.when(modalContent.html(response.post_content)).done(function () {
301                                            // scroll to anchor
302                                            setTimeout(function () {
303                                                if (postAnchor) {
304                                                    $('.modal-wrapper').animate({
305                                                        scrollTop: ($('#modal-content ' + postAnchor).offset().top)
306                                                    }, 300);
307                                                }
308                                            }, 200);
309                                        });
310                                    });
311                            }
312                            // use the default method
313                            else {
314                                $.get(
315                                    postLink,
316                                    function (html) {
317                                        var content = $(html).find(dataDivID),
318                                            htmlContent = (html.indexOf('<html') > -1) ? $(html).find(dataDivID).html() : html;
319
320                                        if (content[0]) {
321                                            $.when(modalContent.html(htmlContent))
322                                                .done(function () {
323                                                    // scroll to anchor
324                                                    setTimeout(function () {
325                                                        if (postAnchor) {
326                                                            $('.modal-wrapper').animate({
327                                                                scrollTop: ($('#modal-content ' + postAnchor).offset().top)
328                                                            }, 300);
329                                                        }
330                                                    }, 200);
331                                                });
332                                        }
333                                        // fallback to load method
334                                        else {
335                                            modalContent.load(postLink, function () {
336                                                modalContent.html($(modalContent.html()).find(dataDivID).html());
337
338                                                setTimeout(function () {
339                                                    if (postAnchor) {
340                                                        $('.modal-wrapper').animate({
341                                                            scrollTop: ($('#modal-content ' + postAnchor).offset().top)
342                                                        }, 300);
343                                                    }
344                                                }, 200);
345                                            });
346                                        }
347                                    });
348                            }
349                        }
350                    }
351
352                    // show modal
353                    $('.modal-wrapper').fadeIn('fast', function () {
354                        // if url state plugin setting is active
355                        showModal(fromPHP.urlState ? postLink : '', $this.isExternal());
356                    });
357                });
358            }
359        }
360
361        // Initiate modal if not IE11
362        if (!disablePopup) initModal();
363    });
364
365    // Window load
366    $(window).on('load', function () {
367        modalCustomizer();
368    });
369
370})(jQuery);

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.