mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-28 17:02:24 -05:00
Fix handling of native classes in tests again
Reverting breaking change in 10bdafa826
This commit is contained in:
parent
5cb93ec46e
commit
1e2bbbdef2
2 changed files with 15 additions and 7 deletions
|
@ -36,6 +36,12 @@ if (typeof window === 'object') {
|
|||
// the code the 2nd time around.
|
||||
load(root + 'src/load.js');
|
||||
} else {
|
||||
// Some native javascript classes have name collisions with Paper.js
|
||||
// classes. Store them to be able to use them later in tests.
|
||||
this.nativeClasses = {
|
||||
Event: window.Event,
|
||||
MouseEvent: window.MouseEvent
|
||||
};
|
||||
include('options.js');
|
||||
// Load constants.js, required by the on-the-fly preprocessing:
|
||||
include('constants.js');
|
||||
|
|
|
@ -35,10 +35,10 @@ if (isNode) {
|
|||
}
|
||||
|
||||
// Some native javascript classes have name collisions with Paper.js classes.
|
||||
// Store them before `paper.install()` to be able to use them later in tests.
|
||||
var nativeClasses = {
|
||||
Event: Event,
|
||||
MouseEvent: MouseEvent
|
||||
// If they have not already been stored in `src/load.js`, do it now:
|
||||
var nativeClasses = this.nativeClasses || {
|
||||
Event: this.Event || {},
|
||||
MouseEvent: this.MouseEvent || {}
|
||||
};
|
||||
|
||||
// The unit-tests expect the paper classes to be global.
|
||||
|
@ -678,10 +678,12 @@ var triggerMouseEvent = function(type, point, target) {
|
|||
target = target || (type === 'mousedown' ? view.element : document);
|
||||
// If `gulp load` was run, there is a name collision between paper Event /
|
||||
// MouseEvent and native javascript classes. In this case, we need to use
|
||||
// native classes stored in global NativeClasses object instead.
|
||||
// native classes stored in the nativeClasses object instead.
|
||||
// MouseEvent class does not exist in PhantomJS, so in that case, we need to
|
||||
// use a polyfill method.
|
||||
var MouseEvent = nativeClasses.MouseEvent || MouseEventPolyfill;
|
||||
// use a polyfill method, see: https://stackoverflow.com/questions/42929639
|
||||
var MouseEvent = typeof nativeClasses.MouseEvent === 'function'
|
||||
? nativeClasses.MouseEvent
|
||||
: MouseEventPolyfill;
|
||||
var event = new MouseEvent(type, {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
|
|
Loading…
Reference in a new issue