Created
July 25, 2012 17:04
-
-
Save twhid/3177280 to your computer and use it in GitHub Desktop.
elledecor/1stdibs cross-frame helper code
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
<!-- | |
* 1stdibs cross-domain iframe helper | |
* put this near the top of the page | |
--> | |
<script type="text/javascript"> | |
(function () { | |
// SET DOCUMENT.DOMAIN FOR CROSS-FRAME COMMUNICATION | |
var domain = document.location.hostname.split('.'); | |
document.domain = domain[domain.length-2] + '.' + domain[domain.length-1]; | |
}()); | |
</script> | |
<!-- | |
* 1stdibs iframe navigation helper | |
* load after jQuery | |
--> | |
<script type="text/javascript"> | |
jQuery(function ($) { | |
// NAVIGATE DIBS IFRAME | |
var dibsSubDomain = '1stdibs.lookbook.', | |
search = document.location.search, | |
path = search.charAt(0) === '?' ? search.slice(1, search.length) : search, | |
loc = document.location.protocol + '//' + dibsSubDomain + document.domain + '/' + decodeURIComponent(path), | |
dibsFrameElem = $("#dibsElledecorIframe").get(0); | |
// load dibs URL in dibs iframe | |
dibsFrameElem.src = loc; | |
// SUPPORT 1STDIBS KEYBOARD NAVIGATION | |
var dibsFrameDoc = window.frames['dibs'], | |
keyMap = { | |
'13': 'RETURN', | |
'37': 'LEFT', | |
'38': 'RIGHT', | |
'39': 'RIGHT', | |
'40': 'DOWN' | |
}; | |
$('body').keydown(function (e) { | |
if (dibsFrameDoc.HotKey && dibsFrameDoc.HotKey.hotkeys) { | |
var hotkeyInstance = dibsFrameDoc.HotKey.hotkeys.find(function (hotkey) { | |
return hotkey.letter === keyMap[e.which.toString()]; | |
}); | |
if (hotkeyInstance && hotkeyInstance.trigger) { | |
hotkeyInstance.trigger(); | |
} | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment