Skip to content
This repository has been archived by the owner on Oct 22, 2019. It is now read-only.

Commit

Permalink
Add a getHref method to look for the attribute
Browse files Browse the repository at this point in the history
This allows the overlay trigger to be something other than an <a> tag
  • Loading branch information
bryanjswift committed Mar 19, 2013
1 parent afe23ed commit 4cd44a9
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions js/modules/overlay.js
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 4cd44a9

Please sign in to comment.