").addClass("option").css({cursor:"pointer",display:"flex","align-items":"center"}).append(o).append(l);n._runPromises&&n.print(l.empty())._runPromises(),e!=n&&e!=i||o.attr("checked",!0),this.disabled&&o.attr("disabled",!0),o[0].onchange=()=>{this.choice(this.buttons[i]||n,"checkbox"==s&&!o[0].checked),this.jQueryElement.find("label").css("outline","none"),"buttons"==s&&l.css("outline","dotted 1px black")},"buttons"==s&&o.css("display","none"),"top"==this.labels?h.css("flex-direction","column-reverse"):"bottom"==this.labels?h.css("flex-direction","column"):"left"==this.labels&&h.css("flex-direction","row-reverse"),this.jQueryElement.append(h),"radio"==s&&!1===this.labels?l.css("display","none"):this.buttons[i]instanceof t.PennElementCommands&&await this.buttons[i].print(l.empty())._runPromises()}"vertical"==i&&this.jQueryElement.css("flex-direction","column")}this.width||this.jQueryElement.css("max-width","max-content")}this.immediate=function(t,...e){e.length||(e=[t],void 0!==t&&"string"==typeof t&&0!=t.length||(t="Scale")),this.id=t,"string"!=typeof e[0]&&Number(e[0])>0?this.initialButtons=new Array(Number(e[0])):this.initialButtons=e},this.uponCreation=function(e){this.jQueryElement=$("
").css("display","inline-block"),this.choices=[],this.log=!1,this.labels=!1,this.disabled=!1,this.vertical=!1,this.scaleType="radio",this.defaultValue=null,this.orientation="horizontal",this.width=null,this.keys=[],this.buttons=this.initialButtons,this.choice=(t,e)=>{if(this.disabled)return;this.unselected=e||void 0,t&&t._runPromises&&(t=t._element.id);let i=null;"slider"==this.scaleType&&this.firstClick&&(i=Date.now()-this.firstClick,this.firstClick=void 0),this.choices.push([e?"Unselect":"Choice",t,Date.now(),i||"NULL"])},t.controllers.running.safeBind($(document),"keydown",t=>{if(!this.disabled)for(let e=0;e-1)for(let e in this.choices)t.controllers.running.save(this.type,this.id,...this.choices[e]);else this.log.indexOf("first")>-1&&t.controllers.running.save(this.type,this.id,...this.choices[0]),this.log.indexOf("last")>-1&&t.controllers.running.save(this.type,this.id,...this.choices[this.choices.length-1]);else t.controllers.running.save(this.type,this.id,"Choice","NA","Never","No selection happened")},this.value=function(){return this.choices.length&&void 0===this.unselected?this.choices[this.choices.length-1][1]:NaN},this.actions={print:async function(e,...i){await n.apply(this),t.elements.standardCommands.actions.print.apply(this,[e,...i])},select:function(e,i,n){for(var l=0;l=this.buttons.length)return e(t.debug.error("Option "+i+" not found for selection on Scale "+this.id));s.apply(this,[l,n]),e()},unselect:function(t){if("slider"==this.scaleType){let t=this.jQueryElement.find("input[type=range]")[0];t.value=(t.max-t.min)/2}else this.jQueryElement.find("input").removeAttr("checked").change();this.unselected=!0,t()},wait:function(t,e){if("first"==e&&this.choices.length)t();else{let i=!1,s=this.choice;this.choice=n=>{if(s.apply(this,[n]),!i)if(e instanceof Object&&e._runPromises&&e.success){let s=this.disabled;this.disabled="tmp",e._runPromises().then(e=>{"success"==e&&(i=!0,t()),"tmp"==this.disabled&&(this.disabled=s)})}else i=!0,t()}}}},this.settings={button:async function(t){this.scaleType="buttons",await n.apply(this),t()},callback:function(t,...e){let i=this.choice;this.choice=async function(t){let s=this.disabled;if(i.apply(this,[t]),!s)for(let t in e)await e[t]._runPromises()},t()},checkbox:async function(t){this.scaleType="checkbox",await n.apply(this),t()},default:function(e,i){this.buttons.indexOf(i)>-1||Number(i)>=0&&Number(i)"string"==typeof t&&1==t.length).length!=i.length)return e(t.debug.error("Every key should be a string of length 1 in Scale "+this.id,i));this.keys=i.map(t=>t.toUpperCase())}else this.buttons.filter(t=>"string"==typeof t&&1==t.length).length==this.buttons.length?this.keys=this.buttons.map(t=>t.toUpperCase()):this.keys=Array.from({length:this.buttons.length},(t,e)=>e+1);e()},label:async function(t,e,i){if(isNaN(Number(e))||e<0||e>=this.buttons.length)return t();this.buttons[e]=i,await n.apply(this),t()},labels:function(t,e){this.labels=e,t()},labelsPosition:async function(t,e){this.labels=e,await n.apply(this),t()},log:function(t,...e){e.length?this.log=e:this.log=["last"],t()},once:function(t){if(this.hasClicked)e.apply(this);else{let t=this.choice;this.choice=i=>{t.apply(this,[i]),e.apply(this)}}t()},radio:async function(t){this.scaleType="radio",await n.apply(this),t()},size:async function(e,i,s){this.width=i,await n.apply(this),t.elements.standardCommands.settings.size.apply(this,[e,i,s])},slider:async function(t){this.scaleType="slider",await n.apply(this),t()},vertical:async function(t){this.orientation="vertical",this.jQueryElement.parent().length&&await n.apply(this),t()}},this.test={selected:function(t){return!(!this.choices.length||this.unselected)&&(null==t||t==this.choices[this.choices.length-1][1])}}}))}});