-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 增加"preventDefaultExclude"参数, 用来排除不需要阻止默认事件的元素
- Loading branch information
Showing
7 changed files
with
87 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// import TouchSimulator from './utils/TouchSimulator'; | ||
// import sleep from './utils/sleep'; | ||
import AnyTouch from '../src/main' | ||
const el = document.createElement('div'); | ||
// const childEl = document.createElement('input'); | ||
// childEl.type = 'checkbox'; | ||
// // input | ||
// el.appendChild(childEl); | ||
|
||
// 暂时没想到如何触发元素的默认行为, 所以没法完美还原实际情况 | ||
test('preventDefaultExclude通过函数指定排除', async (done) => { | ||
const at = new AnyTouch(el, { | ||
preventDefaultExclude(ev) { | ||
return 'div' === (<any>ev).target.tagName; | ||
} | ||
}); | ||
const canPreventDefault = at.canPreventDefault((<any>{ target: { tagName: 'div' } })); | ||
expect(canPreventDefault).toBeTruthy(); | ||
done(); | ||
}); | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
const ObjectToString = Object.prototype.toString; | ||
|
||
export function isRegExp(input: any): input is RegExp { | ||
return '[object RegExp]' === ObjectToString.call(input); | ||
} | ||
|
||
export function isFunction(input: any): input is Function { | ||
return '[object Function]' === ObjectToString.call(input); | ||
} |