InterMine JavaScript API Loader
Note See also GitHub repo for source code.
Note If you are loading JavaScript libraries on a page, you should use a loader (count of 1). Why not use ours?
Purpose#
To simplify loading of CSS and JS libraries. The API Loader automatically works out the order the libraries should be loaded based on dependencies between them. It also skips libraries that already exist on a page or that pass a specific check.
How to use#
Note If you are passing a string or an array as the first parameter into the library, these are @deprecated but still working for backwards compatibility.
First you require the API Loader. You can, for example, use the following shorthand notation that always points to the latest version.
Now, you can use the loader by passing in an object that looks for example like so:
The object works like so:
- You pass in either a
jsor acssobject based on whether you are requesting JavaScript or CSS libraries (or both). - The key inside the object, like
jQuerythen refers to your library. If this key is on awindowobject (as is the case with jQuery library), we won't load the library since it already exists. - If you do not like the previous check and want something more robust, pass a sync function under the
testkey. Returntrueif a library should NOT be loaded. pathrepresents the URL pointing to the library.- Use
dependskey, passing an array if a library depends on other libraries in your list. In the example, you can see thatBackbonedepends onjQueryand_(underscore.js). The appropriate loading order will be worked out from this. - Check the
errvariable passed in the callback function (second parameter).