17 lines
6.0 KiB
JavaScript
17 lines
6.0 KiB
JavaScript
/*
|
|
* @author ThemePunch <info@themepunch.com>
|
|
* @link http://www.themepunch.com/
|
|
* @copyright 2018 ThemePunch
|
|
*/
|
|
;(function(){function n(a,b,d,c,e,k,t,u,g,l){this.pause=!0;this.options=b;this.slide=d;this.img=c;this.slot=e;this.levels=k;this.widths=t;this.slider=a;this.fixEdges=u;this.edgeFix=g;l&&(b=document.createElement("style"),b.type="text/css",document.head.appendChild(b),this.blurstyle={sheet:b,css:"."+l+" .tp-bgimg, ."+l+" .slot {filter: blur({{blur}}px);}"},this.resizeBlur(),a.on("revolution.slide.afterdraw",this.blurSizer.bind(this)))}jQuery("li[data-revaddonpaintbrush]").each(function(){var a=jQuery(this);
|
|
a.children("img").attr({"data-bgposition":"center center","data-kenburns":"off"}).data({bgposition:"center center",kenburns:"off"});a.attr("data-revaddonpaintbrushedges")&&a.attr("data-transition","fade").data("transition","fade")});jQuery("li[data-revaddonpaintbrushfallback]").each(function(){var a=jQuery(this),b=a.children("img");a=a.attr("data-revaddonpaintbrushfallback");var d=b.attr("data-lazyload");b.attr(d?"data-lazyload":"src",a);d&&b.data("lazyload",a)});var p,v="ontouchend"in document;window.RevSliderPaintBrush=
|
|
function(a,b){if(p=a)b.on("revolution.slide.onloaded",function(){var a="",c=b[0].opt,e=c.responsiveLevels,k=c.gridwidth;Array.isArray(e)||(e=[e]);Array.isArray(k)||(k=[k]);b.find(".tp-revslider-slidesli[data-revaddonpaintbrush]").each(function(){var c,d=new Image,g=p(this).addClass("revaddon-paintbrush"),l=g.attr("data-index"),q=g.find(".slotholder"),f=JSON.parse(this.getAttribute("data-revaddonpaintbrush"));if(f.blur){var h="revaddonblurfilter_"+l;f.scaleblur?c=h:a+="."+h+" .tp-bgimg, ."+h+" .slot {filter: blur("+
|
|
f.blurAmount+"px);}";g.addClass(h)}if(f.fixedges&&f.edgefix){var r=1+.01*f.edgefix;var m=r.toFixed(2);m="scale("+m+", "+m+")";q.find(".tp-bgimg").css("transform",m);h="revaddonblurfilterfix_"+l;a+="."+h+" .tp-bgimg {transform: "+m+" !important}";g.addClass(h)}d.onload=function(){f.width=this.naturalWidth;f.height=this.naturalHeight;var a=new n(b,f,g,d,q[0],e,k,m,r,c);g.data("revaddonbrush",a);!a.pause&&a.ready&&(a.pause=!1,a.inited||a.init())};d.onerror=function(){console.log("PaintBrush Addon: background image could not be loaded")};
|
|
d.src=f.image});a&&(c=document.createElement("style"),c.type="text/css",c.innerHTML=a,document.head.appendChild(c))}).on("revolution.slide.onbeforeswap",function(a,c){var b=c.currentslide.data("revaddonbrush");b&&b.canvas&&(b.canvas.className="revaddonpaintbrush swapping")}).on("revolution.slide.onafterswap",function(a,c){var b;c.prevslide&&(b=c.prevslide.data("revaddonbrush"))&&(b.pause=!0,b.reset(),b.canvas&&(b.canvas.className="revaddonpaintbrush"));if(b=c.currentslide.data("revaddonbrush"))b.pause=
|
|
!1,b.ready=!0,b.inited||b.init()})};n.prototype={init:function(){this.canvas=document.createElement("canvas");this.brush=document.createElement("canvas");this.canvas.className="revaddonpaintbrush";this.context=this.canvas.getContext("2d");this.ctx=this.brush.getContext("2d");this.slot.parentNode.insertBefore(this.canvas,this.slot.nextSibling);this.inited=!0;this.steps=[];this.options.carousel?setTimeout(this.start.bind(this),100):this.start()},start:function(){if(this.options.carousel)this.slide.on("mousemove touchmove",
|
|
this.onMove.bind(this));else this.slider.on("mousemove touchmove",this.onMove.bind(this));this.slider.on("revolution.slide.afterdraw",this.sizer.bind(this));this.resize()},onMove:function(a){if(!this.pause){v&&(a=a.originalEvent,a.preventDefault(),a.touches&&(a=a.touches[0]));var b=this.canvas.getBoundingClientRect();this.steps.unshift({time:Date.now(),x:a.clientX-b.left,y:a.clientY-b.top});this.draw()}},updateSteps:function(){for(var a=Date.now(),b=0;b<this.steps.length;b++)a-this.steps[b].time>
|
|
this.options.fade&&(this.steps.length=b)},paint:function(){for(var a=this.steps.length,b=Date.now(),d,c=1;c<a;c++)d=(b-this.steps[c].time)/this.options.fadetime,d=Math.max(1-d,0),this.ctx.lineCap=this.options.style,this.ctx.strokeStyle="rgba(0, 0, 0, "+d+")",this.ctx.shadowBlur=this.options.strength,this.ctx.shadowColor="#000000",this.ctx.lineWidth=this.options.size,this.ctx.beginPath(),this.ctx.moveTo(this.steps[c-1].x,this.steps[c-1].y),this.ctx.lineTo(this.steps[c].x,this.steps[c].y),this.ctx.stroke()},
|
|
draw:function(){this.updateSteps();cancelAnimationFrame(this.frame);this.steps.length&&(this.frame=window.requestAnimationFrame(this.draw.bind(this)));this.context.clearRect(0,0,this.canvas.width,this.canvas.height);this.options.disappear&&this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);this.paint();this.context.drawImage(this.img,this.cx,this.cy,this.cw,this.ch,0,0,this.canvas.width,this.canvas.height);this.context.globalCompositeOperation="destination-in";this.context.drawImage(this.brush,
|
|
0,0);this.context.globalCompositeOperation="source-over"},reset:function(){this.context&&(cancelAnimationFrame(this.frame),this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height))},sizer:function(){this.options.carousel?(clearTimeout(this.timer),this.timer=setTimeout(this.resize.bind(this),250)):this.resize()},resize:function(a){a||this.reset();var b=this.slide.width(),d=this.slide.height();this.edgeFix&&(b*=this.edgeFix,d*=this.edgeFix);
|
|
var c=Math.min(b/this.options.width,d/this.options.height);if(a)return c;a=this.options.width*c;c*=this.options.height;var e=1;a<b&&(e=b/a);1E-14>Math.abs(e-1)&&c<d&&(e=d/c);this.cw=this.options.width/(a*e/b);this.ch=this.options.height/(c*e/d);this.cx=.5*(this.options.width-this.cw);this.cy=.5*(this.options.height-this.ch);this.canvas.width=this.brush.width=b;this.canvas.height=this.brush.height=d;if(this.options.responsive){d=this.levels.length;for(c=a=0;c<d;c++)b<this.levels[c]&&(a=c);this.options.size=
|
|
this.options.origsize*Math.min(b/this.widths[a],1)}},blurSizer:function(){this.options.carousel?(clearTimeout(this.blurTimer),this.blurTimer=setTimeout(this.resizeBlur.bind(this),250)):this.resizeBlur()},resizeBlur:function(){var a=this.blurstyle;a.sheet.innerHTML=a.css.replace("{{blur}}",Math.max(Math.round(this.options.blurAmount*this.resize(!0)),1))}}})(); |