var React = require('react');

/*
	NOTES

	1. Stop content jumping around when overflow is hidden on the body.
	2. Mobile Safari ignores { overflow: hidden } declaration on the body.
*/

var ScrollLock = React.createClass({
	componentWillMount: function () {
		if (!canUseDom) return;

		const scrollbarWidth = window.innerWidth - document.body.clientWidth; // 1.
		const target = document.body;

		target.addEventListener('touchmove', preventTouchMove, false); // 2.

		target.style.paddingRight = scrollbarWidth + 'px';
		target.style.overflowY = 'hidden';
	},
	componentWillUnmount: function () {
		if (!canUseDom) return;

		const target = document.body;

		target.removeEventListener('touchmove', preventTouchMove, false);

		target.style.paddingRight = '';
		target.style.overflowY = '';
	},
	render: function () {
		return null;
	}
});

function preventTouchMove (e) {
	e.preventDefault();
};

function canUseDom () {
	return !!(
		typeof window !== 'undefined'
		&& window.document
		&& window.document.createElement
	);
};

module.exports = ScrollLock;

@@ -176,16 +176,53 @@
 e body.%0A
+%093. Allow scroll on provided target.%0A
 */%0A%0Avar 
@@ -254,16 +254,74 @@
 Class(%7B%0A
+%09propTypes: %7B%0A%09%09scrollTarget: React.PropTypes.object,%0A%09%7D,%0A
 %09compone
@@ -322,20 +322,19 @@
 omponent
-Will
+Did
 Mount: f
@@ -375,21 +375,65 @@
 urn;%0A%0A%09%09
-const
+var scrollTarget = this.props.scrollTarget;%0A%09%09var
  scrollb
@@ -497,21 +497,19 @@
 // 1.%0A%09%09
-const
+var
  target 
@@ -539,395 +539,799 @@
 get.
-addEventListener('touchmove', preventTouchMove, false); // 2.%0A%0A%09%09target.style.paddingRight = scrollbarWidth + 'px';%0A%09%09target.style.overflowY = 'hidden';%0A%09%7D,%0A%09componentWillUnmount: function () %7B%0A%09%09if (!canUseDom) return;%0A%0A%09%09const target = document.body;%0A%0A%09%09target.removeEventListener('touchmove', preventTouchMove, false);%0A%0A%09%09target.style.paddingRight = ''
+style.paddingRight = scrollbarWidth + 'px';%0A%09%09target.style.overflowY = 'hidden';%0A%0A%09%09target.addEventListener('touchmove', preventTouchMove, false); // 2.%0A%0A%09%09if (scrollTarget) %7B%0A%09%09%09scrollTarget.addEventListener('touchstart', preventInertiaScroll, false); // 3.%0A%09%09%09scrollTarget.addEventListener('touchmove', allowTouchMove, false); // 3.%0A%09%09%7D%0A%09%7D,%0A%09componentWillUnmount: function () %7B%0A%09%09if (!canUseDom) return;%0A%0A%09%09var scrollTarget = this.props.scrollTarget;%0A%09%09var target = document.body;%0A%0A%09%09target.style.paddingRight = '';%0A%09%09target.style.overflowY = '';%0A%0A%09%09target.removeEventListener('touchmove', preventTouchMove, false);%0A%0A%09%09if (scrollTarget) %7B%0A%09%09%09scrollTarget.addEventListener('touchstart', preventInertiaScroll, false)
 ;%0A%09%09
+%09
-target.style.overflowY = '';
+scrollTarget.addEventListener('touchmove', allowTouchMove, false);%0A%09%09%7D
 %0A%09%7D,
@@ -1434,16 +1434,338 @@
 ();%0A%7D;%0A%0A
+function allowTouchMove (e) %7B%0A%09e.stopPropagation();%0A%7D;%0A%0Afunction preventInertiaScroll () %7B%0A%09var top = this.scrollTop;%0A%09var totalScroll = this.scrollHeight;%0A%09var currentScroll = top + this.offsetHeight;%0A%0A%09if (top === 0) %7B%0A%09%09this.scrollTop = 1;%0A%09%7D else if (currentScroll === totalScroll) %7B%0A%09%09this.scrollTop = top - 1;%0A%09%7D%0A%7D%0A%0A
 function

allow scroll on provided target