From fa39819ed6cb85f48c0b4a35bec62f001caeaef1 Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Wed, 10 Jun 2015 18:37:07 -0300 Subject: [PATCH 1/6] Added support for options.skrollrBody --- src/skrollr.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/skrollr.js b/src/skrollr.js index 89b98e9a..10c6a116 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -279,7 +279,13 @@ })()); if(_isMobile) { - _skrollrBody = document.getElementById(options.skrollrBody || DEFAULT_SKROLLRBODY); + + // Allow to set the container object directly from init options. + if (typeof options.skrollrBody == "object") { + _skrollrBody = options.skrollrBody; + } else { + _skrollrBody = document.getElementById(options.skrollrBody || DEFAULT_SKROLLRBODY); + } //Detect 3d transform if there's a skrollr-body (only needed for #skrollr-body). if(_skrollrBody) { From 30ff376c43b989c2c2cc7feebc246736c466b472 Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Fri, 12 Jun 2015 17:24:45 -0300 Subject: [PATCH 2/6] Fix mobile scrolling after clicking objects that may affect page height. --- src/skrollr.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/skrollr.js b/src/skrollr.js index 10c6a116..52e18b04 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -783,6 +783,10 @@ initialElement.dispatchEvent(clickEvent); } + // Needed to recalculate scrolling for objects that might have changed + // the size of the page after clicking them. + _instance.refresh(); + return; } From 2c69d245d1e7f3bab1ca3d41685ed4aaa396d80e Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Sat, 13 Jun 2015 12:07:47 -0300 Subject: [PATCH 3/6] Added an option to set compatibility with jQuery Mobile. --- src/skrollr.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/skrollr.js b/src/skrollr.js index 52e18b04..1bb0da43 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -59,6 +59,9 @@ var ANCHOR_CENTER = 'center'; var ANCHOR_BOTTOM = 'bottom'; + // Make it compatible with jQuery Mobile + var JQM_COMPATIBLE = false; + //The property which will be added to the DOM element to hold the ID of the skrollable. var SKROLLABLE_ID_DOM_PROPERTY = '___skrollable_id'; @@ -243,6 +246,8 @@ } } + _jqmCompatible = options.jqmCompatible || JQM_COMPATIBLE; + _edgeStrategy = options.edgeStrategy || 'set'; _listeners = { @@ -677,6 +682,7 @@ _skrollrBody = undefined; _listeners = undefined; _forceHeight = undefined; + _jqmCompatible = false; _maxKeyFrame = 0; _scale = 1; _constants = undefined; @@ -777,15 +783,23 @@ if(!rxTouchIgnoreTags.test(initialElement.tagName)) { initialElement.focus(); - //It was a tap, click the element. - var clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent('click', true, true, e.view, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, 0, null); - initialElement.dispatchEvent(clickEvent); - } + // It was a tap, click the element. + // Note: If jqmCompatible is TRUE, a little delay is added + // to properly render for some JQM elements. + setTimeout(function () { - // Needed to recalculate scrolling for objects that might have changed - // the size of the page after clicking them. - _instance.refresh(); + var clickEvent = document.createEvent('MouseEvents'); + + clickEvent.initMouseEvent('click', true, true, e.view, 1, touch.screenX, + touch.screenY, touch.clientX, touch.clientY, e.ctrlKey, e.altKey, + e.shiftKey, e.metaKey, 0, null); + initialElement.dispatchEvent(clickEvent); + + // Needed to recalculate scrolling for objects that might have changed + // the size of the page after clicking them. + _instance.refresh(); + }, (_jqmCompatible ? 50 : 0)); + } return; } @@ -1718,6 +1732,7 @@ var _listeners; var _forceHeight; + var _jqmCompatible; var _maxKeyFrame = 0; var _scale = 1; From f448608cde469ca8bcec449afb5b4818a5537f2a Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Sat, 13 Jun 2015 12:09:09 -0300 Subject: [PATCH 4/6] Sorry, replaced tabs with spaces in previous commit. --- src/skrollr.js | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/skrollr.js b/src/skrollr.js index 1bb0da43..6baf9d0d 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -59,8 +59,8 @@ var ANCHOR_CENTER = 'center'; var ANCHOR_BOTTOM = 'bottom'; - // Make it compatible with jQuery Mobile - var JQM_COMPATIBLE = false; + // Make it compatible with jQuery Mobile + var JQM_COMPATIBLE = false; //The property which will be added to the DOM element to hold the ID of the skrollable. var SKROLLABLE_ID_DOM_PROPERTY = '___skrollable_id'; @@ -246,7 +246,7 @@ } } - _jqmCompatible = options.jqmCompatible || JQM_COMPATIBLE; + _jqmCompatible = options.jqmCompatible || JQM_COMPATIBLE; _edgeStrategy = options.edgeStrategy || 'set'; @@ -682,7 +682,7 @@ _skrollrBody = undefined; _listeners = undefined; _forceHeight = undefined; - _jqmCompatible = false; + _jqmCompatible = false; _maxKeyFrame = 0; _scale = 1; _constants = undefined; @@ -784,21 +784,21 @@ initialElement.focus(); // It was a tap, click the element. - // Note: If jqmCompatible is TRUE, a little delay is added - // to properly render for some JQM elements. - setTimeout(function () { + // Note: If jqmCompatible is TRUE, a little delay is added + // to properly render for some JQM elements. + setTimeout(function () { - var clickEvent = document.createEvent('MouseEvents'); + var clickEvent = document.createEvent('MouseEvents'); - clickEvent.initMouseEvent('click', true, true, e.view, 1, touch.screenX, - touch.screenY, touch.clientX, touch.clientY, e.ctrlKey, e.altKey, - e.shiftKey, e.metaKey, 0, null); - initialElement.dispatchEvent(clickEvent); + clickEvent.initMouseEvent('click', true, true, e.view, 1, touch.screenX, + touch.screenY, touch.clientX, touch.clientY, e.ctrlKey, e.altKey, + e.shiftKey, e.metaKey, 0, null); + initialElement.dispatchEvent(clickEvent); - // Needed to recalculate scrolling for objects that might have changed - // the size of the page after clicking them. - _instance.refresh(); - }, (_jqmCompatible ? 50 : 0)); + // Needed to recalculate scrolling for objects that might have changed + // the size of the page after clicking them. + _instance.refresh(); + }, (_jqmCompatible ? 50 : 0)); } return; @@ -1732,7 +1732,7 @@ var _listeners; var _forceHeight; - var _jqmCompatible; + var _jqmCompatible; var _maxKeyFrame = 0; var _scale = 1; From a4e19c1088ff79433dcfc3a9469e1a1a6fbf6bae Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Sun, 14 Jun 2015 01:41:28 -0300 Subject: [PATCH 5/6] Fix for js error on double tap. --- src/skrollr.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/skrollr.js b/src/skrollr.js index 6baf9d0d..776c2e5b 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -780,13 +780,17 @@ //Check if it was more like a tap (moved less than 7px). if(distance2 < 49) { - if(!rxTouchIgnoreTags.test(initialElement.tagName)) { + + // initialElement is undefined for double tap + if(initialElement && !rxTouchIgnoreTags.test(initialElement.tagName)) { initialElement.focus(); // It was a tap, click the element. // Note: If jqmCompatible is TRUE, a little delay is added // to properly render for some JQM elements. - setTimeout(function () { + // Note 2: Need to pass initialElement to setTimeout() because it won't be + // in context any longer after being executed + setTimeout(function (initialElement) { var clickEvent = document.createEvent('MouseEvents'); @@ -798,7 +802,9 @@ // Needed to recalculate scrolling for objects that might have changed // the size of the page after clicking them. _instance.refresh(); - }, (_jqmCompatible ? 50 : 0)); + }, + (_jqmCompatible ? 50 : 0), + initialElement); } return; From f86c89487b2ab2683db9583799752fd3e333a0dc Mon Sep 17 00:00:00 2001 From: Luciano Fantuzzi Date: Sun, 14 Jun 2015 19:17:07 -0300 Subject: [PATCH 6/6] Little fix for undefined _instance in some circumstances. --- src/skrollr.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/skrollr.js b/src/skrollr.js index 776c2e5b..54d01878 100644 --- a/src/skrollr.js +++ b/src/skrollr.js @@ -801,7 +801,9 @@ // Needed to recalculate scrolling for objects that might have changed // the size of the page after clicking them. - _instance.refresh(); + if (_instance) { + _instance.refresh(); + } }, (_jqmCompatible ? 50 : 0), initialElement);