Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 KB | None | 0 0
  1. !function(e){window.llms=window.llms||{},window.llms.metabox_product=function(){this.temp_id=Math.floor(7777*Math.random()+777),this.init=function(){var l=e("#lifterlms-product #llms-product-options-access-plans");if(l.length){var a,t=this,s=0;a=setInterval(function(){if(s>=300)l.html(LLMS.l10n.translate("There was an error loading the necessary resources. Please try again."));else{if("undefined"==typeof tinyMCE)return void s++;t.bind()}clearInterval(a)},100)}},this.bind=function(){var l=this;e("#llms-save-access-plans").on("click",function(){e("#publish").trigger("click")}),e("#llms-access-plans").on("change","[data-controller-id]",function(){l.controller_change(e(this))}),e("#llms-access-plans .llms-access-plan-datepicker").datepicker({dateFormat:"mm/dd/yy"}),e("#llms-access-plans [data-controller-id]").trigger("change"),e("#llms-new-access-plan").on("click",function(){var a=e(this);l.init_plan(),a.attr("disabled","disabled"),setTimeout(function(){a.removeAttr("disabled")},500)}),e("#llms-access-plans").sortable({handle:".llms-drag-handle",items:".llms-access-plan",start:function(l,a){e("#llms-access-plans").addClass("dragging")},stop:function(a,t){e("#llms-access-plans").removeClass("dragging"),l.update_plan_orders()}}),e("#llms-access-plans").on("keyup","input.llms-plan-title",function(){var l=e(this),a=l.closest(".llms-access-plan"),t=a.find("span.llms-plan-title"),s=l.val(),n=s?s:t.attr("data-default");t.text(n)}),e("#llms-access-plans").on("click",".llms-plan-delete",function(a){a.stopPropagation(),l.delete_plan(e(this))}),window.llms.metaboxes.post_select(e("#llms-access-plans .llms-availability-restrictions")),e("#_llms_plans_content_llms-new-access-plan-model").attr("disabled","disabled"),tinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,"_llms_plans_content_llms-new-access-plan-model"),e("#publish").on("click",function(l){e("#llms-access-plans input").each(function(){if(e(this).is(":invalid")){var l=e(this).closest(".llms-access-plan");return l.hasClass("opened")||l.find(".llms-collapsible-header").trigger("click"),!1}})})},this.delete_plan=function(l){var a=this,t=l.closest(".llms-access-plan"),s=t.attr("data-id");s?e("#llms-delete-plan-modal").topModal({open:function(){e("#llms-confirm-delete-plan").on("click",function(){e("#llms-delete-plan-modal .topModalClose").trigger("click"),window.LLMS.Ajax.call({data:{action:"delete_access_plan",plan_id:s},success:function(e){e.success?a.remove_plan_el(t):e.message&&alert(e.message)}})})},closed:function(){e("#llms-delete-plan-modal").attr("data-plan-id",""),e("#llms-confirm-delete-plan").off("click")}}).attr("data-plan-id",s):a.remove_plan_el(t)},this.controller_change=function(l){var a=l.attr("data-controller-id"),t=l.val(),s=l.closest(".llms-access-plan"),n=s.find('[data-controller="'+a+'"]');"checkbox"===l.attr("type")&&(t=l.is(":checked")?t:"no"),n.each(function(){var l,a,s=e(this),n="SELECT"===s[0].nodeName||"INPUT"===s[0].nodeName||"TEXTAREA"===s[0].nodeName?s:s.find("input, select, textarea"),i=s.attr("data-value-is"),c=s.attr("data-value-is-not");switch("undefined"!=typeof i&&i!==!1?a="==":"undefined"!=typeof c&&c!==!1&&(a="!="),a){case"==":l=t==i?"show":"hide";break;case"!=":l=t!=c?"show":"hide"}"show"===l?(s.show(),n.removeAttr("disabled").trigger("change")):"hide"===l&&(s.hide(),n.attr("disabled","disabled"))})},this.has_plan_limit_been_reached=function(){var l=window.llms.product.access_plan_limit,a=e("#llms-access-plans .llms-access-plan").length;return a>=l},this.init_plan=function(){if(!this.has_plan_limit_been_reached()){var l=e("#llms-new-access-plan-model").clone();$existing_plans=e("#llms-access-plans .llms-access-plan"),$editor=l.find("#_llms_plans_content_llms-new-access-plan-model"),l.removeAttr("id"),$editor.removeAttr("id").attr("id","_llms_plans_content_"+this.temp_id),this.temp_id++,l.find("select, input, textarea").each(function(){e(this).removeAttr("disabled")}),l.find(".llms-access-plan-datepicker").datepicker({dateFormat:"mm/dd/yy"}),l.appendTo("#llms-access-plans"),this.update_plan_orders(),l.find(".llms-collapsible-header").trigger("click"),this.has_plan_limit_been_reached()&&this.toggle_create_button("disable"),window.llms.metaboxes.post_select(l.find(".llms-availability-restrictions")),l.find("[data-controller-id]").trigger("change")}},this.toggle_create_button=function(l){var a=e("#llms-new-access-plan"),t=a.next("p");"disable"===l?(a.attr("disabled","disabled"),t.show()):(a.removeAttr("disabled"),t.hide())},this.remove_plan_el=function(e){var l=this;e.fadeOut(400),setTimeout(function(){e.remove(),l.has_plan_limit_been_reached()||l.toggle_create_button("enable")},450)},this.update_plan_orders=function(){e("#llms-access-plans .llms-access-plan").each(function(){var l=e(this),a=l.find(".plan-order"),t=l.find('textarea[id^="_llms_plans_content_"]'),s=t.attr("id"),n=1*a.val(),i=l.index();tinyMCE.EditorManager.execCommand("mceRemoveEditor",!0,s),l.find("select, input, textarea").each(function(){var l=e(this).attr("name");l&&e(this).attr("name",l.replace(n,i))}),tinyMCE.EditorManager.execCommand("mceAddEditor",!0,s),a.val(i)})},this.init()};new window.llms.metabox_product}(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement