From 75e849033139041e2279bcc7d837f40c7f154539 Mon Sep 17 00:00:00 2001 From: pcolleoni Date: Mon, 17 Feb 2014 15:47:10 +0900 Subject: [PATCH 1/5] Keep the touch listener from being added every time the disable scrolling method is called --- index.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) mode change 100644 => 100755 index.js diff --git a/index.js b/index.js old mode 100644 new mode 100755 index b31e887..f0ddf0b --- a/index.js +++ b/index.js @@ -44,23 +44,44 @@ WuiView.prototype.close = function () { * disableScrolling */ WuiView.prototype.disableScrolling = function () { - this.allowDomEvents(); - this.scrollingDisabled = true; - var that = this; + if (this.scrollingDisabled === undefined) { + + var that = this; + this.allowDomEvents(); + this.scrollingDisabled = true; + + this.on('dom.touchmove', function (e) { + // note: this does not work on a desktop - this.on('dom.touchmove', function (e) { - // note: this does not work on a desktop + if (that.scrollingDisabled) { + e.preventDefault(); + } + }); + } - if (that.scrollingDisabled) { - e.preventDefault(); - } - }); + this.scrollingDisabled = true; }; /** * enableScrolling */ WuiView.prototype.enableScrolling = function () { + + if (this.scrollingDisabled === undefined) { + + var that = this; + this.allowDomEvents(); + this.scrollingDisabled = false; + + this.on('dom.touchmove', function (e) { + // note: this does not work on a desktop + + if (that.scrollingDisabled) { + e.preventDefault(); + } + }); + } + this.scrollingDisabled = false; }; \ No newline at end of file From c965a738274e11386d0cecc57d7bfe320969f458 Mon Sep 17 00:00:00 2001 From: pcolleoni Date: Mon, 17 Feb 2014 15:55:58 +0900 Subject: [PATCH 2/5] Refactored code --- index.js | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index f0ddf0b..afbff46 100755 --- a/index.js +++ b/index.js @@ -41,25 +41,29 @@ WuiView.prototype.close = function () { }; /** - * disableScrolling + * add a touch listener to the view */ -WuiView.prototype.disableScrolling = function () { +WuiView.prototype._addScrollingListener = function () { if (this.scrollingDisabled === undefined) { - var that = this; this.allowDomEvents(); - this.scrollingDisabled = true; this.on('dom.touchmove', function (e) { - // note: this does not work on a desktop + // TODO: this does not work on a desktop if (that.scrollingDisabled) { e.preventDefault(); } }); } +}; +/** + * disableScrolling + */ +WuiView.prototype.disableScrolling = function () { + this._addScrollingListener(); this.scrollingDisabled = true; }; @@ -67,21 +71,6 @@ WuiView.prototype.disableScrolling = function () { * enableScrolling */ WuiView.prototype.enableScrolling = function () { - - if (this.scrollingDisabled === undefined) { - - var that = this; - this.allowDomEvents(); - this.scrollingDisabled = false; - - this.on('dom.touchmove', function (e) { - // note: this does not work on a desktop - - if (that.scrollingDisabled) { - e.preventDefault(); - } - }); - } - + this._addScrollingListener(); this.scrollingDisabled = false; }; \ No newline at end of file From 63b61bbe86d848462da34ffd1ee017e9b99a6953 Mon Sep 17 00:00:00 2001 From: pcolleoni Date: Mon, 17 Feb 2014 16:13:15 +0900 Subject: [PATCH 3/5] Refactored --- index.js | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index afbff46..a47e1ef 100755 --- a/index.js +++ b/index.js @@ -10,6 +10,7 @@ function WuiView() { WuiDom.call(this); this.assign('div', { className: 'WuiView' }); this.hideMethod(); + this._hasTouchListener = false; } inherit(WuiView, WuiDom); @@ -41,11 +42,11 @@ WuiView.prototype.close = function () { }; /** - * add a touch listener to the view + * disableScrolling */ -WuiView.prototype._addScrollingListener = function () { - - if (this.scrollingDisabled === undefined) { +WuiView.prototype.disableScrolling = function () { + if (!this._hasTouchListener) { + this._hasTouchListener = true; var that = this; this.allowDomEvents(); @@ -57,13 +58,6 @@ WuiView.prototype._addScrollingListener = function () { } }); } -}; - -/** - * disableScrolling - */ -WuiView.prototype.disableScrolling = function () { - this._addScrollingListener(); this.scrollingDisabled = true; }; @@ -71,6 +65,5 @@ WuiView.prototype.disableScrolling = function () { * enableScrolling */ WuiView.prototype.enableScrolling = function () { - this._addScrollingListener(); this.scrollingDisabled = false; }; \ No newline at end of file From 5fc2beee6be7e04fb7e8269621387de108551815 Mon Sep 17 00:00:00 2001 From: pcolleoni Date: Tue, 18 Feb 2014 11:46:35 +0900 Subject: [PATCH 4/5] Last refactoring --- index.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index a47e1ef..833545b 100755 --- a/index.js +++ b/index.js @@ -10,7 +10,6 @@ function WuiView() { WuiDom.call(this); this.assign('div', { className: 'WuiView' }); this.hideMethod(); - this._hasTouchListener = false; } inherit(WuiView, WuiDom); @@ -42,28 +41,34 @@ WuiView.prototype.close = function () { }; /** - * disableScrolling + * set scrolling listener */ -WuiView.prototype.disableScrolling = function () { - if (!this._hasTouchListener) { - this._hasTouchListener = true; - var that = this; - this.allowDomEvents(); +function setScrolling(view, value) { + if (view.scrollingDisabled === undefined) { + view.allowDomEvents(); - this.on('dom.touchmove', function (e) { + view.on('dom.touchmove', function (e) { // TODO: this does not work on a desktop - if (that.scrollingDisabled) { + if (view.scrollingDisabled) { e.preventDefault(); } }); } - this.scrollingDisabled = true; + + view.scrollingDisabled = value; +} + +/** + * disableScrolling + */ +WuiView.prototype.disableScrolling = function () { + setScrolling(this, false); }; /** * enableScrolling */ WuiView.prototype.enableScrolling = function () { - this.scrollingDisabled = false; + setScrolling(this, true); }; \ No newline at end of file From 8adfe525c9d85dfd7aa875ca54a5d51f9bded103 Mon Sep 17 00:00:00 2001 From: pcolleoni Date: Tue, 18 Feb 2014 12:54:16 +0900 Subject: [PATCH 5/5] Small fix --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 833545b..299a925 100755 --- a/index.js +++ b/index.js @@ -63,12 +63,12 @@ function setScrolling(view, value) { * disableScrolling */ WuiView.prototype.disableScrolling = function () { - setScrolling(this, false); + setScrolling(this, true); }; /** * enableScrolling */ WuiView.prototype.enableScrolling = function () { - setScrolling(this, true); + setScrolling(this, false); }; \ No newline at end of file