Hello i need to build a 3rd Party Widgets with JavaScript and php. This Widgets will need to use in jQuery and jQuery UI and maybe in the future other jQuery Libraries and Plugins. so when my client put this Widget to his site i need to know if jQuery and jQuery UI is already loaded and if not load it my self. I built something but it not working.
<script>
if (typeof jQuery == 'undefined') {
// jQuery is not loaded
//alert('jQuery is not loaded');
var script = document.createElement('script');
script.type = "text/javascript";
script.src = "http://code.jquery.com/jquery-1.9.1.js";
document.getElementsByTagName('head')[0].appendChild(script);
var script_ui = document.createElement('script');
script_ui.type = "text/javascript";
script_ui.src = "http://code.jquery.com/ui/1.10.3/jquery-ui.js";
document.getElementsByTagName('head')[0].appendChild(script_ui);
} else {
// jQuery is loaded
//alert('jQuery is loaded');
if (typeof jQuery.ui !== 'undefined') {
// ui plugin exists
alert('ui plugin exists');
} else {
// ui plugin DOES NOT exist
//alert('ui plugin DOES NOT exist');
var script_ui = document.createElement('script');
script_ui.type = "text/javascript";
script_ui.src = "http://code.jquery.com/ui/1.10.3/jquery-ui.js";
document.getElementsByTagName('head')[0].appendChild(script_ui);
}
}
</script>
This working fine but when i try to work with jQuery datepicker i get ReferenceError: jQuery is not defined.
<script>
jQuery(document).ready(function() {
// Handler for .ready() called.
jQuery(function() {
jQuery( "#datepicker" ).datepicker();
});
});
</script>
Even without the jQuery(document).ready(function() It does not work
Please Hellp...