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