0

I have a problem with the theme i use, no longer supported .

***/wp-content/themes/country-inn/assets/js/page-builder-widgets.js: jQuery.fn.live() is deprecated

The problem is in this line:

jQuery(“.pt-country-inn-remove”).live(‘click’, function() { jQuery(this).parent().parent().remove();

Can anyone please tell me how can i change the code on this line of code to update and use use the on() instead.

Hope you can help me.

Playdiune
  • 3
  • 3

2 Answers2

0

The updated code looks like following:

   jQuery(“.pt-country-inn-remove”).on(‘click’, 'body' ,function() {

   jQuery(this).parent().parent().remove();

   });

See this Stackoverflow Answer for further info.

Fewture
  • 33
  • 6
  • Hello, thanks for your response. after i upgrade the line as you told me to do i still get the same error advice on this file and i can check on the site that the problem is still there. I'll leave the complete file below to find out if there are any further changes needed. Please, help me. – Playdiune Nov 24 '20 at 17:28
  • @Playdiune Can You provide the exact error message, you are receiving? Also in which line does the error occur? – Fewture Nov 24 '20 at 18:26
  • The error is the one i mentioned in the first post. I allready did the change you told me to do. The entire file is below. I still Get the same error. – Playdiune Nov 24 '20 at 18:49
  • This is the Message i get from the plugin o installed to help me: jQuery Migrate Helper — Warnings encountered This page generated the following warnings: https://digusto.pt/wp-content/themes/country-inn/assets/js/page-builder-widgets.js: jQuery.fn.live() is deprecated – Playdiune Nov 24 '20 at 19:10
  • @Playdiune Use DevTools for debugging purposes please. Use e.g chrome , and click F12 on your keyboard. Show me the Console Output afterwards... – Fewture Nov 24 '20 at 19:46
  • Found the problem . It was a browser cache problem. After i clean the browser cache, everything is ok. Thanks a lot for your help. After i used the devtools, i saw the changes i had made didnt load on browser. – Playdiune Nov 25 '20 at 19:53
  • @Playdiune Perfect, if my answer was the one that solved your problem, do not forget to mark it as the accepted answer! :) – Fewture Nov 26 '20 at 15:28
0

This is the file reported. Pleaqse tell me if there is something more to update.

jQuery(document).ready(function($) {

        var at_document = $(document);

    at_document.on('click','.media-image-upload', function(e){

        // Prevents the default action from occuring.
        e.preventDefault();
        var media_image_upload = $(this);
        var media_title = $(this).data('title');
        var media_button = $(this).data('button');
        var media_input_val = $(this).prev();
        var media_image_url_value = $(this).prev().prev().children('img');
        var media_image_url = $(this).siblings('.img-preview-wrap');

        var meta_image_frame = wp.media.frames.meta_image_frame = wp.media({
            title: media_title,
            button: { text:  media_button },
            library: { type: 'image' }
        });
        // Opens the media library frame.
        meta_image_frame.open();
        // Runs when an image is selected.
        meta_image_frame.on('select', function(){

            // Grabs the attachment selection and creates a JSON representation of the model.
            var media_attachment = meta_image_frame.state().get('selection').first().toJSON();

            // Sends the attachment URL to our custom image input field.
            media_input_val.val(media_attachment.url);
            if( media_image_url_value !== null ){
                media_image_url_value.attr( 'src', media_attachment.url );
                media_image_url.show();
                LATESTVALUE(media_image_upload.closest("p"));
            }
        });
    });

   // Runs when the image button is clicked.
    jQuery('body').on('click','.media-image-remove', function(e){
        $(this).siblings('.img-preview-wrap').hide();
        $(this).prev().prev().val('');
    });
   
    var LATESTVALUE = function (wrapObject) {
        wrapObject.find('[name]').each(function(){
            $(this).trigger('change');
        });
    };  

});


jQuery(document).ready(function($) {

    var count = 0;
    jQuery("body").on('click','.pt-country-inn-add', function(e) {

      e.preventDefault();
       
      var widget_id = $(this).attr('data-id');

      var ID=  $(this).attr('id');
      var arr11 = ID.split('-');
      var num= arr11[2];
      var additional = $(this).parent().parent().find('.pt-country-inn-additional');
      var add = $(this).parent().parent().find('.pt-country-inn-add');
      count = additional.find('.pt-country-inn-sec').length;
   
      //Json response
      $.ajax({
        type      : "GET",
        url       : ajaxurl,
        data      : {
            action: 'business_way_wp_pages_plucker',
        },
        dataType: "json",
        success: function (data) {

            var options = '<option disabled>Select pages</option>';

            $.each(data, function( index, value ) {
                var option = '<option value="'+index+'">'+value+'</option>';
                options += option;
            });


            additional.append(
                '<div class="pt-country-inn-sec"><div class="sub-option section widget-upload">'+
                '<label for="widget-'+widget_id+'-'+num+'-features-'+count+'">Pages</label>'+
                '<select class="widefat" id="widget-'+widget_id+'-'+num+'-features-'+count+'-page_ids"'+
                'name="widgets['+num+'][features]['+count+'][page_ids]">'+ options + '</select>' +
                '<a class="pt-country-inn-remove delete">Remove Feature</a></div></div>' );

        }   
        });   
      
    });

    jQuery(".pt-country-inn-remove").on('click', 'body', function() {
        jQuery(this).parent().parent().remove();
    });

});
Playdiune
  • 3
  • 3