learndash-admin-shortcodes.min.js
4.36 KB
var learndash_shortcodes=jQuery.extend(learndash_shortcodes||{},{tinymce_editor:null,show_popup_html:function(){if("undefined"!=typeof learndash_admin_shortcodes_assets&&""!=learndash_admin_shortcodes_assets||(learndash_admin_shortcodes_assets={}),jQuery("#learndash_shortcodes_holder").length)learndash_shortcodes.popup_show();else{jQuery("body").append('<div id="learndash_shortcodes_holder" style="display: none;"><div id="learndash_shortcodes"></div></div>');var e={action:"learndash_generate_shortcodes_content",atts:learndash_admin_shortcodes_assets};jQuery.ajax({type:"POST",url:ajaxurl,dataType:"html",cache:!1,data:e,error:function(e,s,t){},success:function(e){void 0!==e&&jQuery("#learndash_shortcodes").html(e),learndash_shortcodes.popup_init(),learndash_shortcodes.popup_show()}})}},popup_show:function(){if("thickbox"===learndash_admin_shortcodes_assets.popup_type){var e=learndash_shortcodes.get_tinymce_url();tb_show(learndash_admin_shortcodes_assets.popup_title,e)}else if("jQuery-dialog"===learndash_admin_shortcodes_assets.popup_type){var s=.9*jQuery(window).width(),t=.9*jQuery(window).height();jQuery("#learndash_shortcodes").dialog({title:learndash_admin_shortcodes_assets.popup_title,dialogClass:"wp-dialog ld-shortcodes",autoOpen:!0,draggable:!1,width:s,height:t,modal:!0,resizable:!1,closeOnEscape:!0,position:{my:"center",at:"center",of:window},open:function(){jQuery(".ui-widget-overlay").on("click",(function(){jQuery("#my-dialog").dialog("close")}))},create:function(){jQuery(".ui-dialog-titlebar-close").addClass("ui-button")}}),learndash_shortcodes.popup_set_dimensions(),jQuery("#learndash_shortcodes").dialog("open")}},popup_set_dimensions:function(){var e=.9*jQuery(window).width(),s=.9*jQuery(window).height();if(jQuery("#learndash_shortcodes").dialog("option","width",e),jQuery("#learndash_shortcodes").dialog("option","height",s),window.isRtl){var t=parseInt(jQuery(".ui-dialog.ld-shortcodes").css("left")),o=parseInt(jQuery(".ui-dialog.ld-shortcodes").css("right"));o=-1*t,jQuery(".ui-dialog.ld-shortcodes").css("right",o+"px")}},get_tinymce_url:function(){var e=jQuery(window).width(),s=950<e?950:e,t=jQuery(window).height();return"#TB_inline?width="+(s-=80)+"&height="+(t-=84)+"&inlineId=learndash_shortcodes"},tinymce_callback:function(e){learndash_shortcodes.tinymce_editor=e,learndash_shortcodes.show_popup_html()},qt_callback:function(){learndash_shortcodes.tinymce_editor=null,learndash_shortcodes.show_popup_html()},popup_init:function(){jQuery("#learndash_shortcodes_tabs a").on("click",(function(e){e.preventDefault(),learndash_shortcodes.tabs_switch(jQuery(this))})),learndash_shortcodes.tabs_switch(jQuery("#learndash_shortcodes a").first()),jQuery("form.learndash_shortcodes_form").on("submit",(function(e){e.preventDefault(),tb_remove(),learndash_shortcodes.popup_submit(this)})),jQuery(window).resize((function(){learndash_shortcodes.popup_set_dimensions()}))},tabs_switch:function(e){jQuery("#learndash_shortcodes_sections .hidable").hide(),jQuery("#learndash_shortcodes_sections #tabs-"+e.attr("data-nav")).show(),jQuery("#learndash_shortcodes_tabs li").removeClass("current"),e.parent().addClass("current")},get_selected_text:function(){var e=document.getElementById("content"),s=e.selectionStart,t=e.selectionEnd;return e.value.substring(s,t)},popup_submit:function(e){"jQuery-dialog"===learndash_admin_shortcodes_assets.popup_type&&jQuery("#learndash_shortcodes").dialog("close");var s=jQuery(e).attr("shortcode_slug"),t=jQuery(e).attr("shortcode_type");void 0===t&&(t=1);var o="["+s,a=e.elements,r="";if(a.length>0)for(var d=0;d<a.length;){var n=a[d];d+=1;var i=n.getAttribute("data-shortcode-exclude");if(void 0===i||"1"!=i)switch(n.type){case"textarea":2==t?r=n.value:o+=" "+n.name+'="'+n.value.replace(/"/g,'\\"')+'"';break;case"checkbox":n.checked&&void 0!==n.value&&""!=n.value&&"0"!=n.value&&(o+=" "+n.name+'="'+n.value.replace(/"/g,'\\"')+'"');break;case"submit":break;case"select-multiple":var h=jQuery(n).attr("name").replace("[]",""),l="";jQuery(":selected",n).each((function(e,s){var t=jQuery(s).val();void 0!==t&&""!=t&&(l.length>0&&(l+=","),l+=t.replace(/"/g,'\\"'))})),l.length>0&&(o+=" "+h+'="'+l+'"');break;default:void 0!==n.value&&""!=n.value&&(o+=" "+n.name+'="'+n.value.replace(/"/g,'\\"')+'"')}}o+="]",2==t&&""!=r&&(o+=r,o+="[/"+s+"]"),null!==learndash_shortcodes.tinymce_editor?learndash_shortcodes.tinymce_editor.setContent(o):"undefined"!=typeof QTags&&QTags.insertContent(o)}});