jquery-waves
Version:
A simple waves effect library
6 lines • 3.88 kB
JavaScript
;function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function _iterableToArrayLimit(e,t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e)){var r=[],n=!0,o=!1,a=void 0;try{for(var i,u=e[Symbol.iterator]();!(n=(i=u.next()).done)&&(r.push(i.value),!t||r.length!==t);n=!0);}catch(e){o=!0,a=e}finally{try{n||null==u.return||u.return()}finally{if(o)throw a}}return r}}function _arrayWithHoles(e){if(Array.isArray(e))return e}
// (c) 2020 İsa Eken
// jquery-waves may be freely distributed under the MIT license.
// for all details and documentation:
// https://github.com/isaeken/jquery-waves
if(!window.jQuery)throw"jquery-waves is requires jquery!";if("function"!=typeof anime)throw"jquery-waves is required anime.js!";var rippleContainerSelector=".wave-effect, .waves-effect, [data-waves]",rippleClass="ie-waves-ripple";!function(l){l.fn.getElementData=function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,r=l(this);return r[0].hasAttribute("data-"+e)?r.data(e):t},l.fn.ripple=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,r=2<arguments.length&&void 0!==arguments[2]?arguments[2]:function(){},n=l(this),o=l('<div class="'.concat(rippleClass,'"></div>')),a=n.getElementData("waves-background-color",null),i=n.getElementData("waves-opacity",1),u=n.getElementData("waves-duration",600);null==e&&(e=n.innerWidth()/2),null==t&&(t=n.innerHeight()/2),"string"==typeof a&&"random"===a.toLowerCase().trim()&&(a=function(e,t){var r=1<arguments.length&&void 0!==t?t:1,t=(n=_slicedToArray(e.match(/\w\w/g).map(function(e){return parseInt(e,16)}),3))[0],e=n[1],n=n[2];return"rgba(".concat(t,", ").concat(e,", ").concat(n,", ").concat(r,")")}(function(){for(var e="#",t=0;t<6;t++)e+="0123456789ABCDEF"[Math.floor(16*Math.random())];return e}(),.35)),o.css({top:t,left:e,backgroundColor:a,opacity:i}),n.css({overflow:"hidden",position:"relative"}).append(o);i=n.outerWidth(!0);return n.outerWidth(!0)<n.outerHeight(!0)&&(i=n.outerHeight()),i*=2.5,anime({targets:o[0],duration:u,easing:"easeInOutQuad",width:i+"px",height:i+"px",update:function(e){o.data("ripple-animation-progress",Math.round(e.progress))},complete:function(){"function"==typeof r&&r()}}),o},l.fn.hideRipple=function(e){return null!=e&&0<e.length&&e.hasClass(rippleClass)&&anime({targets:e[0],duration:l(this).getElementData("waves-hide-duration",800),easing:"easeInOutQuad",opacity:0,complete:function(){e.remove()}}),l(this)},l.fn.rippleAnimation=function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,r=l(this),n=r.ripple(e,t,function(){r.hideRipple(n)});return r}}(jQuery),$(document).ready(function(){$(rippleContainerSelector).each(function(){var t=$(this),r=null;t.on("keyup",function(){return t.rippleAnimation()}).on("touchstart click focus keydown",function(){return null}).on("mousedown",function(e){return r=t.ripple(e.pageX-t.offset().left,e.pageY-t.offset().top)}).on("touchend mouseup mouseleave blur dragleave",function(e){return t.hideRipple(r)})})});