!function(){"use strict";var t={311:function(t){t.exports=jQuery}},e={};function i(d){var n=e[d];if(void 0!==n)return n.exports;var a=e[d]={exports:{}};return t[d](a,a.exports,i),a.exports}!function(){var t=i(311);t.entwine("ss",(t=>{t(".WidgetAreaEditor").entwine({onmatch(){const e=t(this).attr("name");this.rewriteWidgetAreaAttributes(),t(`#availableWidgets-${e}`).children().each((function(){1===t(this)[0].nodeType&&(t(this)[0].id=`${t(this)[0].id}-${e}`)}));const i=t(this);t(this).find(".usedWidgets").sortable({opacity:.6,handle:".handle",update(t,e){i.updateWidgets(t,e)},placeholder:"ui-state-highlight",forcePlaceholderSize:!0,start(e,i){const d=t(i.item).closest(".Widget").find("textarea.htmleditor");t.each(d,((e,i)=>{tinyMCE.execCommand("mceRemoveControl",!1,t(i).attr("id"))}))},stop(e,i){const d=t(i.item).closest(".Widget").find("textarea.htmleditor");t.each(d,((e,i)=>{tinyMCE.execCommand("mceAddControl",!0,t(i).attr("id"))}))}}),t(".cms-container").bind("submitform",(t=>{i.beforeSave(t)}))},rewriteWidgetAreaAttributes(){const e=t(this).attr("name"),i=function(e,i){e&&e.each((function(){const e=t(this)[0];e.rewritten||!e.id&&!e.name||(e.id&&0===e.id.indexOf("Widget[")&&(e.id=e.id.replace(/Widget\[/,`Widget[${i}][`)),e.name&&0===e.name.indexOf("Widget[")&&(e.name=e.name.replace(/Widget\[/,`Widget[${i}][`)),e.rewritten="yes")}))};i(t(`#WidgetAreaEditor-${e} .Widget`),e),i(t(`#WidgetAreaEditor-${e} .Widget *`),e)},beforeSave(){const e=t(`#usedWidgets-${t(this).attr("name")}`);e&&(this.sortWidgets(),e.children().each((function(){t(this).beforeSave&&t(this).beforeSave()})))},addWidget(e,i){if(t(`#WidgetAreaEditor-${i}`).attr("maxwidgets")){const e=t(`#WidgetAreaEditor-${i}`).attr("maxwidgets");if(t(`#usedWidgets-${i} .Widget`).length+1>e)return void alert(ss.i18n._t("WidgetAreaEditor.TOOMANY"))}const d=t(this),n=t(this).closest("form").find("input[name=Locale]").val();t.ajax({url:`WidgetController/EditableSegment/${e}`,success(t){d.insertWidgetEditor(t)},data:{locale:n}})},updateWidgets(e,i){const d=t(this).attr("id").split("-").pop();let n=0;t(`#usedWidgets-${d}`).children().each((function(){const e=t(this)[0];e.id&&(t(this).find(`input[name=${e.id.replace(/\]/g,"\\]").replace(/\[/g,"\\[")}\\[Sort\\]]`).val(n),n+=1)}))},insertWidgetEditor(e){const i=t(e).find(".formid").val(),d=e.replace(/Widget\[0\]/gi,`Widget[${i}]`);t(`#usedWidgets-${t(this).attr("name")}`).append(d),this.rewriteWidgetAreaAttributes()},sortWidgets(){t(`#usedWidgets-${t(this).attr("name")}`).children().each((function(e){const i=t(this)[0];if("#comment"!==i.nodeName){const t=i.getElementsByTagName("input");let d;for(let n=0;d=t.item(n);n++)d.name===`${i.id}[Sort]`&&(d.value=e)}}))},deleteWidget(t){t.remove()}}),t("div.availableWidgets .Widget h3").entwine({onclick(e){const i=t(this).parent().attr("id").split("-"),d=i.pop(),n=i.pop();t(`#WidgetAreaEditor-${d}`).addWidget(n,d)}}),t("div.usedWidgets div.Widget").entwine({onmatch(){t(this).find("span.widgetDelete").click((function(){t(this).closest(".WidgetAreaEditor").deleteWidget(t(this).parent().parent())}))}})}))}()}();