1 line
1.5 KiB
JavaScript
1 line
1.5 KiB
JavaScript
var a11yCheckboxGroupBinding=new Shiny.InputBinding;$.extend(a11yCheckboxGroupBinding,{find:function(e){return $(e).find(".shiny-input-a11ycheckboxgroup")},getValue:function(e){var n=$('input:checkbox[name="'+e.id+'"]:checked'),t=new Array(n.length);for(let e=0;e<n.length;e++)t[e]=n[e].value;return t},setValue:function(n,t){if(t=t||[],$('input:checkbox[name="'+n.id+'"]').prop("checked",!1),t instanceof Array)for(let e=0;e<t.length;e++)$('input:checkbox[name="'+n.id+'"][value="'+t[e]+'"]').prop("checked",!0);else $('input:checkbox[name="'+n.id+'"][value="'+t+'"]').prop("checked",!0)},getState:function(e){var n=$('input:checkbox[name="'+e.id+'"]'),t=new Array(n.length);for(let e=0;e<t.length;e++)t[e]={value:n[e].value,label:getLabel(n[e])};return{label:getLabelNode(e).text(),value:this.getValue(e),options:t}},receiveMessage:async function(e,n){var t=$(e);Object.prototype.hasOwnProperty.call(n,"options")&&void 0!==n.options&&(t.find("div.shiny-options-group").remove(),t.find("label.checkbox").remove(),t.append(n.options),t.find(".select-all-container").appendTo(t)),Object.prototype.hasOwnProperty.call(n,"value")&&void 0!==n.value&&this.setValue(e,n.value),Object.prototype.hasOwnProperty.call(n,"label")&&void 0!==n.label&&await updateLabel(n.label,t.find("legend")),$(e).trigger("change")},subscribe:function(e,n){$(e).on("change.checkboxGroupInputBinding",function(){n(!1)})},unsubscribe:function(e){$(e).off(".checkboxGroupInputBinding")}}),Shiny.inputBindings.register(a11yCheckboxGroupBinding); |