Skip to content

Instantly share code, notes, and snippets.

@christabor
Created February 14, 2014 22:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christabor/9011010 to your computer and use it in GitHub Desktop.
Save christabor/9011010 to your computer and use it in GitHub Desktop.
<a href="#" data-load-css="wtf.css" data-load-fn="wtfFn">Some module link</a>
<form action="">
<button data-load-css="wtf2.css" data-load-fn="wtf2Fn">Yeah buddy</button>
</form>
var moduleFuncs = {
wtfFn: function() {},
wtf2Fn: function() {}
};
$('[data-load-css]').on('click.load-modules', loadModule);
function loadModule(event) {
event.preventDefault();
var url = $(this).data('load-css');
var callback = $(this).data('load-fn');
var urlpromise = $.ajax(url);
$.when(urlpromise).then(moduleFuncs[callback]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment