<% if params[:embed] %> Widget = (function() { var iFrame; var initialContent; var iFrameDoc; function htmlLayout() { return '<%= escape_javascript(< #{stylesheet_link_tag 'YOUR STYLESHEETS HERE', :cache => 'widget'} #{javascript_include_tag 'jquery', 'YOUR JAVASCRIPT LIBRARIES HERE', 'widget_support', :cache => 'widget'}
EOHTML %>'; } function locateIFrameDoc() { var doc; if ( iFrame.contentDocument ) { doc = iFrame.contentDocument; } else if ( iFrame.contentWindow ) { doc = iFrame.contentWindow.document; } else { doc = window.frames[iFrame.name].document; } return doc; } function createIFrame() { var canvas = document.getElementById('widget_canvas'); iFrame = document.createElement('iframe'); iFrame.name = iFrame.id = 'widget_iframe'; iFrame.frameBorder = '0'; iFrame.scrolling = 'no'; iFrame.width = '700'; canvas.style.width = '700px'; canvas.appendChild(iFrame); iFrame.onload = insertInitialContent; iFrameDoc = locateIFrameDoc(); } function populateIFrame() { iFrameDoc.write(htmlLayout()); iFrameDoc.close(); initialContent = '<%= escape_javascript(yield) %>'; } function replaceContent(content) { if ( iFrame.contentWindow.replaceIFrameContent ) { iFrame.contentWindow.replaceIFrameContent(content); } resizeIFrame(); } function insertInitialContent() { if ( initialContent ) { replaceContent(initialContent); initialContent = null; } } function resizeIFrame() { iFrame.height = iFrameDoc.body.scrollHeight; } function replaceContentWithScript(scriptHref) { var scriptTag = document.createElement('script'); scriptTag.type = 'text/javascript'; scriptTag.src = scriptHref; document.body.appendChild(scriptTag); } function init() { createIFrame(); populateIFrame(); stylePoweredByLink(); } init(); return { replaceContent: replaceContent, replaceContentWithScript: replaceContentWithScript }; })(); <% else %> Widget.replaceContent('<%= escape_javascript(yield) %>'); <% end %>