!function(e){e.fn.llmsCollapsible=function(){returnthis.on("click",".llms-collapsible-header",function(){vart=e(this).closest(".llms-collapsible"),a=t.siblings(".llms-collapsible");t.toggleClass("opened").trigger("llms-collapsible-toggled"),t.find(".llms-collapsible-body").slideToggle(400),a.each(function(){e(this).removeClass("opened"),e(this).find(".llms-collapsible-body").slideUp(400)})}),this},window.llms=window.llms||{};vart=function(){this.repeaters={metaboxes:this,$repeaters:null,init:function(){vart=this;t.$repeaters=e(".llms-mb-list.repeater"),t.$repeaters.length&&(LLMS.wait_for(function(){return"undefined"!=typeoftinyMCE},function(){t.load(),t.bind()}),e('#post input[type="submit"], #post-preview').on("click",function(){e(this).attr("data-llms-clicked","yes")}),e("#post").on("submit",t.handle_submit))},bind:function(){vart=this;t.$repeaters.each(function(){vara=e(this),l=a.find(".llms-repeater-rows");a.find(".llms-repeater-new-btn").on("click",function(){t.add_row(a,null,!0)}),l.sortable({handle:".llms-drag-handle",items:".llms-repeater-row",start:function(e,t){l.addClass("dragging")},stop:function(n,i){l.removeClass("dragging");vars=i.item.find("textarea.wp-editor-area");s.each(function(){vart=e(this).attr("id");tinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,t),tinyMCE.EditorManager.execCommand("mceAddEditor",!0,t)}),t.save(a)}}),a.on("click",".llms-repeater-remove",function(l){l.stopPropagation();varn=e(this).closest(".llms-repeater-row");window.confirm(LLMS.l10n.translate("Are you sure you want to delete this row? This cannot be undone."))&&(n.remove(),setTimeout(function(){t.save(a)},1))})})},add_row:function(t,a,l){varn=this,i=t.find(".llms-repeater-rows"),s=t.find(".llms-repeater-model"),r=n.clone_row(s.find(".llms-repeater-row")),o=t.find(".llms-repeater-row").length,d=n.reindex(r,o);a&&e.each(a,function(t,a){varl=r.find('[name^="'+t+'"]');l.hasClass("llms-select2-student")?(e.each(a,function(e,t){l.append('<option value="'+t.key+'" selected="selected">'+t.title+"</option>")}),l.trigger("change")):l.val(a)}),setTimeout(function(){n.bind_row(r)},1),i.append(r),l&&r.find(".llms-collapsible-header").trigger("click"),tinyMCE.EditorManager.execCommand("mceAddEditor",!0,d),t.trigger("llms-new-repeater-row",{$row:r,data:a})},bind_row:function(e){this.bind_row_header(e),e.find(".llms-select2").llmsSelect2({width:"100%"}),e.find(".llms-select2-student").llmsStudentsSelect2(),this.metaboxes.bind_datepickers(e.find(".llms-datepicker")),this.metaboxes.bind_controllers(e.find("[data-is-controller]"))},bind_row_header:function(t){vara=t.find(".llms-repeater-title"),l=t.find(".llms-collapsible-header-title-field");a.attr("data-default",a.text()),l.on("keyup focusout blur",function(){vart=e(this).val();t||(t=a.attr("data-default")),a.text(t)}).trigger("keyup")},clone_row:function(e){return$ed=e.find(".editor textarea"),$ed.length&&tinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,$ed.attr("id")),e.clone()},handle_submit:function(t){vara=e('#post [data-llms-clicked="yes"]'),l=a.parent().find(".spinner");if(a.is("#post-preview"))returnvoida.removeAttr("data-llms-clicked");t.preventDefault(),e('#post input[type="submit"]').addClass("disabled").attr("disabled","disabled"),l.addClass("is-active");varn,i=window.llms.metaboxes.repeaters,s=0;i.$repeaters.each(function(){i.save(e(this))}),n=setInterval(function(){s>=59||!e(".llms-mb-list.repeater.processing").length?(clearInterval(n),e("#post").off("submit",this.handle_submit),l.removeClass("is-active"),a.removeClass("disabled").removeAttr("disabled").trigger("click")):s++},1e3)},load:function(){vart=this;t.$repeaters.each(function(){vara=e(this);a.hasClass("is-loaded")||a.hasClass("processing")||t.store(a,"load",function(l){a.addClass("is-loaded"),e.each(l.data,function(e,l){t.add_row(a,l,!1)}),a.find(".llms-repeater-rows .llms-repeater-row").each(function(){t.bind_row(e(this))})})})},reindex:function(t,a){functionl(t,l){t.each(function(){vart=e(this).attr(l);e(this).attr(l,t.replace(n,a))})}varn=t.attr("data-row-order"),i=t.find(".llms-mb-list.editor textarea");returntinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,i.attr("id")),t.attr("data-row-order",a),l(t,"data-row-order"),l(t.find("button.insert-media"),"data-editor"),l(t.find('input[name^="_llms"], textarea[name^="_llms"], select[name^="_llms"]'),"id"),l(t.find('input[name^="_llms"], textarea[name^="_llms"], select[name^="_llms"]'),"name"),l(t.find("[data-controller]"),"data-controller"),l(t.find("[data-controller]"),"data-controller"),l(t.find("button.wp-switch-editor"),"data-wp-editor-id"),l(t.find("button.wp-switch-editor"),"id"),l(t.find(".wp-editor-tools"),"id"),l(t.find(".wp-editor-container"),"id"),i.attr("id")},save:function(e){e.trigger("llms-repeater-before-save",{$el:e}),this.store(e,"save")},serialize:function(t){vara=[];returnt.find(".llms-repeater-rows .llms-repeater-row").each(function(){vart={};e(this).find('input[name^="_llms"], select[name^="_llms"]').each(function(){t[e(this).attr("name")]=e(this).val()}),e(this).find('textarea[name^="_llms"]').each(function(){vara=e(this).attr("name");tinyMCE.editors[a]?t[a]=tinyMCE.editors[a].getContent():t[a]=e(this).val()}),a.push(t)}),a},store:function(e,t,a){a=a||function(){};varl=this,n={action:e.find(".llms-repeater-field-handler").val(),store_action:t};"save"===t&&(n.rows=l.serialize(e)),LLMS.Ajax.call({data:n,beforeSend:function(){e.addClass("processing"),LLMS.Spinner.start(e)},success:function(t){a(t),LLMS.Spinner.stop(e),e.removeClass("processing")}})}},this.repeaters.init(),this.init=function(){vart=this;e(".llms-select2-post").each(function(){t.post_select(e(this))}),e(".llms-collapsible-group").llmsCollapsible(),this.bind_tabs(),this.bind_mce_fixes();vara=[{selector:e(".llms-datepicker"),func:"bind_datepickers"},{selector:e(".llms-select2"),func:function(e){e.llmsSelect2({width:"100%"})}},{selector:e(".llms-select2-student"),func:function(e){e.llmsStudentsSelect2()}},{selector:e('input[type="checkbox"][data-controls]'),func:"bind_cb_controllers"},{selector:e("[data-is-controller]"),func:"bind_controllers"},{selector:e(".llms-table"),func:"bind_tables"},{selector:e(".llms-merge-code-wrapper"),func:"bind_merge_code_buttons"},{selector:e("a.llms-editable, button.llms-editable"),func:"bind_editables"}];if(e.each(a,function(a,l){if(l.selector.length){varn=l.selector.filter(function(){return0===e(this).closest(".llms-repeater-model").length});"string"==typeofl.func?t[l.func](n):"function"==typeofl.func&&l.func(n)}}),window.llms.post.post_type){varl="bind_"+window.llms.post.post_type;"function"==typeofthis[l]&&this[l]()}},this.bind_cb_controllers=function(t){t=t||e('input[type="checkbox"][data-controls]'),t.each(function(){vart=e(this),a=e(t.attr("data-controls")).closest(".llms-mb-list");t.on("change",function(){e(this).is(":checked")?a.slideDown(200):a.slideUp(200)}),t.trigger("change")})},this.bind_controllers=function(t){t=t||e("[data-is-controller]"),t.each(function(){vart,a=e(this),l=e('[data-controller="#'+a.attr("id")+'"]');a.on("change",function(){t="checkbox"===a.attr("type")?a.is(":checked")?a.val():"false":a.val(),l.each(function(){vara=e(this).attr("data-controller-value"),l=[];-1!==a.indexOf(",")?l=a.split(","):l.push(a),-1!==l.indexOf(t)?e(this).slideDown(200):e(this).slideUp(200)})}),a.trigger("change")})},this.bind_datepicker=function(e){vart=e.attr("data-format")||"mm/dd/yy",a=e.attr("data-max-date")||null,l=e.attr("data-min-date")||null;e.datepicker({dateFormat:t,maxDate:a,minDate:l})},this.bind_datepickers=function(t){vara=this;t=t||e(".llms-datepicker"),t.each(function(){a.bind_datepicker(e(this))})},this.bind_editables=function(){functiont(t){varl,n=t.find("label").clone(),i=t.attr("data-llms-editable"),s=t.attr("data-llms-editable-type"),r=t.attr("data-llms-editable-required")||"no",o=t.attr("data-llms-editable-value");if(r="yes"===r?' required="required"':"","select"===s){vard,c=JSON.parse(t.attr("data-llms-editable-options"));l=e('<select name="'+i+'"'+r+" />");for(varminc)d=o===m?' selected="selected"':"",l.append('<option value="'+m+'"'+d+">"+c[m]+"</option>")}elseif("datetime"===s){l=e('<div class="llms-datetime-field" />'),o=JSON.parse(o);varu=t.attr("data-llms-editable-date-format")||"",f=t.attr("data-llms-editable-date-min")||"",p=t.attr("data-llms-editable-date-max")||"";$picker=e('<input class="llms-date-input llms-datepicker" data-format="'+u+'" data-max-date="'+p+'" data-min-date="'+f+'" name="'+i+'[date]" type="text" value="'+o.date+'">'),a.bind_datepicker($picker),l.append($picker),l.append("<em>@</em>"),l.append('<input class="llms-time-input" max="23" min="0" name="'+i+'[hour]" type="number" value="'+o.hour+'">'),l.append("<em>:</em>"),l.append('<input class="llms-time-input" max="59" min="0" name="'+i+'[minute]" type="number" value="'+o.minute+'">')}elsel=e('<input name="'+i+'" type="'+s+'" value="'+o+'"'+r+">");t.empty().append(n).append(l),"select"===s&&setTimeout(function(){l.trigger("change")},100)}vara=this;e("a.llms-editable, button.llms-editable").on("click",function(a){a.preventDefault();varl,n=e(this);l=n.attr("data-fields")?e(n.attr("data-fields")):n.closest(".llms-metabox-section").find("[data-llms-editable]"),n.remove(),l.each(function(){t(e(this))})})},this.bind_llms_engagement=function(){vart=this;e("#_llms_engagement_type").on("change",function(){e("#_llms_engagement").trigger("llms-engagement-type-change",e(this).val())}),e("#_llms_engagement").on("llms-engagement-type-change",function(a,l){varn=e(this);switch(l){case"achievement":case"certificate":case"email":vari="llms_"+l;n.val(null).attr("data-post-type",i).trigger("change"),t.post_select(n);break;default:n.trigger("llms-engagement-type-change-external",l)}})},this.bind_llms_membership=function(){functiont(){vare=l.find("tbody tr");1===e.length?e.first().show():e.first().hide()}functiona(){vart=[];returnl.find('tbody tr a[href="#llms-course-remove"]').each(function(){t.push(e(this).attr("data-id"))}),t}varl=e(".llms-mb-list._llms_content_table");t(),l.on("click",'a[href="#llms-course-remove"]',function(a){a.preventDefault();varl=e(this),n=l.closest("tr"),i=l.closest(".llms-mb-list");LLMS.Spinner.start(i),window.LLMS.Ajax.call({data:{action:"membership_remove_auto_enroll_course",course_id:l.attr("data-id")},beforeSend:function(){i.find("p.error").remove()},success:function(e){e.success?(n.fadeOut(200),setTimeout(function(){n.remove(),t()},400)):i.prepend('<p class="error">'+e.message+"</p>"),LLMS.Spinner.stop(i)}})}),l.on("click",'a[href="#llms-course-bulk-enroll"]',function(t){t.preventDefault();vara=e(this),l=(a.closest("tr"),a.closest(".llms-mb-list"));window.confirm(LLMS.l10n.translate("Click okay to enroll all active members into the selected course. Enrollment will take place in the background and you may leave your site after confirmation. This action cannot be undone!"))&&(LLMS.Spinner.start(l),window.LLMS.Ajax.call({data:{action:"bulk_enroll_membership_into_course",course_id:a.attr("data-id")},beforeSend:function(){l.find("p.error").remove()},success:function(e){e.success?a.replaceWith('<strong style="float:right;">'+e.data.message+" </strong>"):l.prepend('<p class="error">'+e.message+"</p>"),LLMS.Spinner.stop(l)}}))}),e("#_llms_auto_enroll").on("change",function(){varl=e(this).val(),n=e(this).find('option[value="'+e(this).val()+'"]').text();if(l){if(-1!==a().indexOf(l))returnalert(LLMS.l10n.replace('"%s" is already in the course list.',{"%s":n})),voide(this).val("").trigger("change");vari=e(".llms-mb-list._llms_content_table");$tr=e("<tr />"),$tr.append('<td><span class="llms-drag-handle" style="color:#999;"><i class="fa fa-ellipsis-v" aria-hidden="true" style="margin-right:2px;"></i><i class="fa fa-ellipsis-v" aria-hidden="true"></i></span></td>'),$tr.append('<td><a href="'+window.llms.admin_url+"post.php?action=edit&post="+l+'">'+n+"</a></td>"),$tr.append('<td><a class="llms-button-danger small" data-id="'+l+'" href="#llms-course-remove" style="float:right;">'+LLMS.l10n.translate("Remove course")+'</a><a class="llms-button-secondary small" data-id="'+l+'" href="#llms-course-bulk-enroll" style="float:right;">'+LLMS.l10n.translate("Enroll All Members")+"</a></td>"),i.find("table tbody").append($tr),e(this).val("").trigger("change"),t(),i.trigger("llms-save-autoenroll-courses")}}),l.find("table tbody").sortable({handle:".llms-drag-handle",stop:function(e,t){t.item.closest(".llms-mb-list").trigger("llms-save-autoenroll-courses")}}),l.on("llms-save-autoenroll-courses",function(){vart=e(this);LLMS.Spinner.start(t),window.LLMS.Ajax.call({data:{action:"llms_save_membership_autoenroll_courses",courses:a()},error:function(e,t,a){alert(a)},complete:function(){LLMS.Spinner.stop(t)}})})},this.bind_llms_order=function(){e('button[name="llms-refund-toggle"]').on("click",function(){vart=e(this),a=t.closest("tr"),l=a.attr("data-transaction-id"),n=t.attr("data-refundable"),i="1"===t.attr("data-gateway-supports"),s=t.attr("data-gateway"),r=e("#llms-txn-refund-model .llms-txn-refund-form").clone(),o=r.find(".gateway-btn");"remove"!==t.attr("data-action")?(t.text(LLMS.l10n.translate("Cancel")),t.attr("data-action","remove"),r.find("input").removeAttr("disabled"),r.find('input[name="llms_refund_amount"]').attr("max",n),r.find('input[name="llms_refund_txn_id"]').val(l),i&&(o.find(".llms-gateway-title").text(s),o.show()),a.after(r)):(t.text(LLMS.l10n.translate("Refund")),t.attr("data-action",""),a.next("tr").remove())}),e('button[name="llms-manual-txn-toggle"]').on("click",function(){vart=e(this),a=t.closest("tr"),l=e("#llms-manual-txn-model .llms-manual-txn-form").clone();"remove"!==t.attr("data-action")?(t.text(LLMS.l10n.translate("Cancel")),t.attr("data-action","remove"),l.find("input").removeAttr("disabled"),a.after(l)):(t.text(LLMS.l10n.translate("Record a Manual Payment")),t.attr("data-action",""),a.next("tr").remove())}),e(".llms-metabox").one("focus",'.llms-metabox-field[data-llms-editable="payment_gateway"] select',function(){e(this).attr("data-original-value")||e(this).attr("data-original-value",e(this).val())}),e(".llms-metabox").on("change",'.llms-metabox-field[data-llms-editable="payment_gateway"] select',function(){vart=e(this),a=t.val(),l=JSON.parse(t.closest(".llms-metabox-field").attr("data-gateway-fields")),n=l[a];for(variinn){vars=e('input[name="'+n[i].name+'"]'),r=s.closest(".llms-metabox-field");n[i].enabled?(r.show(),s.attr("required","required"),s.removeAttr("disabled"),a===t.attr("data-original-value")&&s.val(r.attr("data-llms-editable-value"))):(s.attr("value",""),s.removeAttr("required"),r.hide())}})},this.bind_mce_fixes=function(){void0!==wp.data&&null!==wp.data.select("core/edit-post")&&LLMS.wait_for(function(){returnvoid0!==wp.data.select("core/edit-post").getMetaBoxesPerLocation("normal")},function(){functione(e){return"excerpt"===e||-1!==e.indexOf("llms")||-1!==e.indexOf("lifterlms")}vart=!1;find=["lifterlms-product","lifterlms-membership","lifterlms-course-options"],metaboxes=wp.data.select("core/edit-post").getMetaBoxesPerLocation("normal");for(varainmetaboxes)if(-1!==find.indexOf(metaboxes[a].id)){t=!0;break}if(t){varl={};for(varaintinyMCE.EditorManager.editors)e(a)&&(l[a]=tinyMCE.EditorManager.get(a),tinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,a));setTimeout(function(){for(vareinl)tinyMCE.EditorManager.init(l[e].settings||tinyMCE.EditorManager.settings)},500)}})},this.bind_merge_code_buttons=function(t){t=t||e(".llms-merge-code-wrapper"),t.find(".llms-merge-code-button").on("click",function(){e(this).next(".llms-merge-codes").toggleClass("active")}),t.find(".llms-merge-codes li").on("click",function(){vart=e(this),a=t.closest(".llms-merge-codes"),l=a.attr("data-target"),n=t.attr("data-code");if(-1===l.indexOf("#")){vari=window.tinymce.editors[l];i?i.insertContent(n):alert(LLMS.l10n.translate("Copy this code and paste it into the desired area")+": "+n)}elsee(l).val(e(l).val()+n);a.removeClass("active")})},this.bind_tabs=function(){e(".llms-nav-tab-wrapper .tabs li").on("click",function(){vart=e(this),a=t.closest(".llms-mb-container"),l=t.attr("data-tab");t.siblings().removeClass("llms-active"),a.find(".tab-content").removeClass("llms-active"),t.addClass("llms-active"),e("#"+l).addClass("llms-active")})},this.post_select=function(t){vara="multiple"===t.attr("multiple");if(t.llmsPostsSelect2({width:a?"100%":"65%"}),!a&&!t.attr("data-no-view-button")){varl=LLMS.l10n.translate("View"),n=e('<a class="llms-button-secondary small" style="margin-left:5px;" target="_blank" href="#">'+l+' <i class="fa fa-external-link" aria-hidden="true"></i></a>');t.next(".select2").after(n),t.on("change",function(){vart=e(this).val();t?n.attr("href","/?p="+t).show():n.hide()}).trigger("change")}},this.bind_tables=function(){e('.llms-table button[name="llms-expand-table"]').on("click",function(){vart=e(this),a=t.closest(".llms-table");if(t.attr("data-text")){varl=t.text();t.text(t.attr("data-text")),t.attr("data-text",l)}a.find(".expandable").each(function(){e(this).hasClass("closed")?e(this).addClass("opened").removeClass("closed"):e(this).addClass("closed").removeClass("opened")})})},this.init()};window.llms.metaboxes=newt}(jQuery);//# sourceMappingURL=../maps/js/llms-metaboxes.min.js.map