Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Requirejs loading plugins

I'm trying to load a plugin using requirejs but occasionally get an error, "$.fn is undefined" but if I reload the page the error disappears almost like now jquery is cached the problem is removed. I'm loading my libraries like this:

require(["jquery-1.4", "/script/jquery.autoSuggest.packed.js"], function($) {
   $(function() {
       //code
    });
});

Can you see if there is anything wrong with this implementation that would cause this error? Require js is being added to the page as so:

<script type="text/javascript" src="http://website.co.uk/frameworks/requirejs/0.2.4/sharedmodules/require.js">
</script> 
<script type="text/javascript">  requireMap = {
     "jquery-1.4":"http://website.co.uk/sharedmodules/jquery-1.4"
}; 

    require({ baseUrl: 'http://website.co.uk/', paths: requireMap });      
</script>

This can't be changed as it's part of the framework I'm using.

Any suggestions?

Thanks!

like image 283
FlimFlam Avatar asked Mar 17 '11 11:03

FlimFlam


1 Answers

order plugin is removed. use shim loading as follows

requirejs.config({
   paths: {
        'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min',
        'bootstrap': '../bootstrap/js/bootstrap.min',
        'select2': 'vendor/select2',
        'jshashtable': 'vendor/jshashtable-2.1',
        'jquery.numberformatter': 'vendor/jquery.numberformatter-1.2.3.min',
        'jq-datepicker': 'vendor/bootstrap-datepicker',
        'jq-datepicker.da': 'vendor/bootstrap-datepicker.da'
    }, 

    // Use shim for plugins that does not support AMD
    shim: {
        'bootstrap': ['jquery'],
        'select2': ['jquery'],
        'jq-datepicker': ['jquery'],
        'jshashtable': ['jquery'],
        'jquery.numberformatter': ['jquery', 'jshashtable']
    },

});

reference : http://requirejs.org/docs/api.html#config-shim

like image 116
kongaraju Avatar answered Oct 23 '22 02:10

kongaraju