!function(e){"function"==typeof define&&define.amd?define("repeaterField",e):e()}(function(){"use strict";function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}jQuery(function(f){function e(){f(".resturant-menu-repeater").each(function(){var l=f(this),c=l.find("[data-repeater-list]"),s=l.find("[data-repeater-create]");c.length&&"function"==typeof f.fn.sortable&&!c.hasClass("ui-sortable")&&c.sortable({animation:150,handle:".repeater-drag-handle",placeholder:"sortable-placeholder",forcePlaceholderSize:!0,helper:"clone",appendTo:l,items:"> [data-repeater-item]",start:function(e,t){t.placeholder.height(t.item.outerHeight()),t.item.addClass("sortable-dragging")},stop:function(e,t){t.item.removeClass("sortable-dragging"),c.trigger("repeater:reordered",{item:t.item,newIndex:t.item.index()})}}),c.off("click.repeaterDuplicate").on("click.repeaterDuplicate",".repeater-duplicate-action",function(e){e.preventDefault();var e=f(this).closest("[data-repeater-item]"),t=parseInt(l.attr("data-selection-limit"),10);if(!isNaN(t)&&0<t&&t<=c.find("[data-repeater-item]").length)return;var a,i,r,n,o,d={},t=(e.find("input, textarea, select").each(function(){var e=f(this),t=e.attr("name");t&&(t=t.match(/\[([^\]]+)\]$/))&&t[1]&&(t=t[1],e.is(":checkbox")?d[t]=e.prop("checked"):e.is(":radio")?e.prop("checked")&&(d[t]=e.val()):e.is('input[type="file"]')||(d[t]=e.val()))}),s.trigger("click"),c.find("[data-repeater-item]:last")),p=(t.find("input, textarea, select").each(function(){var e=f(this),t=e.attr("name");t&&(t=t.match(/\[([^\]]+)\]$/))&&t[1]&&(t=t[1],d.hasOwnProperty(t))&&(e.is(":checkbox")?e.prop("checked",d[t]):e.is(":radio")?e.val()===d[t]?e.prop("checked",!0):e.prop("checked",!1):e.is('input[type="file"]')||e.val(d[t]))}),"mylisting_accordion_photo");d.hasOwnProperty(p)&&d[p]&&(a=d[p],(p=t.find('input[type="file"][name$="['+p+']"]')).length)&&p.attr("name")&&(i=p.attr("name"),(r=t.find('input[type="hidden"][name="'+i+'"]')).length||(r=f('<input type="hidden">').attr("name",i).addClass("input-text outer-photo"),p.after(r)),r.val(a),(r=t.find(".job-manager-uploaded-files")).empty(),a&&"object"===("undefined"==typeof CASE27?"undefined":u(CASE27))&&CASE27.js_field_html_img&&((n=f(f.parseHTML(CASE27.js_field_html_img))).find(".job-manager-uploaded-file-preview img").attr("src",a),(o=n.find(".input-text")).val(a),o.attr("name","current_"+i),r.append(n),"function"==typeof RemoveUploadedFile)&&RemoveUploadedFile(r),p.val("")),"function"==typeof RepeaterUploadFiles&&RepeaterUploadFiles(t),t.trigger("repeater:item:duplicated",{originalItem:e.get(0),newItem:t.get(0)}),f(document).trigger("mylisting:refresh-scripts")})})}function t(){f(".resturant-menu-repeater").each(function(){var e,t=f(this),a=t.find("[data-repeater-list]"),i=t.find("[data-repeater-create]"),r=parseInt(t.attr("data-selection-limit"),10);function n(){var e=a.find("[data-repeater-item]").length;r<=e?(t.find(".repeater-duplicate-action").prop("disabled",!0).addClass("disabled"),i.prop("disabled",!0).addClass("disabled")):(t.find(".repeater-duplicate-action").prop("disabled",!1).removeClass("disabled"),i.prop("disabled",!1).removeClass("disabled"))}isNaN(r)||r<=0||(n(),e=new MutationObserver(function(e){e.forEach(function(e){"childList"===e.type&&n()})}),a.length&&a.get(0)&&e.observe(a.get(0),{childList:!0}),i.on("click",function(){setTimeout(n,50)}))})}function a(){"function"==typeof RepeaterUploadFiles?f(".resturant-menu-repeater [data-repeater-item]").each(function(){RepeaterUploadFiles(f(this))}):setTimeout(a,500)}e(),t(),a(),f(document).on("repeater-initialized c27-tab-changed",function(){e(),t(),a()})})});
