Skip to content

Instantly share code, notes, and snippets.

@hcliff
Created September 21, 2012 19:36
Show Gist options
  • Save hcliff/3763439 to your computer and use it in GitHub Desktop.
Save hcliff/3763439 to your computer and use it in GitHub Desktop.
( ($, window)->
# Store the actual iframe
frame = null
# When the iframe sends us a message
receiveMessage = (event)->
data = JSON.parse event.data
# The iframe says that it needs to expand
if data.fragment is 'resize'
resize data.height
# when the iframes content changes size, reshape the iframe to match it
resize = (height)->
$('#spling-iframe').height height.iframe-10
$('#spling-widget').height height.placeholder
# When the user has reached the bottom of the feed.
# > Account for the fact the widget may not be at the
# bottom of the page
scrolling = (e)->
iframeBottom = $('#spling-iframe').offset().top + $('#spling-iframe').height()
scrollPosition = $(document).scrollTop()+$(window).height()
if scrollPosition >= iframeBottom
$('#spling-iframe').get(0).contentWindow.postMessage 'scrolling', '*'
$ ->
# Listen for events from spling.com
listen = window.addEventListener || window.attachEvent
listen 'message', receiveMessage, false
$(window).scroll scrolling
# Build the iframe
frame = $('<iframe id="spling-iframe" allowTransparency="true" frameBorder="0">')
# If explicitly told where to put the board use it
# otherwise put it before the script tags
unless window.SPLING_BEFORE_ELEMENT
window.SPLING_BEFORE_ELEMENT = 'spling-script'
placeholder.insertBefore $('#'+window.SPLING_BEFORE_ELEMENT)
frame.css
'overflow' : 'hidden'
'border' : 'none'
'z-index' : '1'
'position' : 'absolute'
'width' : '960px'
'height' : '660px'
placeholder.append(frame)
frame.attr 'src', window.SPLING_URL
)(jQuery, window)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment