JAVASCRIPT   26
jq2 jQuery noConflict
Guest on 11th March 2023 12:13:14 AM


  1. jq2 = jQuery.noConflict();
  2. jq2(function($) {
  3.     //Custom auto-fill title field in form listing
  4.     var currentPage = jQuery('#submit-job-form');
  5.     if (currentPage.length) {
  6.         console.log('CurrentPage submit form:', currentPage);
  7.         var job_title = jQuery('#job_title');
  8.         job_title.prop("readonly", true);
  9.         // get fields  
  10.         var manufacturing_year = jQuery('#manufacturing-year');
  11.         var car_brand_model = jQuery('#car-brand-model');
  12.         var car_brand_model_selected = jQuery('#car-brand-model');
  13.         var length_ft = jQuery('#length-ft');
  14.         var car_price = jQuery('#car-price');
  15.  
  16.         // Add events
  17.         manufacturing_year.change(function() {
  18.             updateTitle();
  19.         }).change();
  20.         car_brand_model.change(function() {
  21.             updateTitle();
  22.         }).change();
  23.         length_ft.change(function() {
  24.             updateTitle();
  25.         }).change();
  26.         car_price.change(function() {
  27.             updateTitle();
  28.         }).change();
  29.  
  30.         // function to change title value
  31.         function updateTitle() {
  32.             var separator = ' -';
  33.             var p1 = (manufacturing_year.val() && manufacturing_year.val().trim() != '' ? manufacturing_year.val().trim() + separator : '');
  34.             var p2 = '';
  35.             var car_brand_model_selected = '';
  36.             if (car_brand_model.hasClass("select2-hidden-accessible")) {
  37.                 // Select2 has been initialized
  38.                 car_brand_model_selected = car_brand_model.select2('data')[0].text;
  39.             } else if (car_brand_model.text()) {
  40.                 car_brand_model_selected = car_brand_model.text();
  41.             }
  42.             p2 = (car_brand_model_selected && car_brand_model_selected.trim() != '' ? car_brand_model_selected.trim() + separator : '');
  43.             var p3 = (length_ft.val() && length_ft.val().trim() != '' ? length_ft.val().trim() + ' (ft)' + separator : '');
  44.             var p4 = (car_price.val() && car_price.val().trim() != '' ? 'US$ ' + car_price.val().trim() : '');
  45.             job_title.val(`${p1} ${p2} ${p3} ${p4}`);
  46.         }
  47.     } // end add-listing custom js for fields
  48.  
  49.         var searchPage = jQuery('.elementor-page-53');
  50.     if (searchPage.length) {
  51.       $(document).ajaxSuccess(function(event, xhr, ajaxOptions, data) {
  52.         $(".makerTexts").css("display", "none");
  53.         var searchMaker = GetURLParameter('car-brand-model');
  54.         if(searchMaker) {
  55.           searchMaker = searchMaker.split(',')[0];
  56.         }
  57.         //For each brand text we need a line like the following
  58.         if(searchMaker == 'bayliner') $("#baylinerMakerText").css("display", "block");
  59.       });    
  60.     }
  61.  
  62.     // add hide/display phone on mouse over, only for desktop
  63.     var boatCallPhone = jQuery('#boatCallPhone');
  64.     if ($(window).width() > 769) {
  65.         console.log('Activate hide phone numbers.');
  66.     }
  67.     if ($(window).width() > 769) {
  68.         boatCallPhone.mouseover(function() {
  69.             $("#boatHidePhone").css("display", "block");
  70.         }).mouseout(function() {
  71.             $("#boatHidePhone").css("display", "none");
  72.         });
  73.     }
  74.  
  75.     // add hide/display phone on mouse over Call Us Btn, only for desktop
  76.     var callNowBtn = jQuery('.callNowBtn');
  77.     if ($(window).width() > 769) {
  78.         callNowBtn.mouseover(function() {
  79.             $(".callNowHideBtn").css("display", "inline");
  80.         }).mouseout(function() {
  81.             $(".callNowHideBtn").css("display", "none");
  82.         });
  83.     }
  84.  
  85.     var currentPageListing = jQuery('.single-job-listing');
  86.     if (currentPageListing.length) {
  87.         //add content to subject your-subject
  88.         var title = $(document).attr('title');
  89.         var your_subject = jQuery("input[name='your-subject']");
  90.         console.log('Add content to subject.', title);
  91.         if (your_subject && your_subject.val) {
  92.             your_subject.attr('value', title);
  93.             your_subject.val(title);
  94.         }
  95.  
  96.     }
  97. });

Raw Paste

Login or Register to edit or fork this paste. It's free.