text: function show_notification(e,t,i){i=i||!1,$("#notify_message").removeClass(),$("#notify_message").addClass("notify_message-"+t),$("#notify_message").html(e),$("#notify_message").slideDown(600).delay(1200).slideUp(600,function(){!0===i&&location.reload()})}function search_form(e){$("form#"+e).submit()}function convertToSlug(e){return e.toLowerCase().replace(/ /g,"-").replace(/[^\w-]+/g,"")}$(document).ready(function(){if($(".body_text img").each(function(){$(this).addClass("img-responsive")}),!0===config.links_blank_page&&$(".body_text a").attr("target","_blank"),"undefined"!=typeof mermaid&&mermaid.initialize({startOnLoad:!0}),$("table").each(function(){$(this).addClass("table table-hover")}),$(document).on("change","#kb_versions",function(){$.ajax({method:"POST",url:$("#app_context").val()+"/api/getArticleJson",data:{kb_id:$(this).val()}}).done(function(e){$("#frm_kb_title").val(e.kb_title),a.value(e.kb_body),$("#btnSettingsMenu").trigger("click")}).fail(function(e){show_notification(e.responseText,"danger")})}),!0===config.typeahead_search&&$("#frm_search").length&&$("#frm_search").on("keyup",function(){2<$("#frm_search").val().length?$.ajax({method:"POST",url:$("#app_context").val()+"/search_api",data:{searchTerm:$("#frm_search").val()}}).done(function(e){0===e.length?$("#searchResult").addClass("hidden"):($(".searchResultList").empty(),$(".searchResultList").append('<li class="list-group-item list-group-heading">Search results</li>'),$.each(e,function(e,t){var i=t.kb_permalink;void 0!==i&&""!==i||(i=t._id);var n='<li class="list-group-item"><a href="'+$("#app_context").val()+"/"+config.route_name+"/"+i+'">'+t.kb_title+"</a></li>";$(".searchResultList").append(n)}),$("#searchResult").removeClass("hidden"))}):($(".searchResultList").empty(),$("#searchResult").addClass("hidden"))}),$(".toggle-menu").length&&$(".toggle-menu").jPushMenu({closeOnClickOutside:!1}),$("pre code").each(function(e,t){hljs.highlightBlock(t)}),!0===config.add_header_anchors&&$(".body_text > h1, .body_text > h2, .body_text > h3, .body_text > h4, .body_text > h5").each(function(){$(this).attr("id",convertToSlug($(this).text())),$(this).prepend('<a class="headerAnchor" href="#'+convertToSlug($(this).text())+'">#</a> ')}),window.location.hash&&$(window.location.hash).length){var e=$(window.location.hash);$(window).scrollTop(e.offset().top).scrollLeft(e.offset().left)}if($("#frm_kb_keywords").length&&$("#frm_kb_keywords").tokenfield(),$("#editor").length){var a=new SimpleMDE({element:$("#editor")[0],spellChecker:config.enable_spellchecker,toolbar:["bold","italic","heading","|","quote","unordered-list","ordered-list","|","link","image","|","table","horizontal-rule","code","guide"]});inlineAttachment.editors.codemirror4.attach(a.codemirror,{uploadUrl:$("#app_context").val()+"/file/upload_file"}),t(),a.codemirror.on("change",function(){t()});var o=document.getElementById("preview");if(null!==o){var l=!1,r=!1;a.codemirror.on("scroll",function(e){if(l)l=!1;else{r=!0;var t=e.getScrollInfo().height-e.getScrollInfo().clientHeight,i=parseFloat(e.getScrollInfo().top)/t,n=(o.scrollHeight-o.clientHeight)*i;o.scrollTop=n}}),o.onscroll=function(){if(r)r=!1;else{l=!0;var e=o.scrollHeight-o.clientHeight,t=parseFloat(o.scrollTop)/e,i=(a.codemirror.getScrollInfo().height-a.codemirror.getScrollInfo().clientHeight)*t;a.codemirror.scrollTo(0,i)}}}}function t(){var e=window.markdownItClassy,t=window.markdown_it_plantuml,i=window.markdownit({html:!0,linkify:!0,typographer:!0,breaks:!0});i.use(e),i.use(t);var n=i.render(a.value()).replace(/<img/g,"<img class='img-responsive' ");n=n.replace(/<table/g,"<table class='table table-hover' ");var o=sanitizeHtml(n,{allowedTags:["h1","h2","h3","h4","h5","h6","blockquote","p","a","ul","ol","nl","li","b","i","strong","em","strike","code","hr","br","div","table","thead","caption","tbody","tr","th","td","pre","img","iframe"],allowedAttributes:!1});$("#preview").html(o),$("pre code").each(function(e,t){hljs.highlightBlock(t)})}if($(document).on("click","#frm_edit_kb_save",function(e){e.preventDefault(),$("#versionSidebar").length&&""===$("#frm_kb_edit_reason").val()?(show_notification("Please enter a reason for editing article","danger"),$("#btnVersionMenu").trigger("click"),$("#frm_kb_edit_reason").focus()):$("#edit_form").submit()}),$(document).on("click",".btnEditVersion",function(){$("#btnVersionMenu").trigger("click"),$.LoadingOverlay("show",{zIndex:9999}),$.ajax({method:"POST",url:$("#app_context").val()+"/api/getArticleJson",data:{kb_id:$(this).parent().attr("id")}}).done(function(e){$.LoadingOverlay("hide"),$("#frm_kb_title").val(e.kb_title),a.value(e.kb_body)}).fail(function(e){$.LoadingOverlay("hide"),show_notification(e,"danger")})}),$(document).on("click",".btnDeleteVersion",function(){var e=$(this).closest(".versionWrapper");$("#btnVersionMenu").trigger("click"),$.ajax({method:"POST",url:$("#app_context").val()+"/api/deleteVersion",data:{kb_id:$(this).parent().attr("id")}}).done(function(){e.remove(),show_notification("Version removed successfully","success")}).fail(function(e){show_notification(JSON.parse(e.responseText).message,"danger")})}),"true"===$("#frm_editor").val()&&$(window).bind("keydown",function(e){(e.ctrlKey||e.metaKey)&&"s"===String.fromCharCode(e.which).toLowerCase()&&(e.preventDefault(),$("#frm_edit_kb_save").click())}),$("input[class='published_state']").change(function(){$.ajax({method:"POST",url:$("#app_context").val()+"/published_state",data:{id:this.id,state:this.checked}}).done(function(e){show_notification(e,"success")}).fail(function(e){show_notification(e.responseText,"danger")})}),$(document).on("click","#btnUpvote",function(){$.ajax({method:"POST",url:$("#app_context").val()+"/vote",data:{doc_id:$("#doc_id").val(),vote_type:"upvote"}}).done(function(e){show_notification(e,"success",!0)}).fail(function(e){show_notification(e.responseText,"danger")})}),$(document).on("click","#btnDownvote",function(){$.ajax({method:"POST",url:$("#app_context").val()+"/vote",data:{doc_id:$("#doc_id").val(),vote_type:"downvote"}}).done(function(e){show_notification(e,"success",!0)}).fail(function(e){show_notification(e.responseText,"danger")})}),$("#validate_permalink").click(function(){""!==$("#frm_kb_permalink").val()?$.ajax({method:"POST",url:$("#app_context").val()+"/api/validate_permalink",data:{permalink:$("#frm_kb_permalink").val(),doc_id:$("#frm_kb_id").val()}}).done(function(e){show_notification(e,"success")}).fail(function(e){show_notification(e.responseText,"danger")}):show_notification("Please enter a permalink to validate","danger")}),$("#generate_permalink").click(function(){var e=Math.floor(9e5*Math.random())+1e5;$("#frm_kb_permalink").val(e)}),$("#frm_kb_title").change(function(){var e=$(this).val();e&&5<e.length?($("#generate_permalink_from_title").removeClass("disabled"),$("#generate_permalink_from_title").click(function(){var e=$("#frm_kb_title").val();e&&5<e.length&&$("#frm_kb_permalink").val(function(e){return $.trim(e).replace(/[^a-z0-9-æøå]/gi,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").replace(/æ/gi,"ae").replace(/ø/gi,"oe").replace(/å/gi,"a").toLowerCase()}(e))})):$("#generate_permalink_from_title").addClass("disabled")}),$("#btn_articles_filter").click(function(){window.location.href=$("#app_context").val()+"/articles/"+encodeURIComponent($("#article_filter").val())}),$("#btn_articles_reset").click(function(){window.location.href=$("#app_context").val()+"/articles"}),$("#btn_search").click(function(e){""===$("#frm_search").val()&&(show_notification("Please enter a search value","danger"),e.preventDefault())}),""!==$("#input_notify_message").val()){var i=$("#input_notify_message").val(),n=$("#input_notify_message_type").val();$("#input_notify_message").val(""),$("#input_notify_message_type").val(""),show_notification(i,n,!1)}}),$(document).on("click",".file_delete_confirm",function(e){e.preventDefault();var t=$(this).attr("data-id"),i=$(this).attr("data-path");window.confirm("Are you sure you want to delete the file?")&&$.ajax({method:"POST",url:$("#app_context").val()+"/file/delete",data:{img:i}}).done(function(e){$("#file-"+t).remove(),show_notification(e,"success")}).fail(function(e){show_notification(e,"danger")})});