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