Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jquery ui with requirejs

I want to use jQuery UI's addClass function in my application.

Beside I am using the normal jQuery, underscore, backbone all tiered together with requirejs.

I have configured jQuery UI like this:

require.config({      deps: ["main"],      paths: {         "text": "lib/text"         , "jquery": "lib/jquery"         , "jquery-ui": "lib/jquery-ui"         , "underscore": "lib/underscore"         , "backbone": "lib/backbone"         , "bootstrap": "lib/bootstrap"         , "templates": "../templates"     },      shim: {         "jquery-ui": {             exports: "$",             deps: ['jquery']         },         "underscore": {             exports: "_"         },         "backbone": {             exports: "Backbone",             deps: ["underscore", "jquery"]         },         "bootstrap": ['jquery']     }  }); 

In the application I do:

define(['jquery', 'underscore', 'backbone'], function($, _, Backbone) {     $('div').addClass('white'); }); 

Unfortunately this only does the normal addClass not the animated one from jQuery UI.

PS: I use the full jQuery edition.

like image 392
bodokaiser Avatar asked Aug 24 '12 16:08

bodokaiser


People also ask

What is jQuery UI library?

jQuery UI is a curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library. Whether you're building highly interactive web applications, or you just need to add a date picker to a form control, jQuery UI is a perfect choice.

Does jQuery have dependencies?

jQuery is a roughly 30 KiB dependency that nearly 84% of mobile pages used in 2021—and for good reason.


1 Answers

You need to include jquery-ui:

define(['jquery-ui', 'backbone'], function() {     $('div').addClass('white'); }); 

jquery should be required automatically as it is a dependency of jquery-ui

Additionally, none of these scripts return anything, but their variables are assigned to the window object. No need to assign them.

like image 148
Austin Avatar answered Oct 15 '22 01:10

Austin