hedgedoc/public/vendor/gist-embed.min.js

1 line
2.2 KiB
JavaScript

!function(a){"use strict";function b(a){var c,d,b=[];if("number"==typeof a)b.push(a);else{d=a.split(",");for(var e=0;e<d.length;e++)if(c=d[e].split("-"),2===c.length)for(var f=parseInt(c[0],10);f<=c[1];f++)b.push(f);else 1===c.length&&b.push(parseInt(c[0],10))}return b}a.fn.gist=function(){return this.each(function(){var d,e,f,g,h,i,j,k,l,m,c=a(this),n={};return c.css("display","block"),d=c.data("gist-id")||"",f=c.data("gist-file"),j=c.data("gist-hide-footer")===!0,k=c.data("gist-hide-line-numbers")===!0,g=c.data("gist-line"),i=c.data("gist-highlight-line"),m=c.data("gist-show-spinner")===!0,l=m?!1:void 0!==c.data("gist-show-loading")?c.data("gist-show-loading"):!0,f&&(n.file=f),d?(e="https://gist.github.com/"+d+".json",h="Loading gist "+e+(n.file?", file: "+n.file:"")+"...",l&&c.html(h),m&&c.html('<img style="display:block;margin-left:auto;margin-right:auto" alt="'+h+'" src="https://assets-cdn.github.com/images/spinners/octocat-spinner-32.gif">'),void a.ajax({url:e,data:n,dataType:"jsonp",timeout:1e4,success:function(d){var f,h,l,m,n;d&&d.div?(d.stylesheet&&(0===d.stylesheet.indexOf("<link")?d.stylesheet=d.stylesheet.replace(/\\/g,"").match(/href=\"([^\s]*)\"/)[1]:0!==d.stylesheet.indexOf("http")&&(0!==d.stylesheet.indexOf("/")&&(d.stylesheet="/"+d.stylesheet),d.stylesheet="https://gist.github.com"+d.stylesheet)),d.stylesheet&&0===a('link[href="'+d.stylesheet+'"]').length&&(f=document.createElement("link"),h=document.getElementsByTagName("head")[0],f.type="text/css",f.rel="stylesheet",f.href=d.stylesheet,h.insertBefore(f,h.firstChild)),n=a(d.div),n.removeAttr("id"),c.html("").append(n),i&&(m=b(i),n.find("td.line-data").css({width:"100%"}),n.find(".js-file-line").each(function(b){-1!==a.inArray(b+1,m)&&a(this).css({"background-color":"rgb(255, 255, 204)"})})),g&&(l=b(g),n.find(".js-file-line").each(function(b){-1===a.inArray(b+1,l)&&a(this).parent().remove()})),j&&(n.find(".gist-meta").remove(),n.find(".gist-data").css("border-bottom","0px"),n.find(".gist-file").css("border-bottom","1px solid #ddd")),k&&n.find(".js-line-number").remove()):c.html("Failed loading gist "+e)},error:function(a,b){c.html("Failed loading gist "+e+": "+b)}})):!1})},a(function(){a("[data-gist-id]").gist()})}(jQuery);