Permalink
Browse files

Add a getHref method to look for the attribute

This allows the overlay trigger to be something other than an <a> tag
  • Loading branch information...
1 parent afe23ed commit 4cd44a92fafadfed8ebef83a514ebda941815bcd @bryanjswift committed Mar 19, 2013
Showing with 8 additions and 4 deletions.
  1. +8 −4 js/modules/overlay.js
View
@@ -5,8 +5,8 @@
* license MIT
*/
define(
- ['underscore', 'modules/addEvent', 'modules/clazz', 'modules/addScript'],
- function(_, addEvent, clazz, addScript) {
+ ['underscore', 'modules/addEvent', 'modules/clazz', 'modules/data-attrs', 'modules/addScript'],
+ function(_, addEvent, clazz, data, addScript) {
window.onYouTubeIframeAPIReady = apiCallbackYoutube;
addScript("youtube-api", "//www.youtube.com/iframe_api");
@@ -64,7 +64,7 @@ define(
e.returnValue = false;
closeOverlay(e, true);
- var id = (a.href || a.getAttribute('href')).replace(/^.*#(.*)$/, '$1');
+ var id = getHref(a).replace(/^.*#(.*)$/, '$1');
clazz.add(document.getElementById(id), 'overlay-visible');
clazz.add(backdrop, 'backdrop-visible');
addEvent(window, 'keyup', overlayKeypress);
@@ -85,7 +85,7 @@ define(
}
function initOverlay(a) {
- var id = a.href.replace(/^.*#(.*)$/, '$1');
+ var id = getHref(a).replace(/^.*#(.*)$/, '$1');
if (!id) { return; }
var overlay = document.getElementById(id);
document.body.appendChild(overlay);
@@ -94,6 +94,10 @@ define(
addEvent(a, 'click', _.bind(triggerOverlay, this, a));
}
+ function getHref(a) {
+ return a.href || a.getAttribute('href') || data.get(a, 'href');
+ }
+
return {
initAll: initAllOverlays,
init: initOverlay

0 comments on commit 4cd44a9

Please sign in to comment.