Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The module ID of the custom JS file is 'configbox/custom/custom'. Use this typical structure to make the custom.js an AMD module:

Code Block
languagejsphp
define(['cbj'], function($) {
	// return an object if you have a use for it in other modules.
	// In the example we require jQuery, you'll have it as $ in your module. See below for more info on jQuery and plugins.
});

...

This sample is your custom.js file. Assume you have a module file called module1.js in your customisation directory already.

Code Block
languagephp
define(['configbox/custom/module1'], function(module1) {
	
});

Here, the same, requiring both jQuery and module1

Code Block
define(['cbj', 'configbox/custom/module1'], function($, module1) {
	
});

Here - going a step further - you require both modules and also require another module (module2) during runtimeĀ 

Code Block
define(['cbj', 'configbox/custom/module1'], function($, module1) {

	cbrequire(['configbox/custom/module2'], function(module2) {
		..
	});

});

What is cbrequire? cbrequire is require.js' require function using ConfigBox' configuration, with mappings and various settings made. Always use it instead of require()

...

We use jQuery 3 and upgrade jQuery regularly. We made strict isolation of 'our' jQuery from any jQuery library loaded in your CMS. Our jQuery does not write itself to the global scope and defines itself anonymously. To get a reference to jQuery, use this code

Code Block
languagephp
cbrequire(['cbj'], function($) {
	// Do stuff with $
});

Using jQuery plugins

Bundled plugins and their module IDs

...

When you add a jQuery plugin to the customisation folder, wrap the plugin code with this:

Code Block
define(['cbj'], function(jQuery) {
	// Plugin code
});

Sounds concerning, but it works reliably. Modifying standard plugins isn't great, but the benefits are - plus the modification is straight-forward. See how it's done in other jQuery plugins in the app folder at /assets/kenedo/external/jquery.*

Get jQuery with your plugin like this:

Code Block
cbrequire(['configbox/custom/yourPlugin'], function($) {
	// $ gives you CB's jQuery with yourPlugin added to the fn list
});