Last active
April 12, 2017 00:03
-
-
Save vanpelt/e70458f4de8af1833c1d1b7bafff40a1 to your computer and use it in GitHub Desktop.
Using require.js in CrowdFlower Jobs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//The test question interface doesn't have require.js, this mimics minimal functionality | |
var require = window.require || function() { | |
var args = Array.prototype.slice.call(arguments); | |
var opts_or_list = args.shift(), opts, list | |
if(Array.isArray(opts_or_list)) { | |
opts = {}, list = opts_or_list | |
} else { | |
list = args.shift(), opts = opts_or_list | |
} | |
var libraries = ['//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js'] | |
if(opts.paths) { | |
libraries = libraries.concat(Object.values(opts.paths).map(function(url) { | |
return url.replace(/\.js$/, "") + ".js" | |
})) | |
} | |
var callback = args.shift() | |
function load(url) { | |
Asset.javascript(url, { | |
onLoad: function(){ | |
libraries.length === 0 ? callback(null,null,null) : load(libraries.pop()); | |
} | |
}) | |
} | |
load(libraries.pop()) | |
} | |
require({paths: { leaflet: "https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet"}}, | |
['jquery-noconflict','bootstrap-popover'], function() { | |
var $ = window.jQuery; | |
//Custom code goes here, $ is now jQuery | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment