Skip to content

Instantly share code, notes, and snippets.

@gcpantazis
Last active December 16, 2015 14:09
Show Gist options
  • Save gcpantazis/5447085 to your computer and use it in GitHub Desktop.
Save gcpantazis/5447085 to your computer and use it in GitHub Desktop.
Exposing jQuery plugins via require, instead of accessing them via the jQuery global object.
// Returning the jQuery plugin at the end of its requirejs module.
return function( $elem, options ) {
return $elem.someJQueryPlugin.apply($elem, Array.prototype.slice.call( arguments, 1 ));
};
// Instead of this:
$foo.someJQueryPlugin({'bar': true});
// More like this:
var thePlugin = require('path/to/plugins/someJQueryPlugin')
thePlugin($foo, {'bar': true});
// Aside from letting you use jQuery plugins in an AMD/DI setting, also optimizes your minification:
a(b,{'bar':true});
// instead of
b.someJQueryPlugin({'bar':true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment