Files
Batflat/inc/jscripts/editor/markitup.highlight.min.js
2018-03-12 13:23:44 +01:00

1 line
1.3 KiB
JavaScript

!function(a){a.fn.highlight=function(b){function i(b,c){var d=a(b).val(),e=j(d+"\n");a(c).html(e),a(c).each(function(a,b){hljs.highlightBlock(b)})}function j(a){return a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function k(){var b=a("<div>").css({visibility:"hidden",width:100,overflow:"scroll"}).appendTo("body"),c=a("<div>").css({width:"100%"}).appendTo(b).outerWidth();return b.remove(),100-c}if(!document.documentMode&&!window.StyleMedia&&!/Mobi/i.test(navigator.userAgent)){var c=this,d=k();if(b=a.extend({whiteSpace:"pre-wrap",lang:c.data("lang")},b),b.lang)var e=b.lang;else var e=c.closest('div[class^="markItUpSet"]').attr("class").replace("markItUpSet-","");var f=document.createElement("div");a(f).addClass("markItUpHighlight"),a(c).wrap(f);var g=document.createElement("pre");a(g).addClass("markItUpSyntax").appendTo(c.parent());var h=document.createElement("code");a(h).addClass(e).appendTo(a(g)),a(g).css("white-space",b.whiteSpace),c.css("white-space",b.whiteSpace),c.attr("spellcheck",!1),c[0].scrollHeight>c[0].clientHeight?a(h).css("right",d):a(h).css("right",0),i(c,h),c.on("input mouseup",function(){this.scrollHeight>this.clientHeight?a(h).css("right",d):a(h).css("right",0),i(this,h)}),c.scroll(function(){a(h).css({top:-c.scrollTop(),left:-c.scrollLeft()})})}}}(jQuery);