-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more tests and a few more EventTarget interface features
- Loading branch information
1 parent
c6c7275
commit c844665
Showing
9 changed files
with
478 additions
and
27 deletions.
There are no files selected for viewing
15 changes: 0 additions & 15 deletions
15
polyfills/MediaQueryList/prototype/EventTarget/polyfill.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
14 changes: 11 additions & 3 deletions
14
...eryList/prototype/EventTarget/config.toml → ...st/prototype/addEventListener/config.toml
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
2 changes: 1 addition & 1 deletion
2
...QueryList/prototype/EventTarget/detect.js → ...List/prototype/addEventListener/detect.js
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 |
---|---|---|
@@ -1 +1 @@ | ||
'MediaQueryList' in self && 'addEventListener' in self.MediaQueryList | ||
'MediaQueryList' in self && 'addEventListener' in self.MediaQueryList.prototype |
88 changes: 88 additions & 0 deletions
88
polyfills/MediaQueryList/prototype/addEventListener/polyfill.js
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,88 @@ | ||
(function(global) { | ||
"use strict"; | ||
|
||
var _addListener = global.MediaQueryList.prototype.addListener; | ||
var _removeListener = global.MediaQueryList.prototype.removeListener; | ||
|
||
global.MediaQueryList.prototype.addListener = function addListener(listener) { | ||
var handler = listener; | ||
if (handler.handleEvent) { | ||
handler = handler.handleEvent; | ||
} | ||
|
||
_addListener.call(this, handler); | ||
}; | ||
|
||
global.MediaQueryList.prototype.removeListener = function removeListener(listener) { | ||
var handler = listener; | ||
if (handler.handleEvent) { | ||
handler = handler.handleEvent; | ||
} | ||
|
||
_removeListener.call(this, handler); | ||
}; | ||
|
||
global.MediaQueryList.prototype.addEventListener = function addEventListener(type, listener) { | ||
if (type === 'change') { | ||
this.addListener(listener); | ||
} | ||
|
||
if (arguments[2] && arguments[2].once) { | ||
var _this = this; | ||
var remover = function () { | ||
_this.removeListener(remover); | ||
_this.removeListener(listener); | ||
} | ||
this.addListener(remover); | ||
} | ||
}; | ||
|
||
global.MediaQueryList.prototype.removeEventListener = function removeEventListener(type, listener) { | ||
if (type === 'change') { | ||
this.removeListener(listener); | ||
} | ||
}; | ||
|
||
// Best effort. | ||
// Some browsers don't support setters. | ||
if ((function () { | ||
// supports setters (not IE8) | ||
try { | ||
var a = {}; | ||
global.Object.defineProperty(a, 't', { | ||
configurable: true, | ||
enumerable: false, | ||
get: function () { return this._v; }, | ||
set: function (v) { this._v = v + v; } | ||
}); | ||
a.t = 1; | ||
return (a.t === 2); | ||
} catch (e) { | ||
return false; | ||
} | ||
}())) { | ||
global.Object.defineProperty(global.MediaQueryList.prototype, "onchange", { | ||
enumerable: true, | ||
configurable: true, | ||
get: function () { | ||
return this._onchangeHandler || null; | ||
}, | ||
set: function (listener) { | ||
var _this = this; | ||
if (!_this._onchangeListener) { | ||
_this._onchangeListener = function () { | ||
if (typeof _this._onchangeHandler !== 'function') { | ||
return; | ||
} | ||
|
||
_this._onchangeHandler.call(_this, arguments[0]); | ||
}; | ||
|
||
_this.addEventListener('change', _this._onchangeListener); | ||
} | ||
|
||
_this._onchangeHandler = listener; | ||
} | ||
}); | ||
} | ||
}(self)); |
Oops, something went wrong.