creepyface
Advanced tools
Comparing version 3.5.0 to 3.5.1
@@ -199,3 +199,4 @@ 'use strict'; | ||
fieldofvision = _parseDataAttributes.fieldofvision, | ||
timetodefault = _parseDataAttributes.timetodefault; | ||
timetodefault = _parseDataAttributes.timetodefault, | ||
resetoncancel = _parseDataAttributes.resetoncancel; | ||
@@ -208,2 +209,3 @@ var options = { | ||
if (fieldofvision) options.fieldOfVision = parseFloat(fieldofvision); | ||
if (resetoncancel) options.resetOnCancel = resetoncancel === 'true'; | ||
if (src.hover) options.hover = src.hover; | ||
@@ -229,2 +231,3 @@ if (src.look) options.looks = getLooks(src.look); | ||
timeToDefault: userOptions.timeToDefault || 1000, | ||
resetOnCancel: !(userOptions.resetOnCancel === false), | ||
onDebug: userOptions.onDebug || function () {}, | ||
@@ -338,3 +341,3 @@ onAttach: userOptions.onAttach || function () {}, | ||
subscription.unsubscribe(); | ||
setSrc(options.src); | ||
if (options.resetOnCancel) setSrc(options.src); | ||
options.onDetach(); | ||
@@ -341,0 +344,0 @@ }); |
@@ -195,3 +195,4 @@ import loadImages from 'image-promise'; | ||
fieldofvision = _parseDataAttributes.fieldofvision, | ||
timetodefault = _parseDataAttributes.timetodefault; | ||
timetodefault = _parseDataAttributes.timetodefault, | ||
resetoncancel = _parseDataAttributes.resetoncancel; | ||
@@ -204,2 +205,3 @@ var options = { | ||
if (fieldofvision) options.fieldOfVision = parseFloat(fieldofvision); | ||
if (resetoncancel) options.resetOnCancel = resetoncancel === 'true'; | ||
if (src.hover) options.hover = src.hover; | ||
@@ -225,2 +227,3 @@ if (src.look) options.looks = getLooks(src.look); | ||
timeToDefault: userOptions.timeToDefault || 1000, | ||
resetOnCancel: !(userOptions.resetOnCancel === false), | ||
onDebug: userOptions.onDebug || function () {}, | ||
@@ -334,3 +337,3 @@ onAttach: userOptions.onAttach || function () {}, | ||
subscription.unsubscribe(); | ||
setSrc(options.src); | ||
if (options.resetOnCancel) setSrc(options.src); | ||
options.onDetach(); | ||
@@ -337,0 +340,0 @@ }); |
@@ -1,1 +0,1 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.creepyFace=t()}(this,function(){"use strict";function n(t){if(!t)return Promise.reject();if("string"==typeof t){var e=t;(t=new Image).src=e}else{if(void 0!==t.length){var r=[].map.call(t,function(t){return n(t).catch(function(n){return n})});return Promise.all(r).then(function(n){var t=n.filter(function(n){return n.naturalWidth});return t.length===n.length?t:Promise.reject({loaded:t,errored:n.filter(function(n){return!n.naturalWidth})})})}if("IMG"!==t.tagName)return Promise.reject()}var o=new Promise(function(n,e){function r(){t.naturalWidth?n(t):e(t),t.removeEventListener("load",r),t.removeEventListener("error",r)}t.naturalWidth?n(t):t.complete?e(t):(t.addEventListener("load",r),t.addEventListener("error",r))});return o.image=t,o}function t(n,t){return c(a(t)).then(function(t){n.creepyFaceReachableImages=t})}function e(n){return function(t){var e;return e=/^data\-/.test(t.name),void 0===n?e:e&&n.test(t.name.slice(5))}}function r(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}function o(n){var t=f(n),e=t.src,r=void 0===e?{}:e,o=t.fieldofvision,u=t.timetodefault,i={src:n.getAttribute("src")};return u&&(i.timeToDefault=parseFloat(u)),o&&(i.fieldOfVision=parseFloat(o)),r.hover&&(i.hover=r.hover),r.look&&(i.looks=D(r.look)),i}function u(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Object.assign({},o(n),t);if(!e.src)throw new Error("A default URL must be specified");return{fieldOfVision:e.fieldOfVision||150,src:e.src,hover:e.hover||"",points:e.points||O([v,x]),looks:e.looks||[],timeToDefault:e.timeToDefault||1e3,onDebug:e.onDebug||function(){},onAttach:e.onAttach||function(){},onDetach:e.onDetach||function(){}}}function i(n,t){var e=function(){},r=Y(n,function(){e=X(n,t)},function(){e()});return function(){r(),e()}}var c=n,a=function(n){var t=n.looks.map(function(n){return n.src});return n.src&&t.push(n.src),n.hover&&t.push(n.hover),t},f=function(n,t){var r={};return void 0===(t=t||{}).separator&&(t.separator="-"),Array.prototype.slice.call(n.attributes).filter(e(t.pattern)).forEach(function(n){n.name.slice(5).split(t.separator).reduce(function(t,e,r,o){return"data"===e?t:(r===o.length-1?t[e]=n.value:t[e]=t[e]||{},t[e])},r)}),r},s=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),l=function(){function n(t){r(this,n),this.subscriber=function(n){return function(){}},this.subscriber=t}return s(n,[{key:"subscribe",value:function(n){var t={next:n},e=this.subscriber(t);return"function"==typeof e?{unsubscribe:e}:e}}]),n}(),d=[];document.addEventListener("mousemove",function(n){return d.forEach(function(t){return t.next([n.clientX,n.clientY])})},!0);var v=new l(function(n){return d.push(n),function(){d.splice(d.indexOf(n),1)}}),h=function(n,t){return n.map(function(n,e){return n-t[e]})},m=function(n,t){return n.map(function(n,e){return n+t[e]})},p=function(n){return n?n<0?-1:1:0},b=function(n){return n*Math.PI/180},y=function(n){return 180*n/Math.PI},w=function(n,t){return(t+n%t)%t},g=function(n){return y(w(Math.atan2(n[1],n[0]),2*Math.PI))},E=function(n,t){return[n[0]*Math.cos(b(t))-n[1]*Math.sin(b(t)),n[0]*Math.sin(b(t))+n[1]*Math.cos(b(t))]},M=[];document.addEventListener("touchmove",function(n){return M.forEach(function(t){var e=[0,0],r=!0,o=!1,u=void 0;try{for(var i,c=n.touches[Symbol.iterator]();!(r=(i=c.next()).done);r=!0){var a=i.value;e=m(e,[a.clientX,a.clientY])}}catch(n){o=!0,u=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw u}}t.next(e)})},!0);var x=new l(function(n){return M.push(n),function(){M.splice(M.indexOf(n),1)}}),O=function(n){return new l(function(t){var e=t.next.bind(t),r=n.map(function(n){return n.subscribe(e)});return function(){return r.forEach(function(n){return n.unsubscribe()})}})},D=function(n){var t=[],e=!0,r=!1,o=void 0;try{for(var u,i=Object.keys(n)[Symbol.iterator]();!(e=(u=i.next()).done);e=!0){var c=u.value,a=n[c];a&&t.push({angle:parseFloat(c),src:a})}}catch(n){r=!0,o=n}finally{try{!e&&i.return&&i.return()}finally{if(r)throw o}}return t},T=function(n){var t=n.getBoundingClientRect();return{y:t.top+window.pageYOffset+t.height/2,x:t.left+window.pageXOffset+t.width/2}},j=function(n){var t=T(n);return[t.x,t.y]},L=function(n,t){return g(E(h(m([window.scrollX,window.scrollY],t),j(n)),90))},P=function(){function n(n,t){var e=[],r=!0,o=!1,u=void 0;try{for(var i,c=n[Symbol.iterator]();!(r=(i=c.next()).done)&&(e.push(i.value),!t||e.length!==t);r=!0);}catch(n){o=!0,u=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw u}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return n(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),k=function(n){return Math.abs(n)>180?n-360*p(n):n},A=function(n){return function(t,e){return Math.abs(k(t.angle-n))-Math.abs(k(e.angle-n))}},I=function(n,t){return t.slice(0).sort(A(n))[0]},F=function(n,t,e){return n>=t&&n<=e},N=function(n,t){var e=n.left,r=n.top,o=n.right,u=n.bottom,i=P(t,2),c=i[0],a=i[1];return F(c,e,o)&&F(a,r,u)},R=function(n,t){var e=P(t,2),r=e[0],o=e[1];return document.elementFromPoint?document.elementFromPoint(r,o)===n:N(n.getBoundingClientRect(),[r,o])},S=function(n,t,e,r){var o=r.looks,u=r.hover,i=r.fieldOfVision,c=r.src;if(u&&R(n,t))c=u;else{var a=I(e,o);a&&Math.abs(k(a.angle-e))<i/2&&(c=a.src)}return c},V=function(n,t,e){function r(){var f=Date.now()-c;f<t&&f>=0?o=setTimeout(r,t-f):(o=null,e||(a=n.apply(i,u),i=u=null))}var o,u,i,c,a;null==t&&(t=100);var f=function(){i=this,u=arguments,c=Date.now();var f=e&&!o;return o||(o=setTimeout(r,t)),f&&(a=n.apply(i,u),i=u=null),a};return f.clear=function(){o&&(clearTimeout(o),o=null)},f.flush=function(){o&&(a=n.apply(i,u),i=u=null,clearTimeout(o),o=null)},f},W=function(n,t){return new l(function(e){var r=V(function(){return e.next({src:t.src,options:t})},t.timeToDefault),o=t.points.subscribe(function(o){var u=L(n,o),i=S(n,o,u,t);e.next({point:o,angle:u,src:i,options:t}),r()});return function(){r.clear(),o.unsubscribe()}})},X=function(n,e){var r=u(n,e),o=function(t){n.src=t},i=t(n,r).then(function(){return r.onAttach(),W(n,r).subscribe(function(n){o(n.src),r.onDebug(n)})});return function(){return i.then(function(n){n.unsubscribe(),o(r.src),r.onDetach()})}},Y=function(n,t,e){var r=function(n){return n?t():e()},o=window.MutationObserver;if(o){var u=document.body&&document.body.contains(n);u&&r(!0);var i=new o(function(t){var e=document.body&&document.body.contains(n);!e&&u?(r(!1),u=!1):e&&!u&&(r(!0),u=!0)});return i.observe(document,{childList:!0,subtree:!0}),function(){return i.disconnect()}}return document.body&&document.body.contains(n)&&r(!0),n.addEventListener("DOMNodeInserted",function(){return r(!0)},!1),n.addEventListener("DOMNodeRemoved",function(){return r(!1)},!1),function(){}},C=function(n){return!(!n||"object"!=typeof n)&&("object"==typeof window&&"object"==typeof window.Node?n instanceof window.Node:"number"==typeof n.nodeType&&"string"==typeof n.nodeName)};return function(n){return C(n)?[n]:"string"==typeof n?[].slice.call(document.querySelectorAll(n)):void 0}("img[data-creepy]").forEach(function(n){n instanceof HTMLImageElement&&i(n)}),i}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):n.creepyFace=t()}(this,function(){"use strict";function n(t){if(!t)return Promise.reject();if("string"==typeof t){var e=t;(t=new Image).src=e}else{if(void 0!==t.length){var r=[].map.call(t,function(t){return n(t).catch(function(n){return n})});return Promise.all(r).then(function(n){var t=n.filter(function(n){return n.naturalWidth});return t.length===n.length?t:Promise.reject({loaded:t,errored:n.filter(function(n){return!n.naturalWidth})})})}if("IMG"!==t.tagName)return Promise.reject()}var o=new Promise(function(n,e){function r(){t.naturalWidth?n(t):e(t),t.removeEventListener("load",r),t.removeEventListener("error",r)}t.naturalWidth?n(t):t.complete?e(t):(t.addEventListener("load",r),t.addEventListener("error",r))});return o.image=t,o}function t(n,t){return c(a(t)).then(function(t){n.creepyFaceReachableImages=t})}function e(n){return function(t){var e;return e=/^data\-/.test(t.name),void 0===n?e:e&&n.test(t.name.slice(5))}}function r(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}function o(n){var t=f(n),e=t.src,r=void 0===e?{}:e,o=t.fieldofvision,u=t.timetodefault,i=t.resetoncancel,c={src:n.getAttribute("src")};return u&&(c.timeToDefault=parseFloat(u)),o&&(c.fieldOfVision=parseFloat(o)),i&&(c.resetOnCancel="true"===i),r.hover&&(c.hover=r.hover),r.look&&(c.looks=D(r.look)),c}function u(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},e=Object.assign({},o(n),t);if(!e.src)throw new Error("A default URL must be specified");return{fieldOfVision:e.fieldOfVision||150,src:e.src,hover:e.hover||"",points:e.points||x([v,M]),looks:e.looks||[],timeToDefault:e.timeToDefault||1e3,resetOnCancel:!(!1===e.resetOnCancel),onDebug:e.onDebug||function(){},onAttach:e.onAttach||function(){},onDetach:e.onDetach||function(){}}}function i(n,t){var e=function(){},r=X(n,function(){e=W(n,t)},function(){e()});return function(){r(),e()}}var c=n,a=function(n){var t=n.looks.map(function(n){return n.src});return n.src&&t.push(n.src),n.hover&&t.push(n.hover),t},f=function(n,t){var r={};return void 0===(t=t||{}).separator&&(t.separator="-"),Array.prototype.slice.call(n.attributes).filter(e(t.pattern)).forEach(function(n){n.name.slice(5).split(t.separator).reduce(function(t,e,r,o){return"data"===e?t:(r===o.length-1?t[e]=n.value:t[e]=t[e]||{},t[e])},r)}),r},s=function(){function n(n,t){for(var e=0;e<t.length;e++){var r=t[e];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}return function(t,e,r){return e&&n(t.prototype,e),r&&n(t,r),t}}(),l=function(){function n(t){r(this,n),this.subscriber=function(n){return function(){}},this.subscriber=t}return s(n,[{key:"subscribe",value:function(n){var t={next:n},e=this.subscriber(t);return"function"==typeof e?{unsubscribe:e}:e}}]),n}(),d=[];document.addEventListener("mousemove",function(n){return d.forEach(function(t){return t.next([n.clientX,n.clientY])})},!0);var v=new l(function(n){return d.push(n),function(){d.splice(d.indexOf(n),1)}}),h=function(n,t){return n.map(function(n,e){return n-t[e]})},m=function(n,t){return n.map(function(n,e){return n+t[e]})},p=function(n){return n?n<0?-1:1:0},b=function(n){return n*Math.PI/180},y=function(n){return 180*n/Math.PI},w=function(n,t){return(t+n%t)%t},g=function(n){return y(w(Math.atan2(n[1],n[0]),2*Math.PI))},O=function(n,t){return[n[0]*Math.cos(b(t))-n[1]*Math.sin(b(t)),n[0]*Math.sin(b(t))+n[1]*Math.cos(b(t))]},E=[];document.addEventListener("touchmove",function(n){return E.forEach(function(t){var e=[0,0],r=!0,o=!1,u=void 0;try{for(var i,c=n.touches[Symbol.iterator]();!(r=(i=c.next()).done);r=!0){var a=i.value;e=m(e,[a.clientX,a.clientY])}}catch(n){o=!0,u=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw u}}t.next(e)})},!0);var M=new l(function(n){return E.push(n),function(){E.splice(E.indexOf(n),1)}}),x=function(n){return new l(function(t){var e=t.next.bind(t),r=n.map(function(n){return n.subscribe(e)});return function(){return r.forEach(function(n){return n.unsubscribe()})}})},D=function(n){var t=[],e=!0,r=!1,o=void 0;try{for(var u,i=Object.keys(n)[Symbol.iterator]();!(e=(u=i.next()).done);e=!0){var c=u.value,a=n[c];a&&t.push({angle:parseFloat(c),src:a})}}catch(n){r=!0,o=n}finally{try{!e&&i.return&&i.return()}finally{if(r)throw o}}return t},T=function(n){var t=n.getBoundingClientRect();return{y:t.top+window.pageYOffset+t.height/2,x:t.left+window.pageXOffset+t.width/2}},j=function(n){var t=T(n);return[t.x,t.y]},L=function(n,t){return g(O(h(m([window.scrollX,window.scrollY],t),j(n)),90))},P=function(){function n(n,t){var e=[],r=!0,o=!1,u=void 0;try{for(var i,c=n[Symbol.iterator]();!(r=(i=c.next()).done)&&(e.push(i.value),!t||e.length!==t);r=!0);}catch(n){o=!0,u=n}finally{try{!r&&c.return&&c.return()}finally{if(o)throw u}}return e}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return n(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),k=function(n){return Math.abs(n)>180?n-360*p(n):n},A=function(n){return function(t,e){return Math.abs(k(t.angle-n))-Math.abs(k(e.angle-n))}},I=function(n,t){return t.slice(0).sort(A(n))[0]},C=function(n,t,e){return n>=t&&n<=e},F=function(n,t){var e=n.left,r=n.top,o=n.right,u=n.bottom,i=P(t,2),c=i[0],a=i[1];return C(c,e,o)&&C(a,r,u)},N=function(n,t){var e=P(t,2),r=e[0],o=e[1];return document.elementFromPoint?document.elementFromPoint(r,o)===n:F(n.getBoundingClientRect(),[r,o])},R=function(n,t,e,r){var o=r.looks,u=r.hover,i=r.fieldOfVision,c=r.src;if(u&&N(n,t))c=u;else{var a=I(e,o);a&&Math.abs(k(a.angle-e))<i/2&&(c=a.src)}return c},S=function(n,t,e){function r(){var f=Date.now()-c;f<t&&f>=0?o=setTimeout(r,t-f):(o=null,e||(a=n.apply(i,u),i=u=null))}var o,u,i,c,a;null==t&&(t=100);var f=function(){i=this,u=arguments,c=Date.now();var f=e&&!o;return o||(o=setTimeout(r,t)),f&&(a=n.apply(i,u),i=u=null),a};return f.clear=function(){o&&(clearTimeout(o),o=null)},f.flush=function(){o&&(a=n.apply(i,u),i=u=null,clearTimeout(o),o=null)},f},V=function(n,t){return new l(function(e){var r=S(function(){return e.next({src:t.src,options:t})},t.timeToDefault),o=t.points.subscribe(function(o){var u=L(n,o),i=R(n,o,u,t);e.next({point:o,angle:u,src:i,options:t}),r()});return function(){r.clear(),o.unsubscribe()}})},W=function(n,e){var r=u(n,e),o=function(t){n.src=t},i=t(n,r).then(function(){return r.onAttach(),V(n,r).subscribe(function(n){o(n.src),r.onDebug(n)})});return function(){return i.then(function(n){n.unsubscribe(),r.resetOnCancel&&o(r.src),r.onDetach()})}},X=function(n,t,e){var r=function(n){return n?t():e()},o=window.MutationObserver;if(o){var u=document.body&&document.body.contains(n);u&&r(!0);var i=new o(function(t){var e=document.body&&document.body.contains(n);!e&&u?(r(!1),u=!1):e&&!u&&(r(!0),u=!0)});return i.observe(document,{childList:!0,subtree:!0}),function(){return i.disconnect()}}return document.body&&document.body.contains(n)&&r(!0),n.addEventListener("DOMNodeInserted",function(){return r(!0)},!1),n.addEventListener("DOMNodeRemoved",function(){return r(!1)},!1),function(){}},Y=function(n){return!(!n||"object"!=typeof n)&&("object"==typeof window&&"object"==typeof window.Node?n instanceof window.Node:"number"==typeof n.nodeType&&"string"==typeof n.nodeName)};return function(n){return Y(n)?[n]:"string"==typeof n?[].slice.call(document.querySelectorAll(n)):void 0}("img[data-creepy]").forEach(function(n){n instanceof HTMLImageElement&&i(n)}),i}); |
{ | ||
"name": "creepyface", | ||
"version": "3.5.0", | ||
"version": "3.5.1", | ||
"author": "Alejandro Tardín <alejandro@tardin.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
48973
715