forked from kevinburke/doony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
doony.min.js
2 lines (2 loc) · 9.07 KB
/
doony.min.js
1
2
/* Doony v0.1 | (c) 2013 Kevin Burke | License: MIT */
!function(a,b){var c=function(a){var b,c;if(b=c=0,a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(null!==(a=a.offsetParent));return[b,c]},ProgressCircle=function(a){this.canvas=a.canvas,this.minRadius=a.minRadius||15,this.arcWidth=a.arcWidth||5,this.gapWidth=a.gapWidth||3,this.centerX=a.centerX||this.canvas.width/2,this.centerY=a.centerY||this.canvas.height/2,this.infoLineLength=a.infoLineLength||60,this.horizLineLength=a.horizLineLength||10,this.infoLineAngleInterval=a.infoLineAngleInterval||Math.PI/8,this.infoLineBaseAngle=a.infoLineBaseAngle||Math.PI/6,this.context=this.canvas.getContext("2d"),this.width=this.canvas.width,this.height=this.canvas.height,this.circles=[],this.runningCount=0};ProgressCircle.prototype={constructor:ProgressCircle,addEntry:function(a){return this.circles.push(new d({canvas:this.canvas,context:this.context,centerX:this.centerX,centerY:this.centerY,innerRadius:this.minRadius+this.circles.length*(this.gapWidth+this.arcWidth),arcWidth:this.arcWidth,infoLineLength:this.infoLineLength,horizLineLength:this.horizLineLength,id:this.circles.length,fillColor:a.fillColor,outlineColor:a.outlineColor,progressListener:a.progressListener,infoListener:a.infoListener,infoLineAngle:this.infoLineBaseAngle+this.circles.length*this.infoLineAngleInterval})),this},start:function(a){var b=this;return this.timer=setInterval(function(){b._update()},a||33),this},stop:function(){clearTimeout(this.timer)},_update:function(){return this._clear(),this.circles.forEach(function(a){a.update()}),this},_clear:function(){return this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this}};var d=function(a){if(this.id=a.id,this.canvas=a.canvas,this.context=a.context,this.centerX=a.centerX,this.centerY=a.centerY,this.arcWidth=a.arcWidth,this.innerRadius=a.innerRadius||0,this.fillColor=a.fillColor||"#fff",this.outlineColor=a.outlineColor||this.fillColor,this.progressListener=a.progressListener,this.infoLineLength=a.infoLineLength||250,this.horizLineLength=a.horizLineLength||50,this.infoListener=a.infoListener,this.infoLineAngle=a.infoLineAngle,this.outerRadius=this.innerRadius+this.arcWidth,this.infoListener){var d=this.infoLineAngle,e=(this.innerRadius+this.outerRadius)/2,f=Math.sin(d),g=Math.cos(d);this.infoLineStartX=this.centerX+f*e,this.infoLineStartY=this.centerY-g*e,this.infoLineMidX=this.centerX+f*this.infoLineLength,this.infoLineMidY=this.centerY-g*this.infoLineLength,this.infoLineEndX=this.infoLineMidX+(0>f?-this.horizLineLength:this.horizLineLength),this.infoLineEndY=this.infoLineMidY;var h=b.createElement("div"),i=h.style;i.color=this.fillColor,i.position="absolute",i.left=this.infoLineEndX+c(this.canvas)[0]+"px",h.className="ProgressCircleInfo",h.id="progress_circle_info_"+this.id,b.body.appendChild(h),this.infoText=h}};d.prototype={constructor:d,update:function(){this.progress=this.progressListener(),this._draw(),this.infoListener&&(this.info=this.infoListener(),this._drawInfo())},_draw:function(){var a=this.context,b=-Math.PI/2,c=0+b,d=c+2*this.progress*Math.PI,e=this.centerX,f=this.centerY,g=this.innerRadius,h=this.outerRadius;return a.fillStyle=this.fillColor,a.strokeStyle=this.outlineColor,a.beginPath(),a.arc(e,f,g,c,d,!1),a.arc(e,f,h,d,c,!0),a.closePath(),a.stroke(),a.fill(),this},_drawInfo:function(){var a,b;return a=[[this.infoLineStartX,this.infoLineStartY],[this.infoLineMidX,this.infoLineMidY],[this.infoLineEndX,this.infoLineEndY]],this._drawSegments(a,!1),this.infoText.innerHTML=this.info,b=this.infoText.offsetHeight,this.infoText.style.top=this.infoLineEndY+c(this.canvas)[1]-b/2+"px",this},_drawSegments:function(a,b){var c=this.context;c.beginPath(),c.moveTo(a[0][0],a[0][1]);for(var d=1;d<a.length;++d)c.lineTo(a[d][0],a[d][1]);b&&c.closePath(),c.stroke()}},a.ProgressCircle=ProgressCircle}(window,document),jQuery(function(a){var b=["#C02942","#4ecdc4","#d95b43","#556270","#542437","#8fbe00"],c=function(a){var b=a.split(".");return b.length<=2?b.join("."):b.slice(0,-2).join(".")},d=function(a){var b,c,d=0;if(0===a.length)return d;for(b=0,l=a.length;l>b;b++)c=a.charCodeAt(b),d=(d<<5)-d+c,d|=0;return d},e=function(a){return null!==a.match(/^\/job\/.*?\//)},f=function(a){return null!==a.match(/^\/job\/.*?\/(.*?=.*?\/)?$/)},g=function(a){return null!==a.match(/^\/job\/.*?\/$/)},h=function(a){return a.match(/^\/job\/.*?\//)[0]},i=function(a){return a.match(/^\/job\/.*?\/(.*?=.*?\/)?/)[0]},j=function(b,c){a.getJSON(b+"api/json?tree=builds[number]",function(a){for(var d=0;d<a.builds.length;d++){var e=a.builds[d];e.number===c&&(window.location.href=b+c+"/consoleFull")}setTimeout(function(){j(b,c)},1e3)})},k=function(b,c){return g(b)?(a.getJSON(b+"api/json?tree=activeConfigurations[name]",function(a){if("{}"!==JSON.stringify(a)&&"activeConfigurations"in a){var d=b+a.activeConfigurations[0].name+"/";return j(d,c)}return j(b,c)}),void 0):j(b,c)},m=function(b){var c=document.createElement("div");c.className="alert alert-warning doony-alert",c.innerHTML=b,a("#main-panel").prepend(c)},n=a("#top-panel a").first(),o=c(window.location.hostname);n.html("<div id='doony-title'>"+o+"</div>");var p=b[Math.abs(d(o))%b.length];a("#top-panel").css("background-color",p),a(".task").each(function(){a("a img",a(this)).remove(),a(this).html(function(a,b){var c=b.replace(/ /g,"","g");return c})});var q=function(a,b){return"<div class='doony-callout doony-callout-info'><a "+(null===b?"":"href='"+b+"'")+">"+a+"</a></div>"},r=function(b,c){a.getJSON(b+c+"api/json?tree=lastBuild[number]",function(d){null!==d.lastBuild&&"number"in d.lastBuild&&a("#matrix .model-link").each(function(e,f){if(f.getAttribute("href")===c){var g=b+c+d.lastBuild.number+"/consoleFull";a(f).next(".doony-callout").children("a").attr("href",g)}})})};a("#matrix").length&&setInterval(function(){var b=i(window.location.pathname);a("#matrix .doony-downstream-link").length||(a("#matrix .model-link").wrap("<div class='doony-downstream-link'>"),a("#matrix .model-link").each(function(b,c){var d="View console output for the latest build";a(c).after(q(d,null))}),a.getJSON(b+"api/json?tree=activeConfigurations[name]",function(a){for(var c=0;c<a.activeConfigurations.length;c++){var d=a.activeConfigurations[c];r(b,d.name+"/")}}))},50);var s=function(b,c){a(b).each(function(){var b=document.createElement("div");b.className="doony-circle doony-circle-"+c,b.style.display="inline-block";var d;"48"===this.getAttribute("width")||"24"===this.getAttribute("width")?(d=.5*this.getAttribute("width")+8,b.style.marginRight="15px",b.style.verticalAlign="middle"):this.classList.contains("icon32x32")?(d=24,b.style.marginTop="4px",b.style.marginLeft="4px"):d=this.getAttribute("width")||12,a(b).css("width",d),a(b).css("height",d),a(this).after(b).remove()})},t=function(b,c){a(b).each(function(){if(!a(this).next(".doony-canvas").length){var b=document.createElement("canvas");b.className="doony-canvas";var d;"48"===this.getAttribute("width")||"24"===this.getAttribute("width")?(d=.5*this.getAttribute("width")+8,b.style.marginRight="15px",b.style.verticalAlign="middle"):this.classList.contains("icon32x32")?(d=24,b.style.marginTop="4px",b.style.marginLeft="4px"):d=this.getAttribute("width")||12,b.setAttribute("width",d),b.setAttribute("height",d);var e=new ProgressCircle({canvas:b,minRadius:3*d/8-2,arcWidth:d/8+1}),f=0;e.addEntry({fillColor:c,progressListener:function(){return f>=1&&(f=0),f+=.005}}),e.start(24),a(this).after(b).css("display","none")}})},u="#4f9f4f";if(setInterval(function(){t("img[src*='red_anime.gif']","#d9534f"),t("img[src*='blue_anime.gif']",u),t("img[src*='grey_anime.gif']","#999"),t("img[src*='yellow_anime.gif']","#f0ad4e")},10),setInterval(function(){s("img[src*='/grey.png']","aborted"),s("img[src*='/blue.png']","success"),s("img[src*='/red.png']","failure"),s("img[src*='/yellow.png']","warning")},10),f(window.location.pathname)){var v=i(window.location.pathname);a.getJSON(v+"api/json?tree=lastBuild[number]",function(b){if("lastBuild"in b&&null!==b.lastBuild&&"number"in b.lastBuild){var c="View console output for the latest build",d=v+b.lastBuild.number+"/consoleFull",e=a("h2:contains('Permalinks')");e.after(q(c,d))}})}if(e(window.location.pathname)){var w=document.createElement("button");w.className="btn btn-primary doony-build",w.innerHTML="Build Now",a(w).click(function(){var b=h(window.location.pathname);a.getJSON(b+"api/json?depth=1&tree=nextBuildNumber,lastBuild[building]",function(c){a.post(b+"build",function(){var a="Build #"+c.nextBuildNumber+" created, you will be redirected when it is ready.";"{}"!==JSON.stringify(c)&&"lastBuild"in c&&null!==c.lastBuild&&c.lastBuild.building&&(a+=" <a href='#' id='doony-clear-build'>Cancel the current build</a>"),m(a),k(i(window.location.pathname),c.nextBuildNumber)})})}),a(document).on("click","#doony-clear-build",function(b){b.preventDefault();var c=h(window.location.pathname);a.getJSON(c+"api/json?tree=lastBuild[number]",function(b){a.post(c+b.lastBuild.number+"/stop")})});var x=a("#main-panel h1").first();x.children("div").length?x.append(w):(x.css("display","inline-block"),x.after(w))}a("#l10n-footer").after("<span class='doony-theme'>Browsing Jenkins with the <a target='_blank' href='https://github.com/kevinburke/doony'>Doony theme</a></span>")});