File: /home/henzergrouphenz/public_html/wp-content/themes/metro/assets/js/jquery.ripples.min.js
/**
* https://github.com/kowsar89/jquery.ripples
*/
!function(){"use strict";var e,t=jQuery,r=t(window);function i(e){return"%"==e[e.length-1]}function o(t,r,i){function o(t,r){var i=e.createShader(t);if(e.shaderSource(i,r),e.compileShader(i),!e.getShaderParameter(i,e.COMPILE_STATUS))throw new Error("compile error: "+e.getShaderInfoLog(i));return i}var n={};if(n.id=e.createProgram(),e.attachShader(n.id,o(e.VERTEX_SHADER,t)),e.attachShader(n.id,o(e.FRAGMENT_SHADER,r)),e.linkProgram(n.id),!e.getProgramParameter(n.id,e.LINK_STATUS))throw new Error("link error: "+e.getProgramInfoLog(n.id));n.uniforms={},n.locations={},e.useProgram(n.id),e.enableVertexAttribArray(0);for(var a,s,u=/uniform (\w+) (\w+)/g,h=t+r;null!=(a=u.exec(h));)s=a[2],n.locations[s]=e.getUniformLocation(n.id,s);return n}function n(t,r){e.activeTexture(e.TEXTURE0+(r||0)),e.bindTexture(e.TEXTURE_2D,t)}function a(e){var t=/url\(["']?([^"']*)["']?\)/.exec(e);return null==t?null:t[1]}var s=function(){var t=document.createElement("canvas");if(!(e=t.getContext("webgl")||t.getContext("experimental-webgl")))return null;var r={};if(["OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear"].forEach(function(t){var i=e.getExtension(t);i&&(r[t]=i)}),!r.OES_texture_float)return null;var i=[];function o(e,t,i){var o="OES_texture_"+e,n=o+"_linear",a=n in r,s=[o];return a&&s.push(n),{type:t,arrayType:i,linearSupport:a,extensions:s}}i.push(o("float",e.FLOAT,Float32Array)),r.OES_texture_half_float&&i.push(o("half_float",r.OES_texture_half_float.HALF_FLOAT_OES,null));var n=e.createTexture(),a=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,a),e.bindTexture(e.TEXTURE_2D,n),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE);for(var s=null,u=0;u<i.length;u++)if(e.texImage2D(e.TEXTURE_2D,0,e.RGBA,32,32,0,e.RGBA,i[u].type,null),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE){s=i[u];break}return s}(),u=function(e,t){try{return new ImageData(e,t)}catch(r){return document.createElement("canvas").getContext("2d").createImageData(e,t)}}(32,32);t("head").prepend("<style>.jquery-ripples { position: relative; z-index: 0; }</style>");var h=function(r,i){var o=this;this.$el=t(r),this.interactive=i.interactive,this.resolution=i.resolution,this.textureDelta=new Float32Array([1/this.resolution,1/this.resolution]),this.perturbance=i.perturbance,this.dropRadius=i.dropRadius,this.crossOrigin=i.crossOrigin,this.imageUrl=i.imageUrl;var n=document.createElement("canvas");n.width=this.$el.innerWidth(),n.height=this.$el.innerHeight(),this.canvas=n,this.$canvas=t(n),this.$canvas.css({position:"absolute",left:0,top:0,right:0,bottom:0,zIndex:-1}),this.$el.addClass("jquery-ripples").append(n),this.context=e=n.getContext("webgl")||n.getContext("experimental-webgl"),s.extensions.forEach(function(t){e.getExtension(t)}),t(window).on("resize",function(){o.updateSize()}),this.textures=[],this.framebuffers=[],this.bufferWriteIndex=0,this.bufferReadIndex=1;for(var a=s.arrayType,u=a?new a(this.resolution*this.resolution*4):null,h=0;h<2;h++){var c=e.createTexture(),d=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,d),e.bindTexture(e.TEXTURE_2D,c),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,s.linearSupport?e.LINEAR:e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,s.linearSupport?e.LINEAR:e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.resolution,this.resolution,0,e.RGBA,s.type,u),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,c,0),this.textures.push(c),this.framebuffers.push(d)}this.quad=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,this.quad),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,1,1,-1,1]),e.STATIC_DRAW),this.initShaders(),this.initTexture(),this.setTransparentTexture(),this.loadImage(),e.clearColor(0,0,0,0),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),this.visible=!0,this.running=!0,this.inited=!0,this.destroyed=!1,this.setupPointerEvents(),requestAnimationFrame(function e(){o.destroyed||(o.step(),requestAnimationFrame(e))})};h.DEFAULTS={imageUrl:null,resolution:256,dropRadius:20,perturbance:.03,interactive:!0,crossOrigin:""},h.prototype={setupPointerEvents:function(){var e=this;function t(t,r){e.visible&&e.running&&e.interactive&&e.dropAtPointer(t,e.dropRadius*(r?1.5:1),r?.14:.01)}this.$el.on("mousemove.ripples",function(e){t(e)}).on("touchmove.ripples, touchstart.ripples",function(e){for(var r=e.originalEvent.changedTouches,i=0;i<r.length;i++)t(r[i])}).on("mousedown.ripples",function(e){t(e,!0)})},loadImage:function(){var t=this;e=this.context;var r=this.imageUrl||a(this.originalCssBackgroundImage)||a(this.$el.css("backgroundImage"));if(r!=this.imageSource)if(this.imageSource=r,this.imageSource){var i=new Image;i.onload=function(){function r(e){return 0==(e&e-1)}e=t.context;var o=r(i.width)&&r(i.height)?e.REPEAT:e.CLAMP_TO_EDGE;e.bindTexture(e.TEXTURE_2D,t.backgroundTexture),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,o),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,o),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,i),t.backgroundWidth=i.width,t.backgroundHeight=i.height,t.hideCssBackground()},i.onerror=function(){e=t.context,t.setTransparentTexture()},i.crossOrigin=this.imageSource.match(/^data:/)?null:this.crossOrigin,i.src=this.imageSource}else this.setTransparentTexture()},step:function(){e=this.context,this.visible&&(this.computeTextureBoundaries(),this.running&&this.update(),this.render())},drawQuad:function(){e.bindBuffer(e.ARRAY_BUFFER,this.quad),e.vertexAttribPointer(0,2,e.FLOAT,!1,0,0),e.drawArrays(e.TRIANGLE_FAN,0,4)},render:function(){e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.canvas.width,this.canvas.height),e.enable(e.BLEND),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT),e.useProgram(this.renderProgram.id),n(this.backgroundTexture,0),n(this.textures[0],1),e.uniform1f(this.renderProgram.locations.perturbance,this.perturbance),e.uniform2fv(this.renderProgram.locations.topLeft,this.renderProgram.uniforms.topLeft),e.uniform2fv(this.renderProgram.locations.bottomRight,this.renderProgram.uniforms.bottomRight),e.uniform2fv(this.renderProgram.locations.containerRatio,this.renderProgram.uniforms.containerRatio),e.uniform1i(this.renderProgram.locations.samplerBackground,0),e.uniform1i(this.renderProgram.locations.samplerRipples,1),this.drawQuad(),e.disable(e.BLEND)},update:function(){e.viewport(0,0,this.resolution,this.resolution),e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffers[this.bufferWriteIndex]),n(this.textures[this.bufferReadIndex]),e.useProgram(this.updateProgram.id),this.drawQuad(),this.swapBufferIndices()},swapBufferIndices:function(){this.bufferWriteIndex=1-this.bufferWriteIndex,this.bufferReadIndex=1-this.bufferReadIndex},computeTextureBoundaries:function(){var e,t=this.$el.css("background-size"),o=this.$el.css("background-attachment"),n=function(e){var t=e.split(" ");if(1!==t.length)return t.map(function(t){switch(e){case"center":return"50%";case"top":case"left":return"0";case"right":case"bottom":return"100%";default:return t}});switch(e){case"center":return["50%","50%"];case"top":return["50%","0"];case"bottom":return["50%","100%"];case"left":return["0","50%"];case"right":return["100%","50%"];default:return[e,"50%"]}}(this.$el.css("background-position"));if("fixed"==o?((e={left:window.pageXOffset,top:window.pageYOffset}).width=r.width(),e.height=r.height()):((e=this.$el.offset()).width=this.$el.innerWidth(),e.height=this.$el.innerHeight()),"cover"==t)var a=Math.max(e.width/this.backgroundWidth,e.height/this.backgroundHeight),s=this.backgroundWidth*a,u=this.backgroundHeight*a;else if("contain"==t)a=Math.min(e.width/this.backgroundWidth,e.height/this.backgroundHeight),s=this.backgroundWidth*a,u=this.backgroundHeight*a;else{s=(t=t.split(" "))[0]||"",u=t[1]||s;i(s)?s=e.width*parseFloat(s)/100:"auto"!=s&&(s=parseFloat(s)),i(u)?u=e.height*parseFloat(u)/100:"auto"!=u&&(u=parseFloat(u)),"auto"==s&&"auto"==u?(s=this.backgroundWidth,u=this.backgroundHeight):("auto"==s&&(s=this.backgroundWidth*(u/this.backgroundHeight)),"auto"==u&&(u=this.backgroundHeight*(s/this.backgroundWidth)))}var h=n[0],c=n[1];h=i(h)?e.left+(e.width-s)*parseFloat(h)/100:e.left+parseFloat(h),c=i(c)?e.top+(e.height-u)*parseFloat(c)/100:e.top+parseFloat(c);var d=this.$el.offset();this.renderProgram.uniforms.topLeft=new Float32Array([(d.left-h)/s,(d.top-c)/u]),this.renderProgram.uniforms.bottomRight=new Float32Array([this.renderProgram.uniforms.topLeft[0]+this.$el.innerWidth()/s,this.renderProgram.uniforms.topLeft[1]+this.$el.innerHeight()/u]);var l=Math.max(this.canvas.width,this.canvas.height);this.renderProgram.uniforms.containerRatio=new Float32Array([this.canvas.width/l,this.canvas.height/l])},initShaders:function(){var t=["attribute vec2 vertex;","varying vec2 coord;","void main() {","coord = vertex * 0.5 + 0.5;","gl_Position = vec4(vertex, 0.0, 1.0);","}"].join("\n");this.dropProgram=o(t,["precision highp float;","const float PI = 3.141592653589793;","uniform sampler2D texture;","uniform vec2 center;","uniform float radius;","uniform float strength;","varying vec2 coord;","void main() {","vec4 info = texture2D(texture, coord);","float drop = max(0.0, 1.0 - length(center * 0.5 + 0.5 - coord) / radius);","drop = 0.5 - cos(drop * PI) * 0.5;","info.r += drop * strength;","gl_FragColor = info;","}"].join("\n")),this.updateProgram=o(t,["precision highp float;","uniform sampler2D texture;","uniform vec2 delta;","varying vec2 coord;","void main() {","vec4 info = texture2D(texture, coord);","vec2 dx = vec2(delta.x, 0.0);","vec2 dy = vec2(0.0, delta.y);","float average = (","texture2D(texture, coord - dx).r +","texture2D(texture, coord - dy).r +","texture2D(texture, coord + dx).r +","texture2D(texture, coord + dy).r",") * 0.25;","info.g += (average - info.r) * 2.0;","info.g *= 0.995;","info.r += info.g;","gl_FragColor = info;","}"].join("\n")),e.uniform2fv(this.updateProgram.locations.delta,this.textureDelta),this.renderProgram=o(["precision highp float;","attribute vec2 vertex;","uniform vec2 topLeft;","uniform vec2 bottomRight;","uniform vec2 containerRatio;","varying vec2 ripplesCoord;","varying vec2 backgroundCoord;","void main() {","backgroundCoord = mix(topLeft, bottomRight, vertex * 0.5 + 0.5);","backgroundCoord.y = 1.0 - backgroundCoord.y;","ripplesCoord = vec2(vertex.x, -vertex.y) * containerRatio * 0.5 + 0.5;","gl_Position = vec4(vertex.x, -vertex.y, 0.0, 1.0);","}"].join("\n"),["precision highp float;","uniform sampler2D samplerBackground;","uniform sampler2D samplerRipples;","uniform vec2 delta;","uniform float perturbance;","varying vec2 ripplesCoord;","varying vec2 backgroundCoord;","void main() {","float height = texture2D(samplerRipples, ripplesCoord).r;","float heightX = texture2D(samplerRipples, vec2(ripplesCoord.x + delta.x, ripplesCoord.y)).r;","float heightY = texture2D(samplerRipples, vec2(ripplesCoord.x, ripplesCoord.y + delta.y)).r;","vec3 dx = vec3(delta.x, heightX - height, 0.0);","vec3 dy = vec3(0.0, heightY - height, delta.y);","vec2 offset = -normalize(cross(dy, dx)).xz;","float specular = pow(max(0.0, dot(offset, normalize(vec2(-0.6, 1.0)))), 4.0);","gl_FragColor = texture2D(samplerBackground, backgroundCoord + offset * perturbance) + specular;","}"].join("\n")),e.uniform2fv(this.renderProgram.locations.delta,this.textureDelta)},initTexture:function(){this.backgroundTexture=e.createTexture(),e.bindTexture(e.TEXTURE_2D,this.backgroundTexture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,1),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR)},setTransparentTexture:function(){e.bindTexture(e.TEXTURE_2D,this.backgroundTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,u)},hideCssBackground:function(){var e=this.$el[0].style.backgroundImage;"none"!=e&&(this.originalInlineCss=e,this.originalCssBackgroundImage=this.$el.css("backgroundImage"),this.$el.css("backgroundImage","none"))},restoreCssBackground:function(){this.$el.css("backgroundImage",this.originalInlineCss||"")},dropAtPointer:function(e,t,r){var i=parseInt(this.$el.css("border-left-width"))||0,o=parseInt(this.$el.css("border-top-width"))||0;this.drop(e.pageX-this.$el.offset().left-i,e.pageY-this.$el.offset().top-o,t,r)},drop:function(t,r,i,o){e=this.context;var a=this.$el.innerWidth(),s=this.$el.innerHeight(),u=Math.max(a,s);i/=u;var h=new Float32Array([(2*t-a)/u,(s-2*r)/u]);e.viewport(0,0,this.resolution,this.resolution),e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffers[this.bufferWriteIndex]),n(this.textures[this.bufferReadIndex]),e.useProgram(this.dropProgram.id),e.uniform2fv(this.dropProgram.locations.center,h),e.uniform1f(this.dropProgram.locations.radius,i),e.uniform1f(this.dropProgram.locations.strength,o),this.drawQuad(),this.swapBufferIndices()},updateSize:function(){var e=this.$el.innerWidth(),t=this.$el.innerHeight();e==this.canvas.width&&t==this.canvas.height||(this.canvas.width=e,this.canvas.height=t)},destroy:function(){this.$el.off(".ripples").removeClass("jquery-ripples").removeData("ripples"),this.$canvas.remove(),this.restoreCssBackground(),this.destroyed=!0},show:function(){this.visible=!0,this.$canvas.show(),this.hideCssBackground()},hide:function(){this.visible=!1,this.$canvas.hide(),this.restoreCssBackground()},pause:function(){this.running=!1},play:function(){this.running=!0},set:function(e,t){switch(e){case"dropRadius":case"perturbance":case"interactive":case"crossOrigin":this[e]=t;break;case"imageUrl":this.imageUrl=t,this.loadImage()}}};var c=t.fn.ripples;t.fn.ripples=function(e){if(!s)throw new Error("Your browser does not support WebGL, the OES_texture_float extension or rendering to floating point textures.");var r=arguments.length>1?Array.prototype.slice.call(arguments,1):void 0;return this.each(function(){var i=t(this),o=i.data("ripples"),n=t.extend({},h.DEFAULTS,i.data(),"object"==typeof e&&e);(o||"string"!=typeof e)&&(o?"string"==typeof e&&h.prototype[e].apply(o,r):i.data("ripples",o=new h(this,n)))})},t.fn.ripples.Constructor=h,t.fn.ripples.noConflict=function(){return t.fn.ripples=c,this}}();