mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Simplify preserving of native classes in tests
This commit is contained in:
parent
c30767ed2e
commit
10bdafa826
2 changed files with 8 additions and 23 deletions
|
@ -36,13 +36,6 @@ if (typeof window === 'object') {
|
||||||
// the code the 2nd time around.
|
// the code the 2nd time around.
|
||||||
load(root + 'src/load.js');
|
load(root + 'src/load.js');
|
||||||
} else {
|
} else {
|
||||||
// Some native javascript classes have name collisions with Paper.js
|
|
||||||
// classes. Store them to be able to use them later in tests.
|
|
||||||
NativeClasses = {
|
|
||||||
Event: Event,
|
|
||||||
MouseEvent: MouseEvent
|
|
||||||
};
|
|
||||||
|
|
||||||
include('options.js');
|
include('options.js');
|
||||||
// Load constants.js, required by the on-the-fly preprocessing:
|
// Load constants.js, required by the on-the-fly preprocessing:
|
||||||
include('constants.js');
|
include('constants.js');
|
||||||
|
|
|
@ -35,14 +35,11 @@ if (isNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some native javascript classes have name collisions with Paper.js classes.
|
// Some native javascript classes have name collisions with Paper.js classes.
|
||||||
// If they have not already been stored in src/load.js, we dot it now.
|
// Store them before `paper.install()` to be able to use them later in tests.
|
||||||
if (!isNode && typeof NativeClasses === 'undefined')
|
var nativeClasses = {
|
||||||
{
|
|
||||||
NativeClasses = {
|
|
||||||
Event: Event,
|
Event: Event,
|
||||||
MouseEvent: MouseEvent
|
MouseEvent: MouseEvent
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// The unit-tests expect the paper classes to be global.
|
// The unit-tests expect the paper classes to be global.
|
||||||
paper.install(scope);
|
paper.install(scope);
|
||||||
|
@ -662,8 +659,8 @@ var MouseEventPolyfill = function(type, params) {
|
||||||
);
|
);
|
||||||
return mouseEvent;
|
return mouseEvent;
|
||||||
};
|
};
|
||||||
MouseEventPolyfill.prototype = typeof NativeClasses !== 'undefined'
|
|
||||||
&& NativeClasses.Event.prototype || Event.prototype;
|
MouseEventPolyfill.prototype = nativeClasses.Event.prototype;
|
||||||
|
|
||||||
var triggerMouseEvent = function(type, point, target) {
|
var triggerMouseEvent = function(type, point, target) {
|
||||||
// Depending on event type, events have to be triggered on different
|
// Depending on event type, events have to be triggered on different
|
||||||
|
@ -676,14 +673,9 @@ var triggerMouseEvent = function(type, point, target) {
|
||||||
// If `gulp load` was run, there is a name collision between paper Event /
|
// 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
|
// MouseEvent and native javascript classes. In this case, we need to use
|
||||||
// native classes stored in global NativeClasses object instead.
|
// native classes stored in global NativeClasses object instead.
|
||||||
var constructor = typeof NativeClasses !== 'undefined'
|
|
||||||
&& NativeClasses.MouseEvent || MouseEvent;
|
|
||||||
|
|
||||||
// MouseEvent class does not exist in PhantomJS, so in that case, we need to
|
// MouseEvent class does not exist in PhantomJS, so in that case, we need to
|
||||||
// use a polyfill method.
|
// use a polyfill method.
|
||||||
if (typeof constructor !== 'function') {
|
var constructor = nativeClasses.MouseEvent || MouseEventPolyfill;
|
||||||
constructor = MouseEventPolyfill;
|
|
||||||
}
|
|
||||||
|
|
||||||
var event = new constructor(type, {
|
var event = new constructor(type, {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
|
|
Loading…
Reference in a new issue