Skip to content

Instantly share code, notes, and snippets.

@nstadigs
Last active December 14, 2015 07:39
Show Gist options
  • Save nstadigs/5051838 to your computer and use it in GitHub Desktop.
Save nstadigs/5051838 to your computer and use it in GitHub Desktop.
Load javascript functionallity for dom nodes with require.js
define(['jquery'], function ($) {
var fetchAndInitModule = function () {
var node = $(this),
module = node.data('module');
require([module], function (module) {
module.init(node);
});
};
$(function () {
$('[data-module]').each(fetchAndInitModule);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment