Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Last active August 29, 2015 14:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomhodgins/d588a88931798a587356 to your computer and use it in GitHub Desktop.
Save tomhodgins/d588a88931798a587356 to your computer and use it in GitHub Desktop.
Self Executing JavaScript Widget (HTML + EQCSS): just place a link to this script in your HTML where you want the content to appear, like <script src="myWidget.js"></script>
(function() {
if (typeof EQCSS === 'undefined') {
var eq = document.createElement('script');
eq.src = 'http://elementqueries.com/EQCSS.js';
document.body.appendChild(eq);
};
var myWidget = document.createElement('section'),
widgetStyles = document.createElement('script'),
tag = document.querySelectorAll('[src*=\'myWidget\']')[0];
myWidget.innerHTML = '\
<!-- Add your HTML here, with line-breaks escaped by a "\" backslash character. -->\
<!-- (Don\'t forget: you can escape any character, like quotes, as well -->\
Hello\
';
widgetStyles.type = 'text/eqcss';
widgetStyles.innerHTML = '\
/* Add your EQCSS here, with line-breaks escaped by a "\" backslash character */\
@element "html" and (min-width: 0px) { html { background: #09f; } }\
';
function populateWidget(content) {
tag.parentNode.insertBefore(content, tag.nextSibling);
};
populateWidget(widgetStyles);
populateWidget(myWidget);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment