JSFiddle - React, Tailwind, and code Playground
HTML
<h3>Demo instructions:</h3>
<ol>
<li>Checkout an example of the widget:<br/>
<div class="page">
<h2></h2>
<div class="my-widget">
<input type="text" value="my widget - for any website!"/>
<button><span>Join</span><br/><strong>Today</strong></button>
<style>
.my-widget {
background : #EFEFEF;
border : 1px solid #0c0c0c;
color : #0D0D0D;
font-family : "Palatino Linotype", "Book Antiqua", Palatino, serif;
padding : 20px;
min-width : 300px;
max-width : 600px;
}
.my-widget > * {
padding : 10px;
}
.my-widget input {
width : 70%;
font-size : 1.7em;
}
.my-widget button {
background : #ff0066;
border : none;
color : $ffffff;
float : right;
width : 20%;
}
</style>
</div>
</div>
</li>
<li class="second"><a href="#" class="expectations">Click here</a> to see how should it look on the page.</li>
<li><a href="#" class="reality">Click here</a> to see what you can get in our reality.</li>
<li class="last"><button id="IFRAMEr">Activate IFRAMEr</button> and check how it looks now.</li>
</ol>
CSS
.page.expectations { /* nothing affects widget's design */ }
.page.reality {
background : yellow;
color : red;
font-family : "Comic Sans MS", cursive, sans-serif;
font-size : 20px;
padding : 0 5%;
}
.page.reality * > * {
transform : rotate(7deg);
font-size : 0.7em;
}
.page.reality * > *:first-child + *{
position : relative;
right : 50%;
transform : rotate(-7deg);
}
li, #IFRAMEr { padding: 5px; }
li:nth-child(1), li:nth-child(4) { padding: 10px; }
.page.reality, .page.expectations { border : 1px solid black; margin: 10px 0; padding: 10px; }
JavaScript
$('ol a').click(function(){
$('.page h2').text('"'+this.className+'" page:');
$('.page').get(0).className = 'page '+this.className;
});
$('#IFRAMEr').click(function (){
var $widget = $('.my-widget');
var $template = $('<script>').attr('type','widget/html');
$template
.text( $widget.get(0).outerHTML )
.insertAfter($widget);
$widget.hide();
$(this).hide();
(function iframer( scripts, tasks ){
for( var i=0; i<scripts.length; i++){
var script = scripts[i];
if( script.type == 'widget/html' ) {
var parent = script.parentNode || document;
var next = script.nextElementSibling || script.nextSibling;
var iframe = document.createElement( 'iframe' );
var iscript = (next.type == 'widget/javascript') ? ('<'+'script>' + next.innerHTML + '</'+'script>') : '';
var ihtml = script.innerHTML + iscript;
iframe.width = '0';
iframe.height = '0';
parent.insertBefore( iframe, script );
parent.removeChild( script );
if(iscript) parent.removeChild( next );
var iwindow = iframe.contentWindow;
var idocument = iframe.contentDocument || iwindow.document;
idocument.open();
for( var taskName in tasks ){
try {
tasks[taskName]( iframe, iwindow, idocument );
} catch( error ) {
if( window.console && console.log ) {
console.log( 'iframit task exception', taskName, script.name, error.message );
}
}
}
idocument['wri'+'te']( ihtml );
}
}
})(document.getElementsByTagName( 'script' ),
{
resizeToFitContainer : function(iframe, iwindow, idocument){
iframe.style['background'] = 'transparent';
...