Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.16 KB

README.md

File metadata and controls

44 lines (34 loc) · 1.16 KB

plug

A simple AMD loader plugin for loaders like RequireJS that makes it easier to set up plugins for libraries like jQuery.

This allows you to load additional plugin scripts that depend on a master library script before the loading of the master script is completed. In this way you can finish plugging the library before it is used.

Usage

plug only works with AMD loaders that support module config, like RequireJS 2.0.

First, set up a module config for plug and list out the plugins for your master library.

require.config({
	config: {
		plug: {
			"jquery": [ "jquery.ui", "jquery.validate" ]
		}
	}
});

In this example, the jQuery library will be plugged with both jQuery UI and a forms validation plugin.

Then, to load your master library along with all of its plugins, use the plug! loader prefix ID:

define(["plug!jquery"], function ( $ ) {
	// jQuery will have been plugged with jQuery UI and the validation
	// plugin by the time this function is called.
    
	$( "#popup-form" )
		.validate()
		.dialog();    
});