Skip to content

Instantly share code, notes, and snippets.

@alfg
Last active November 20, 2019 01:20
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save alfg/7935982 to your computer and use it in GitHub Desktop.
Save alfg/7935982 to your computer and use it in GitHub Desktop.
Bootstrap files for creating embedded widgets for your site
<html>
<head>
<title>Sample Widget Page</title>
</head>
<body>
<h1>Sample Widget Page</h1>
<script type="text/javascript" src="http://localhost:81/widget-bootstrap.js"></script>
<div id="widget-container"></div>
</body>
</html>
(function () {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.8.2') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("src",
"http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function ($) {
var baseURL = "http://localhost:81/content/widgets/";
/******* Load CSS *******/
var css_link = $("<link>", {
rel: "stylesheet",
type: "text/css",
href: baseURL + "widget.css"
});
css_link.appendTo('head');
alert('testing');
/******* Load HTML *******/
});
}
})(); // We call our anonymous function immediately
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment