1/** 2 * RWC Base entry point. 3 * 4 * @package RWC Base JS 5 * @author Road Warrior Creative 6 * @license GPL-2.0-or-later 7 */ 8 9var rwcBase = ( function( $ ) { 10 'use strict'; 11 12 /** 13 * Change the text of the 'You successfully added a sub account' message to 'You successfully added a member'. 14 */ 15 function rwc_ce_change_sub_account_text() { 16 var divs = document.querySelectorAll('.mepr_updated'); 17 divs.forEach(function(div) { 18 if (div.textContent.trim() === 'You successfully added a sub account') { 19 div.textContent = 'You successfully added a member'; 20 } 21 }); 22 } 23 rwc_ce_change_sub_account_text(); 24 25 /** 26 * Add active class to the current account menu item. 27 * 28 * Memberpress uses the query string to determine which account page to display. 29 */ 30 function rwc_ce_active_account_menu_item() { 31 var action = new URLSearchParams(window.location.search).get('action'); 32 var actions = ['subscriptions', 'payments', 'manage_sub_accounts']; // Extend this array as needed. 33 var menuItems = document.querySelectorAll('#menu-account-pages-menu li a'); 34 35 // Check if the current action is one of the specified actions. 36 if (actions.includes(action)) { 37 // Iterate over all menu items to remove active classes and aria-current attributes. 38 menuItems.forEach(function(item) { 39 item.parentElement.classList.remove('current-menu-item', 'current_page_item'); 40 item.removeAttribute('aria-current'); 41 }); 42 43 // Add active class and aria-current to the matching item. 44 menuItems.forEach(function(item) { 45 var itemAction = new URL(item.href).searchParams.get('action'); 46 if (itemAction === action) { 47 item.parentElement.classList.add('current-menu-item', 'current_page_item'); 48 item.setAttribute('aria-current', 'page'); 49 } 50 }); 51 } 52 } 53 rwc_ce_active_account_menu_item(); 54 55 /** 56 * Add ID to the input element with the class 'mpca-clipboard-input' 57 * 58 * Memberpress uses this class for the copy to clipboard functionality. 59 */ 60 function rwc_ce_mpcaAddIdToInput() { 61 var input = document.querySelector('.mpca-clipboard-input'); 62 if(input) { 63 input.id = 'mpca-clipboard-input'; 64 } 65 } 66 rwc_ce_mpcaAddIdToInput(); 67 68 // close popup after 7 seconds 69 $('#pum-39857').on('pumAfterOpen', function () { 70 var $popup = $(this); 71 72 $('#pum-39857 .pum-container').prepend('<div id="countdown"><div id="countdown-number"></div><svg><circle r="18" cx="20" cy="20"></circle></svg></div>'); 73 74 var countdownNumberEl = document.getElementById('countdown-number'); 75 var countdown = 7; 76 77 countdownNumberEl.textContent = countdown; 78 79 setInterval(function() { 80 countdown = --countdown <= 0 ? 7 : countdown; 81 countdownNumberEl.textContent = countdown; 82 if(countdown == 7){ 83 $popup.popmake('close'); 84 } 85 }, 1000); 86 87 }); 88 89 // update subscription table text 90 if($('#user-subscriptions').length){ 91 if($('.upgrade_link').length){ 92 $('.upgrade_link').text(' Modify '); 93 } 94 if($('td.upgraded').length){ 95 $('td.upgraded').text('Modified '); 96 } 97 } 98 99 function post_first_word() { 100 // Find the first <p> after .entry-date 101 var first_paragraph = $('.entry-date').nextAll('p').first(); 102 103 // Debugging output 104 console.log('Selected first paragraph:', first_paragraph); 105 106 if (first_paragraph.length > 0) { 107 var first_text = first_paragraph.text().trim(); // Get text content 108 console.log('Text content of the first paragraph:', first_text); 109 110 var words = first_text.split(/\s+/); // Split into words 111 112 if (words.length > 0 && ( 113 words[0].toLowerCase() === 'c&e' || 114 words[0].toLowerCase() === "c&eâs" || 115 words[0].toLowerCase() === "c&e's" 116 )) { 117 words[0] = '<span class="first-word">' + words[0] + '</span>'; 118 first_paragraph.html(words.join(" ")); // Update paragraph content 119 console.log('Updated first paragraph:', first_paragraph.html()); 120 } else { 121 first_paragraph.addClass('no-first-word'); 122 console.log('No match for the first word. Class added:', first_paragraph); 123 } 124 } else { 125 console.log('No paragraph found after .entry-date.'); 126 } 127 } 128 post_first_word(); 129 130 // wrap first word in span 131 $('.subscribe-sidebar-form_wrapper .gform_title').each(function(){ 132 var me = $(this); 133 me.html( me.text().replace(/(^\w+)/,'$1<span>') + '</span>' ); 134 }); 135 136 $('.match-height').matchHeight(); 137 138 $('.directory-filters-toggle').click(function(e){ 139 $('.consultant-search-form').slideToggle(); 140 $(this).addClass('active'); 141 }); 142 143 // Select all links with hashes 144 $('a[href*="#"]') 145 // Remove links that don't actually link to anything 146 .not('[href="#"]') 147 .not('[href="#0"]') 148 .not('[href*="#tab-"]') 149 .not('[href*="#rising-stars-block-nav"]') 150 .not('[href*="#uagb-tabs__"]') 151 .not('[href*="#update-listing"]') 152 .click(function(event) { 153 // On-page links 154 if (
155 location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') 156 && 157 location.hostname == this.hostname 158 ) { 159 // Figure out element to scroll to 160 var target = $(this.hash); 161 target = target.length ? target : $('[name=' + this.hash.slice(1) + ']'); 162 // Does a scroll target exist? 163 if (target.length) { 164 // Only prevent default if animation is actually gonna happen 165 event.preventDefault(); 166 $('html, body').animate({ 167 scrollTop: target.offset().top 168 }, 1000, function() { 169 // Callback after animation 170 // Must change focus! 171 var $target = $(target); 172 $target.focus(); 173 if ($target.is(":focus")) { // Checking if the target was focused 174 return false; 175 } else { 176 $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable 177 $target.focus(); // Set focus again 178 }; 179 }); 180 } 181 } 182 }); 183 184 /** 185 * detect IE 186 */ 187 var ua = window.navigator.userAgent; 188 var isIE = /MSIE|Trident/.test(ua); 189 if ( isIE ) { 190 var answer = confirm("You are using an outdated browser. Please upgrade your browser to improve your experience.") 191 if(answer){ 192 window.location="http://browsehappy.com"; 193 } 194 } 195 196 var resizeSearchForm = function(){ 197 if($(window).width() < 1024){ 198 $('.search-form').css('width', $(window).width()); 199 }else{ 200 $('.search-form').css('width', ''); 201 } 202 } 203 204 /** 205 * Adjust site inner margin top to compensate for sticky header height. 206 * 207 * @since 2.6.0 208 */ 209 var moveContentBelowFixedHeader = function() { 210 /* 211 var siteInnerMarginTop = 0; 212 213 if( $('.site-header').css('position') === 'fixed' ) { 214 siteInnerMarginTop = $('.site-header').outerHeight(); 215 } 216 217 $('.site-inner').css('margin-top', siteInnerMarginTop); 218 */ 219 220 if($('.above-header').length){ 221 var above_header_height = 0; 222 if( $('.site-header').css('position') === 'fixed' ) { 223 above_header_height = $('.above-header').outerHeight(); 224 } 225 $('.site-header').css('margin-top', above_header_height); 226 $('.above-header-placeholder').height(above_header_height); 227 } 228 }, 229 230 /** 231 * Initialize RWC Base. 232 * 233 * Internal functions to execute on full page load. 234 * 235 * @since 2.6.0 236 */ 237 load = function() { 238 moveContentBelowFixedHeader(); 239 resizeSearchForm(); 240 241 $( window ).resize(function() { 242 moveContentBelowFixedHeader(); 243 resizeSearchForm(); 244 }); 245 246 // Run after the Customizer updates. 247 // 1.5s delay is to allow logo area reflow. 248 /* if (typeof wp != "undefined" && typeof wp.customize != "undefined") { 249 wp.customize.bind( 'change', function ( setting ) { 250 setTimeout(function() { 251 moveContentBelowFixedHeader(); 252 }, 1500); 253 }); 254 } */ 255 }; 256 257 // Search toggle 258 $('.nav-top-left .search-toggle').click(function(e){ 259 e.preventDefault(); 260 $(this).parent().toggleClass('active').find('input[type="search"]').focus(); 261 }); 262 $('.search-submit').click(function(e){ 263 if( $(this).parent().find('.search-field').val() == '' ) { 264 e.preventDefault(); 265 $(this).parent().parent().removeClass('active'); 266 } 267 }); 268 $('.search-form-close').click(function(e){ 269 e.preventDefault(); 270 $(this).parent().parent().parent().toggleClass('active'); 271 }); 272 273 // reports category on load 274 if($('.reports-category').length){ 275 $('.reports-category').each(function(){ 276 $(this).data('id'); 277 rwc_ce_reports_ajax($(this).data('id'), 1); 278 $(this).addClass('loading'); 279 }); 280 } 281 282 // reports category load more button on click 283 if($('.reports-category-load').length){ 284 $('.reports-category-load').click(function(e){ 285 $(this).prop("disabled",true); 286 rwc_ce_reports_ajax($(this).parent().data('id'), $(this).attr('data-page')); 287 $(this).parent().addClass('loading'); 288 }); 289 } 290 291 // reports category ajax 292 function rwc_ce_reports_ajax(term, page){ 293 $.ajax({ 294 url: ajaxurl, 295 method: 'GET', 296 data: { action: 'rwc_ce_reports_ajax', nonce: rwc_base_vars.nonce, term: term, page: page } 297 }).done(function( response ) { 298 299 if( true === response.success ) { 300 301 let response_json = $.parseJSON( response.data ); 302 303 //console.log(response_json); 304 305 var container = $('[data-id=' + term + ']'); 306 307 $('.reports-category-posts',container).append(response_json.posts); 308 309 if(page > 1){ 310 $('.post-'+response_json.post+' .entry-image', container).focus(); 311 } 312 313 container.removeClass('loading'); 314 315 if(response_json.page){
316 $('.reports-category-load',container).prop("disabled",false).attr('data-page',response_json.page); 317 $('.reports-category-load',container).show(); 318 }else{ 319 $('.reports-category-load',container).hide(); 320 } 321 322 } else { 323 console.log(response); 324 } 325 }); 326 } 327 328 // Moves the draft mode field to the top of the update directory listing form. 329 document.addEventListener( 'DOMContentLoaded', (event) => { 330 const form = document.querySelector( '.acf-form' ); 331 const field = document.querySelector( '.acf-field-6644301e738b5' ); 332 333 if ( form && field ) { 334 form.insertBefore( field, form.firstChild ); 335 } 336 } ); 337 338 // Show/hide the Other Area of Expertise field based on the Other checkbox 339 document.addEventListener('DOMContentLoaded', function() { 340 const otherCheckbox = document.getElementById('mepr_vendor_areas_of_expertise-1-other'); 341 const otherAreaOfExpertiseField = document.querySelector('.mepr_mepr_other_area_of_expertise'); 342 343 if (!otherCheckbox || !otherAreaOfExpertiseField) { 344 return; 345 } 346 347 // Hide the Other Area of Expertise field by default 348 otherAreaOfExpertiseField.style.display = 'none'; 349 otherAreaOfExpertiseField.querySelector('input').required = false; 350 351 // Function to toggle visibility and required attribute of the Other Area of Expertise field 352 function toggleOtherAreaOfExpertise() { 353 if (otherCheckbox.checked) { 354 otherAreaOfExpertiseField.style.display = 'block'; 355 otherAreaOfExpertiseField.querySelector('input').required = true; 356 } else { 357 otherAreaOfExpertiseField.style.display = 'none'; 358 otherAreaOfExpertiseField.querySelector('input').required = false; 359 } 360 } 361 362 // Add event listener to the Other checkbox 363 otherCheckbox.addEventListener('change', toggleOtherAreaOfExpertise); 364 365 // Call the function initially in case the checkbox is already checked 366 toggleOtherAreaOfExpertise(); 367 }); 368 369 // Expose the load and ready functions. 370 return { 371 load: load 372 }; 373 374})( jQuery ); 375 376jQuery( window ).on( 'load', rwcBase.load ); 377 378/** 379 * Memberpress sub account redirect. 380 * Added outside of the rwcBase.load function to ensure it runs immediately. 381 * 382 * @param {string} name param name. 383 * @returns 384 */ 385function rwcGetQueryParam( name ) { 386 var urlParams = new URLSearchParams( window.location.search ); 387 return urlParams.get( name ); 388} 389if ( rwcGetQueryParam( 'sub' ) === '1' ) { 390 // Find the link with the specific class and redirect 391 var link = document.querySelector( 'a.mepr-account-manage-sub-accounts' ); 392 if ( link ) { 393 window.location.href = link.href; 394 } 395}
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.