Skip to content

Commit 8615ade

Browse files
fabiomcostavjeux
authored andcommitted
adding warning about the lack of support for onScroll on IE8
Adding `console.warn` about the lack of support for `onScroll` event on IE8 Related to this issue on github #631
1 parent dbae31d commit 8615ade

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/event/CallbackRegistry.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
"use strict";
2121

22+
var isEventSupported = require('isEventSupported');
23+
2224
var listenerBank = {};
2325

2426
/**
@@ -40,6 +42,14 @@ var CallbackRegistry = {
4042
* @param {?function} listener The callback to store.
4143
*/
4244
putListener: function(id, registrationName, listener) {
45+
if (__DEV__) {
46+
// IE8 has no API for event capturing and the `onScroll` event doesn't
47+
// bubble.
48+
if (registrationName === 'onScroll' &&
49+
!isEventSupported('scroll', true)) {
50+
console.warn('This browser doesn\'t support the `onScroll` event');
51+
}
52+
}
4353
var bankForRegistrationName =
4454
listenerBank[registrationName] || (listenerBank[registrationName] = {});
4555
bankForRegistrationName[id] = listener;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* Copyright 2013 Facebook, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* @emails react-core
17+
*/
18+
19+
"use strict";
20+
21+
require('mock-modules')
22+
.dontMock('CallbackRegistry')
23+
.mock('isEventSupported');
24+
25+
describe('CallbackRegistry', function() {
26+
var CallbackRegistry;
27+
var isEventSupported;
28+
29+
beforeEach(function() {
30+
require('mock-modules').dumpCache();
31+
CallbackRegistry = require('CallbackRegistry');
32+
isEventSupported = require('isEventSupported');
33+
isEventSupported.mockReturnValue(false);
34+
});
35+
36+
it('should warn about the `onScroll` issue on IE8', function() {
37+
spyOn(console, 'warn');
38+
CallbackRegistry.putListener(1, 'onScroll', function(){});
39+
expect(console.warn.callCount).toBe(1);
40+
expect(console.warn.mostRecentCall.args[0]).toBe(
41+
'This browser doesn\'t support the `onScroll` event'
42+
);
43+
});
44+
45+
});

0 commit comments

Comments
 (0)