(function($) {
    'use strict';

    $(document).ready(function() {
        // For color selection form field
        if ($('.gridpress-color-field').length > 0) {
            $('.gridpress-color-field').wpColorPicker();
        }

        if ($('.gridpress-carditms-holdr').length > 0) {
            $(".gridpress-carditms-holdr").sortable({
                items: '.gridpress-card-itm',
                placeholder: "gridpress-card-placeholder",
                handle: ".carditm-sorter",
                start : function(e, ui) {
                    var this_item = ui.item;
                    //
                },
                update : function(e, ui) {
                    var this_item = ui.item;
                    //
                }
            }).disableSelection();
        }

        if ($('.gridpress-page-selecter').length > 0) {
            $('.gridpress-page-selecter').select2({
                width: '100%',
                ajax: {
                    type: "POST",
                    url: gridpress_adminscript_str.ajax_url,
                    dataType: 'json',
                    data: function (params) {
                        var query = {
                            q: params.term,
                            gridpress_nonce: gridpress_adminscript_str.nonce,
                            action: 'gridpress_ajax_get_page_results',
                        }
                        return query;
                    },
                    processResults: function(data) {
                        var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                        if (nonce_err == 'failed') {
                            return false;
                        }
                        return {
                            results: data.results
                        };
                    }
                },
                minimumInputLength: 1,
                language: {
                    inputTooShort: function () {
                        return gridpress_func_str.type_to_search;
                    }
                }
            });
        }

        if ($('.gridpress-postitms-selectr').length > 0) {
            $('.gridpress-postitms-selectr').select2({
                width: '100%',
                placeholder: gridpress_adminscript_str.srch_post_itms,
                ajax: {
                    type: "POST",
                    url: gridpress_adminscript_str.ajax_url,
                    dataType: 'json',
                    data: function (params) {
                        var query = {
                            q: params.term,
                            pstype: $(this).attr('data-ptype'),
                            gridpress_nonce: gridpress_adminscript_str.nonce,
                            action: 'gridpress_ajax_get_posts_results'
                        }
                        return query;
                    },
                    processResults: function(data) {
                        var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                        if (nonce_err == 'failed') {
                            return false;
                        }
                        return {
                            results: data.results
                        };
                    }
                },
                minimumInputLength: 1,
                language: {
                    inputTooShort: function () {
                        return gridpress_func_str.type_to_search;
                    }
                }
            });
        }

        if ($('.gridpress-taxterms-selectr').length > 0) {
            $('.gridpress-taxterms-selectr').each(function() {
                $.gridpress_taxterms_slect_drpdwn($(this));
            });
        }

        if ($('.gridpress-gridpsettins-main').length > 0) {
            $('.gridpress-gridpsettins-main').each(function() {
                $.gridpress_grid_settings_con_adjustr($(this));
            });
        }
    });

    $(window).on("resize", function () {
        if ($('.gridpress-gridpsettins-main').length > 0) {
            $('.gridpress-gridpsettins-main').each(function() {
                $.gridpress_grid_settings_con_adjustr($(this));
            });
        }
    });

    $.gridpress_grid_settings_con_adjustr = function (target) {
        var cont_width = target.width();
        target.removeClass(function(index, className) {
            return (className.match(/(^|\s)gridpress-settinsadjustr-\S+/g) || []).join(' ');
        });
        if (cont_width >= 1000) {
            target.addClass('gridpress-settinsadjustr-full');
        } else if (cont_width < 1000 && cont_width >= 800) {
            target.addClass('gridpress-settinsadjustr-medium');
        } else if (cont_width < 800 && cont_width >= 500) {
            target.addClass('gridpress-settinsadjustr-small');
        } else {
            target.addClass('gridpress-settinsadjustr-mobile');
        }
    }

    $.gridpress_taxterms_slect_drpdwn = function (target) {
        target.select2({
            width: '100%',
            placeholder: gridpress_adminscript_str.srch_term_itms,
            ajax: {
                type: "POST",
                url: gridpress_adminscript_str.ajax_url,
                dataType: 'json',
                data: function (params) {
                    var query = {
                        q: params.term,
                        tax_name: target.attr('data-tax'),
                        gridpress_nonce: gridpress_adminscript_str.nonce,
                        action: 'gridpress_ajax_get_terms_results'
                    }
                    return query;
                },
                processResults: function(data) {

                    var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                    if (nonce_err == 'failed') {
                        return false;
                    }
                    return {
                        results: data.results
                    };
                }
            },
            minimumInputLength: 1,
            language: {
                inputTooShort: function () {
                    return gridpress_func_str.type_to_search;
                }
            }
        });
    }

    // For image upload form field
    $('body').on( 'click', '.gridpress-form-imgfield .gridpress-upload-imgbtn, .gridpress-form-imgfield .gridpress-field-inputcon input', function() {
        var button = $(this);
        var main_parent = button.parents('.gridpress-form-imgfield');
        var custom_uploader = wp.media({
            title: gridpress_adminscript_str.insert_img_lbl,
            library : {
                type : 'image'
            },
            button: {
                text: gridpress_adminscript_str.use_img_lbl // button label text
            },
            multiple: false
        }).on('select', function() {
            var attachment = custom_uploader.state().get('selection').first().toJSON();
            main_parent.find('img').attr('src', attachment.url);
            main_parent.find('.gridpress-field-inputcon input[type="text"]').val(attachment.url);
            main_parent.find('.gridpress-field-inputcon input[type="hidden"]').val(attachment.id);
            main_parent.find('.gridpress-field-imgcon').removeClass('gridpress-hide');
            main_parent.find('.gridpress-field-btnscon .gridpress-remvupload-imgbtn').removeClass('gridpress-hide');
        }).open();
    });

    // For removing uploaded image form field
    $('body').on('click', '.gridpress-form-imgfield .gridpress-remvupload-imgbtn', function() {
        var button = $(this);
        var main_parent = button.parents('.gridpress-form-imgfield');
        main_parent.find('.gridpress-field-inputcon input').val('');
        main_parent.find('.gridpress-field-imgcon').addClass('gridpress-hide');
        main_parent.find('.gridpress-field-btnscon .gridpress-remvupload-imgbtn').addClass('gridpress-hide');
    });

    // For file upload form field
    $('body').on( 'click', '.gridpress-form-filefield .gridpress-upload-filebtn', function() {
        var button = $(this);
        var main_parent = button.parents('.gridpress-form-filefield');
        var custom_uploader = wp.media({
            title: gridpress_adminscript_str.insert_video_lbl,
            library : {
                type : 'video'
            },
            button: {
                text: gridpress_adminscript_str.use_video_lbl // button label text
            },
            multiple: false
        }).on('select', function() {
            var attachment = custom_uploader.state().get('selection').first().toJSON();
            main_parent.find('.gridpress-field-inputcon input').val(attachment.url);
        }).open();
    });

    $('.grid-impexprt-impbtn').on('click', function(ev) {
        ev.preventDefault();
        var this_btn = $(this);
        this_btn.closest('.grid-impexprt-btnholder').append('<form method="post"><input type="hidden" name="gridpress_import_json_settings" value="1"><input type="hidden" name="grid_id" value="' + $('#post_ID').val() + '"><input type="hidden" name="gridpress_nonce" value="' + gridpress_adminscript_str.nonce + '"></form>');
        this_btn.closest('.grid-impexprt-btnholder').find('form').trigger('submit');
    });

    $('#export-json-to-grid').on('change', function(ev) {
        ev.preventDefault();
        var this_file = $(this);

        var impexprt_hlder = this_file.closest('.grid-impexprt-btnholder');

        impexprt_hlder.append($.gridpress_delay_loader_html());

        var file = this.files[0];
        var form_data = new FormData();
        form_data.append('json_file', file);
        form_data.append('grid_id', $('#post_ID').val());
        form_data.append('gridpress_nonce', gridpress_adminscript_str.nonce);
        form_data.append('action', 'gridpress_ajax_export_grid_settings');
        $.ajax({
            type: "POST",
            dataType: "json",
            url: gridpress_func_str.ajax_url,
            data: form_data,
            processData: false,
            contentType: false,
            success: function (data) {
                var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                if (nonce_err == 'failed') {
                    return false;
                }

                if (data.error == '0') {
                    $.gridpress_submit_msg_alert({
                        msg: data.msg,
                        class: 'gridpress-alert-success'
                    });
                    window.location.reload();
                } else {
                    $.gridpress_submit_msg_alert({
                        msg: data.msg,
                        class: 'gridpress-alert-danger'
                    });
                }

                $.gridpress_remove_delay_loader({
                    target: impexprt_hlder
                });
            },
            error: function () {
                $.gridpress_remove_delay_loader({
                    target: impexprt_hlder
                });
            }
        });
    });

    $('.gridpress-gridpsettins-main .gridpsettins-tabs-cont').on('click', '.gridpsettins-tab-lbl', function() {
        var this_btn = $(this);
        var this_slug = this_btn.attr('data-slug');
        var tabs_cont = this_btn.closest('.gridpress-gridpsettins-main').find('.gridpsettins-tabs-cont');
        var contnt_cont = this_btn.closest('.gridpress-gridpsettins-main').find('.gridpsettins-content-cont');

        tabs_cont.find('.gridpsettins-tab-lbl').each(function() {
            $(this).removeClass('active-gridpsettin-tab');
        });
        this_btn.addClass('active-gridpsettin-tab');
        contnt_cont.find('.gridpsettins-itmcontnt-con').each(function() {
            if (!$(this).hasClass('gridpress-hidden-item')) {
                $(this).addClass('gridpress-hidden-item');
            }
            $(this).removeClass('active-gridpsettin-cont');
        });
        contnt_cont.find('.pseting_contnt_' + this_slug).removeClass('gridpress-hidden-item').addClass('active-gridpsettin-cont');
    });

    $('.gridpress-gridpsettins-main').on('change', '.gridpress-grid-datasource-slecter', function() {
        var this_slecter = $(this);
        var this_cont = this_slecter.closest('.settins-itmcontnt-inner');
        //
        var display_sect_con = this_slecter.closest('.gridpress-gridpsettins-main').find('.pseting_contnt_display');
        //
        if (this_slecter.val() == 'manual') {
            this_cont.find('.gridpress-datamanual-fields').removeClass('gridpress-hidden-item');
            this_cont.find('.gridpress-dataposts-fields').addClass('gridpress-hidden-item');
            if (!display_sect_con.find('.gridpress-posts-topfiltrs-fields').hasClass('gridpress-hidden-item')) {
                display_sect_con.find('.gridpress-posts-topfiltrs-fields').addClass('gridpress-hidden-item');
            }
            if (!display_sect_con.find('.gridpress-posts-topsorting').hasClass('gridpress-hidden-item')) {
                display_sect_con.find('.gridpress-posts-topsorting').addClass('gridpress-hidden-item');
            }
        } else {
            this_cont.find('.gridpress-datamanual-fields').addClass('gridpress-hidden-item');
            this_cont.find('.gridpress-dataposts-fields').removeClass('gridpress-hidden-item');
            //
            display_sect_con.find('.gridpress-posts-topfiltrs-fields').removeClass('gridpress-hidden-item');
            display_sect_con.find('.gridpress-posts-topsorting').removeClass('gridpress-hidden-item');
        }
    });

    $('.gridpress-gridpsettins-main').on('change', '.gridpress-grid-pstsdatatype-slecter', function() {
        var this_slecter = $(this);
        var this_cont = this_slecter.closest('.gridpress-dataposts-fields');
        if (this_slecter.val() == 'selected') {
            this_cont.find('.gridpress-dataposts-slectedfields').removeClass('gridpress-hidden-item');
            this_cont.find('.gridpress-dataposts-allfields').addClass('gridpress-hidden-item');
        } else {
            this_cont.find('.gridpress-dataposts-slectedfields').addClass('gridpress-hidden-item');
            this_cont.find('.gridpress-dataposts-allfields').removeClass('gridpress-hidden-item');
        }
    });

    $('.gridpress-gridpsettins-main').on('change', '.gridpress-grid-psttype-slecter', function() {
        var this_slecter = $(this);
        var this_cont = this_slecter.closest('.gridpress-dataposts-fields');
        var this_val = this_slecter.val();
        var postitms_slectr = this_cont.find('.gridpress-postitms-selectr');
        //
        postitms_slectr.attr('data-ptype', this_val);
        postitms_slectr.val(null).trigger('change');
        //
        var display_sect_con = this_slecter.closest('.gridpress-gridpsettins-main').find('.pseting_contnt_display');
        //
        var tax_fields_con = this_cont.find('.gridpress-psttax-fields');
        tax_fields_con.append($.gridpress_delay_loader_html());
        $.ajax({
            type: "POST",
            dataType: "json",
            url: gridpress_func_str.ajax_url,
            data: {
                pstype: this_val,
                gid: tax_fields_con.attr('data-id'),
                gridpress_nonce: gridpress_adminscript_str.nonce,
                action: 'gridpress_ajax_get_post_taxonomies_html'
            },
            success: function (data) {
                var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                if (nonce_err == 'failed') {
                    return false;
                }

                tax_fields_con.html(data.html);
                if (tax_fields_con.find('.gridpress-taxterms-selectr').length) {
                    tax_fields_con.find('.gridpress-taxterms-selectr').each(function() {
                        $.gridpress_taxterms_slect_drpdwn($(this));
                    });
                }
                //
                if (display_sect_con.find('.gridpress-topfiltrs-slectdtax').length) {
                    display_sect_con.find('.gridpress-topfiltrs-slectdtax').find('.formseting-field-entry').html(data.filtrs_tax_html);
                }
                if (data.filtrs_tax_html == '') {
                    if (!display_sect_con.find('.gridpress-posts-topfiltrs-fields').hasClass('gridpress-hidden-item')) {
                        display_sect_con.find('.gridpress-posts-topfiltrs-fields').addClass('gridpress-hidden-item');
                    }
                } else {
                    display_sect_con.find('.gridpress-posts-topfiltrs-fields').removeClass('gridpress-hidden-item');
                }

                $.gridpress_remove_delay_loader({
                    target: tax_fields_con
                });
            },
            error: function () {
                $.gridpress_remove_delay_loader({
                    target: tax_fields_con
                });
            }
        });
    });

    $('.gridpress-gridpsettins-main').on('click', '.gridpress-card-itm .gridcard-itm-hder .carditm-titlecon, .gridpress-card-itm .gridcard-itm-hder .carditm-updte-btn, .gridpress-card-itm .gridcard-box-closebtn', function() {
        var this_btn = $(this);
        var itm_holder = this_btn.closest('.gridpress-card-itm');
        itm_holder.toggleClass('gridpress-card-itmopen');
        itm_holder.find('.gridcard-itm-contntcon').slideToggle();
    });

    $('.gridpress-gridpsettins-main').on('change', '.gridpress-card-itm .gridpress-card-mediaslect-btn', function() {
        var this_btn = $(this);
        var itm_holder = this_btn.closest('.gridpress-card-itm');
        if (this_btn.val() == 'video') {
            itm_holder.find('.gridpress-carditm-videocon').removeClass('gridpress-hidden-item');
            if (!itm_holder.find('.gridpress-carditm-imgcon').hasClass('gridpress-hidden-item')) {
                itm_holder.find('.gridpress-carditm-imgcon').addClass('gridpress-hidden-item');
            }
        } else {
            itm_holder.find('.gridpress-carditm-imgcon').removeClass('gridpress-hidden-item');
            if (!itm_holder.find('.gridpress-carditm-videocon').hasClass('gridpress-hidden-item')) {
                itm_holder.find('.gridpress-carditm-videocon').addClass('gridpress-hidden-item');
            }
        }
    });

    $('.gridpress-gridpsettins-main').on('click', '.gridpress-card-itm .gridcard-itm-hder .carditm-rmv-btn', function() {
        var this_btn = $(this);
        var itm_holder = this_btn.closest('.gridpress-card-itm');
        $.gridpress_confirm_box({
            title: gridpress_func_str.confirm_comon_title,
            message: gridpress_func_str.delet_common_msg,
            buttons: {
                yes: {
                    title: gridpress_func_str.delet_btn_lbl,
                    class: 'gridpress-delitm-btn',
                    action: function() {
                        itm_holder.remove();
                        $.gridpress_confirm_box.hide();
                    }
                },
                no: {
                    title: gridpress_func_str.cancel_btn_lbl,
                    class: 'gridpress-cancel-act',
                    action: function() {
                        $.gridpress_confirm_box.hide();
                    }
                }
            }
        });
    });

    $('.gridpress-gridpsettins-main').on('click', '.gridpress-card-itm .gridcard-itm-hder .carditm-clone-btn', function() {
        var this_btn = $(this);
        var itm_holder = this_btn.closest('.gridpress-card-itm');
        var cloned_item = itm_holder.clone(); // Clone the element first

        var cloned_id = cloned_item.attr('data-id');
        const new_key = Math.floor(Math.random() * 100000000) + 1;

        cloned_item.html(function(i, html) {
            return html.replace(new RegExp(cloned_id, 'g'), new_key);
        });
        cloned_item.attr('data-id', new_key);

        itm_holder.after(cloned_item);
    });

    $('.gridpress-gridpsettins-main').on('click', '.gridpress-datamanual-fields .gridpress-cardadd-btnholdr a', function() {
        var this_btn = $(this);
        var setins_maincon = this_btn.closest('.gridpress-gridpsettins-main');
        var this_maincon = this_btn.closest('.gridpress-datamanual-fields');
        var itms_con = this_maincon.find('.gridpress-gridmnul-itmscon');
        var itms_holder = itms_con.find('.gridpress-carditms-holdr');

        var genrl_settins_cont = setins_maincon.find('.pseting_contnt_general');
        var grid_style = genrl_settins_cont.find('.gridpress-styles-rdslectr input[type="radio"]:checked').val();

        this_maincon.append($.gridpress_delay_loader_html());
        $.ajax({
            type: "POST",
            dataType: "json",
            url: gridpress_func_str.ajax_url,
            data: {
                gid: itms_con.attr('data-id'),
                style: grid_style,
                gridpress_nonce: gridpress_adminscript_str.nonce,
                action: 'gridpress_ajax_add_manulcard_itm_html'
            },
            success: function (data) {
                var nonce_err = $.gridpress_ajax_security_err_reload({result: data});
                if (nonce_err == 'failed') {
                    return false;
                }

                itms_holder.append(data.html);
                if (itms_holder.find('.gridpress-card-itm:last-child').find('.gridpress-color-field').length) {
                    itms_holder.find('.gridpress-card-itm:last-child').find('.gridpress-color-field').wpColorPicker();
                }

                $.gridpress_remove_delay_loader({
                    target: this_maincon
                });
            },
            error: function () {
                $.gridpress_remove_delay_loader({
                    target: this_maincon
                });
            }
        });
    });

    $('.gridpress-gridpsettins-main').on('keyup', '.gridpress-datamanual-fields .gridpress-card-itm .gridpress-carditm-titlefield', function() {
        var this_field = $(this);
        var this_hdr_labl = this_field.closest('.gridpress-card-itm').find('.gridcard-itm-hder .carditm-titlecon strong');
        this_hdr_labl.html(this_field.val());
    });

    $('.gridpress-styles-rdslectr').on('change', 'input[type="radio"]', function() {
        var this_btn = $(this);
        var slected_style = this_btn.val();
        var setins_maincon = this_btn.closest('.gridpress-gridpsettins-main');
        var datasource_cont = setins_maincon.find('.pseting_contnt_data_source');
        var datadisply_cont = setins_maincon.find('.pseting_contnt_display');
        var datatypo_cont = setins_maincon.find('.pseting_contnt_typography');
        var datasrc_frst_field = datasource_cont.find('.gridpress-formfields-con').find('>.gridpress-formseting-field:nth-child(1)');
        if (slected_style == 'style15' || slected_style == 'style19' || slected_style == 'style21' || slected_style == 'style22' || slected_style == 'style23') {
            if (!datasrc_frst_field.hasClass('gridpress-hidden-item')) {
                datasrc_frst_field.addClass('gridpress-hidden-item');
            }
            datasrc_frst_field.find('.gridpress-form-optbtn').each(function() {
                if ($(this).find('input[type="radio"]').val() == 'manual') {
                    $(this).find('input[type="radio"][value="manual"]').prop('checked', true).trigger('change');
                } else {
                    $(this).find('input[type="radio"]').prop('checked', false);
                }
            });
        } else {
            datasrc_frst_field.removeClass('gridpress-hidden-item');
        }
        //
        if (slected_style == 'style21' || slected_style == 'style22' || slected_style == 'style23') {
            //
            datasource_cont.find('.gridpress-datamanual-fields .gridpress-carditms-holdr').find('.gridpress-card-itm').each(function() {
                var this_mediatype_field = $(this).find('.gridpress-card-mediatype-slctrfield');
                this_mediatype_field.find('.gridpress-form-optbtn').each(function() {
                    if ($(this).find('input[type="radio"]').val() == 'video') {
                        $(this).find('input[type="radio"][value="video"]').prop('checked', true).trigger('change');
                    } else {
                        $(this).find('input[type="radio"]').prop('checked', false);
                    }
                });
                if (!this_mediatype_field.hasClass('gridpress-hidden-item')) {
                    this_mediatype_field.addClass('gridpress-hidden-item');
                }
            });
            //
            if (!datadisply_cont.find('.gridpress-displynpsts-fields').hasClass('gridpress-hidden-item')) {
                datadisply_cont.find('.gridpress-displynpsts-fields').addClass('gridpress-hidden-item');
            }
            datadisply_cont.find('.gridpress-displyvids-fields').removeClass('gridpress-hidden-item');
            //
            if (!datatypo_cont.find('.gridpress-typonpsts-fields').hasClass('gridpress-hidden-item')) {
                datatypo_cont.find('.gridpress-typonpsts-fields').addClass('gridpress-hidden-item');
            }
            datatypo_cont.find('.gridpress-typovids-fields').removeClass('gridpress-hidden-item');
        } else {
            //
            datasource_cont.find('.gridpress-datamanual-fields .gridpress-carditms-holdr').find('.gridpress-card-itm').each(function() {
                var this_mediatype_field = $(this).find('.gridpress-card-mediatype-slctrfield');
                this_mediatype_field.find('.gridpress-form-optbtn').each(function() {
                    if ($(this).find('input[type="radio"]').val() == 'image') {
                        $(this).find('input[type="radio"][value="image"]').prop('checked', true).trigger('change');
                    } else {
                        $(this).find('input[type="radio"]').prop('checked', false);
                    }
                });
                if (!this_mediatype_field.hasClass('gridpress-hidden-item')) {
                    this_mediatype_field.addClass('gridpress-hidden-item');
                }
            });
            //
            if (!datadisply_cont.find('.gridpress-displyvids-fields').hasClass('gridpress-hidden-item')) {
                datadisply_cont.find('.gridpress-displyvids-fields').addClass('gridpress-hidden-item');
            }
            datadisply_cont.find('.gridpress-displynpsts-fields').removeClass('gridpress-hidden-item');
            //
            if (!datatypo_cont.find('.gridpress-typovids-fields').hasClass('gridpress-hidden-item')) {
                datatypo_cont.find('.gridpress-typovids-fields').addClass('gridpress-hidden-item');
            }
            datatypo_cont.find('.gridpress-typonpsts-fields').removeClass('gridpress-hidden-item');
        }
        //
        if (slected_style == 'style19') {
            datasource_cont.find('.gridpress-datamanual-fields .gridpress-carditms-holdr').find('.gridpress-card-itm').each(function() {
                if (!$(this).find('.gridpress-carditm-datefield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-datefield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-catsfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-catsfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                }
                if (!$(this).find('.gridpress-carditm-dbleimgfields').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-dbleimgfields').addClass('gridpress-hidden-item');
                }
                $(this).find('.gridpress-carditm-bgfield').removeClass('gridpress-hidden-item');
            });
        } else {
            datasource_cont.find('.gridpress-datamanual-fields .gridpress-carditms-holdr').find('.gridpress-card-itm').each(function() {
                if (!$(this).find('.gridpress-carditm-bgfield').hasClass('gridpress-hidden-item')) {
                    $(this).find('.gridpress-carditm-bgfield').addClass('gridpress-hidden-item');
                }
                // For style 15
                if (slected_style == 'style15') {
                    $(this).find('.gridpress-carditm-dbleimgfields').removeClass('gridpress-hidden-item');
                } else {
                    if (!$(this).find('.gridpress-carditm-dbleimgfields').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-dbleimgfields').addClass('gridpress-hidden-item');
                    }
                }
                //
                if (slected_style == 'style1') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style2') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-authorfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-commentsfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style3') {
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-commentsfield').removeClass('gridpress-hidden-item');
                } else if (slected_style == 'style4') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-authorfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-excerptfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style5') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-authorfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style6') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-commentsfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style7') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-catsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-catsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style10') {
                    if (!$(this).find('.gridpress-carditm-datefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-datefield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                } else if (slected_style == 'style27') {
                    $(this).find('.gridpress-carditm-datefield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-catsfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-likesfield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                } else if (slected_style == 'style28') {
                    $(this).find('.gridpress-carditm-authorfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-viewsfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-likesfield').removeClass('gridpress-hidden-item');
                    $(this).find('.gridpress-carditm-behancefield').removeClass('gridpress-hidden-item');
                    if (!$(this).find('.gridpress-carditm-catsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-catsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-datefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-datefield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                } else {
                    //
                    if (!$(this).find('.gridpress-carditm-datefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-datefield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-authorfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-authorfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-commentsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-commentsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-catsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-catsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-excerptfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-excerptfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-viewsfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-viewsfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-likesfield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-likesfield').addClass('gridpress-hidden-item');
                    }
                    if (!$(this).find('.gridpress-carditm-behancefield').hasClass('gridpress-hidden-item')) {
                        $(this).find('.gridpress-carditm-behancefield').addClass('gridpress-hidden-item');
                    }
                }
            });
        }
    });

})(jQuery);