Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
perf: bind touch start event only when picker is shown
Browse files Browse the repository at this point in the history
  • Loading branch information
fengyuanchen committed Jan 19, 2019
1 parent b1342f8 commit 97dbf68
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/js/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
EVENT_KEYUP,
EVENT_PICK,
EVENT_SHOW,
EVENT_TOUCH_START,
IS_TOUCH_DEVICE,
LANGUAGES,
NAMESPACE,
VIEWS,
Expand Down Expand Up @@ -193,10 +191,6 @@ class Datepicker {
} else {
$this.on(EVENT_CLICK, $.proxy(this.show, this));
}

if (IS_TOUCH_DEVICE) {
$(document).on(EVENT_TOUCH_START, $.proxy(this.touchstart, this));
}
}
}

Expand Down Expand Up @@ -227,10 +221,6 @@ class Datepicker {
} else {
$this.off(EVENT_CLICK, this.show);
}

if (IS_TOUCH_DEVICE) {
$(document).off(EVENT_TOUCH_START, this.touchstart);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/js/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
EVENT_RESIZE,
EVENT_SCROLL,
EVENT_SHOW,
EVENT_TOUCH_START,
IS_TOUCH_DEVICE,
NAMESPACE,
} from './constants';
import {
Expand Down Expand Up @@ -45,6 +47,11 @@ export default {
$(window).on(EVENT_RESIZE, (this.onResize = proxy(this.place, this)));
$(document).on(EVENT_CLICK, (this.onGlobalClick = proxy(this.globalClick, this)));
$(document).on(EVENT_KEYUP, (this.onGlobalKeyup = proxy(this.globalKeyup, this)));

if (IS_TOUCH_DEVICE) {
$(document).on(EVENT_TOUCH_START, (this.onTouchStart = proxy(this.touchstart, this)));
}

this.place();
}
},
Expand All @@ -67,6 +74,10 @@ export default {
$(window).off(EVENT_RESIZE, this.onResize);
$(document).off(EVENT_CLICK, this.onGlobalClick);
$(document).off(EVENT_KEYUP, this.onGlobalKeyup);

if (IS_TOUCH_DEVICE) {
$(document).off(EVENT_TOUCH_START, this.onTouchStart);
}
}
},

Expand Down

0 comments on commit 97dbf68

Please sign in to comment.