From 730616d16cfa1ab62bf4bd272f4931ace0b1a826 Mon Sep 17 00:00:00 2001 From: "Alfiana E. Sibuea" Date: Tue, 12 Aug 2014 11:23:29 +0700 Subject: [PATCH] BUG FIX: Broken waves-ripple position --- dist/waves.js | 36 ++++++++++++++++++++++-------------- dist/waves.min.js | 4 ++-- dist/waves.min.js.map | 2 +- src/js/waves.js | 36 ++++++++++++++++++++++-------------- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/dist/waves.js b/dist/waves.js index 0f8ca81..9a2e158 100644 --- a/dist/waves.js +++ b/dist/waves.js @@ -1,6 +1,6 @@ /*! - * Waves v0.5.0 + * Waves v0.5.1 * https://publicis-indonesia.github.io/Waves * * Copyright 2014 Publicis Metro Indonesia, PT. and other contributors @@ -15,21 +15,29 @@ var $$ = document.querySelectorAll.bind(document); // Find exact position of element - function position(obj) { + function isWindow(obj) { + return obj !== null && obj === obj.window; + } - var left = 0; - var top = 0; - - if (obj.offsetParent) { - do { - left += obj.offsetLeft; - top += obj.offsetTop; - } while (obj === obj.offsetParent); - } + function getWindow(elem) { + return isWindow(elem) ? elem : elem.nodeType === 9 && elem.defaultView; + } + function offset(elem) { + + var docElem, win, + box = {top: 0, left: 0}, + doc = elem && elem.ownerDocument; + + docElem = doc.documentElement; + + if (typeof elem.getBoundingClientRect !== typeof undefined) { + box = elem.getBoundingClientRect(); + } + win = getWindow(doc); return { - top: top, - left: left + top: box.top + win.pageYOffset - docElem.clientTop, + left: box.left + win.pageXOffset - docElem.clientLeft }; } @@ -61,7 +69,7 @@ el.appendChild(ripple); // Get click coordinate and element witdh - var pos = position(el); + var pos = offset(el); var relativeY = (e.pageY - pos.top) - 45; var relativeX = (e.pageX - pos.left) - 45; var scale = 'scale('+((el.clientWidth / 100) * 2.5)+')'; diff --git a/dist/waves.min.js b/dist/waves.min.js index 7a32b04..026c8ab 100644 --- a/dist/waves.min.js +++ b/dist/waves.min.js @@ -1,10 +1,10 @@ /*! - * Waves v0.5.0 + * Waves v0.5.1 * https://publicis-indonesia.github.io/Waves * * Copyright 2014 Publicis Metro Indonesia, PT. and other contributors * Released under the BSD license * https://github.com/publicis-indonesia/Waves/blob/master/LICENSE */ -!function(a){"use strict";function b(a){var b=0,c=0;if(a.offsetParent)do b+=a.offsetLeft,c+=a.offsetTop;while(a===a.offsetParent);return{top:c,left:b}}function c(a){var b="";for(var c in a)a.hasOwnProperty(c)&&(b+=c+":"+a[c]+";");return b}var d=d||{},e=document.querySelectorAll.bind(document),f={duration:500,show:function(a){var d=this,e=document.createElement("div");e.className="waves-ripple",d.appendChild(e);var g=b(d),h=a.pageY-g.top-45,i=a.pageX-g.left-45,j="scale("+d.clientWidth/100*2.5+")";e.setAttribute("data-hold",Date.now()),e.setAttribute("data-scale",j),e.setAttribute("data-x",i),e.setAttribute("data-y",h);var k={top:h+"px",left:i+"px"};e.className=e.className+" waves-notransition",e.setAttribute("style",c(k)),e.className=e.className.replace("waves-notransition",""),k["-webkit-transform"]=j,k["-moz-transform"]=j,k["-ms-transform"]=j,k["-o-transform"]=j,k.transform=j,k.opacity="1",k["-webkit-transition-duration"]=f.duration+"ms",k["-moz-transition-duration"]=f.duration+"ms",k["-o-transition-duration"]=f.duration+"ms",k["transition-duration"]=f.duration+"ms",e.setAttribute("style",c(k))},hide:function(){for(var a=this,b=(1.4*a.clientWidth,null),d=a.children.length,e=0;d>e;e++)-1===a.children[e].className.indexOf("waves-ripple")||(b=a.children[e]);if(!b)return!1;var g=b.getAttribute("data-x"),h=b.getAttribute("data-y"),i=b.getAttribute("data-scale"),j=Date.now()-Number(b.getAttribute("data-hold")),k=500-j;0>k&&(k=0),setTimeout(function(){var d={top:h+"px",left:g+"px",opacity:"0","-webkit-transition-duration":f.duration+"ms","-moz-transition-duration":f.duration+"ms","-o-transition-duration":f.duration+"ms","transition-duration":f.duration+"ms","-webkit-transform":i,"-moz-transform":i,"-ms-transform":i,"-o-transform":i,transform:i};b.setAttribute("style",c(d)),setTimeout(function(){try{a.removeChild(b)}catch(c){return!1}},f.duration)},k)},wrapInput:function(a){for(var b=0;bd;d++)-1===a.children[d].className.indexOf("waves-ripple")||(b=a.children[d]);if(!b)return!1;var f=b.getAttribute("data-x"),g=b.getAttribute("data-y"),i=b.getAttribute("data-scale"),j=Date.now()-Number(b.getAttribute("data-hold")),k=500-j;0>k&&(k=0),setTimeout(function(){var c={top:g+"px",left:f+"px",opacity:"0","-webkit-transition-duration":h.duration+"ms","-moz-transition-duration":h.duration+"ms","-o-transition-duration":h.duration+"ms","transition-duration":h.duration+"ms","-webkit-transform":i,"-moz-transform":i,"-ms-transform":i,"-o-transform":i,transform:i};b.setAttribute("style",e(c)),setTimeout(function(){try{a.removeChild(b)}catch(c){return!1}},h.duration)},k)},wrapInput:function(a){for(var b=0;b