Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use the domEvents module

Instead of the addEvent module and an inline removeEvent function.
  • Loading branch information...
commit 831d4e125ffd430cb225af7995c955e59c7b2cba 1 parent 4cd44a9
Bryan J Swift authored
Showing with 9 additions and 19 deletions.
  1. +9 −19 js/modules/overlay.js
28 js/modules/overlay.js
View
@@ -5,8 +5,8 @@
* license MIT
*/
define(
- ['underscore', 'modules/addEvent', 'modules/clazz', 'modules/data-attrs', 'modules/addScript'],
- function(_, addEvent, clazz, data, addScript) {
+ ['underscore', 'modules/domEvents', 'modules/clazz', 'modules/data-attrs', 'modules/addScript'],
+ function(_, evt, clazz, data, addScript) {
window.onYouTubeIframeAPIReady = apiCallbackYoutube;
addScript("youtube-api", "//www.youtube.com/iframe_api");
@@ -16,7 +16,7 @@ define(
var de = document.documentElement;
var backdrop = document.querySelector('.overlay-backdrop');
resize();
- addEvent(backdrop, 'click', closeOverlay);
+ evt.on(backdrop, 'click', closeOverlay);
function apiCallbackYoutube() {
_.each(document.querySelectorAll('.youtube'), function(frame) {
@@ -24,16 +24,6 @@ define(
});
}
- function removeEvent(node, name, handler) {
- if (node && node.removeEventListener) {
- node.removeEventListener(name, handler);
- } else if (node && node.attachEvent) {
- node.detachEvent('on' + name, handler);
- } else if (console && console.warn) {
- console.warn('no way to remove event from', node, name);
- }
- }
-
function resize(e) {
backdrop.setAttribute('style', 'height: ' + de.clientHeight + 'px; width: ' + de.clientWidth + 'px;');
}
@@ -55,8 +45,8 @@ define(
clazz.remove(overlay, 'overlay-visible');
});
- removeEvent(window, 'keyup', overlayKeypress);
- removeEvent(window, 'resize', resize);
+ evt.off(window, 'keyup', overlayKeypress);
+ evt.off(window, 'resize', resize);
}
function triggerOverlay(a, e) {
@@ -67,8 +57,8 @@ define(
var id = getHref(a).replace(/^.*#(.*)$/, '$1');
clazz.add(document.getElementById(id), 'overlay-visible');
clazz.add(backdrop, 'backdrop-visible');
- addEvent(window, 'keyup', overlayKeypress);
- addEvent(window, 'resize', resize);
+ evt.on(window, 'keyup', overlayKeypress);
+ evt.on(window, 'resize', resize);
}
function initAllOverlays() {
@@ -90,8 +80,8 @@ define(
var overlay = document.getElementById(id);
document.body.appendChild(overlay);
var close = overlay.querySelector('.overlay-close');
- addEvent(close, 'click', closeOverlay);
- addEvent(a, 'click', _.bind(triggerOverlay, this, a));
+ evt.on(close, 'click', closeOverlay);
+ evt.on(a, 'click', _.bind(triggerOverlay, this, a));
}
function getHref(a) {
Please sign in to comment.
Something went wrong with that request. Please try again.