mirror of
https://github.com/mdbootstrap/mdb-ui-kit.git
synced 2025-10-19 18:24:26 +03:00
1 line
1.8 KiB
JavaScript
1 line
1.8 KiB
JavaScript
window.ripples={init:function(a){"use strict";function b(a,b){var c=a.matches||a.matchesSelector||a.webkitMatchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector;return c.call(a,b)}var c=100,d=500,e=function(a,c,d){document.addEventListener(a,function(a){var e="number"!=typeof a.detail?a.detail:a.target;b(e,c)&&d(a,e)})},f=function(a,b){var c,e,f=b,g=f.parentNode,h=document.createElement("div"),j=g.getBoundingClientRect(),k={x:a.clientX-j.left,y:a.clientY-j.top},l="transform:scale("+Math.round(f.offsetWidth/5)+")",m=new CustomEvent("rippleEnd",{detail:h}),n=.2;i=h,h.className="ripple",h.setAttribute("style","left:"+k.x+"px; top:"+k.y+"px;"),(" "+g.className+" ").replace(/[\n\t]/g," ").indexOf(" btn-flat ")>-1&&(c=window.getComputedStyle(g).color,c=c.replace(")"," ,"+n+")").replace("rgb","rgba")),f.appendChild(h),e=window.getComputedStyle(h).opacity,h.dataset.animating=1,h.className="ripple ripple-on",h.setAttribute("style",h.getAttribute("style")+"background-color: "+c+";"+["-ms-"+l,"-moz-"+l,"-webkit-"+l,l].join(";")),setTimeout(function(){h.dataset.animating=0,document.dispatchEvent(m)},d)},g=function(a){a.className="ripple ripple-on ripple-out",setTimeout(function(){a.remove()},c)},h=!1;document.body.onmousedown=function(){h=!0},document.body.onmouseup=function(){h=!1};var i,j=function(a,b){if(0===b.getElementsByClassName("ripple-wrapper").length){b.className+=" withripple";var c=document.createElement("div");c.className="ripple-wrapper",b.appendChild(c)}};e("mouseover",a,j),e("mousedown",".ripple-wrapper",function(a,b){(1===a.which||2===a.which)&&f(a,b)}),e("rippleEnd",".ripple-wrapper .ripple",function(a,b){var c=b.parentNode.getElementsByClassName("ripple");(!h||c[0]==b&&c.length>1)&&g(b)}),e("mouseup",".ripple-wrapper",function(){var a=i;a&&1!=a.dataset.animating&&g(a)})}}; |