Skip to content

jQuery plugin for use with requirejs. Allows you to do $(selector).require([plugin], function() { $(this).plugin; }); With the advantage that it only loads the dependencies when at least one element is selected. Let's $(selector).require()!

License

Notifications You must be signed in to change notification settings

doedje/jquery.require

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

jquery.require

file: jquery.require.js version: 0.1.1

jQuery plugin for use with requirejs

This script is basically a wrapper for require.js

With the advantage that it will first check the length of $(selector) and only calls the requirejs function when this length > 0.

$(selector).require(['jquery.plugin'], function() {
	$(this).plugin(...);
});

Source:

require(['jquery',
		'require'],
function($,
		req) {
		// require is given back in the req variable,
		// this way the optimizer won't include it in a build and
		// the dependencies are loaded only when needed...
	$.fn.require = function(dependencies, callback) {
		var el = this;
		if (this.length > 0) {
			req(dependencies, function() {
				callback.apply(el, arguments);
			});
		}
		return this;
	};
});

Dependencies

Script Url
require.js http://www.requirejs.org

Authors

Remy Blom, The Netherlands remy.blom@kmt.hku.nl

Changelog

Version Changes
0.1.1 changed the variable giving back require the new name 'req'
0.1.0 first version of $.require

About

jQuery plugin for use with requirejs. Allows you to do $(selector).require([plugin], function() { $(this).plugin; }); With the advantage that it only loads the dependencies when at least one element is selected. Let's $(selector).require()!

Resources

License

Stars

Watchers

Forks

Packages

No packages published