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