0

I previously asked this question, and got one plug-in to work. Now, I'm trying to get another plug-in to work using the solution for the first plug-in, but that solution isn't working.

I'm trying to get this plug-in to work, but the chrome console spits out this error:

Uncaught ReferenceError: jQuery is not defined :3000/js/libs/textarea_auto_expand.js:41

My code is this:

require.config({
    paths: {
      jquery: '/js/libs/jquery/jquery-2.0.3',
     underscore: '/js/libs/underscore/underscore-min',
     backbone: '/js/libs/backbone/backbone-min',
  //text: '/js/libs/text'
 templates: '../templates'
 ,sockets: '/socket.io/socket.io' 
 ,rangyInputs: '/js/libs/rangyinputs-jquery-1.1.2'
 , textareaAutoExpand: 'js/libs/textarea_auto_expand'

},
shim: {
  'Backbone': ['Underscore', 'jQuery'],
  'sockets': {exports: 'io'}, 
  'rangyinputs-jquery': {deps: ['jquery'], exports: '$'}, 
  'textarea_auto_expand': {deps: ['jquery'], exports: '$'}

} 
});

  require(['jquery', 'router', 'libs/a_myLib/keydownHandler', 'libs/textarea_auto_expand' ], 
function($, router, keydownHandler, ta_ae){
$("body").on("keydown", "textarea", keydownHandler);
router.initialize();
$("textarea").textareaAutoExpand();
})

1 Answer 1

0

The problem is that, you used path name jquery, but specified jQuery in you Backbones deps:

'Backbone': ['Underscore', 'jQuery'],

Again, here is working example of main.js

index.html

<!doctype html>
<html>
    <head></head>
    <body>
        <script data-main="main" src="require.js"></script>
    </body>
</html>

main.js

require.config({
    paths : {
        jquery : 'jquery-2.0.3',
        'rangyinputs-jquery' : 'rangyinputs-jquery-1.1.2',
        textareaAutoExpand: 'js/libs/textarea_auto_expand'
    },
    shim : {
        'rangyinputs-jquery' : {deps : ['jquery'], exports : '$'},
        'textarea_auto_expand': {deps: ['jquery'], exports: '$'}
    }
});


require(['jquery', 'rangyinputs-jquery', 'textarea_auto_expand'], function($) {
    console.log('Type of $.fn.textareaAutoExpand ' + typeof $.fn.textareaAutoExpand );
    var t = $('<textarea/>').textareaAutoExpand();
    $('body').append(t);
});
3
  • Thanks! This gets rid of the console error, but the text-areas aren't actually expanding.
    – curtissv
    Jan 5, 2014 at 19:57
  • Updated example. They do expand in this case. Jan 5, 2014 at 20:01
  • It doesn't work for me. I thought it might be because the textareas I was using were dynamically added, so I tried directly adding one to the HTML. No Luck. I think I'm just going to switch to browserify, since this is a really small project that doesn't need to be too performant.
    – curtissv
    Jan 5, 2014 at 20:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.