mirror of
				https://github.com/mdbootstrap/mdb-ui-kit.git
				synced 2025-11-04 09:57:36 +03:00 
			
		
		
		
	improved ripples.js
This commit is contained in:
		
							parent
							
								
									9368546e7c
								
							
						
					
					
						commit
						d9722a936c
					
				
							
								
								
									
										48
									
								
								dist/js/ripples.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										48
									
								
								dist/js/ripples.js
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1,15 +1,17 @@
 | 
				
			||||||
/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
					/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
				
			||||||
/* globals CustomEvent */
 | 
					/* globals CustomEvent */
 | 
				
			||||||
/*jshint maxlen: 500 */
 | 
					 | 
				
			||||||
window.ripples = {
 | 
					window.ripples = {
 | 
				
			||||||
    init : function(withRipple) {
 | 
					    init : function(withRipple) {
 | 
				
			||||||
        "use strict";
 | 
					        "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Cross browser matches function
 | 
					        // Cross browser matches function
 | 
				
			||||||
        function matchesSelector(domElement, selector) {
 | 
					        function matchesSelector(domElement, selector) {
 | 
				
			||||||
            var matches = domElement.matches || domElement.matchesSelector || domElement.webkitMatchesSelector ||
 | 
					            var matches = domElement.matches ||
 | 
				
			||||||
 | 
					                domElement.matchesSelector ||
 | 
				
			||||||
 | 
					                domElement.webkitMatchesSelector ||
 | 
				
			||||||
                domElement.mozMatchesSelector ||
 | 
					                domElement.mozMatchesSelector ||
 | 
				
			||||||
                    domElement.msMatchesSelector || domElement.oMatchesSelector;
 | 
					                domElement.msMatchesSelector ||
 | 
				
			||||||
 | 
					                domElement.oMatchesSelector;
 | 
				
			||||||
            return matches.call(domElement, selector);
 | 
					            return matches.call(domElement, selector);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,31 +38,24 @@ window.ripples = {
 | 
				
			||||||
                $ripple             = document.createElement("div"),
 | 
					                $ripple             = document.createElement("div"),
 | 
				
			||||||
                elPos               = $el.getBoundingClientRect(),
 | 
					                elPos               = $el.getBoundingClientRect(),
 | 
				
			||||||
                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
					                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
				
			||||||
                scale                 = "transform:scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
					                scale               = "scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
				
			||||||
                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
					                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
				
			||||||
                __rippleOpacity__     = 0.05,
 | 
					                _rippleOpacity      = 0.1,
 | 
				
			||||||
                targetColor,
 | 
					 | 
				
			||||||
                rgbArr,
 | 
					 | 
				
			||||||
                refreshElementStyle;
 | 
					                refreshElementStyle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $ripplecache = $ripple;
 | 
					            $ripplecache = $ripple;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Set ripple class
 | 
					            // Set ripple class
 | 
				
			||||||
            $ripple.className = "ripple";
 | 
					            $ripple.className = "ripple";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Move ripple to the mouse position            
 | 
					            // Move ripple to the mouse position            
 | 
				
			||||||
            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
					            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get the clicked targets text color, this will be applied to the ripple as background-color.
 | 
					            // Get the clicked target's text color, this will be applied to the ripple as background-color.
 | 
				
			||||||
            targetColor = window.getComputedStyle($el).color;            
 | 
					            var targetColor = window.getComputedStyle($el).color;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            // This changes the alpha value of the rgba (opacity) to the constant __rippleOpacity__
 | 
					 | 
				
			||||||
            // Not sure if regexp is quicker... 
 | 
					 | 
				
			||||||
            rgbArr = targetColor.split(",");                        
 | 
					 | 
				
			||||||
            rgbArr.pop();
 | 
					 | 
				
			||||||
            rgbArr.push(" " + __rippleOpacity__ + ")");
 | 
					 | 
				
			||||||
            targetColor = rgbArr.join(",");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Convert the rgb color to an rgba color with opacity set to __rippleOpacity__
 | 
				
			||||||
 | 
					            targetColor = targetColor.replace("rgb", "rgba").replace(")",  ", " + _rippleOpacity + ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Insert new ripple into ripple wrapper
 | 
					            // Insert new ripple into ripple wrapper
 | 
				
			||||||
            $rippleWrapper.appendChild($ripple);    
 | 
					            $rippleWrapper.appendChild($ripple);    
 | 
				
			||||||
| 
						 | 
					@ -70,11 +65,22 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Let other funtions know that this element is animating
 | 
					            // Let other funtions know that this element is animating
 | 
				
			||||||
            $ripple.dataset.animating = 1;
 | 
					            $ripple.dataset.animating = 1;
 | 
				
			||||||
                // + "background-color: " + targetColor + ";" 
 | 
					
 | 
				
			||||||
            // Set scale value, background-color and opacity to ripple and animate it
 | 
					            // Set scale value, background-color and opacity to ripple and animate it
 | 
				
			||||||
            $ripple.className = "ripple ripple-on";
 | 
					            $ripple.className = "ripple ripple-on";
 | 
				
			||||||
            $ripple.setAttribute("style", $ripple.getAttribute("style") + "background-color: " + targetColor + ";" + ["-ms-" + scale,"-moz-" + scale,"-webkit-" + scale,scale].join(";"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Prepare the style of the ripple
 | 
				
			||||||
 | 
					            var rippleStyle = [
 | 
				
			||||||
 | 
					                $ripple.getAttribute("style"),
 | 
				
			||||||
 | 
					                "background-color: " + targetColor,
 | 
				
			||||||
 | 
					                "-ms-transform: " + scale,
 | 
				
			||||||
 | 
					                "-moz-transform" + scale,
 | 
				
			||||||
 | 
					                "-webkit-transform" + scale,
 | 
				
			||||||
 | 
					                "transform: " + scale
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Apply the style
 | 
				
			||||||
 | 
					            $ripple.setAttribute("style", rippleStyle.join(";"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // This function is called when the animation is finished
 | 
					            // This function is called when the animation is finished
 | 
				
			||||||
            setTimeout(function() {
 | 
					            setTimeout(function() {
 | 
				
			||||||
| 
						 | 
					@ -108,14 +114,12 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Append ripple wrapper if not exists already
 | 
					        // Append ripple wrapper if not exists already
 | 
				
			||||||
        var rippleInit = function(e, target) {
 | 
					        var rippleInit = function(e, target) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
					            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
				
			||||||
                target.className += " withripple";
 | 
					                target.className += " withripple";
 | 
				
			||||||
                var $rippleWrapper = document.createElement("div");
 | 
					                var $rippleWrapper = document.createElement("div");
 | 
				
			||||||
                $rippleWrapper.className = "ripple-wrapper";
 | 
					                $rippleWrapper.className = "ripple-wrapper";
 | 
				
			||||||
                target.appendChild($rippleWrapper);
 | 
					                target.appendChild($rippleWrapper);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +136,7 @@ window.ripples = {
 | 
				
			||||||
                rippleStart(e, $ripple);
 | 
					                rippleStart(e, $ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if animation ends and user is not holding mouse then destroy the ripple
 | 
					        // if animation ends and user is not holding mouse then destroy the ripple
 | 
				
			||||||
        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
					        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,6 +146,7 @@ window.ripples = {
 | 
				
			||||||
                rippleOut($ripple);
 | 
					                rippleOut($ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
					        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
				
			||||||
        bind("mouseup", ".ripple-wrapper", function() {
 | 
					        bind("mouseup", ".ripple-wrapper", function() {
 | 
				
			||||||
            var $ripple = $ripplecache;
 | 
					            var $ripple = $ripplecache;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								dist/js/ripples.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/js/ripples.min.js
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
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,g=b,h=g.parentNode,j=document.createElement("div"),k=h.getBoundingClientRect(),l={x:a.clientX-k.left,y:a.clientY-k.top},m="transform:scale("+Math.round(g.offsetWidth/5)+")",n=new CustomEvent("rippleEnd",{detail:j}),o=.05;i=j,j.className="ripple",j.setAttribute("style","left:"+l.x+"px; top:"+l.y+"px;"),c=window.getComputedStyle(h).color,e=c.split(","),e.pop(),e.push(" "+o+")"),c=e.join(","),g.appendChild(j),f=window.getComputedStyle(j).opacity,j.dataset.animating=1,j.className="ripple ripple-on",j.setAttribute("style",j.getAttribute("style")+"background-color: "+c+";"+["-ms-"+m,"-moz-"+m,"-webkit-"+m,m].join(";")),setTimeout(function(){j.dataset.animating=0,document.dispatchEvent(n)},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)})}};
 | 
					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=b,f=e.parentNode,g=document.createElement("div"),h=f.getBoundingClientRect(),j={x:a.clientX-h.left,y:a.clientY-h.top},k="scale("+Math.round(e.offsetWidth/5)+")",l=new CustomEvent("rippleEnd",{detail:g}),m=.1;i=g,g.className="ripple",g.setAttribute("style","left:"+j.x+"px; top:"+j.y+"px;");var n=window.getComputedStyle(f).color;n=n.replace("rgb","rgba").replace(")",", "+m+")"),e.appendChild(g),c=window.getComputedStyle(g).opacity,g.dataset.animating=1,g.className="ripple ripple-on";var o=[g.getAttribute("style"),"background-color: "+n,"-ms-transform: "+k,"-moz-transform"+k,"-webkit-transform"+k,"transform: "+k];g.setAttribute("style",o.join(";")),setTimeout(function(){g.dataset.animating=0,document.dispatchEvent(l)},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)})}};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,17 @@
 | 
				
			||||||
/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
					/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
				
			||||||
/* globals CustomEvent */
 | 
					/* globals CustomEvent */
 | 
				
			||||||
/*jshint maxlen: 500 */
 | 
					 | 
				
			||||||
window.ripples = {
 | 
					window.ripples = {
 | 
				
			||||||
    init : function(withRipple) {
 | 
					    init : function(withRipple) {
 | 
				
			||||||
        "use strict";
 | 
					        "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Cross browser matches function
 | 
					        // Cross browser matches function
 | 
				
			||||||
        function matchesSelector(domElement, selector) {
 | 
					        function matchesSelector(domElement, selector) {
 | 
				
			||||||
            var matches = domElement.matches || domElement.matchesSelector || domElement.webkitMatchesSelector ||
 | 
					            var matches = domElement.matches ||
 | 
				
			||||||
 | 
					                domElement.matchesSelector ||
 | 
				
			||||||
 | 
					                domElement.webkitMatchesSelector ||
 | 
				
			||||||
                domElement.mozMatchesSelector ||
 | 
					                domElement.mozMatchesSelector ||
 | 
				
			||||||
                    domElement.msMatchesSelector || domElement.oMatchesSelector;
 | 
					                domElement.msMatchesSelector ||
 | 
				
			||||||
 | 
					                domElement.oMatchesSelector;
 | 
				
			||||||
            return matches.call(domElement, selector);
 | 
					            return matches.call(domElement, selector);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,31 +38,24 @@ window.ripples = {
 | 
				
			||||||
                $ripple             = document.createElement("div"),
 | 
					                $ripple             = document.createElement("div"),
 | 
				
			||||||
                elPos               = $el.getBoundingClientRect(),
 | 
					                elPos               = $el.getBoundingClientRect(),
 | 
				
			||||||
                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
					                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
				
			||||||
                scale                 = "transform:scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
					                scale               = "scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
				
			||||||
                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
					                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
				
			||||||
                __rippleOpacity__     = 0.05,
 | 
					                _rippleOpacity      = 0.1,
 | 
				
			||||||
                targetColor,
 | 
					 | 
				
			||||||
                rgbArr,
 | 
					 | 
				
			||||||
                refreshElementStyle;
 | 
					                refreshElementStyle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $ripplecache = $ripple;
 | 
					            $ripplecache = $ripple;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Set ripple class
 | 
					            // Set ripple class
 | 
				
			||||||
            $ripple.className = "ripple";
 | 
					            $ripple.className = "ripple";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Move ripple to the mouse position            
 | 
					            // Move ripple to the mouse position            
 | 
				
			||||||
            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
					            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get the clicked targets text color, this will be applied to the ripple as background-color.
 | 
					            // Get the clicked target's text color, this will be applied to the ripple as background-color.
 | 
				
			||||||
            targetColor = window.getComputedStyle($el).color;            
 | 
					            var targetColor = window.getComputedStyle($el).color;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            // This changes the alpha value of the rgba (opacity) to the constant __rippleOpacity__
 | 
					 | 
				
			||||||
            // Not sure if regexp is quicker... 
 | 
					 | 
				
			||||||
            rgbArr = targetColor.split(",");                        
 | 
					 | 
				
			||||||
            rgbArr.pop();
 | 
					 | 
				
			||||||
            rgbArr.push(" " + __rippleOpacity__ + ")");
 | 
					 | 
				
			||||||
            targetColor = rgbArr.join(",");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Convert the rgb color to an rgba color with opacity set to __rippleOpacity__
 | 
				
			||||||
 | 
					            targetColor = targetColor.replace("rgb", "rgba").replace(")",  ", " + _rippleOpacity + ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Insert new ripple into ripple wrapper
 | 
					            // Insert new ripple into ripple wrapper
 | 
				
			||||||
            $rippleWrapper.appendChild($ripple);    
 | 
					            $rippleWrapper.appendChild($ripple);    
 | 
				
			||||||
| 
						 | 
					@ -70,11 +65,22 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Let other funtions know that this element is animating
 | 
					            // Let other funtions know that this element is animating
 | 
				
			||||||
            $ripple.dataset.animating = 1;
 | 
					            $ripple.dataset.animating = 1;
 | 
				
			||||||
                // + "background-color: " + targetColor + ";" 
 | 
					
 | 
				
			||||||
            // Set scale value, background-color and opacity to ripple and animate it
 | 
					            // Set scale value, background-color and opacity to ripple and animate it
 | 
				
			||||||
            $ripple.className = "ripple ripple-on";
 | 
					            $ripple.className = "ripple ripple-on";
 | 
				
			||||||
            $ripple.setAttribute("style", $ripple.getAttribute("style") + "background-color: " + targetColor + ";" + ["-ms-" + scale,"-moz-" + scale,"-webkit-" + scale,scale].join(";"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Prepare the style of the ripple
 | 
				
			||||||
 | 
					            var rippleStyle = [
 | 
				
			||||||
 | 
					                $ripple.getAttribute("style"),
 | 
				
			||||||
 | 
					                "background-color: " + targetColor,
 | 
				
			||||||
 | 
					                "-ms-transform: " + scale,
 | 
				
			||||||
 | 
					                "-moz-transform" + scale,
 | 
				
			||||||
 | 
					                "-webkit-transform" + scale,
 | 
				
			||||||
 | 
					                "transform: " + scale
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Apply the style
 | 
				
			||||||
 | 
					            $ripple.setAttribute("style", rippleStyle.join(";"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // This function is called when the animation is finished
 | 
					            // This function is called when the animation is finished
 | 
				
			||||||
            setTimeout(function() {
 | 
					            setTimeout(function() {
 | 
				
			||||||
| 
						 | 
					@ -108,14 +114,12 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Append ripple wrapper if not exists already
 | 
					        // Append ripple wrapper if not exists already
 | 
				
			||||||
        var rippleInit = function(e, target) {
 | 
					        var rippleInit = function(e, target) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
					            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
				
			||||||
                target.className += " withripple";
 | 
					                target.className += " withripple";
 | 
				
			||||||
                var $rippleWrapper = document.createElement("div");
 | 
					                var $rippleWrapper = document.createElement("div");
 | 
				
			||||||
                $rippleWrapper.className = "ripple-wrapper";
 | 
					                $rippleWrapper.className = "ripple-wrapper";
 | 
				
			||||||
                target.appendChild($rippleWrapper);
 | 
					                target.appendChild($rippleWrapper);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +136,7 @@ window.ripples = {
 | 
				
			||||||
                rippleStart(e, $ripple);
 | 
					                rippleStart(e, $ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if animation ends and user is not holding mouse then destroy the ripple
 | 
					        // if animation ends and user is not holding mouse then destroy the ripple
 | 
				
			||||||
        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
					        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,6 +146,7 @@ window.ripples = {
 | 
				
			||||||
                rippleOut($ripple);
 | 
					                rippleOut($ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
					        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
				
			||||||
        bind("mouseup", ".ripple-wrapper", function() {
 | 
					        bind("mouseup", ".ripple-wrapper", function() {
 | 
				
			||||||
            var $ripple = $ripplecache;
 | 
					            var $ripple = $ripplecache;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,15 +1,17 @@
 | 
				
			||||||
/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
					/* Copyright 2014+, Federico Zivolo, LICENSE at https://github.com/FezVrasta/bootstrap-material-design/blob/master/LICENSE.md */
 | 
				
			||||||
/* globals CustomEvent */
 | 
					/* globals CustomEvent */
 | 
				
			||||||
/*jshint maxlen: 500 */
 | 
					 | 
				
			||||||
window.ripples = {
 | 
					window.ripples = {
 | 
				
			||||||
    init : function(withRipple) {
 | 
					    init : function(withRipple) {
 | 
				
			||||||
        "use strict";
 | 
					        "use strict";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Cross browser matches function
 | 
					        // Cross browser matches function
 | 
				
			||||||
        function matchesSelector(domElement, selector) {
 | 
					        function matchesSelector(domElement, selector) {
 | 
				
			||||||
            var matches = domElement.matches || domElement.matchesSelector || domElement.webkitMatchesSelector ||
 | 
					            var matches = domElement.matches ||
 | 
				
			||||||
 | 
					                domElement.matchesSelector ||
 | 
				
			||||||
 | 
					                domElement.webkitMatchesSelector ||
 | 
				
			||||||
                domElement.mozMatchesSelector ||
 | 
					                domElement.mozMatchesSelector ||
 | 
				
			||||||
                    domElement.msMatchesSelector || domElement.oMatchesSelector;
 | 
					                domElement.msMatchesSelector ||
 | 
				
			||||||
 | 
					                domElement.oMatchesSelector;
 | 
				
			||||||
            return matches.call(domElement, selector);
 | 
					            return matches.call(domElement, selector);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -36,31 +38,24 @@ window.ripples = {
 | 
				
			||||||
                $ripple             = document.createElement("div"),
 | 
					                $ripple             = document.createElement("div"),
 | 
				
			||||||
                elPos               = $el.getBoundingClientRect(),
 | 
					                elPos               = $el.getBoundingClientRect(),
 | 
				
			||||||
                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
					                mousePos            = {x: e.clientX - elPos.left, y: e.clientY - elPos.top},
 | 
				
			||||||
                scale                 = "transform:scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
					                scale               = "scale(" + Math.round($rippleWrapper.offsetWidth / 5) + ")",
 | 
				
			||||||
                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
					                rippleEnd           = new CustomEvent("rippleEnd", {detail: $ripple}),
 | 
				
			||||||
                __rippleOpacity__     = 0.05,
 | 
					                _rippleOpacity      = 0.1,
 | 
				
			||||||
                targetColor,
 | 
					 | 
				
			||||||
                rgbArr,
 | 
					 | 
				
			||||||
                refreshElementStyle;
 | 
					                refreshElementStyle;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $ripplecache = $ripple;
 | 
					            $ripplecache = $ripple;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Set ripple class
 | 
					            // Set ripple class
 | 
				
			||||||
            $ripple.className = "ripple";
 | 
					            $ripple.className = "ripple";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Move ripple to the mouse position            
 | 
					            // Move ripple to the mouse position            
 | 
				
			||||||
            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
					            $ripple.setAttribute("style", "left:" + mousePos.x + "px; top:" + mousePos.y + "px;");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Get the clicked targets text color, this will be applied to the ripple as background-color.
 | 
					            // Get the clicked target's text color, this will be applied to the ripple as background-color.
 | 
				
			||||||
            targetColor = window.getComputedStyle($el).color;            
 | 
					            var targetColor = window.getComputedStyle($el).color;
 | 
				
			||||||
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            // This changes the alpha value of the rgba (opacity) to the constant __rippleOpacity__
 | 
					 | 
				
			||||||
            // Not sure if regexp is quicker... 
 | 
					 | 
				
			||||||
            rgbArr = targetColor.split(",");                        
 | 
					 | 
				
			||||||
            rgbArr.pop();
 | 
					 | 
				
			||||||
            rgbArr.push(" " + __rippleOpacity__ + ")");
 | 
					 | 
				
			||||||
            targetColor = rgbArr.join(",");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Convert the rgb color to an rgba color with opacity set to __rippleOpacity__
 | 
				
			||||||
 | 
					            targetColor = targetColor.replace("rgb", "rgba").replace(")",  ", " + _rippleOpacity + ")");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Insert new ripple into ripple wrapper
 | 
					            // Insert new ripple into ripple wrapper
 | 
				
			||||||
            $rippleWrapper.appendChild($ripple);    
 | 
					            $rippleWrapper.appendChild($ripple);    
 | 
				
			||||||
| 
						 | 
					@ -70,11 +65,22 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Let other funtions know that this element is animating
 | 
					            // Let other funtions know that this element is animating
 | 
				
			||||||
            $ripple.dataset.animating = 1;
 | 
					            $ripple.dataset.animating = 1;
 | 
				
			||||||
                // + "background-color: " + targetColor + ";" 
 | 
					
 | 
				
			||||||
            // Set scale value, background-color and opacity to ripple and animate it
 | 
					            // Set scale value, background-color and opacity to ripple and animate it
 | 
				
			||||||
            $ripple.className = "ripple ripple-on";
 | 
					            $ripple.className = "ripple ripple-on";
 | 
				
			||||||
            $ripple.setAttribute("style", $ripple.getAttribute("style") + "background-color: " + targetColor + ";" + ["-ms-" + scale,"-moz-" + scale,"-webkit-" + scale,scale].join(";"));
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Prepare the style of the ripple
 | 
				
			||||||
 | 
					            var rippleStyle = [
 | 
				
			||||||
 | 
					                $ripple.getAttribute("style"),
 | 
				
			||||||
 | 
					                "background-color: " + targetColor,
 | 
				
			||||||
 | 
					                "-ms-transform: " + scale,
 | 
				
			||||||
 | 
					                "-moz-transform" + scale,
 | 
				
			||||||
 | 
					                "-webkit-transform" + scale,
 | 
				
			||||||
 | 
					                "transform: " + scale
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Apply the style
 | 
				
			||||||
 | 
					            $ripple.setAttribute("style", rippleStyle.join(";"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // This function is called when the animation is finished
 | 
					            // This function is called when the animation is finished
 | 
				
			||||||
            setTimeout(function() {
 | 
					            setTimeout(function() {
 | 
				
			||||||
| 
						 | 
					@ -108,14 +114,12 @@ window.ripples = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Append ripple wrapper if not exists already
 | 
					        // Append ripple wrapper if not exists already
 | 
				
			||||||
        var rippleInit = function(e, target) {
 | 
					        var rippleInit = function(e, target) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
					            if (target.getElementsByClassName("ripple-wrapper").length === 0) {
 | 
				
			||||||
                target.className += " withripple";
 | 
					                target.className += " withripple";
 | 
				
			||||||
                var $rippleWrapper = document.createElement("div");
 | 
					                var $rippleWrapper = document.createElement("div");
 | 
				
			||||||
                $rippleWrapper.className = "ripple-wrapper";
 | 
					                $rippleWrapper.className = "ripple-wrapper";
 | 
				
			||||||
                target.appendChild($rippleWrapper);
 | 
					                target.appendChild($rippleWrapper);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,6 +136,7 @@ window.ripples = {
 | 
				
			||||||
                rippleStart(e, $ripple);
 | 
					                rippleStart(e, $ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // if animation ends and user is not holding mouse then destroy the ripple
 | 
					        // if animation ends and user is not holding mouse then destroy the ripple
 | 
				
			||||||
        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
					        bind("rippleEnd", ".ripple-wrapper .ripple", function(e, $ripple) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -141,6 +146,7 @@ window.ripples = {
 | 
				
			||||||
                rippleOut($ripple);
 | 
					                rippleOut($ripple);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
					        // Destroy ripple when mouse is not holded anymore if the ripple still exists
 | 
				
			||||||
        bind("mouseup", ".ripple-wrapper", function() {
 | 
					        bind("mouseup", ".ripple-wrapper", function() {
 | 
				
			||||||
            var $ripple = $ripplecache;
 | 
					            var $ripple = $ripplecache;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										2
									
								
								template/material/js/ripples.min.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								template/material/js/ripples.min.js
									
									
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
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,g=b,h=g.parentNode,j=document.createElement("div"),k=h.getBoundingClientRect(),l={x:a.clientX-k.left,y:a.clientY-k.top},m="transform:scale("+Math.round(g.offsetWidth/5)+")",n=new CustomEvent("rippleEnd",{detail:j}),o=.05;i=j,j.className="ripple",j.setAttribute("style","left:"+l.x+"px; top:"+l.y+"px;"),c=window.getComputedStyle(h).color,e=c.split(","),e.pop(),e.push(" "+o+")"),c=e.join(","),g.appendChild(j),f=window.getComputedStyle(j).opacity,j.dataset.animating=1,j.className="ripple ripple-on",j.setAttribute("style",j.getAttribute("style")+"background-color: "+c+";"+["-ms-"+m,"-moz-"+m,"-webkit-"+m,m].join(";")),setTimeout(function(){j.dataset.animating=0,document.dispatchEvent(n)},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)})}};
 | 
					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=b,f=e.parentNode,g=document.createElement("div"),h=f.getBoundingClientRect(),j={x:a.clientX-h.left,y:a.clientY-h.top},k="scale("+Math.round(e.offsetWidth/5)+")",l=new CustomEvent("rippleEnd",{detail:g}),m=.1;i=g,g.className="ripple",g.setAttribute("style","left:"+j.x+"px; top:"+j.y+"px;");var n=window.getComputedStyle(f).color;n=n.replace("rgb","rgba").replace(")",", "+m+")"),e.appendChild(g),c=window.getComputedStyle(g).opacity,g.dataset.animating=1,g.className="ripple ripple-on";var o=[g.getAttribute("style"),"background-color: "+n,"-ms-transform: "+k,"-moz-transform"+k,"-webkit-transform"+k,"transform: "+k];g.setAttribute("style",o.join(";")),setTimeout(function(){g.dataset.animating=0,document.dispatchEvent(l)},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)})}};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user