Plugin Directory

Changeset 2042078


Ignore:
Timestamp:
03/01/2019 11:49:09 AM (7 years ago)
Author:
nikolam
Message:

Fix dynamic element not hiding when no values

Location:
sermon-manager-for-wordpress/trunk/assets/js/admin/settings
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sermon-manager-for-wordpress/trunk/assets/js/admin/settings/conditionals.js

    r2042060 r2042078  
    130130            'category': current_value,
    131131            'option_id': table_row.find( 'select' ).attr( 'id' ),
    132             'podcast_id': $_GET['post'],
     132            'podcast_id': $_GET[ 'post' ],
    133133        };
    134134
     
    168168                                }
    169169                            );
     170
    170171                            jQuery.each(
    171172                                response.options,
     
    174175                                }
    175176                            );
     177
    176178                            if ( response.selected ) {
    177179                                table_row.find( 'select' ).val( response.selected ).change();
    178180                            } else {
    179181                                table_row.find( 'select' ).prop( "selectedIndex", 0 );
     182                            }
     183
     184                            if ( Object.keys( response.options ).length === 0 ) {
     185                                table_row.addClass( 'hidden' );
     186                                return;
    180187                            }
    181188                            break;
  • sermon-manager-for-wordpress/trunk/assets/js/admin/settings/conditionals.min.js

    r2042060 r2042078  
    1 "undefined"!=typeof sm_conditionals&&jQuery(function(){jQuery.each(sm_conditionals,function(a,b){let c=jQuery("#"+a),d=c.closest("tr");jQuery.each(b,function(a,b){let c=b.id,e=jQuery("#"+c),f=sm_isset(b.value)?b.value:b["!value"],g=sm_isset(b["!value"]);e.on("change",function(){let a=this.value;sm_hide_show_elements(f,a,g,d)}),sm_hide_show_elements(f,e.val(),g,d)})})});function sm_hide_show_elements(a,b,c,d){let e=d.find("select"),f=a!==b,g=!!e.data("ajax")&&e.data("ajax");if(f=c?!f:f,g||(f?d.addClass("hidden"):d.removeClass("hidden")),g){sm_reset_option_value(e,!d.hasClass("hidden"));let a=sm_get_query_params(document.location.search),c={action:"sm_settings_get_select_data",category:b,option_id:d.find("select").attr("id"),podcast_id:a.post};jQuery.ajax({method:"POST",url:ajaxurl,data:c}).always(function(){sm_reset_option_value(e,!d.hasClass("hidden"))}).done(function(a){if("false"===a)a=!1;else try{a=JSON.parse(a)}catch(b){a=!1}if("object"==typeof a)switch(d.removeClass("hidden"),e.prop("tagName")){case"SELECT":e.find("option").each(function(){jQuery(this.remove())}),jQuery.each(a.options,function(a,b){d.find("select").append(jQuery("<option/>").val(a).text(b))}),a.selected?d.find("select").val(a.selected).change():d.find("select").prop("selectedIndex",0);}!1===a&&d.addClass("hidden")}).fail(function(){switch(e.prop("tabName")){case"SELECT":e.append(jQuery("<option/>").val("").text("Error."));}})}}function sm_reset_option_value(a,b){switch(a.prop("tagName")){case"SELECT":a.find("option").each(function(){jQuery(this.remove())});}b&&a.append(jQuery("<option/>").val("").text("Loading..."))}function sm_isset(a){try{return"undefined"!=typeof a}catch(a){return!1}}function sm_get_query_params(a){a=a.split("+").join(" ");for(var b,c={},d=/[?&]?([^=]+)=([^&]*)/g;b=d.exec(a);)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c}
     1"undefined"!=typeof sm_conditionals&&jQuery(function(){jQuery.each(sm_conditionals,function(a,b){let c=jQuery("#"+a),d=c.closest("tr");jQuery.each(b,function(a,b){let c=b.id,e=jQuery("#"+c),f=sm_isset(b.value)?b.value:b["!value"],g=sm_isset(b["!value"]);e.on("change",function(){let a=this.value;sm_hide_show_elements(f,a,g,d)}),sm_hide_show_elements(f,e.val(),g,d)})})});function sm_hide_show_elements(a,b,c,d){let e=d.find("select"),f=a!==b,g=!!e.data("ajax")&&e.data("ajax");if(f=c?!f:f,g||(f?d.addClass("hidden"):d.removeClass("hidden")),g){sm_reset_option_value(e,!d.hasClass("hidden"));let a=sm_get_query_params(document.location.search),c={action:"sm_settings_get_select_data",category:b,option_id:d.find("select").attr("id"),podcast_id:a.post};jQuery.ajax({method:"POST",url:ajaxurl,data:c}).always(function(){sm_reset_option_value(e,!d.hasClass("hidden"))}).done(function(a){if("false"===a)a=!1;else try{a=JSON.parse(a)}catch(b){a=!1}if("object"==typeof a)switch(d.removeClass("hidden"),e.prop("tagName")){case"SELECT":if(e.find("option").each(function(){jQuery(this.remove())}),jQuery.each(a.options,function(a,b){d.find("select").append(jQuery("<option/>").val(a).text(b))}),a.selected?d.find("select").val(a.selected).change():d.find("select").prop("selectedIndex",0),0===Object.keys(a.options).length)return void d.addClass("hidden");}!1===a&&d.addClass("hidden")}).fail(function(){switch(e.prop("tabName")){case"SELECT":e.append(jQuery("<option/>").val("").text("Error."));}})}}function sm_reset_option_value(a,b){switch(a.prop("tagName")){case"SELECT":a.find("option").each(function(){jQuery(this.remove())});}b&&a.append(jQuery("<option/>").val("").text("Loading..."))}function sm_isset(a){try{return"undefined"!=typeof a}catch(a){return!1}}function sm_get_query_params(a){a=a.split("+").join(" ");for(var b,c={},d=/[?&]?([^=]+)=([^&]*)/g;b=d.exec(a);)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c}
Note: See TracChangeset for help on using the changeset viewer.