diff --git a/dist/interdimensional.css b/dist/interdimensional.css index b9a5408..ec3c901 100644 --- a/dist/interdimensional.css +++ b/dist/interdimensional.css @@ -1,5 +1,5 @@ /* - * Interdimensional - v0.0.1-alpha + * Interdimensional - v0.0.1 * Spatial scrolling for your web pages. * http://vodkabears.github.io/interdimensional/ * diff --git a/dist/interdimensional.js b/dist/interdimensional.js index bc4730a..d5af569 100644 --- a/dist/interdimensional.js +++ b/dist/interdimensional.js @@ -1,5 +1,5 @@ /* - * Interdimensional - v0.0.1-alpha + * Interdimensional - v0.0.1 * Spatial scrolling for your web pages. * http://vodkabears.github.io/interdimensional/ * @@ -158,66 +158,6 @@ window.addEventListener('deviceorientation', deviceOrientationHandler, false); } - /** - * Parses a string with options - * @private - * @param {String} str - * @returns {Object|String} - */ - function parseOptions(str) { - var obj = {}; - var delimiterIndex; - var option; - var prop; - var val; - var arr; - var len; - var i; - - // remove spaces around delimiters and split - arr = str.replace(/\s*:\s*/g, ':').replace(/\s*,\s*/g, ',').split(','); - - // parse a string - for (i = 0, len = arr.length; i < len; i++) { - option = arr[i]; - - // Ignore urls and a string without colon delimiters - if (option.search(/^(http|https|ftp):\/\//) !== -1 || - option.search(':') === -1) { - - break; - } - - delimiterIndex = option.indexOf(':'); - prop = option.substring(0, delimiterIndex); - val = option.substring(delimiterIndex + 1); - - // if val is an empty string, make it undefined - if (!val) { - val = undefined; - } - - // convert a string value if it is like a boolean - if (typeof val === 'string') { - val = val === 'true' || (val === 'false' ? false : val); - } - - // convert a string value if it is like a number - if (typeof val === 'string') { - val = !isNaN(val) ? +val : val; - } - - obj[prop] = val; - } - - // if nothing is parsed - if (prop == null && val == null) { - return str; - } - - return obj; - } - /** * Calculates a number of pixels to scroll * @private @@ -312,21 +252,6 @@ Interdimensional.kick(); } - /** - * Initializes declaratively - * @private - * @listens DOMContentLoaded - */ - function handleDOMContentLoadedEvent() { - var data = document.body.getAttribute('data-interdimensional'); - - if (data != null) { - Interdimensional.charge(parseOptions(data)); - } - } - - document.addEventListener('DOMContentLoaded', handleDOMContentLoadedEvent, false); - return { /** @@ -349,6 +274,10 @@ * Initializes * @public * @param {Object} options + * @param {Number} options.PPD Pixels per difference between tilts + * @param {Number} options.insensitivity Minimum difference between tilts + * @param {Boolean} options.useControl Use the control or not + * @param {HTMLElement|null} Interdimensional control, if null - the default control will be used */ charge: function(options) { if (!isCharged && !isCharging) { @@ -445,7 +374,7 @@ Interdimensional.kick(); isCharged = false; - settings.useControl && document.body.removeChild(control); + !settings.control && settings.useControl && document.body.removeChild(control); // Remove event listeners control.removeEventListener('touchstart', handleTouchStartEvent, false); diff --git a/dist/interdimensional.min.js b/dist/interdimensional.min.js index c61750a..f96756e 100644 --- a/dist/interdimensional.min.js +++ b/dist/interdimensional.min.js @@ -1,5 +1,5 @@ /* - * Interdimensional - v0.0.1-alpha + * Interdimensional - v0.0.1 * Spatial scrolling for your web pages. * http://vodkabears.github.io/interdimensional/ * @@ -7,4 +7,4 @@ * Under MIT License */ -!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Interdimensional=b()}(this,function(){"use strict";function a(a,b){if(!("DeviceOrientationEvent"in window))return b();var c=setTimeout(function(){window.removeEventListener("deviceorientation",d,!1),b()},2e3),d=function(e){clearTimeout(c),window.removeEventListener("deviceorientation",d,!1),r&&(null!=e.alpha||null!=e.beta||null!=e.gamma?a():b())};window.addEventListener("deviceorientation",d,!1)}function b(a){var b,c,d,e,f,g,h,i={};for(f=a.replace(/\s*:\s*/g,":").replace(/\s*,\s*/g,",").split(","),h=0,g=f.length;g>h&&(c=f[h],-1===c.search(/^(http|https|ftp):\/\//)&&-1!==c.search(":"));h++)b=c.indexOf(":"),d=c.substring(0,b),e=c.substring(b+1),e||(e=void 0),"string"==typeof e&&(e="true"===e||("false"===e?!1:e)),"string"==typeof e&&(e=isNaN(e)?e:+e),i[d]=e;return null==d&&null==e?a:i}function c(a,b){var c=b-a,d=Math.abs(c),e=0===c?0:c/d;return d>m.insensitivity?m.PPD*(c-e*m.insensitivity):0}function d(a){var b;a&&(a="interdimensional:"+a,window.Event&&"function"==typeof window.Event?b=new Event(a):(b=document.createEvent("Event"),b.initEvent(a,!0,!0)),document.dispatchEvent(b))}function e(){window.scrollBy(t,u),s&&o(e)}function f(){Interdimensional.toggle()}function g(a){s&&null!=j&&null!=k&&null!=l?window.innerHeight>window.innerWidth?(t=c(l,a.gamma),u=c(k,Math.abs(a.gamma)>90&&Math.abs(l)<90?180-a.beta:a.beta)):(t=c(j,a.alpha),u=c(Math.abs(l),Math.abs(a.gamma))):(j=a.alpha,k=a.beta,l=a.gamma)}function h(){Interdimensional.kick()}function i(){var a=document.body.getAttribute("data-interdimensional");null!=a&&Interdimensional.charge(b(a))}var j,k,l,m,n,o=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,1e3/60)},p={PPD:.8,insensitivity:5,useControl:!0,control:null},q=!1,r=!1,s=!1,t=0,u=0;return document.addEventListener("DOMContentLoaded",i,!1),{isCharged:function(){return q},isOn:function(){return s},charge:function(b){q||r||(r=!0,a(function(){q=!0,r=!1,m={};for(var a in p)p.hasOwnProperty(a)&&(m[a]=b&&"undefined"!=typeof b[a]?b[a]:p[a]);m.control?n=m.control:(n=document.createElement("div"),n.className="interdimensional-control"),m.useControl&&document.body.appendChild(n),n.addEventListener("touchstart",f,!1),window.addEventListener("deviceorientation",g,!1),window.addEventListener("orientationchange",h,!1),d("charge")},function(){r=!1,d("fail")}))},jump:function(){q&&(s=!0,n.classList.add("interdimensional-control-is-active"),e(),d("jump"))},kick:function(){q&&(s=!1,t=0,u=0,n.classList.remove("interdimensional-control-is-active"),d("kick"))},toggle:function(){s?Interdimensional.kick():Interdimensional.jump()},discharge:function(){q&&(Interdimensional.kick(),q=!1,m.useControl&&document.body.removeChild(n),n.removeEventListener("touchstart",f,!1),window.removeEventListener("deviceorientation",g,!1),window.removeEventListener("orientationchange",h,!1),d("discharge"))}}}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define(b):"object"==typeof exports?module.exports=b():a.Interdimensional=b()}(this,function(){"use strict";function a(a,b){if(!("DeviceOrientationEvent"in window))return b();var c=setTimeout(function(){window.removeEventListener("deviceorientation",d,!1),b()},2e3),d=function(e){clearTimeout(c),window.removeEventListener("deviceorientation",d,!1),p&&(null!=e.alpha||null!=e.beta||null!=e.gamma?a():b())};window.addEventListener("deviceorientation",d,!1)}function b(a,b){var c=b-a,d=Math.abs(c),e=0===c?0:c/d;return d>k.insensitivity?k.PPD*(c-e*k.insensitivity):0}function c(a){var b;a&&(a="interdimensional:"+a,window.Event&&"function"==typeof window.Event?b=new Event(a):(b=document.createEvent("Event"),b.initEvent(a,!0,!0)),document.dispatchEvent(b))}function d(){window.scrollBy(r,s),q&&m(d)}function e(){Interdimensional.toggle()}function f(a){q&&null!=h&&null!=i&&null!=j?window.innerHeight>window.innerWidth?(r=b(j,a.gamma),s=b(i,Math.abs(a.gamma)>90&&Math.abs(j)<90?180-a.beta:a.beta)):(r=b(h,a.alpha),s=b(Math.abs(j),Math.abs(a.gamma))):(h=a.alpha,i=a.beta,j=a.gamma)}function g(){Interdimensional.kick()}var h,i,j,k,l,m=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,1e3/60)},n={PPD:.8,insensitivity:5,useControl:!0,control:null},o=!1,p=!1,q=!1,r=0,s=0;return{isCharged:function(){return o},isOn:function(){return q},charge:function(b){o||p||(p=!0,a(function(){o=!0,p=!1,k={};for(var a in n)n.hasOwnProperty(a)&&(k[a]=b&&"undefined"!=typeof b[a]?b[a]:n[a]);k.control?l=k.control:(l=document.createElement("div"),l.className="interdimensional-control"),k.useControl&&document.body.appendChild(l),l.addEventListener("touchstart",e,!1),window.addEventListener("deviceorientation",f,!1),window.addEventListener("orientationchange",g,!1),c("charge")},function(){p=!1,c("fail")}))},jump:function(){o&&(q=!0,l.classList.add("interdimensional-control-is-active"),d(),c("jump"))},kick:function(){o&&(q=!1,r=0,s=0,l.classList.remove("interdimensional-control-is-active"),c("kick"))},toggle:function(){q?Interdimensional.kick():Interdimensional.jump()},discharge:function(){o&&(Interdimensional.kick(),o=!1,!k.control&&k.useControl&&document.body.removeChild(l),l.removeEventListener("touchstart",e,!1),window.removeEventListener("deviceorientation",f,!1),window.removeEventListener("orientationchange",g,!1),c("discharge"))}}}); \ No newline at end of file