!function(r,l){"use strict";function o(e,t){var n=e.scrollTop,a=0,c=e.selectionStart||"0"==e.selectionStart?"ff":!!r.selection&&"ie",l=("ie"==c?(e.focus(),(l=r.selection.createRange()).moveStart("character",-e.value.length),a=l.text.length):"ff"==c&&(a=e.selectionStart),e.value.substring(0,a)),o=e.value.substring(a,e.value.length);e.value=l+t+o,a+=t.length,"ie"==c?(e.focus(),(l=r.selection.createRange()).moveStart("character",-e.value.length),l.moveStart("character",a),l.moveEnd("character",0),l.select()):"ff"==c&&(e.selectionStart=a,e.selectionEnd=a,e.focus()),e.scrollTop=n,e.focus()}r.addEventListener("DOMContentLoaded",function(){r.querySelector(".nrEditor").addEventListener("fields.displayOptions",function(e){var t,n,a,e=e.detail.el.querySelector(".calculation-builder");function c(){t.FieldsHelper.getFieldsArray().filter(function(e){return void 0!==e.name}).forEach(function(e){var t=r.createElement("option");t.value=e.shortcode,t.innerHTML=e.label,a.appendChild(t)}),a.options[0].selected=!0}e&&!(e=e).classList.contains("init")&&((t=l.ConvertFormsBuilder).loadStylesheet("media/plg_convertformstools_calculations/css/calculation_builder.css"),n=e.querySelector("textarea"),(a=e.querySelector("select")).addEventListener("focus",function(){for(var e=a.options.length-1;0<=e;e--)a.options[e].disabled||a.remove(e);c()}),a.addEventListener("change",function(e){o(n,e.target.value)}),e.addEventListener("click",function(e){"submit"==e.target.type&&(e.preventDefault(),e.target.classList.contains("backspace")?(n.value=n.value.slice(0,n.value.length-1),n.focus()):e.target.classList.contains("clear")?(n.value="",n.focus()):o(n,e.target.innerText))}),c(),e.classList.add("init"))})})}(document,window);

