From 3b8ee6d5d4c020fdc41a2b84b6350cc2de971529 Mon Sep 17 00:00:00 2001 From: Juha Lindstedt Date: Thu, 3 Sep 2015 13:50:59 +0300 Subject: [PATCH] simplified prefix.js --- dist/deck.js | 46 ++++++++++------------------------------------ dist/deck.min.js | 2 +- lib/prefix.js | 46 ++++++++++------------------------------------ 3 files changed, 21 insertions(+), 73 deletions(-) diff --git a/dist/deck.js b/dist/deck.js index 7ead36c..7f3504b 100644 --- a/dist/deck.js +++ b/dist/deck.js @@ -3,6 +3,7 @@ var Deck = (function () { 'use strict'; + var style = document.createElement('p').style; var memoized = {}; function prefix(param) { @@ -10,48 +11,21 @@ var Deck = (function () { return memoized[param]; } - var style = document.createElement('p').style; - if (typeof style[param] !== 'undefined') { memoized[param] = param; return param; } var camelCase = param[0].toUpperCase() + param.slice(1); - - var test = 'webkit' + camelCase; - - if (typeof style[test] !== 'undefined') { - memoized[param] = test; - return test; - } - - test = 'moz' + camelCase; - - if (typeof style[test] !== 'undefined') { - memoized[param] = test; - return test; - } - - test = 'Moz' + camelCase; - - if (typeof style[test] !== 'undefined') { - memoized[param] = test; - return test; - } - - test = 'o' + camelCase; - - if (typeof style[test] !== 'undefined') { - memoized[param] = test; - return test; - } - - test = 'ms' + camelCase; - - if (typeof style[test] !== 'undefined') { - memoized[param] = test; - return test; + var prefixes = ['webkit', 'moz', 'Moz', 'ms', 'o']; + var test; + + for (var i = 0, len = prefixes.length; i < len; i++) { + test = prefixes[i] + camelCase; + if (typeof style[test] !== 'undefined') { + memoized[param] = test; + return test; + } } } diff --git a/dist/deck.min.js b/dist/deck.min.js index b007a5f..b70142a 100644 --- a/dist/deck.min.js +++ b/dist/deck.min.js @@ -1 +1 @@ -"use strict";var Deck=function(){function t(t){if("undefined"!=typeof v[t])return v[t];var n=document.createElement("p").style;if("undefined"!=typeof n[t])return v[t]=t,t;var e=t[0].toUpperCase()+t.slice(1),o="webkit"+e;return"undefined"!=typeof n[o]?(v[t]=o,o):(o="moz"+e,"undefined"!=typeof n[o]?(v[t]=o,o):(o="Moz"+e,"undefined"!=typeof n[o]?(v[t]=o,o):(o="o"+e,"undefined"!=typeof n[o]?(v[t]=o,o):(o="ms"+e,"undefined"!=typeof n[o]?(v[t]=o,o):void 0))))}function n(n,e){var o=t("transform"),i=t("transformOrigin"),u=t("transition"),s=t("transitionDelay");n.fan=function(t,n){var r=t/5,c=10*t,f=t/51*260-130;e.style[i]="50% 110%",setTimeout(function(){e.style[u]=".3s all cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[s]=c/1e3+"s",e.style[o]="translate(-"+r+"px, -"+r+"px)",setTimeout(function(){e.style[s]="",e.style[o]="rotate("+f+"deg)"},300+c)},0),e.style.zIndex=t,setTimeout(function(){n(t)},1e3+c)}}function e(n,e){var o=t("transform"),i=t("transition"),u=t("transitionDelay"),s=n.value,r=n.suit;n.bysuit=function(t){var c=n.i,f=10*c,a=20*-(7-s),l=105*-(1.5-r);setTimeout(function(){e.style[i]="all .5s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[u]=f/1e3+"s",e.style[o]="translate("+a+"%,"+l+"%)",e.style.zIndex=c,setTimeout(function(){e.style[i]="",t(c)},500+f)},0)}}function o(n,e){var o=t("transform"),i=t("transition");n.sort=function(t,u,s){var r=t/5,c=10*t;setTimeout(function(){e.style[i]="all .4s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[o]="translate(-"+r+"px, -150%)"},c),setTimeout(function(){e.style.zIndex=t},200+c),setTimeout(function(){e.style[o]="translate(-"+r+"px, -"+r+"px)",setTimeout(function(){e.style[i]="",n.x=-r,n.y=-r,u(t)},500)},400+c)}}function i(t){var n=Math.round(Math.random())?-1:1;return n*t}function u(n,e){var o=t("transform"),u=t("transition"),s=t("transitionDelay");n.shuffle=function(t,r){var c=n.pos,f=c/5,a=i(40*Math.random()+30),l=2*c;e.style[u]="all .25s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[s]=l/1e3+"s",setTimeout(function(){e.style[o]="translate("+a+"%, -"+f+"px)"},0),setTimeout(function(){e.style[s]="",e.style.zIndex=c},125+l),setTimeout(function(){e.style[o]="translate(-"+f+"px, -"+f+"px)",setTimeout(function(){t||(e.style[u]=""),r(c)},250)},250+l)}}function s(n,e){var o=t("transform"),i=t("transition"),u=t("transitionDelay");n.intro=function(t,n){var s=10*t+250,r=t/5;e.style[o]="translate(-"+r+"px, -250%)",e.style.opacity=0,e.style.zIndex=t,setTimeout(function(){e.style[i]="all 1s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[u]=s/1e3+"s",e.style[o]="translate(-"+r+"px, -"+r+"px)",e.style.opacity=1,setTimeout(function(){e.style[i]="",n&&n(t)},1e3+s)},0)}}function r(t){return document.createElement(t)}function c(i){function c(t){function n(t){var n={};"mousemove"===t.type?(n.x=t.clientX,n.y=t.clientY):(n.x=t.touches[0].clientX,n.y=t.touches[0].clientY),L.style[v]="translate("+(n.x-o.left)+"px, "+(n.y-o.top)+"px)"}function e(t){"mouseup"===t.type?(l(window,"mousemove",n),l(window,"mouseup",e)):(l(window,"touchmove",n),l(window,"touchend",e)),L.style.zIndex=h++}var o=p.getBoundingClientRect();"mousedown"===t.type?(a(window,"mousemove",n),a(window,"mouseup",e)):(l(window,"touchmove",n),l(window,"touchend",e)),L.style[m]=""}function d(t){t.appendChild(L),p=t}function y(){p&&p.removeChild(L),p=null}var p,m=t("transition"),v=t("transform"),h=52,x=i%13+1,b=1===x?"A":11===x?"J":12===x?"Q":13===x?"K":x,w=i/13|0,T=f(w),z=w%2?"red":"black",g=(52-i)/5,C={i:i,value:x,suit:w,pos:i,$el:L,mount:d,unmount:y},L=r("div"),E=r("div"),I=r("div"),M=r("div");return L.classList.add("card",z),E.classList.add("suit"),I.classList.add("topleft"),M.classList.add("bottomright"),E.textContent=T,I.innerHTML=b+"
"+T,M.innerHTML=b+"
"+T,L.style.zIndex=52-i,L.style[v]="translate(-"+g+"px, -"+g+"px)",L.appendChild(E),L.appendChild(I),L.appendChild(M),s(C,L),u(C,L),o(C,L),e(C,L),n(C,L),a(L,"mousedown",c),a(L,"touchstart",c),C}function f(t){return 0===t?"♠︎":1===t?"♥︎":2===t?"♣︎":"♦"}function a(t,n,e){t.addEventListener(n,e)}function l(t,n,e){t.removeEventListener(n,e)}function d(t,n){function e(t){return 0===o?(o=-1,void(t&&t())):(-1===o?o=2:o--,n.sort(function(){return 100*Math.random()-50}),void n.forEach(function(n,i){n.pos=i,n.shuffle(o,function(n){51===n&&e(t)})}))}var o=-1;t.shuffle=function(){t.queue(e)}}function y(t){function n(t){t&&(o.push(t),1===o.length&&e())}function e(){o[0](function(t){if(t)throw t;o=o.slice(1),o.length&&e()})}var o=[];return t.queue=n,t}function p(t){function n(t,n,e){u[t]||(u[t]=[]),u[t].push({cb:n,ctx:e})}function e(t,n,e){u[t]||(u[t]=[]),u[t].push({cb:n,ctx:e,once:!0})}function o(t){var n=this,e=Array.prototype.slice(arguments,1),o=u[t]||[];o.filter(function(t){return t.cb.apply(n,e),!t.once})}function i(t,n){return t?n?void(u[t]=u[t].filter(function(t){return t.cb!==n})):void(u[t]=[]):void(u={})}var u={};return t.on=n,t.one=e,t.off=i,t.trigger=o,t}function m(){function t(t){u=t,u.appendChild(l)}function n(){u.removeChild(l)}function e(){a.queue(function(t){f.forEach(function(n,e){n.fan(e,function(n){51===n&&t()})})})}function o(){a.sort(!0),a.queue(function(t){f.forEach(function(n){n.bysuit(function(n){51===n&&t()})})})}function i(t){a.queue(function(n){f.sort(function(n,e){return t?n.i-e.i:e.i-n.i}),f.forEach(function(e,o){e.sort(o,function(t){51===t&&n()},t)})})}var u,s,f=new Array(52),a=p({mount:t,unmount:n,cards:f}),l=r("div");return y(a),d(a,f),a.sort=i,a.bysuit=o,a.fan=e,l.classList.add("deck"),a.queue(function(t){for(var n=0,e=f.length;e>n;n++)s=f[n]=c(n),s.intro(n,function(n){51===n&&t()}),s.mount(l)}),a.shuffle(),a.sort(),a}var v={};return m}(); \ No newline at end of file +"use strict";var Deck=function(){function t(t){if("undefined"!=typeof h[t])return h[t];if("undefined"!=typeof v[t])return h[t]=t,t;for(var n,e=t[0].toUpperCase()+t.slice(1),o=["webkit","moz","Moz","ms","o"],i=0,u=o.length;u>i;i++)if(n=o[i]+e,"undefined"!=typeof v[n])return h[t]=n,n}function n(n,e){var o=t("transform"),i=t("transformOrigin"),u=t("transition"),s=t("transitionDelay");n.fan=function(t,n){var r=t/5,c=10*t,a=t/51*260-130;e.style[i]="50% 110%",setTimeout(function(){e.style[u]=".3s all cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[s]=c/1e3+"s",e.style[o]="translate(-"+r+"px, -"+r+"px)",setTimeout(function(){e.style[s]="",e.style[o]="rotate("+a+"deg)"},300+c)},0),e.style.zIndex=t,setTimeout(function(){n(t)},1e3+c)}}function e(n,e){var o=t("transform"),i=t("transition"),u=t("transitionDelay"),s=n.value,r=n.suit;n.bysuit=function(t){var c=n.i,a=10*c,f=20*-(7-s),l=105*-(1.5-r);setTimeout(function(){e.style[i]="all .5s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[u]=a/1e3+"s",e.style[o]="translate("+f+"%,"+l+"%)",e.style.zIndex=c,setTimeout(function(){e.style[i]="",t(c)},500+a)},0)}}function o(n,e){var o=t("transform"),i=t("transition");n.sort=function(t,u,s){var r=t/5,c=10*t;setTimeout(function(){e.style[i]="all .4s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[o]="translate(-"+r+"px, -150%)"},c),setTimeout(function(){e.style.zIndex=t},200+c),setTimeout(function(){e.style[o]="translate(-"+r+"px, -"+r+"px)",setTimeout(function(){e.style[i]="",n.x=-r,n.y=-r,u(t)},500)},400+c)}}function i(t){var n=Math.round(Math.random())?-1:1;return n*t}function u(n,e){var o=t("transform"),u=t("transition"),s=t("transitionDelay");n.shuffle=function(t,r){var c=n.pos,a=c/5,f=i(40*Math.random()+30),l=2*c;e.style[u]="all .25s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[s]=l/1e3+"s",setTimeout(function(){e.style[o]="translate("+f+"%, -"+a+"px)"},0),setTimeout(function(){e.style[s]="",e.style.zIndex=c},125+l),setTimeout(function(){e.style[o]="translate(-"+a+"px, -"+a+"px)",setTimeout(function(){t||(e.style[u]=""),r(c)},250)},250+l)}}function s(n,e){var o=t("transform"),i=t("transition"),u=t("transitionDelay");n.intro=function(t,n){var s=10*t+250,r=t/5;e.style[o]="translate(-"+r+"px, -250%)",e.style.opacity=0,e.style.zIndex=t,setTimeout(function(){e.style[i]="all 1s cubic-bezier(0.645, 0.045, 0.355, 1.000)",e.style[u]=s/1e3+"s",e.style[o]="translate(-"+r+"px, -"+r+"px)",e.style.opacity=1,setTimeout(function(){e.style[i]="",n&&n(t)},1e3+s)},0)}}function r(t){return document.createElement(t)}function c(i){function c(t){function n(t){var n={};"mousemove"===t.type?(n.x=t.clientX,n.y=t.clientY):(n.x=t.touches[0].clientX,n.y=t.touches[0].clientY),L.style[v]="translate("+(n.x-o.left)+"px, "+(n.y-o.top)+"px)"}function e(t){"mouseup"===t.type?(l(window,"mousemove",n),l(window,"mouseup",e)):(l(window,"touchmove",n),l(window,"touchend",e)),L.style.zIndex=h++}var o=m.getBoundingClientRect();"mousedown"===t.type?(f(window,"mousemove",n),f(window,"mouseup",e)):(l(window,"touchmove",n),l(window,"touchend",e)),L.style[p]=""}function d(t){t.appendChild(L),m=t}function y(){m&&m.removeChild(L),m=null}var m,p=t("transition"),v=t("transform"),h=52,x=i%13+1,b=1===x?"A":11===x?"J":12===x?"Q":13===x?"K":x,w=i/13|0,T=a(w),z=w%2?"red":"black",g=(52-i)/5,C={i:i,value:x,suit:w,pos:i,$el:L,mount:d,unmount:y},L=r("div"),E=r("div"),I=r("div"),M=r("div");return L.classList.add("card",z),E.classList.add("suit"),I.classList.add("topleft"),M.classList.add("bottomright"),E.textContent=T,I.innerHTML=b+"
"+T,M.innerHTML=b+"
"+T,L.style.zIndex=52-i,L.style[v]="translate(-"+g+"px, -"+g+"px)",L.appendChild(E),L.appendChild(I),L.appendChild(M),s(C,L),u(C,L),o(C,L),e(C,L),n(C,L),f(L,"mousedown",c),f(L,"touchstart",c),C}function a(t){return 0===t?"♠︎":1===t?"♥︎":2===t?"♣︎":"♦"}function f(t,n,e){t.addEventListener(n,e)}function l(t,n,e){t.removeEventListener(n,e)}function d(t,n){function e(t){return 0===o?(o=-1,void(t&&t())):(-1===o?o=2:o--,n.sort(function(){return 100*Math.random()-50}),void n.forEach(function(n,i){n.pos=i,n.shuffle(o,function(n){51===n&&e(t)})}))}var o=-1;t.shuffle=function(){t.queue(e)}}function y(t){function n(t){t&&(o.push(t),1===o.length&&e())}function e(){o[0](function(t){if(t)throw t;o=o.slice(1),o.length&&e()})}var o=[];return t.queue=n,t}function m(t){function n(t,n,e){u[t]||(u[t]=[]),u[t].push({cb:n,ctx:e})}function e(t,n,e){u[t]||(u[t]=[]),u[t].push({cb:n,ctx:e,once:!0})}function o(t){var n=this,e=Array.prototype.slice(arguments,1),o=u[t]||[];o.filter(function(t){return t.cb.apply(n,e),!t.once})}function i(t,n){return t?n?void(u[t]=u[t].filter(function(t){return t.cb!==n})):void(u[t]=[]):void(u={})}var u={};return t.on=n,t.one=e,t.off=i,t.trigger=o,t}function p(){function t(t){u=t,u.appendChild(l)}function n(){u.removeChild(l)}function e(){f.queue(function(t){a.forEach(function(n,e){n.fan(e,function(n){51===n&&t()})})})}function o(){f.sort(!0),f.queue(function(t){a.forEach(function(n){n.bysuit(function(n){51===n&&t()})})})}function i(t){f.queue(function(n){a.sort(function(n,e){return t?n.i-e.i:e.i-n.i}),a.forEach(function(e,o){e.sort(o,function(t){51===t&&n()},t)})})}var u,s,a=new Array(52),f=m({mount:t,unmount:n,cards:a}),l=r("div");return y(f),d(f,a),f.sort=i,f.bysuit=o,f.fan=e,l.classList.add("deck"),f.queue(function(t){for(var n=0,e=a.length;e>n;n++)s=a[n]=c(n),s.intro(n,function(n){51===n&&t()}),s.mount(l)}),f.shuffle(),f.sort(),f}var v=document.createElement("p").style,h={};return p}(); \ No newline at end of file diff --git a/lib/prefix.js b/lib/prefix.js index 6c31996..d35f8c6 100644 --- a/lib/prefix.js +++ b/lib/prefix.js @@ -1,4 +1,5 @@ +var style = document.createElement('p').style var memoized = {} export default function (param) { @@ -6,48 +7,21 @@ export default function (param) { return memoized[param] } - var style = document.createElement('p').style - if (typeof style[param] !== 'undefined') { memoized[param] = param return param } var camelCase = param[0].toUpperCase() + param.slice(1) - - var test = 'webkit' + camelCase - - if (typeof style[test] !== 'undefined') { - memoized[param] = test - return test - } - - test = 'moz' + camelCase - - if (typeof style[test] !== 'undefined') { - memoized[param] = test - return test - } - - test = 'Moz' + camelCase - - if (typeof style[test] !== 'undefined') { - memoized[param] = test - return test - } - - test = 'o' + camelCase - - if (typeof style[test] !== 'undefined') { - memoized[param] = test - return test - } - - test = 'ms' + camelCase - - if (typeof style[test] !== 'undefined') { - memoized[param] = test - return test + var prefixes = ['webkit', 'moz', 'Moz', 'ms', 'o'] + var test + + for (var i = 0, len = prefixes.length; i < len; i++) { + test = prefixes[i] + camelCase + if (typeof style[test] !== 'undefined') { + memoized[param] = test + return test + } } }