Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IFRAME support for links outside the document Origin #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/facebox.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@
// ajax: anything else
function fillFaceboxFromHref(href, klass) {
// div
if (href.match(/#/)) {
if (href.match(/^#/)) {
var url = window.location.href.split('#')[0]
var target = href.replace(url,'')
if (target == '#') return
Expand All @@ -245,9 +245,17 @@
// image
} else if (href.match($.facebox.settings.imageTypesRegexp)) {
fillFaceboxFromImage(href, klass)
// ajax
// iframe / ajax
} else {
fillFaceboxFromAjax(href, klass)
var host = href.match(/^(?:ht|f)tps?:\/\/([^\/]+)/);

if (host)
host = host[1];

if (!host || host == document.location.host)
fillFaceboxFromAjax(href, klass);
else
fillFaceboxFromIframe(href, klass);
}
}

Expand All @@ -263,6 +271,29 @@
$.facebox.jqxhr = $.get(href, function(data) { $.facebox.reveal(data, klass) })
}

function fillFaceboxFromIframe(href, klass) {
var doc = $(document), width, height;
try {
width = doc.innerWidth();
height = doc.innerHeight();
} catch(e) {
width = doc.width();
height = doc.height();
}

var iframe = $('<iframe/>', {
'src' : href,
'width' : Math.floor(width / 4 * 3),
'height' : Math.floor(height / 5 * 3),
'frameborder' : 0,
'marginheight' : 0,
'marginwidth' : 0,
'allowtransparency': true,
});

$.facebox.reveal(iframe, klass);
}

function skipOverlay() {
return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
}
Expand Down